Skip to content

fix: continue after empty post-tool replies - #93062

Closed
hannesrudolph wants to merge 2 commits into
openclaw:mainfrom
hannesrudolph:fix/post-tool-empty-continuation
Closed

hannesrudolph wants to merge 2 commits into
openclaw:mainfrom
hannesrudolph:fix/post-tool-empty-continuation

Conversation

@hannesrudolph

@hannesrudolph hannesrudolph commented Jun 14, 2026 •

Copy link
Copy Markdown
Member

Origin and reported failure

This PR was born from #90872 and the Discord report that motivated it. The concrete failure is:

  1. Composer 2.5 emits pre-tool progress text such as Looking into it.
  2. It calls a read-only action such as cron status or cron list.
  3. The tool succeeds, for example with {"jobs":[]}.
  4. The provider then emits an empty terminal assistant turn.
  5. OpenClaw promotes the earlier pre-tool progress text into the final reply, so the user sees Looking into it. instead of the scheduler result.

#90872 addresses this by introducing a broad terminal-tool fallback contract: retained tool observations, public terminalSummary / terminalResultFallback metadata, deterministic synthesized replies, delivery/side-effect evidence, loop-abort handling, plugin SDK changes, and expanded prose classification. Peter rejected that scope and approach as a 15k-line solution that could not be right.

This PR isolates the reported failure instead: identify the terminal shape structurally, discard pre-tool narration as a final answer, and perform one bounded continuation from the transcript that already contains the completed result. It does not add public fallback APIs or parse prose to decide whether a turn is complete.

Regression case

The focused runner regression reproduces the exact sequence above:

assistant: "Looking into it." + cron status tool call
tool result: {"jobs":[]}
assistant: empty stop
continuation: "No cron jobs are configured."

It asserts that the runner samples exactly once more from the existing transcript, that the continuation prompt explicitly follows the latest completed tool result, and that Looking into it. is never returned as the terminal reply. Separate tool-lifecycle tests prove that mutation classification uses actual before_tool_call-adjusted execution arguments, while terminal-media and unclassified-plugin regressions prove the continuation fails closed.

#90872 contains related tests for suppressing pre-tool narration and for synthesizing a cron terminalSummary when Composer provides no final answer, but it does not combine the exact reported progress text → read-only cron result → empty assistant → natural final answer sequence. Its published live scheduler proof also reported that cron was unavailable in that channel session, so it did not exercise this exact cron path end to end.

Summary

  • detect the structural terminal shape where a completed tool result is followed by an empty assistant turn
  • prevent assistant text emitted before that tool result (for example, “Looking into it”) from being promoted into the terminal reply
  • continue once from the existing transcript only when the terminal path has no payload/delivery and every completed call is proven replay-safe
  • recompute mutation metadata from hook-adjusted execution arguments, so a call rewritten by before_tool_call is classified from what actually ran
  • fail closed for plugin/client tools without OpenClaw mutation classification while preserving read-only cron status/list continuation

This is a deliberately narrow alternative to #90872. That PR attempts a general terminal-tool fallback contract across 75 files and roughly 16k added lines. Peter’s stated concern was both the size and that this could not be the right approach. This patch addresses the concrete failure without public tool-summary APIs, plugin SDK changes, deterministic tool-output synthesis, or natural-language regex classification of plans/progress/completion.

The decision here is structural: a tool result exists, the terminal assistant turn is empty, no payload/delivery/error/async terminal state supersedes it, and the recorded tool actions are classified replay-safe. The recovery is bounded to one continuation from the transcript that already contains the completed tool result.

Verification

  • node scripts/run-vitest.mjs src/agents/embedded-agent-subscribe.handlers.tools.test.ts src/agents/embedded-agent-runner/run.incomplete-turn.test.ts — 201 passed
  • node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo — passed
  • node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo — passed
  • targeted oxfmt --check and oxlint over all 10 changed files — passed
  • git diff --check — clean
  • CI=true pnpm check:changed reached and passed both core typecheck lanes, then the type-aware src/agents lint shard crashed inside tsgolint with a Go SIGSEGV and hung; targeted non-type-aware lint passed afterward

