Skip to content

fix(agents): finalize settled turns after provider errors - #138353

Closed
roboclaw-bot wants to merge 3 commits into
mainfrom
openclaw/openclaw-openclaw-vacinc-issue-126848
Closed

roboclaw-bot wants to merge 3 commits into
mainfrom
openclaw/openclaw-openclaw-vacinc-issue-126848

Conversation

@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Closes #126848

What Problem This Solves

A tool-using turn can finish and persist its exact tool batch, then lose the final model call to a transient network failure. Whole-turn replay is correctly blocked because tools may have side effects, but terminal preparation converts that provider failure into a generated error payload before the isolated, tool-free finalizer decides whether a usable answer already exists. The generated error is counted as an answer, so finalization never starts and completed work receives only the provider error.

This is the residual composition gap left after #128840 added the settled transcript producer. #133520 handles finalizer failure after finalization starts; it cannot help when this earlier eligibility gate returns null. The trigger and stream-resume work in #119720 and #126845 is related but does not replace failure-safe terminal recovery.

Why This Change Was Made

Reply payloads already carry WeakMap-only producer provenance for generated tool-error warnings. This change adds the matching producer fact for generated terminal model-failure payloads, then makes settled-turn eligibility discount only payloads carrying one of those two generated-failure facts.

Actual assistant output, unmarked or structured errors, media, message delivery, cancellation, unsettled/async tools, and non-transient failures still block finalization through the existing gates. The repair removes the old payload-key shape heuristic and does not change whole-turn retry policy, configuration, persistence, protocol, or provider-specific behavior.

Production LOC: +24/-27 (net -3). Tests and test support: +60/-4.

User Impact

When the exact current tool batch is proven settled and the final provider request fails transiently, OpenClaw now runs the existing isolated zero-tool finalizer and delivers its summary. Completed tools are not replayed. If finalization itself cannot answer, the existing failure-honest fallback remains authoritative.

Evidence

Pre-fix production composition probe on current main:

payloads = [{ text: "LLM request failed: network connection was interrupted.", isError: true }]
finalization prompt = null

The new owner-boundary regression failed before the production repair because the finalizer was called zero times while the other 19 tests passed. After the repair:

  • node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/settled-turn-finalization.test.ts src/agents/embedded-agent-runner/run/settled-tool-evidence.test.ts src/agents/embedded-agent-runner/run/payloads.errors.test.ts src/agents/embedded-agent-runner/run/attempt.settled-turn-finalization-context.test.ts src/agents/embedded-agent-runner/run/attempt-recovery.test.ts — 110 passed
  • node scripts/check-changed.mjs -- <five changed files> — passed core/core-test typecheck, lint, formatting, dead-export, import-cycle, schema, and architecture guards
  • Fresh autoreview through P2 — scoped clean, no actionable findings

The regression exercises full terminal preparation: one persisted tool result, a transient final provider failure, the generated error payload, and one isolated final answer replacing that error. Existing sibling coverage retains negatives for missing finalization context, structured/unmarked output, media/delivery, cancellation, and unsettled or asynchronous work.


View the OpenClaw team session

@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Sep 4, 2026
OpenClaw-Publication: b77ddd12-9afe-4a1c-8208-136de875e56d

Co-authored-by: Vito Cappello <[email protected]>
@roboclaw-bot
roboclaw-bot force-pushed the openclaw/openclaw-openclaw-vacinc-issue-126848 branch from 8f6ba0d to 370d5b6 Compare September 4, 2026 15:21
OpenClaw-Publication: fd424476-611c-4773-8bfe-dc45e168cb81

Co-authored-by: Vito Cappello <[email protected]>
@roboclaw-bot
roboclaw-bot force-pushed the openclaw/openclaw-openclaw-vacinc-issue-126848 branch from 370d5b6 to 261ee55 Compare September 4, 2026 15:22
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review September 4, 2026 15:22
@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. P2 Normal backlog priority with limited blast radius. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 12:07 PM ET / 16:07 UTC.

ClawSweeper review

What this changes

The branch marks generated terminal model-failure replies as internal metadata and lets an exactly settled tool turn use the existing tool-free finalizer instead of treating that generated error as an assistant answer.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep this focused bug-fix PR open: current main still has the brittle payload-shape eligibility gate, while the branch replaces it with producer-owned metadata and retains the settled-tool safety gates. No blocking correctness finding was identified; the protected maintainer label requires explicit maintainer handling before merge.

Priority: P2
Reviewed head: 261ee5570def7e112fed96ca720f9cd410c53778

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-negative production repair with a credible boundary regression and no identified correctness defect.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository State identifies the bot author as a MEMBER, so the external-contributor proof gate does not apply; the supplied focused test nonetheless exercises the changed terminal-preparation and isolated-finalizer path.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository State identifies the bot author as a MEMBER, so the external-contributor proof gate does not apply; the supplied focused test nonetheless exercises the changed terminal-preparation and isolated-finalizer path.
Evidence reviewed 7 items Changed eligibility gate: The introduced gate treats a non-empty payload list as absent only when every payload carries generated terminal-failure or tool-warning metadata.
Producer-owned provenance: Payload construction marks the user-facing error generated from an errored terminal assistant as terminalModelFailure, using the existing WeakMap-only metadata mechanism.
Safety boundary retained: The finalizer still rejects nonzero payloads, unsettled batches, delivery evidence, async work, accepted spawns, client tool calls, and missing settled-turn context for failed terminals.
Findings None None.
Security None None.

How this fits together

The embedded agent runner turns provider results and tool activity into channel reply payloads. Terminal recovery checks whether the exact tool batch is safely settled, then may request a tool-free final answer before channel delivery.

flowchart LR
  A[Provider turn] --> B[Embedded agent runner]
  B --> C[Reply payload preparation]
  C --> D[Terminal recovery decision]
  E[Settled tool transcript] --> D
  D --> F[Tool-free finalizer]
  F --> G[Channel reply]
Loading

Before merge

  • Resolve merge risk (P1) - Merging changes terminal message selection: in the narrowly proven settled-tool case, a generated provider error is replaced by a tool-free finalizer result; this deserves maintainer confirmation of the intended delivery behavior.
  • Complete next step (P2) - Confirm the exact-head terminal-recovery validation and approve the intended generated-error-to-final-summary delivery change before merging.
Agent review details

Security

None.

PR surface

Source -3, Tests +56. Total +53 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 24 27 -3
Tests 2 60 4 +56
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 84 31 +53

Review metrics

Metric Value Why it matters
Production versus test delta production +24/-27 (net -3); tests/test support +60/-4 The bug repair is net-negative in production while adding focused regression coverage at the terminal-finalization boundary.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #126848
Summary: This PR is a candidate fix for the remaining final provider-error eligibility gap described by the canonical issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Accept scoped recovery behavior (recommended)
    Merge after confirming that an exactly settled tool batch may replace its generated provider error with the existing tool-free finalizer output.
  2. Pause for additional transport evidence
    If maintainers want evidence beyond the focused boundary regression, collect an exact-head injected provider-fault trace through the production runner before merging.

Technical review

Best possible solution:

Retain producer-owned generated-failure metadata and the existing exact-settlement gates, then merge after maintainer confirmation that replacing this narrow generated error with an isolated final summary is intended.

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

Yes—source establishes the path: current main counts the generated error payload, while the added focused test constructs the settled-tool/provider-error scenario and exercises the terminal-finalization boundary.

Is this the best way to solve the issue?

Yes—the repair records the fact at the generated-error producer and reuses the settled-turn owner’s existing safety checks, replacing a brittle payload-shape heuristic without whole-turn replay.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add merge-risk: 🚨 message-delivery: The PR changes which terminal reply is delivered after a settled tool batch and provider failure.

Label justifications:

  • P2: This is a bounded fix for completed tool turns receiving a provider error instead of a final response.
  • merge-risk: 🚨 message-delivery: The PR changes which terminal reply is delivered after a settled tool batch and provider failure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository State identifies the bot author as a MEMBER, so the external-contributor proof gate does not apply; the supplied focused test nonetheless exercises the changed terminal-preparation and isolated-finalizer path.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • fuller-stack-dev: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • joshavant: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-04T15:33:55.815Z sha 261ee55 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. label Sep 4, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Closing this parallel duplicate at Vito’s request. The canonical repair is #138362, which includes the producer-owned payload-provenance fix, the additional terminal-safety coverage, and real HTTP 503 loopback proof that completed tools execute only once.

VACInc is credited as co-author on the canonical PR’s commits and in its description. This closure does not merge either PR or delete this branch.

@RomneyDa
RomneyDa deleted the openclaw/openclaw-openclaw-vacinc-issue-126848 branch October 22, 2026 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

2 participants