Skip to content

Commit 6c30c35

Browse files
committed
fix: hide subagent announce handoff prompts
1 parent b66cc66 commit 6c30c35

8 files changed

Lines changed: 183 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ Docs: https://docs.openclaw.ai
203203
### Fixes
204204

205205
- Gateway/maintenance: prune dedupe overflow against a stable excess count and keep active agent retries from starting duplicate runs after cache eviction. (#73841) Thanks @thesomewhatyou.
206+
- Control UI/subagents: suppress internal `subagent_announce` handoff prompts from requester transcripts and hide legacy inter-session wrapper rows so completed subagent results no longer surface runtime context in WebChat history. Fixes #79071. Thanks @CjTruHeart and @COOLBGT.
206207
- Discord: preserve username target resolution for Discord outbound sends. (#79076) Thanks @vincentkoc.
207208
- Gateway/sessions: rotate generated transcript paths when gateway sessions reset, complementing the daily-rollover transcript persistence. (#79076) Thanks @vincentkoc.
208209
- Dependencies: pin the transitive `fast-uri` production dependency to `3.1.2` so the production dependency audit no longer resolves the vulnerable `<=3.1.1` range. Thanks @shakkernerd.

‎src/agents/agent-command.live-model-switch.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,38 @@ describe("agentCommand – LiveSessionModelSwitchError retry", () => {
804804
expect(attemptCalls[1]?.suppressPromptPersistenceOnRetry).toBe(true);
805805
});
806806

807+
it("suppresses prompt persistence for internal handoffs on every fallback attempt", async () => {
808+
type AttemptCall = {
809+
suppressPromptPersistenceOnRetry?: boolean;
810+
};
811+
const attemptCalls: AttemptCall[] = [];
812+
state.runWithModelFallbackMock.mockImplementation(async (params: FallbackRunnerParams) => {
813+
const first = await params.run(params.provider, params.model);
814+
const result = await params.run(params.provider, params.model);
815+
return {
816+
result,
817+
provider: params.provider,
818+
model: params.model,
819+
attempts: [first],
820+
};
821+
});
822+
state.runAgentAttemptMock.mockImplementation(async (attemptParams: AttemptCall) => {
823+
attemptCalls.push(attemptParams);
824+
return makeSuccessResult("openai", "gpt-5.4");
825+
});
826+
827+
await agentCommand({
828+
message: "internal handoff",
829+
to: "+1234567890",
830+
senderIsOwner: true,
831+
suppressPromptPersistence: true,
832+
});
833+
834+
expect(attemptCalls).toHaveLength(2);
835+
expect(attemptCalls[0]?.suppressPromptPersistenceOnRetry).toBe(true);
836+
expect(attemptCalls[1]?.suppressPromptPersistenceOnRetry).toBe(true);
837+
});
838+
807839
it("propagates non-switch errors without retrying and emits lifecycle error", async () => {
808840
state.runWithModelFallbackMock.mockRejectedValueOnce(new Error("provider down"));
809841

‎src/agents/agent-command.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,9 @@ async function agentCommandInternal(
10461046
allowTransientCooldownProbe: runOptions?.allowTransientCooldownProbe,
10471047
sessionHasHistory:
10481048
!isNewSession || (await attemptExecutionRuntime.sessionFileHasContent(sessionFile)),
1049-
suppressPromptPersistenceOnRetry: isFallbackRetry && currentTurnUserMessagePersisted,
1049+
suppressPromptPersistenceOnRetry:
1050+
opts.suppressPromptPersistence === true ||
1051+
(isFallbackRetry && currentTurnUserMessagePersisted),
10501052
onUserMessagePersisted: () => {
10511053
currentTurnUserMessagePersisted = true;
10521054
},

‎src/agents/command/types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ export type AgentCommandOpts = {
118118
promptMode?: PromptMode;
119119
/** Internal ACP-ready session turn source. Manual spawn turns bypass only the dispatch gate. */
120120
acpTurnSource?: AcpTurnSource;
121+
/** Internal handoffs can feed the model without writing the synthetic prompt to transcript. */
122+
suppressPromptPersistence?: boolean;
121123
};
122124

123125
export type AgentCommandIngressOpts = Omit<

‎src/gateway/chat-display-projection.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { isHeartbeatOkResponse, isHeartbeatUserMessage } from "../auto-reply/heartbeat-filter.js";
22
import { HEARTBEAT_PROMPT } from "../auto-reply/heartbeat.js";
3+
import {
4+
INTER_SESSION_PROMPT_PREFIX_BASE,
5+
normalizeInputProvenance,
6+
} from "../sessions/input-provenance.js";
37
import {
48
parseAssistantTextSignature,
59
resolveAssistantMessagePhase,
@@ -505,11 +509,45 @@ function isEmptyTextOnlyContent(content: unknown): boolean {
505509
return sawText;
506510
}
507511

512+
function extractProjectedText(content: unknown): string {
513+
if (typeof content === "string") {
514+
return content;
515+
}
516+
if (!Array.isArray(content)) {
517+
return "";
518+
}
519+
const parts: string[] = [];
520+
for (const block of content) {
521+
if (!block || typeof block !== "object") {
522+
continue;
523+
}
524+
const text = (block as { text?: unknown }).text;
525+
if (typeof text === "string") {
526+
parts.push(text);
527+
}
528+
}
529+
return parts.join("\n");
530+
}
531+
532+
function isSubagentAnnounceInterSessionUserMessage(message: Record<string, unknown>): boolean {
533+
const provenance = normalizeInputProvenance(message.provenance);
534+
if (provenance?.kind === "inter_session" && provenance.sourceTool === "subagent_announce") {
535+
return true;
536+
}
537+
const text = extractProjectedText(message.content ?? message.text);
538+
return (
539+
text.includes(INTER_SESSION_PROMPT_PREFIX_BASE) && text.includes("sourceTool=subagent_announce")
540+
);
541+
}
542+
508543
function shouldHideProjectedHistoryMessage(message: Record<string, unknown>): boolean {
509544
const roleContent = asRoleContentMessage(message);
510545
if (!roleContent) {
511546
return false;
512547
}
548+
if (roleContent.role === "user" && isSubagentAnnounceInterSessionUserMessage(message)) {
549+
return true;
550+
}
513551
if (roleContent.role === "user" && isEmptyTextOnlyContent(message.content ?? message.text)) {
514552
return true;
515553
}

‎src/gateway/server-methods/agent.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,49 @@ describe("gateway agent handler", () => {
10611061
resetTimeConfig();
10621062
});
10631063

1064+
it("suppresses persisted prompts for subagent announce task-completion handoffs", async () => {
1065+
primeMainAgentRun({ cfg: mocks.loadConfigReturn });
1066+
mocks.agentCommand.mockClear();
1067+
1068+
await invokeAgent(
1069+
{
1070+
message: "runtime-only announce bookkeeping",
1071+
agentId: "main",
1072+
sessionKey: "agent:main:main",
1073+
inputProvenance: {
1074+
kind: "inter_session",
1075+
sourceSessionKey: "agent:main:subagent:child",
1076+
sourceTool: "subagent_announce",
1077+
},
1078+
internalEvents: [
1079+
{
1080+
type: "task_completion",
1081+
source: "subagent",
1082+
childSessionKey: "agent:main:subagent:child",
1083+
childSessionId: "child-session-id",
1084+
announceType: "completion",
1085+
taskLabel: "child task",
1086+
status: "ok",
1087+
statusLabel: "completed",
1088+
result: "child result",
1089+
statsLine: "tokens=10",
1090+
replyInstruction: "Deliver the child result.",
1091+
},
1092+
],
1093+
idempotencyKey: "test-subagent-announce-suppress-prompt",
1094+
},
1095+
{ reqId: "subagent-announce-suppress-prompt" },
1096+
);
1097+
1098+
const callArgs = await waitForAgentCommandCall<{
1099+
suppressPromptPersistence?: boolean;
1100+
message?: string;
1101+
}>();
1102+
expect(callArgs.suppressPromptPersistence).toBe(true);
1103+
expect(callArgs.message).toMatch(/^\[Inter-session message\]/);
1104+
expect(callArgs.message).toContain("sourceTool=subagent_announce");
1105+
});
1106+
10641107
it("rejects public transcriptMessage overrides", async () => {
10651108
primeMainAgentRun({ cfg: mocks.loadConfigReturn });
10661109
mocks.agentCommand.mockClear();

‎src/gateway/server-methods/agent.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
resolveAgentAvatar,
1010
resolvePublicAgentAvatarSource,
1111
} from "../../agents/identity-avatar.js";
12+
import { AGENT_INTERNAL_EVENT_TYPE_TASK_COMPLETION } from "../../agents/internal-event-contract.js";
1213
import type { AgentInternalEvent } from "../../agents/internal-events.js";
1314
import { resolveTrustedGroupId } from "../../agents/pi-tools.policy.js";
1415
import { resolveSandboxConfigForAgent } from "../../agents/sandbox/config.js";
@@ -511,6 +512,24 @@ function dispatchAgentRunFromGateway(params: {
511512
});
512513
}
513514

515+
function shouldSuppressAgentPromptPersistence(params: {
516+
inputProvenance?: InputProvenance;
517+
internalEvents?: AgentInternalEvent[];
518+
}): boolean {
519+
if (
520+
params.inputProvenance?.kind !== "inter_session" ||
521+
params.inputProvenance.sourceTool !== "subagent_announce"
522+
) {
523+
return false;
524+
}
525+
return (
526+
params.internalEvents?.some(
527+
(event) =>
528+
event.type === AGENT_INTERNAL_EVENT_TYPE_TASK_COMPLETION && event.source === "subagent",
529+
) === true
530+
);
531+
}
532+
514533
function yieldAfterAgentAcceptedAck(): Promise<void> {
515534
return new Promise((resolve) => {
516535
setTimeout(resolve, 10);
@@ -1414,6 +1433,10 @@ export const agentHandlers: GatewayRequestHandlers = {
14141433
acpTurnSource: request.acpTurnSource,
14151434
internalEvents: request.internalEvents,
14161435
inputProvenance,
1436+
suppressPromptPersistence: shouldSuppressAgentPromptPersistence({
1437+
inputProvenance,
1438+
internalEvents: request.internalEvents,
1439+
}),
14171440
cleanupBundleMcpOnRunEnd: request.cleanupBundleMcpOnRunEnd,
14181441
abortSignal: activeRunAbort.controller.signal,
14191442
// Internal-only: allow workspace override for spawned subagent runs.

‎src/gateway/session-history-state.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,47 @@ describe("SessionHistorySseState", () => {
205205
]);
206206
});
207207

208+
test("drops subagent announce inter-session user messages from projected history", () => {
209+
const snapshot = buildSessionHistorySnapshot({
210+
rawMessages: [
211+
{
212+
role: "user",
213+
content: [
214+
{
215+
type: "text",
216+
text: [
217+
"[Inter-session message] sourceSession=agent:main:subagent:child sourceChannel=webchat sourceTool=subagent_announce isUser=false",
218+
"This content was routed by OpenClaw from another session or internal tool.",
219+
"<<<BEGIN_OPENCLAW_INTERNAL_CONTEXT>>>",
220+
"subagent completion payload",
221+
"<<<END_OPENCLAW_INTERNAL_CONTEXT>>>",
222+
].join("\n"),
223+
},
224+
],
225+
provenance: {
226+
kind: "inter_session",
227+
sourceSessionKey: "agent:main:subagent:child",
228+
sourceTool: "subagent_announce",
229+
},
230+
__openclaw: { seq: 1 },
231+
},
232+
{
233+
role: "assistant",
234+
content: [{ type: "text", text: "clean child result" }],
235+
__openclaw: { seq: 2 },
236+
},
237+
],
238+
});
239+
240+
expect(snapshot.history.messages).toEqual([
241+
{
242+
role: "assistant",
243+
content: [{ type: "text", text: "clean child result" }],
244+
__openclaw: { seq: 2 },
245+
},
246+
]);
247+
});
248+
208249
test("hides heartbeat prompt and ok acknowledgements from visible history", () => {
209250
const snapshot = buildSessionHistorySnapshot({
210251
rawMessages: [

0 commit comments

Comments
 (0)