Real behavior proof

Behavior addressed: A model can emit progress text, successfully call a read-only tool such as cron status, then return an empty post-tool assistant turn. OpenClaw previously promoted the pre-tool progress text into the terminal reply and skipped empty-turn recovery.

Real environment tested: Repository-native embedded runner and tool lifecycle test harnesses in a dedicated worktree based on freshly fetched origin/main.

Exact steps or command run after this patch: node scripts/run-vitest.mjs src/agents/embedded-agent-subscribe.handlers.tools.test.ts src/agents/embedded-agent-runner/run.incomplete-turn.test.ts, both core run-tsgo.mjs commands listed above, targeted oxfmt/oxlint, and git diff --check.

Evidence after fix: The regression covers progress text → read-only cron status → empty assistant → one transcript continuation → visible final answer. Additional coverage proves pre-tool narration is not surfaced, terminal media prevents continuation, mutating cron add does not auto-continue, unclassified plugin tools fail closed, hook-adjusted arguments determine mutation state, a real post-tool answer is left alone, and continuation is bounded.

Observed result after fix: 201 focused tests passed; both core typecheck lanes passed; targeted formatting, lint, and diff checks passed.

What was not tested: No live Discord delivery or live Composer 2.5 provider call was run. This patch does not synthesize tool output as an answer and does not broaden the plugin/tool public contract. The full changed-file lint lane did not complete because the tsgolint process crashed as described above.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Jun 14, 2026
@clawsweeper

clawsweeper Bot commented Jun 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed June 14, 2026, 4:29 PM ET / 20:29 UTC.

Summary
The PR changes embedded agent incomplete-turn handling and tool mutation metadata so replay-safe post-tool empty assistant replies can continue once without surfacing pre-tool progress text.

PR surface: Source +123, Tests +472. Total +595 across 10 files.

Reproducibility: yes. Source inspection gives a high-confidence path: current main can surface pre-tool assistant text, and PR head can lose the new unclassified-tool safety marker before replay metadata is computed.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: vector/embedding metadata: src/agents/embedded-agent-subscribe.handlers.tools.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🌊 off-meta tidepool
Patch quality: 🧂 unranked krab
Result: blocked by patch quality or review findings.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Preserve mutationClassified in toolMetasNormalized.
  • [P2] Add focused coverage proving an unclassified plugin/client tool remains replay-unsafe through the full embedded attempt result path.

Risk before merge

  • [P1] Merging as-is can auto-continue after an unclassified plugin/client tool because the fail-closed mutationClassified signal is lost before replay metadata is computed, which can repeat unknown side effects.
  • [P1] The PR body records focused harness and type/lint proof but no live provider or channel run, so after the source blocker is fixed maintainers may still want a real Composer/channel proof path.

Maintainer options:

  1. Fix replay metadata propagation before merge (recommended)
    Carry mutationClassified through toolMetasNormalized and prove an unclassified plugin/client tool remains replay-unsafe after attempt normalization.
  2. Accept the narrow approach after repair
    After the propagation fix, maintainers can keep this as the small internal runtime repair instead of landing the related broad terminal-fallback API PR.
  3. Pause for live provider proof
    If maintainers want real transport confidence first, keep the draft paused until a provider/channel run demonstrates the post-tool empty assistant path without replaying side effects.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Preserve `mutationClassified` in `runEmbeddedAttempt` toolMetas normalization and add focused coverage that a real unclassified plugin/client tool remains replay-unsafe after attempt normalization.

Next step before merge

  • [P2] A narrow automated repair can carry the missing mutationClassified field through attempt normalization and add the missing full-path regression without deciding product direction.

Security
Cleared: No dependency, workflow, credential, package, or artifact-download changes were found; the replay-safety issue is tracked as a functional merge blocker.

