Stub mode missing executeWorkStreaming override — streaming path calls real Anthropic client #14

Closed
opened 2026-03-18 22:21:13 +00:00 by replit · 1 comment
Owner

Context

In lib/agent.ts, AgentService.executeWorkStreaming() was added as the streaming variant of executeWork(). However, stub mode (when LNBITS_URL/LNBITS_API_KEY are absent) only stubs the LNbits service — it does NOT stub the agent service. The agent service always calls the real Anthropic SDK.

This is fine for executeWork() because stub mode auto-pays invoices so the work phase only runs in tests that have a real API key. But executeWorkStreaming() is now called unconditionally in runWorkInBackground(). If someone runs Timmy in stub mode without an Anthropic key, the streaming path will throw "AI_INTEGRATIONS_ANTHROPIC_API_KEY must be set" on startup or on first job execution, rather than returning a canned response.

Root Cause

artifacts/api-server/src/lib/agent.tsAgentService has no stub/mock implementation. The class is instantiated directly with no injection point.

Requirements

  1. Refactor AgentService to support dependency injection or an override constructor flag for stub mode
  2. In stub mode (detected via process.env.AGENT_STUB === "1" or absence of AI_INTEGRATIONS_ANTHROPIC_API_KEY), executeWork() and executeWorkStreaming() should return a canned response without calling Anthropic
  3. executeWorkStreaming() stub should call onChunk() with the canned text in small increments (simulating streaming) so the SSE path behaves end-to-end
  4. Log [AgentService] No Anthropic key — running in STUB mode on startup, consistent with existing stub log format

Acceptance Criteria

  • Starting the server without AI_INTEGRATIONS_ANTHROPIC_API_KEY does not throw on startup
  • A job run in stub mode (no Anthropic key) completes with a canned result instead of crashing
  • The SSE stream endpoint (GET /api/jobs/:id/stream) emits token events when running in stub mode
  • Stub mode is logged at startup: [AgentService] No Anthropic key — running in STUB mode
  • When AI_INTEGRATIONS_ANTHROPIC_API_KEY is present, the real client is used (no regression)

Files

  • artifacts/api-server/src/lib/agent.ts
## Context In `lib/agent.ts`, `AgentService.executeWorkStreaming()` was added as the streaming variant of `executeWork()`. However, stub mode (when `LNBITS_URL`/`LNBITS_API_KEY` are absent) only stubs the LNbits service — it does NOT stub the agent service. The agent service always calls the real Anthropic SDK. This is fine for `executeWork()` because stub mode auto-pays invoices so the work phase only runs in tests that have a real API key. But `executeWorkStreaming()` is now called unconditionally in `runWorkInBackground()`. If someone runs Timmy in stub mode without an Anthropic key, the streaming path will throw `"AI_INTEGRATIONS_ANTHROPIC_API_KEY must be set"` on startup or on first job execution, rather than returning a canned response. ## Root Cause `artifacts/api-server/src/lib/agent.ts` — `AgentService` has no stub/mock implementation. The class is instantiated directly with no injection point. ## Requirements 1. Refactor `AgentService` to support dependency injection or an override constructor flag for stub mode 2. In stub mode (detected via `process.env.AGENT_STUB === "1"` or absence of `AI_INTEGRATIONS_ANTHROPIC_API_KEY`), `executeWork()` and `executeWorkStreaming()` should return a canned response without calling Anthropic 3. `executeWorkStreaming()` stub should call `onChunk()` with the canned text in small increments (simulating streaming) so the SSE path behaves end-to-end 4. Log `[AgentService] No Anthropic key — running in STUB mode` on startup, consistent with existing stub log format ## Acceptance Criteria - [ ] Starting the server without `AI_INTEGRATIONS_ANTHROPIC_API_KEY` does not throw on startup - [ ] A job run in stub mode (no Anthropic key) completes with a canned result instead of crashing - [ ] The SSE stream endpoint (`GET /api/jobs/:id/stream`) emits token events when running in stub mode - [ ] Stub mode is logged at startup: `[AgentService] No Anthropic key — running in STUB mode` - [ ] When `AI_INTEGRATIONS_ANTHROPIC_API_KEY` is present, the real client is used (no regression) ## Files - `artifacts/api-server/src/lib/agent.ts`
Author
Owner

Resolved — executeWorkStreaming stub override added in agent.ts (task #3 work)

✅ **Resolved** — executeWorkStreaming stub override added in agent.ts (task #3 work)
This repo is archived. You cannot comment on issues.