← Back to PRs

#8879: fix(sessions-spawn): resolve target agent's bound accountId for subagent gateway calls

by gianni-dalerta open 2026-02-04 15:10 View on GitHub →
agents stale
## Summary Builds on top of a13efbe2b (`fix: pass threadId/to/accountId from parent to subagent gateway call`) which correctly forwards requester context (threadId, to, accountId) so sub-agents reply to the correct thread/topic. This PR adds **binding-aware accountId resolution** so that when a sub-agent has its own bot identity configured via `bindings`, it uses that identity instead of inheriting the parent's. **Example scenario:** - Aria (main agent, bound to `aria-bot`) spawns Rex (content agent, bound to `rex-bot`) via `sessions_spawn` - Rex needs to send a Telegram message back to the user - **Before (a13efbe2b only):** Rex replies through Aria's bot (correct thread, wrong identity) - **After (this PR):** Rex replies through Rex's own bot (correct thread, correct identity) The two fixes are complementary: | Fix | Solves | |-----|--------| | a13efbe2b (upstream) | Sub-agent replies land in the correct forum topic/thread | | This PR | Sub-agent replies come from the correct bot identity | ## Changes 1. **Added `resolveAgentBoundAccountId()`** in `src/routing/bindings.ts` - Looks up an agent's bound accountId for a given channel from config bindings - Follows the same pattern as existing `resolveDefaultAgentBoundAccountId()` 2. **Updated `sessions-spawn-tool.ts`** - Resolves the target agent's bound accountId before the gateway call - Uses `targetAccountId ?? requesterOrigin?.accountId` — binding wins when configured, parent context is the fallback - Preserves upstream's `to` and `threadId` passthrough 3. **Added tests** in `sessions-spawn-bound-accountid.test.ts` - Target agent's bound accountId takes priority over requester's - Falls back to requester's accountId when no binding exists - Skips resolution for cron/hook spawns (no channel context) ## Test plan - [x] `pnpm build` passes - [x] `pnpm check` passes - [x] 3 new unit tests pass (binding priority, fallback, cron/hook) - [ ] Manual testing with multi-agent setup (spawning agent with separate Telegram binding)

Most Similar PRs