Skip to content

Commit 1c3fbbd

Browse files
scotthuangsteipete
authored andcommitted
fix(agents): skip sessions_send A2A flow for parent-owned ACP children
The A2A ping-pong + announce flow in runSessionsSendA2AFlow treats the send target as a peer agent and echoes replies back and forth between requester and target. When the target is an ACP child spawned by the requester, this creates an infinite loop: the parent is woken with the child's reply, generates a user-facing response, and has that response forwarded back to the child as a new user message — effectively granting the child an implicit sessions_send capability back to the parent. ACP children already report their results through the [Internal task completion event] announcement path, so no A2A flow is needed when the send target is a parent-owned background ACP session. Detect this case via isParentOwnedBackgroundAcpSession and short-circuit startA2AFlow before runSessionsSendA2AFlow is invoked.
1 parent ff67a89 commit 1c3fbbd

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎src/agents/tools/sessions-send-tool.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import crypto from "node:crypto";
22
import { Type } from "@sinclair/typebox";
3+
import { isParentOwnedBackgroundAcpSession } from "../../acp/session-interaction-mode.js";
34
import type { OpenClawConfig } from "../../config/types.openclaw.js";
45
import { callGateway } from "../../gateway/call.js";
56
import { formatErrorMessage } from "../../infra/errors.js";
@@ -15,6 +16,7 @@ import {
1516
readLatestAssistantReplySnapshot,
1617
waitForAgentRunAndReadUpdatedAssistantReply,
1718
} from "../run-wait.js";
19+
import { loadSessionEntryByKey } from "../subagent-announce-delivery.js";
1820
import {
1921
describeSessionsSendTool,
2022
SESSIONS_SEND_TOOL_DISPLAY_SUMMARY,
@@ -289,7 +291,22 @@ export function createSessionsSendTool(opts?: {
289291
const requesterChannel = opts?.agentChannel;
290292
const maxPingPongTurns = resolvePingPongTurns(cfg);
291293
const delivery = { status: "pending", mode: "announce" as const };
294+
295+
// Skip the A2A ping-pong + announce flow when the target is a
296+
// parent-owned background ACP subagent. Such sessions already report
297+
// their results back to the parent through the
298+
// `[Internal task completion event]` announcement path, and treating
299+
// them as a peer agent causes the parent to be woken with the child's
300+
// reply, generate a user-facing response, and have that response
301+
// forwarded back to the child as a new message — producing an infinite
302+
// ping-pong loop between parent and ACP child.
303+
const targetSessionEntry = loadSessionEntryByKey(resolvedKey);
304+
const skipA2AFlow = isParentOwnedBackgroundAcpSession(targetSessionEntry);
305+
292306
const startA2AFlow = (roundOneReply?: string, waitRunId?: string) => {
307+
if (skipA2AFlow) {
308+
return;
309+
}
293310
void runSessionsSendA2AFlow({
294311
targetSessionKey: resolvedKey,
295312
displayKey,

0 commit comments

Comments
 (0)