Skip to content

Commit f8d8058

Browse files
committed
fix(agents): honor silence after settled tools
1 parent 7334f8d commit f8d8058

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

‎src/agents/embedded-agent-runner/run/incomplete-turn-recovery.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ export function resolveSettledToolTerminalContinuationInstruction(params: {
337337
);
338338
if (
339339
params.payloadCount !== 0 ||
340+
(!params.allowEmptyStopContinuation && hasOnlySilentAssistantReply(attempt.assistantTexts)) ||
340341
params.hasTerminalToolPresentation ||
341342
params.aborted ||
342343
((params.timedOut || terminal.kind === "timeout") && !idlePromptTimeout) ||

‎src/agents/embedded-agent-runner/run/terminal-resolution.test.ts‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,60 @@ describe("terminal resolution", () => {
662662
).toBeNull();
663663
});
664664

665+
it("keeps explicit silence terminal only for reply-optional settled turns", () => {
666+
const toolUseAssistant = buildEmbeddedRunnerAssistant({
667+
stopReason: "toolUse",
668+
content: [{ type: "toolCall", id: "tool-1", name: "write", arguments: {} }],
669+
});
670+
const silentAssistant = buildEmbeddedRunnerAssistant({
671+
stopReason: "stop",
672+
content: [{ type: "text", text: SILENT_REPLY_TOKEN }],
673+
});
674+
const attempt = makeEmbeddedRunnerAttempt({
675+
assistantTexts: [SILENT_REPLY_TOKEN],
676+
toolMetas: [{ toolName: "write", toolCallId: "tool-1", replaySafe: false }],
677+
itemLifecycle: { startedCount: 1, completedCount: 1, activeCount: 0 },
678+
messagesSnapshot: [
679+
{ role: "user", content: [{ type: "text", text: "[OpenClaw heartbeat poll]" }] },
680+
toolUseAssistant,
681+
{ role: "toolResult", toolCallId: "tool-1", toolName: "write", isError: false },
682+
silentAssistant,
683+
] as never,
684+
lastAssistant: silentAssistant,
685+
currentAttemptAssistant: silentAssistant,
686+
replayMetadata: { hadPotentialSideEffects: true, replaySafe: false },
687+
currentAttemptReplayMetadata: { hadPotentialSideEffects: false, replaySafe: true },
688+
});
689+
690+
const request = (runParams: {
691+
trigger: "heartbeat" | "user";
692+
terminalReplyExpectation?: "required";
693+
}) =>
694+
resolveSettledTurnFinalizationRequest({
695+
runParams: {
696+
sessionId: "session:settled-silent",
697+
runId: "run:settled-silent",
698+
...runParams,
699+
} as never,
700+
attempt,
701+
activeErrorContext: { provider: "openai", model: "gpt-5.6-luna" },
702+
modelApi: "openai-responses",
703+
executionContract: undefined,
704+
payloadsWithToolMedia: [],
705+
hasTerminalToolPresentation: false,
706+
terminalState: resolveEmbeddedRunAttemptTerminalState({
707+
attempt,
708+
assistant: silentAssistant,
709+
}),
710+
settledTurnFinalizationAvailable: true,
711+
});
712+
713+
expect(request({ trigger: "heartbeat" })).toBeNull();
714+
expect(request({ trigger: "user", terminalReplyExpectation: "required" })).toBe(
715+
SETTLED_TOOL_TERMINAL_CONTINUATION_INSTRUCTION,
716+
);
717+
});
718+
665719
it("requires an available finalizer and no visible structured error", () => {
666720
const assistant = buildEmbeddedRunnerAssistant({
667721
stopReason: "toolUse",

0 commit comments

Comments
 (0)