Repository navigation
fix(agents): keep settled-tool finalization on the settled transcript - #3
Merged
tomorrowflow merged 2 commits intoSep 11, 2026
Conversation
Two defects in the isolated settled-tool finalizer let heartbeat polls deliver "I don't see the previous tool-call results or the original question in our current transcript" to the owner on Signal, once per poll that ended its tool batch with a content-less assistant message (9x on 2026-09-10, again 09-11). - resolveSettledToolTerminalContinuationInstruction branched on the batch owner's stopReason (the tool-use message). An optional turn whose current assistant ended with a bare "stop" after settled tools therefore took the required-reply branch and requested a visible-answer continuation. Branch on the current assistant; the batch owner only proves settlement. - The built-in harness reopened the session through a store view bounded by max(1024, contextTokenBudget * 8) bytes, newest rows first. When that view cannot hold the settled batch, the finalizer sends the continuation instruction alone (every live finalizer request measured input=50). Carry the settled attempt's messagesSnapshot into the finalization attempt and seed its model context from it; answer persistence is unchanged. Covered end to end through the real built-in harness and embedded runner against a loopback provider over openai-responses and openai-completions with a budget too small for the store view, plus a resolver test for the heartbeat empty-stop shape. Both fail on the original code. Co-Authored-By: Claude Fable 5.1 <[email protected]>
The superseded-runtime retirement path added in 9de3283 calls logWarn without importing it. pnpm tsgo:core fails with TS2304, and the built runtime would throw ReferenceError inside that catch block. Sibling runtime files import it from ../logger.js; do the same here. Co-Authored-By: Claude Fable 5.1 <[email protected]>
tomorrowflow
marked this pull request as ready for review
September 11, 2026 12:49
This was referenced Sep 11, 2026
tomorrowflow
added a commit
that referenced
this pull request
Sep 12, 2026
Heartbeat polls that ran their checks (ls, calendar query, read, write of the state file) and then stopped with an empty assistant message were reported to the owner as "Agent couldn't generate a response. Note: some tool actions may have already been executed" (2026-09-12 11:06 and 13:06). PR #3 correctly stopped finalizing that turn into prose, so it fell through to the incomplete-turn classifier, which saw an empty stop with side effects. The silent-turn guard needs both allowEmptyAssistantReplyAsSilent and an optional reply expectation. Heartbeats deliberately leave the expectation to the trigger, and only group chats set the allowance, so a heartbeat could never qualify. Resolve the effective policy from the trigger when the caller leaves it open: a run that owes no visible reply (heartbeat, cron, whose prompts already offer NO_REPLY) accepts a clean empty stop after settled tools as silence. User and manual runs, and callers that set an explicit expectation, are unchanged.
tomorrowflow
added a commit
that referenced
this pull request
Sep 18, 2026
Heartbeat polls that ran their checks (ls, calendar query, read, write of the state file) and then stopped with an empty assistant message were reported to the owner as "Agent couldn't generate a response. Note: some tool actions may have already been executed" (2026-09-12 11:06 and 13:06). PR #3 correctly stopped finalizing that turn into prose, so it fell through to the incomplete-turn classifier, which saw an empty stop with side effects. The silent-turn guard needs both allowEmptyAssistantReplyAsSilent and an optional reply expectation. Heartbeats deliberately leave the expectation to the trigger, and only group chats set the allowance, so a heartbeat could never qualify. Resolve the effective policy from the trigger when the caller leaves it open: a run that owes no visible reply (heartbeat, cron, whose prompts already offer NO_REPLY) accepts a clean empty stop after settled tools as silence. User and manual runs, and callers that set an explicit expectation, are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #2 (
fix/mcp-runtime-rollover-leak), which the live gateway runs as 2026.9.3 (7a71f6c). Retarget tomainonce #2 lands.Problem
After #2 stopped the empty-response retry from re-prompting an authored
NO_REPLY, the owner still received this on Signal from the isolated heartbeat, roughly once per hour when it happened:The heartbeat run settles its tool batch (read / calendar / todo / write) and ends with an assistant message that has no content blocks. The runner then logs
settled post-tool turn lacked a final answer … running isolated finalization, and the isolated finalizer's request to the model is ~50 input tokens: the continuation instruction and nothing else. The model can only say it cannot see the transcript, the finalizer accepts that as the answer, and heartbeat delivery (which only suppressesHEARTBEAT_OK/NO_REPLY) sends it. Observed 9× on 2026-09-10 and again 2026-09-11 08:06Z; every finalizer request measuredinput=50 cacheRead=0.Two runner defects combine:
resolveSettledToolTerminalContinuationInstructionresolves the tool-use message as the batch owner and then branches on that message'sstopReason. A heartbeat (optional reply) whose current assistant is a barestopafter settled tools therefore took the tool-use branch and requested a visible-answer continuation, bypassing theallowEmptyStopContinuationgate that only a required reply should open.SessionManager.open(target, cwd, { maxBytes: max(1024, contextTokenBudget * 8), maxEvents }), a view sized for a fresh turn that keeps the newest rows first. When that view cannot hold the settled batch, history is empty and only the instruction is sent. The harness already receives the settled attempt, whosemessagesSnapshotis exactly the context being finalized, but ignored it.Solution
incomplete-turn-recovery.ts: branch on the current assistant. A completedstopafter the settled batch is the model's own terminal decision; only a turn that owes a visible reply may reopen it. The batch owner still proves settlement.builtin-openclaw.ts/types.ts/attempt-history-prepare.ts: the restricted finalization attempt carriessettledTurnMessages(the settled attempt'smessagesSnapshot), and history preparation seeds the model context from it forsettled-tool-finalizationinstead of the bounded store read. Persistence of the finalizer's answer is unchanged (still through the store-opened manager).agent-bundle-mcp-manager.ts(separate commit): fix(agents): retire superseded MCP runtimes and keep heartbeats out of memory #2 useslogWarnwithout importing it, which failspnpm tsgo:core. Sibling files import it from../logger.js; this adds the same import. Cherry-pick into fix(agents): retire superseded MCP runtimes and keep heartbeats out of memory #2 if preferred.Impact
Heartbeat polls that end a settled tool batch silently stay silent. When a settled turn legitimately needs finalization (required reply, transient provider failure after tools), the finalizer now sees the user turn, tool calls and tool results it is asked to summarize.
Not changed: heartbeat delivery policy, the store's bounded read, the empty-response retry from #2.
Evidence
settled-turn-finalization.test.ts— new case: heartbeat with a tool-use batch owner and a content-lessstopmust not request finalization; a required user turn still does. Fails on the original code (instruction returned), passes after.settled-turn-finalization.builtin-harness.test.ts— new: real built-in harness + realrunEmbeddedAttempt+ SQLite transcript + loopback provider, overopenai-responsesandopenai-completions, with a context token budget too small for the bounded store view. Asserts the finalizer's request body contains the user turn and the tool output. Fails on the original code (request is the bare instruction, matching the live 50-token requests), passes after.pnpm tsgo:coreclean;oxfmt --checkclean on changed files;git diff --checkclean.settled-turn-finalization*,terminal-resolution,run.incomplete-turn.*,incomplete-turn-recovery,harness/builtin-openclaw,harness/selection,run-embedded-agent.finalization-scope,attempt.spawn-workspace.context-engine,agent-bundle-mcp-manager.lifecycle— 6 shards, 362 tests passed.Proof gaps: the repo lint runner (
scripts/run-lint.mts) refuses to run in this nested worktree ("Declaration input escapes checkout");oxlintwas run directly on the changed files instead. Why the live finalizer's store view was too small is not pinned down (the Kimi model declares a 256K window); the fix removes the finalizer's dependency on that view regardless. No live heartbeat proof yet; verify after deploy by grepping the gateway log forsettled post-tool turn lacked a final answeronagent:main:main:heartbeatruns.🤖 Generated with Claude Code