Review findings

  • [P1] Preserve mutation classification through attempt metadata — src/agents/embedded-agent-runner/run/attempt.ts:5090-5113
Review details

Best possible solution:

Preserve mutationClassified through the embedded attempt normalization path, add a regression that exercises the full runEmbeddedAttempt metadata flow for an unclassified plugin/client tool, then continue with the narrow internal fix instead of the broad public fallback API approach.

Do we have a high-confidence way to reproduce the issue?

Yes. Source inspection gives a high-confidence path: current main can surface pre-tool assistant text, and PR head can lose the new unclassified-tool safety marker before replay metadata is computed.

Is this the best way to solve the issue?

No, not as submitted. The narrow internal continuation approach is preferable to the broad fallback API PR, but the implementation must preserve the mutation-classification marker through the attempt result boundary before it is safe.

Full review comments:

  • [P1] Preserve mutation classification through attempt metadata — src/agents/embedded-agent-runner/run/attempt.ts:5090-5113
    handleToolExecutionEnd now records mutationClassified: false for plugin/client tools, and buildAttemptReplayMetadata relies on seeing that flag to fail closed. This normalization only carries mutatingAction, so an unclassified tool reaches replay metadata as { toolName, mutatingAction: false }; if its name is not heuristically mutating, the new post-tool continuation can replay an unknown side-effectful tool. Carry mutationClassified here and cover the full attempt path before merging.
    Confidence: 0.93

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against f1b8827d20c8.

Label changes

Label justifications:

  • P1: The PR targets a broken agent-runtime reply path and currently has a replay-safety defect that could repeat unknown plugin/client tool side effects.
  • merge-risk: 🚨 compatibility: The diff changes replay behavior around plugin/client tools, and losing the classification marker can make existing custom tool workflows replay unsafely after upgrade.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🌊 off-meta tidepool and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This is a maintainer-associated PR, so the external contributor proof gate does not apply; the body records focused harness/type/lint proof but no live provider/channel run.
Evidence reviewed

PR surface:

Source +123, Tests +472. Total +595 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 8 163 40 +123
Tests 2 472 0 +472
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 635 40 +595

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/agents/embedded-agent-subscribe.handlers.tools.test.ts src/agents/embedded-agent-runner/run.incomplete-turn.test.ts.
  • [P1] node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo.
  • [P1] node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo.
  • [P1] git diff --check.

What I checked:

Likely related people:

  • ragesaq: Blame and file history show the current replay metadata, terminal payload, and tool metadata normalization paths central to this PR came from their recent agent reply commit. (role: recent area contributor; confidence: high; commits: a15427d605fe; files: src/agents/embedded-agent-runner/run.ts, src/agents/embedded-agent-runner/run/attempt.ts, src/agents/embedded-agent-runner/run/incomplete-turn.ts)
  • Vincent Koc: Authored the earlier post-tool empty-reply retry work that this PR extends for pre-tool narration and replay safety. (role: recent adjacent feature owner; confidence: high; commits: 67dc8053149d; files: src/agents/embedded-agent-runner/run/incomplete-turn.ts, src/agents/embedded-agent-runner/run.incomplete-turn.test.ts)
  • NVIDIAN: Recent thinking-only errored-turn retry work touched the same embedded runner and incomplete-turn recovery area. (role: recent adjacent agent-runner contributor; confidence: medium; commits: ecaebfc51b4a; files: src/agents/embedded-agent-runner/run.ts, src/agents/embedded-agent-runner/run/incomplete-turn.ts, src/agents/embedded-agent-runner/run.incomplete-turn.test.ts)
  • sandieman2: Recent final-reply delivery work touched the terminal reply and tool subscribe paths adjacent to this bug class. (role: recent adjacent reply-delivery contributor; confidence: medium; commits: c67dc59b02b0; files: src/agents/embedded-agent-runner/run.ts, src/agents/embedded-agent-subscribe.handlers.tools.ts, src/auto-reply/reply/agent-runner.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. labels Jun 14, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant