Summary
When a spawned subagent completes and the announce flow attempts to deliver to the requester, it fails with:
Delivery failed (whatsapp to +64273938855): Error: No active WhatsApp Web listener (account: default)
The delivery tries to use the default account instead of the correct account (e.g., kev) because accountId is not propagated through the subagent spawn → announce → delivery chain.
Root Cause
The sessions_spawn tool captures agentChannel (e.g., "whatsapp") but not agentAccountId. When the announce flow later calls callGateway({ method: "agent", deliver: true }), it has no way to specify which account to use for delivery.
The delivery code in delivery.ts tries to get accountId from sessionEntry?.lastAccountId, but when the announce triggers a fresh agent run, the session entry lookup may not have the right account context.
Fix
Thread accountId through the entire subagent lifecycle:
sessions-spawn-tool.ts: Accept agentAccountId in tool options, pass to registerSubagentRun()
subagent-registry.ts: Store requesterAccountId in SubagentRunRecord, pass to runSubagentAnnounceFlow()
subagent-announce.ts: Pass channel and accountId to the gateway agent call
agent.ts (gateway handler): Accept accountId param, resolve it with fallback to sessionEntry?.lastAccountId
delivery.ts: Use opts.accountId with fallback to session-based resolution
agent.ts (schema): Add accountId to AgentParamsSchema
Files Changed
src/agents/tools/sessions-spawn-tool.ts
src/agents/subagent-registry.ts
src/agents/subagent-announce.ts
src/agents/clawdbot-tools.ts
src/commands/agent/types.ts
src/commands/agent/delivery.ts
src/gateway/server-methods/agent.ts
src/gateway/protocol/schema/agent.ts
Testing
- Start gateway with WhatsApp account
kev
- Spawn a subagent:
sessions_spawn task="What is 2+2?" agentId="scout"
- Wait for completion
- Verify announce is delivered via correct WhatsApp account
Before fix: Delivery fails with "No active WhatsApp Web listener (account: default)"
After fix: Delivery succeeds via account kev
Summary
When a spawned subagent completes and the announce flow attempts to deliver to the requester, it fails with:
The delivery tries to use the default account instead of the correct account (e.g.,
kev) becauseaccountIdis not propagated through the subagent spawn → announce → delivery chain.Root Cause
The
sessions_spawntool capturesagentChannel(e.g., "whatsapp") but notagentAccountId. When the announce flow later callscallGateway({ method: "agent", deliver: true }), it has no way to specify which account to use for delivery.The delivery code in
delivery.tstries to getaccountIdfromsessionEntry?.lastAccountId, but when the announce triggers a fresh agent run, the session entry lookup may not have the right account context.Fix
Thread
accountIdthrough the entire subagent lifecycle:sessions-spawn-tool.ts: AcceptagentAccountIdin tool options, pass toregisterSubagentRun()subagent-registry.ts: StorerequesterAccountIdinSubagentRunRecord, pass torunSubagentAnnounceFlow()subagent-announce.ts: PasschannelandaccountIdto the gatewayagentcallagent.ts(gateway handler): AcceptaccountIdparam, resolve it with fallback tosessionEntry?.lastAccountIddelivery.ts: Useopts.accountIdwith fallback to session-based resolutionagent.ts(schema): AddaccountIdtoAgentParamsSchemaFiles Changed
src/agents/tools/sessions-spawn-tool.tssrc/agents/subagent-registry.tssrc/agents/subagent-announce.tssrc/agents/clawdbot-tools.tssrc/commands/agent/types.tssrc/commands/agent/delivery.tssrc/gateway/server-methods/agent.tssrc/gateway/protocol/schema/agent.tsTesting
kevsessions_spawn task="What is 2+2?" agentId="scout"Before fix: Delivery fails with "No active WhatsApp Web listener (account: default)"
After fix: Delivery succeeds via account
kev