fix: expose resolvedTo as currentChannelId so sub-agents inherit thread routing#22205
fix: expose resolvedTo as currentChannelId so sub-agents inherit thread routing#22205Galygious wants to merge 1 commit into
Conversation
When a sub-agent is spawned via sessions_spawn, the gateway agent handler already forwards to and threadId from the requester session. However, resolvedTo was never mapped to runContext.currentChannelId, so the message tool zero-param target inference had nothing to fall back on -- resulting in 'Action send requires a target' errors. Sets currentChannelId: resolvedTo in the runContext, flowing through runEmbeddedPiAgent -> createOpenClawCodingTools -> createMessageTool. Sub-agents calling message with no explicit to/channel/threadId now inherit the parent session's originating thread/channel automatically. Verified end-to-end: sub-agents spawned with only a task prompt send Discord messages to the correct thread without explicit routing params. AI-submitted: identified and implemented by Cognis (OpenClaw agent). Manual end-to-end tested. No automated test suite run. A regression test for sub-agent message tool target inference would be a good add.
|
Note on CI failures: The failing checks (src/web/media.test.ts — image compression/MEDIA prefix tests) are pre-existing failures on main that predate this PR by several commits. They are unrelated to this change, which only touches src/gateway/server-methods/agent.ts. |
|
This pull request has been automatically marked as stale due to inactivity. |
|
im not sure why this was marked stale. still a valid pull request to my knowledge |
|
This pull request has been automatically marked as stale due to inactivity. |
|
Closing due to inactivity. |
Summary
When a sub-agent is spawned via
sessions_spawn, the gateway'sagenthandler already receives and resolvestoandthreadIdfrom the requester session context. However,resolvedTowas never mapped torunContext.currentChannelId, leaving the message tool's zero-param target inference with nothing to fall back on.Symptom: Sub-agents calling
messagewithaction=sendand no explicitto,channel, orthreadIdwould fail withAction send requires a target— even though the parent session had a fully-resolved delivery target.Root Cause
buildThreadingToolContext()(inagent-runner-utils.ts) setscurrentChannelId = sessionCtx.To?.trim()for the main session. For sub-agents launched viasessions_spawn,sessionCtx.Tois empty because the sub-agent session has no inbound message context — it only has therunContextpassed from the gateway handler.resolvedTowas present in that handler but was never forwarded intorunContext.currentChannelId.Fix
One line added to
src/gateway/server-methods/agent.ts:This flows through:
agentCommand→runEmbeddedPiAgent→createOpenClawCodingTools→createMessageTool→ tool context inference inmessage-action-runner.ts.Verification
Tested end-to-end on Discord thread sessions:
Count to 10. Send each number as a separate message.— no thread info passedchannel:1474502983390593189)to,channel, orthreadIdparams used by the sub-agentExplicit routing params still take full precedence when provided. This change only affects the fallback inference path.
Drawbacks / Considerations
towas omitted; now they succeed and send to the parent thread. This is almost always desirable but worth noting as a behavior change for sub-agents intended to run silently.resolvedTothe triggering context resolves to, which may be an unrelated channel. Same mitigation as always: pass an explicittoto override.AI-Submitted PR