fix(agent-to-agent): route A2A replies back to originating session (#2267)
Squash merge of PR #2267 by ddaniels. When an agent group has more than one active session, A2A replies landed in the newest session via findSessionByAgentGroup's ORDER BY created_at DESC. The session that asked the question never saw the answer. Adds origin-aware return-path routing with three layers: 1. Direct return-path: if the reply has in_reply_to, look up the triggering inbound row's source_session_id and route there. 2. Peer-affinity fallback: find the most recent A2A inbound from this peer and use its source_session_id. 3. Legacy fallback: newest active session (pre-migration compat). Container-side: MCP send_message/send_file now thread the current batch's in_reply_to through to outbound rows via current-batch.ts. Also flips our A2A bug-documenting test (#2332) from asserting the broken behavior to asserting the fixed behavior. Co-Authored-By: Doug Daniels <ddaniels888@gmail.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -210,6 +210,12 @@ export function writeSessionMessage(
|
||||
* a trigger-1 message does arrive.
|
||||
*/
|
||||
trigger?: 0 | 1;
|
||||
/**
|
||||
* For agent-to-agent inbound: the source session id that emitted the
|
||||
* outbound message which became this inbound row. Used as the return
|
||||
* path so the target's reply routes back to that exact session.
|
||||
*/
|
||||
sourceSessionId?: string | null;
|
||||
},
|
||||
): void {
|
||||
// Extract base64 attachment data, save to inbox, replace with file paths
|
||||
@@ -228,6 +234,7 @@ export function writeSessionMessage(
|
||||
processAfter: message.processAfter ?? null,
|
||||
recurrence: message.recurrence ?? null,
|
||||
trigger: message.trigger ?? 1,
|
||||
sourceSessionId: message.sourceSessionId ?? null,
|
||||
});
|
||||
} finally {
|
||||
db.close();
|
||||
|
||||
Reference in New Issue
Block a user