Skip to content

Bug: Subagent announce delivery fails with wrong WhatsApp account (multi-account routing) #1058

@adam91holt

Description

@adam91holt

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:

  1. sessions-spawn-tool.ts: Accept agentAccountId in tool options, pass to registerSubagentRun()
  2. subagent-registry.ts: Store requesterAccountId in SubagentRunRecord, pass to runSubagentAnnounceFlow()
  3. subagent-announce.ts: Pass channel and accountId to the gateway agent call
  4. agent.ts (gateway handler): Accept accountId param, resolve it with fallback to sessionEntry?.lastAccountId
  5. delivery.ts: Use opts.accountId with fallback to session-based resolution
  6. 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

  1. Start gateway with WhatsApp account kev
  2. Spawn a subagent: sessions_spawn task="What is 2+2?" agentId="scout"
  3. Wait for completion
  4. 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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions