Stub mode missing executeWorkStreaming override — streaming path calls real Anthropic client #14
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
In
lib/agent.ts,AgentService.executeWorkStreaming()was added as the streaming variant ofexecuteWork(). However, stub mode (whenLNBITS_URL/LNBITS_API_KEYare 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. ButexecuteWorkStreaming()is now called unconditionally inrunWorkInBackground(). 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—AgentServicehas no stub/mock implementation. The class is instantiated directly with no injection point.Requirements
AgentServiceto support dependency injection or an override constructor flag for stub modeprocess.env.AGENT_STUB === "1"or absence ofAI_INTEGRATIONS_ANTHROPIC_API_KEY),executeWork()andexecuteWorkStreaming()should return a canned response without calling AnthropicexecuteWorkStreaming()stub should callonChunk()with the canned text in small increments (simulating streaming) so the SSE path behaves end-to-end[AgentService] No Anthropic key — running in STUB modeon startup, consistent with existing stub log formatAcceptance Criteria
AI_INTEGRATIONS_ANTHROPIC_API_KEYdoes not throw on startupGET /api/jobs/:id/stream) emits token events when running in stub mode[AgentService] No Anthropic key — running in STUB modeAI_INTEGRATIONS_ANTHROPIC_API_KEYis present, the real client is used (no regression)Files
artifacts/api-server/src/lib/agent.ts✅ Resolved — executeWorkStreaming stub override added in agent.ts (task #3 work)