Skip to content

fix(agents): recover final summaries after transient post-tool failures - #138362

Merged
VACInc merged 4 commits into
mainfrom
openclaw/open-pr-to-rectify-vacinc-s-gap
Sep 4, 2026
Merged

VACInc merged 4 commits into
mainfrom
openclaw/open-pr-to-rectify-vacinc-s-gap

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #126848 — settled tool work loses its final summary after a transient provider failure.

What Problem This Solves

Fixes an issue where users whose tool work had already completed would receive only a provider-connection error when the final model request failed transiently. This addresses VACInc’s September 4 reopening evidence, not the already-merged context producer in #128840.

Why This Change Was Made

Record generated provider-error provenance at payload creation in existing private reply metadata, then discount only generated plain error surfaces for isolated finalization eligibility. Reuse existing tool-warning provenance instead of identifying tool warnings by shape alone. Prepared payloads remain untouched whenever recovery is rejected.

The canonical finalizer still owns the tool-free request and the failure-honest fallback from #133520. Exact current-batch settlement, captured recovery context, prior final delivery/media, async work, cancellation, and tool presentations retain their gates. Structured provider refusals and ambiguous/previously-produced output are explicitly terminal. Cron tool-authored silence is evaluated after the effective payload count is known.

No whole-turn replay, new retry family, provider/model/error-string special case, config, schema, or protocol change. Production delta: +5 lines across three files. The small growth records a missing producer fact and preserves the terminal-error boundary; shape-only warning inference and duplicated count branching are removed. Tests/test support: +461/-5 lines (net +456) after consolidation, separate from production.

User Impact

Completed work can reach the existing tool-free finalizer and produce a truthful summary instead of only a generated connection-error reply. Completed tools are not executed again. If finalization fails, the existing honest settled-work fallback remains available.

Co-authored with @VACInc, who supplied the live report, composition diagnosis, and repair/coverage requirements.

Evidence

  • Baseline composition regression on a6a979c: generated provider-error payload present, but finalization returned not-attempted instead of answered; 14 safety negatives passed. The real HTTP loopback also fails with that exact eligibility result when only the old terminal-resolution module is restored; the fixed module was restored byte-for-byte afterward.
  • 218 focused/sibling tests passed after test consolidation across the producer, terminal-preparation composition, finalizer, settlement, provider-error payload, structured refusal, and outer provider-failure suites.
  • Real HTTP 503 loopback proof: the production agent loop executes a file-writing tool once and persists its tool result in SQLite. The post-tool request receives a transient upstream-connect 503. Production terminal preparation and the core finalization backend then call a harness finalizer over the real Responses transport with tools disabled. Only one final answer payload and one additional transcript answer remain.
{"httpRequests":3,"requestToolCounts":[1,1,0],"toolExecutions":1,"persistedToolResults":1,"finalAnswerPayloads":1,"additionalTranscriptAnswers":1,"wholeTurnReplays":0}

The loopback uses a synthetic provider identity to avoid unrelated bundled-plugin discovery; the wire transport, agent loop, persistence, payload preparation, finalization eligibility, and core finalization boundary are real. It is not a live external-provider or channel-delivery test. The existing producer integration test is also included; the loopback supplies its settled-context fixture explicitly.

  • Independent autoreview (uncommitted, P0–P2): scoped-clean, no accepted/actionable findings.
  • Changed-scope formatting, lint, types, dead exports, import cycles, and guards: passed. The original six-file implementation plan passed; the subsequent four-file test cleanup passed its complete node scripts/check-changed.mjs plan, including core-test typecheck and all dead-export scans.

Focused validation used node scripts/run-vitest.mjs for the provider-error, HTTP transport, finalizer, unavailable-finalizer, settled-tool-evidence, context-producer, payload-errors, structured-refusal, and outer provider-failure suites.

Named follow-up: a separate raw-socket-reset probe lost transient classifier evidence when the Responses SDK projected a generic connection error. This PR fixes the reported prepared-payload composition for an already-captured transient failure; it deliberately does not broaden upstream transient-error classification or retry policy.

Sibling contract inspection: the existing native harness capture remains unchanged. Inspected upstream Codex codex-rs/protocol/src/protocol.rs:2062-2080,2140-2147 and codex-rs/app-server-protocol/src/protocol/v2/turn.rs:27-36 at 986ff1cc7ced for independent error/completion and interrupted/failed status contracts.

Test consolidation requested by Vito

  • Removed 67 net test/support lines; provider-error suite 231 → 125 lines. No production changes.
  • Kept real payload preparation plus eligibility coverage without mocked finalization backends or transcript writers. The real HTTP503/agent-loop/SQLite/full-finalizer regression remains intact, including one tool execution, a tool-free final request, and one persisted final answer.
  • Shared the settled-provider fixture and reused existing SSE/model helpers. Existing owner tests retain the stronger fallback/control cleanup coverage.
  • Replaced the misleading non-transient selector case with an actual transient/non-transient table at the context producer.
  • Both retained positive regressions still fail against the unfixed terminal gate and pass with the repair. 218 focused/sibling tests passed. Final four-file changed-scope gates passed (exit 0) and independent P0–P2 review is scoped-clean.
  • Updated-head CI: CI run 33919758509 completed successfully on exact published head 588f90ec9344e123ff645eafe1d3341fbc304ee6. The exact-head rollup watcher also completed GREEN (exit 0, zero pending checks). Publication metadata commit and tested cleanup commit share tree 095a3b15203fad77fbb3a4a6e079c73cfb7bc15d.

Review follow-up — September 4, 2026

Original implementation CI passed: CI run 33889653398, head 1a6c543. The subsequent cleanup changes tests only; updated-head CI is tracked above.

ClawSweeper’s latest durable review, reviewed September 4 at 17:43 UTC against 1a6c543f3663ca555ac1a170bec54f401907a433, reports no correctness or security findings, sufficient proof, and high confidence. It recommends ordinary maintainer review rather than automated merging. This is a review of the original implementation, not an exact-head review of the subsequent test-only cleanup.

Its current remaining items are explicitly retained, not treated as waived:

  • Message-delivery merge risk: the recovery gate affects whether a completed turn may produce a final answer. The producer-provenance boundary and existing settlement, no-delivery/media/async, cancellation, and structured-terminal-error gates remain unchanged by this cleanup; the before/after transport regression and safety negatives are retained. No concrete additional defect was identified.
  • Protected-label maintainer decision: a human maintainer must decide whether to land the bounded recovery change or request broader provider/channel evidence. This task only updates the tests and evidence; it does not merge, enable automerge, or claim maintainer approval.

The fresh independent P0–P2 review of the cleanup is scoped-clean. No separate actionable Rank-up moves: list is present in the latest durable review.

The parallel PR #138353 was closed at Vito’s request in favor of this canonical repair. VACInc’s co-author credit is preserved in the original commits and the test-consolidation commit.

Worked on by:

Co-authored-by: VACInc [email protected]

Team session

Worked on by


View the OpenClaw team session

roboclaw-bot and others added 2 commits September 4, 2026 15:25
Record producer-owned error payload provenance so generated provider errors
do not suppress isolated tool-free finalization after completed tool work.
Preserve structured refusals, delivery, async, cancellation, and silence gates.

Co-authored-by: VACInc <[email protected]>
Worked on by:
- @VACInc

Co-authored-by: VACInc <[email protected]>
OpenClaw-Publication: cf00ce96-8d54-4618-bff4-5c73f8a82b44
@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.

@roboclaw-bot
roboclaw-bot marked this pull request as ready for review September 4, 2026 15:28
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Sep 4, 2026

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The producer-side provenance is the right missing fact. Discounting only a payload explicitly marked terminalProviderError lets settled-tool finalisation proceed without shape-based guessing, while structured refusals, tool errors/presentations and prior authored output remain terminal. The no-replay and failure-honest fallback cases cover the risky boundary.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 1:43 PM ET / 17:43 UTC.

ClawSweeper review

What this changes

This PR marks generated terminal provider-error payloads so completed embedded tool runs can use the existing tool-free finalizer after a transient post-tool model failure.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep open. Current main still counts the generated provider-error payload as a reply, so the isolated finalizer cannot run; this patch corrects that narrow eligibility gap without a new correctness or security finding. The protected maintainer label leaves the merge decision to a maintainer.

Priority: P2
Reviewed head: 1a6c543f3663ca555ac1a170bec54f401907a433
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with real-transport regression evidence and no supported correctness or security finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The changed production owner is the terminal finalization eligibility resolver, fed by payload preparation. The supplied exact-head loopback test drives a real Responses HTTP transport through one completed tool, an injected transient 503, and a tool-free final request, observing one tool execution and one recovered answer; the built-in finalizer itself is separately covered by its existing caller/callee contract.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed production owner is the terminal finalization eligibility resolver, fed by payload preparation. The supplied exact-head loopback test drives a real Responses HTTP transport through one completed tool, an injected transient 503, and a tool-free final request, observing one tool execution and one recovered answer; the built-in finalizer itself is separately covered by its existing caller/callee contract.
Evidence reviewed 7 items Current-main behavior: Current main returns early only when finalization is unavailable, then counts the prepared provider-error payload; that leaves the reported transient post-tool case ineligible for finalization.
Producer-owned provenance: The introduced payload boundary records private metadata only when it creates the terminal provider-error surface; no wire payload shape changes.
Recovery safeguards: The introduced resolver discounts only producer-marked simple error payloads, then retains the existing settled-batch, delivery, media, asynchronous-work, cancellation, and terminal-error gates in the finalization owner.
Findings None None.
Security None None.

How this fits together

The embedded agent runner turns model and tool activity into reply payloads for delivery. After all tools settle, its finalizer may make one tool-free request for a summary while preserving cancellation, delivery, media, and unsafe-replay safeguards.

flowchart LR
  U[User turn] --> R[Embedded agent runner]
  R --> T[Completed tool work]
  T --> E[Transient final model error]
  E --> P[Reply payload preparation]
  P --> G{Settled-turn eligibility}
  G -->|eligible| F[Tool-free finalizer]
  G -->|not eligible| O[Existing error or fallback]
  F --> O
Loading

Decision needed

Question Recommendation
Should a maintainer merge this protected-label reliability repair now that its exact-head loopback and focused regression evidence cover the recovered path? Merge after maintainer review: Accept the bounded message-delivery recovery change, retaining the existing settlement and delivery guards.

Why: The PR is labeled maintainer, so automated cleanup must not make the final merge decision even though no discrete defect remains.

Before merge

  • Resolve merge risk (P1) - This changes a final-delivery recovery gate: a wrongly classified error could create an extra final reply after completed work. The introduced provenance check remains bounded by the existing exact-settlement, no-delivery, no-media, no-async-work, cancellation, and structured-terminal-error gates.
  • Complete next step (P2) - A maintainer must make the protected-label merge decision.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

PR surface

Source +5, Tests +523. Total +528 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 31 26 +5
Tests 3 523 0 +523
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 554 26 +528

Review metrics

Metric Value Why it matters
Production versus tests production +5 net; tests +523 The production growth is the private producer fact and resolver consolidation needed to replace payload-shape inference; the tests cover the recovered path and safety negatives.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #126848
Summary: This PR is the active candidate repair for the open transient post-tool final-summary 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 the bounded recovery path (recommended)
    Merge after protected-label maintainer review because the existing delivery and settlement guards remain in force and the real-transport regression covers the changed eligibility path.
  2. Pause for broader delivery evidence
    Request provider or channel-boundary proof before merge if the remaining concern is behavior beyond the exercised loopback transport.

Technical review

Best possible solution:

Keep this producer-to-owner repair as the sole path: mark only generated terminal provider errors privately, then let the existing guarded tool-free finalizer decide whether a summary is safe.

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

Yes. Current main visibly counts the generated provider error as a payload, and the added exact-head loopback test defines a focused transient-503, completed-tool reproduction path; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. Recording provenance at the payload producer and consuming it in the existing recovery owner is narrower and safer than inferring generated warnings from their visible shape or replaying the entire turn.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add merge-risk: 🚨 message-delivery: The PR changes when a settled turn can emit a recovered final reply, so a gate regression could affect reply delivery.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The changed production owner is the terminal finalization eligibility resolver, fed by payload preparation. The supplied exact-head loopback test drives a real Responses HTTP transport through one completed tool, an injected transient 503, and a tool-free final request, observing one tool execution and one recovered answer; the built-in finalizer itself is separately covered by its existing caller/callee contract.

Label justifications:

  • P2: This is a bounded reliability repair for agent replies after completed tool work.
  • merge-risk: 🚨 message-delivery: The PR changes when a settled turn can emit a recovered final reply, so a gate regression could affect reply delivery.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed production owner is the terminal finalization eligibility resolver, fed by payload preparation. The supplied exact-head loopback test drives a real Responses HTTP transport through one completed tool, an injected transient 503, and a tool-free final request, observing one tool execution and one recovered answer; the built-in finalizer itself is separately covered by its existing caller/callee contract.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed production owner is the terminal finalization eligibility resolver, fed by payload preparation. The supplied exact-head loopback test drives a real Responses HTTP transport through one completed tool, an injected transient 503, and a tool-free final request, observing one tool execution and one recovered answer; the built-in finalizer itself is separately covered by its existing caller/callee contract.

Evidence

What I checked:

Likely related people:

  • fuller-stack-dev: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Yigtwxx: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Peter Steinberger: 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-04T16:50:56.095Z sha 1a6c543 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Sep 4, 2026
roboclaw-bot and others added 2 commits September 4, 2026 21:08
Keep the real HTTP 503 and no-replay proof while consolidating fixtures and
removing mocked backend scaffolding. Test non-transient classification at
the actual context producer instead of manufacturing a missing context.

Worked on by:
- @VACInc

Co-authored-by: VACInc <[email protected]>
Worked on by:
- @VACInc

Co-authored-by: VACInc <[email protected]>
OpenClaw-Publication: f762ae96-6ea6-419b-96dd-18307295512e
@VACInc
VACInc merged commit ca3c749 into main Sep 4, 2026
185 checks passed
@VACInc
VACInc deleted the openclaw/open-pr-to-rectify-vacinc-s-gap branch September 4, 2026 21:30
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
…es (openclaw#138362)

* fix(agents): finalize settled work after transient provider errors

Record producer-owned error payload provenance so generated provider errors
do not suppress isolated tool-free finalization after completed tool work.
Preserve structured refusals, delivery, async, cancellation, and silence gates.

Co-authored-by: VACInc <[email protected]>

* fix(agents): recover final summaries after transient post-tool failures

Worked on by:
- @VACInc

Co-authored-by: VACInc <[email protected]>
OpenClaw-Publication: cf00ce96-8d54-4618-bff4-5c73f8a82b44

* test(agents): streamline settled finalization coverage

Keep the real HTTP 503 and no-replay proof while consolidating fixtures and
removing mocked backend scaffolding. Test non-transient classification at
the actual context producer instead of manufacturing a missing context.

Worked on by:
- @VACInc

Co-authored-by: VACInc <[email protected]>

* fix(agents): recover final summaries after transient post-tool failures

Worked on by:
- @VACInc

Co-authored-by: VACInc <[email protected]>
OpenClaw-Publication: f762ae96-6ea6-419b-96dd-18307295512e

---------

Co-authored-by: roboclaw-bot <[email protected]>
Co-authored-by: VACInc <[email protected]>
@VACInc

VACInc commented Sep 6, 2026

Copy link
Copy Markdown
Member

Related follow-up: #138985 has merged for the transport-classification and recovery-eligibility gap tracked in #138959. Linking the subsequent repair here for context; this does not classify the earlier recovery work as unnecessary or superseded. No state change is being made here.

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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

3 participants