Skip to content

fix: recover final answers after WebSocket disconnects - #138985

Merged
VACInc merged 7 commits into
mainfrom
openclaw/openclaw-openclaw-vacinc-issue-138959
Sep 6, 2026
Merged

VACInc merged 7 commits into
mainfrom
openclaw/openclaw-openclaw-vacinc-issue-138959

Conversation

@roboclaw-bot

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

Copy link
Copy Markdown
Collaborator

Closes #138959

What Problem This Solves

A transient provider WebSocket disconnect after tool calls have settled can leave the user with a generic provider-error warning instead of a final answer. Opaque transport errors lost their classification evidence, and assistant-reported errors did not reach the existing tool-free finalizer.

Why This Change Was Made

  • Preserve structured transport codes and nested causes at the WebSocket provider boundary; distinguish transient connection/server closes from permanent policy/protocol closes.
  • Let the attempt-result owner capture recovery context for both thrown prompt failures and completed-assistant failures, using the existing terminal projection and transient-network policy.
  • Remove the payload consumer's redundant thrown-failure requirement. Only producer-marked synthetic provider warnings accompanied by recovery context are discounted; authored answers are not.
  • Honor the permanent-close marker in the existing terminal-assistant-error guard, so retry-looking reason text cannot override it in retry or finalization policy.
  • Adapt the composed regression fixture to the current three-argument attempt-result API after the upstream refactor. This adaptation changes tests only.

The change reuses the existing isolated finalizer. It does not add a retry loop, broaden generic WebSocket message matching, change configuration or storage, or replay a settled tool operation. Production change: +71/-40 (net +31); tests and test support: net +501; assertion baseline: net 0. The production increase records explicit transport facts and supports the provider's actual failure representation rather than adding another recovery mechanism.

User Impact

After eligible completed tool work, transient transport failure can produce a final summary without repeating actions. Permanent close codes and refusals take precedence over message text. Existing cancellation, timeout, unfinished-tool, asynchronous-work, intentional-silence, and already-delivered-output exclusions remain in force. Recovery summarizes completed results; it does not imply that failed tools succeeded.

Evidence

Final candidate: 5808e6a, based on ba45712.

Focused regression command:

node scripts/run-vitest.mjs packages/ai/src/providers/openai-chatgpt-responses.websocket-errors.test.ts src/agents/embedded-agent-runner/run/attempt-result.test.ts src/agents/embedded-agent-runner/run/settled-turn-finalization.provider-error.test.ts src/agents/embedded-agent-runner/run/settled-turn-finalization.transport.test.ts src/agents/embedded-agent-runner/run/settled-tool-evidence.test.ts src/llm/utils/retry.test.ts src/infra/unhandled-rejections.test.ts

Review follow-up: the previous ClawSweeper payload-gate P1 and requested real-assistant composition coverage are addressed. The permanent-close follow-up also has a regression for retry-looking reason text and stale finalization context. Fresh ClawSweeper review of this exact final head completed September 6, 2026 at 14:10 UTC with no actionable findings, no before-merge items, and proof marked sufficient for this internal-reliability boundary. Review: #138985 (comment).

Worked on by:


View the OpenClaw team session

@clawsweeper

clawsweeper Bot commented Sep 5, 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: M maintainer Maintainer-authored PR labels Sep 5, 2026
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review September 5, 2026 09:30
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 6, 2026, 10:25 AM ET / 14:25 UTC.

ClawSweeper review

What this changes

Preserves WebSocket failure classifications and lets OpenClaw recover a final answer after completed tool work without repeating those tools.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary: current main still has the reported recovery gap. The earlier payload-gate finding is resolved, the supplied transport proof covers the repaired boundary, and no actionable defect remains.

Priority: P1
Reviewed head: 5808e6afab09450effc5b8712cdab6d2569e1256

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful transport-boundary proof and resolved prior findings.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (linked_artifact): The supplied final-head execution record and inspected HTTP/WebSocket harness exercise actual transport clients through the changed projector and finalization owners, observing one write, tool-free recovery, one final payload, and preserved history; deployed-channel outage testing is outside this bounded internal-reliability proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The supplied final-head execution record and inspected HTTP/WebSocket harness exercise actual transport clients through the changed projector and finalization owners, observing one write, tool-free recovery, one final payload, and preserved history; deployed-channel outage testing is outside this bounded internal-reliability proof.
Evidence reviewed 9 items Current main still needs this repair: The fetched main revision requires a thrown prompt failure before capturing recovery context; completed-assistant errors remain excluded. Comparison with the reviewed head confirms the central production changes are still absent.
Latest release retains opaque transport errors: The v2026.9.2 provider still constructs an unclassified WebSocket error and uses the previous close-error representation.
Producer and consumer repair: The context producer now accepts structured assistant-reported transport failures while preserving timeout and abort exclusions. The payload consumer discounts only producer-marked synthetic warnings with recovery context, resolving the earlier review finding.
Findings None None.
Security None None.

How this fits together

OpenClaw’s provider adapter turns network failures into assistant results. The agent runner uses those results and completed-tool evidence to decide whether its existing tool-free finalizer can produce an answer.

flowchart TD
  A[Provider WebSocket] --> B[Classify transport failure]
  B --> C[Project assistant result]
  D[Completed tool results] --> C
  C --> E{Recovery checks pass?}
  E -->|Yes| F[Tool-free finalizer]
  F --> G[Final answer]
  E -->|No| H[Preserve terminal outcome]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +31, Tests +501, Other 0. Total +532 across 14 files.

View PR surface stats
Area Files Added Removed Net
Source 6 71 40 +31
Tests 7 568 67 +501
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 14 640 108 +532

Review metrics

Metric Value Why it matters
Recovery boundary proof 2 transports; request tool counts [1, 1, 0] The composed scenarios verify that recovery produces an answer without repeating the completed tool.
Production versus test growth Production net +31; tests and support net +501 Production growth records structured transport facts and repairs the existing recovery gates; most added code supplies regression coverage.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #138959
Summary: This PR is the candidate repair for the reported classification and finalization gap; persistence starvation and transcript rewriting have separate owners.

Members:

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

Technical review

Best possible solution:

Keep recovery in the existing tool-free finalizer, driven by structured provider facts and exact tool-settlement evidence.

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

Yes: current-main source shows opaque WebSocket errors losing classification and assistant-reported failures missing recovery context; the supplied controlled disconnect scenario exercises that path. This read-only review did not execute it.

Is this the best way to solve the issue?

Yes: repairing transport facts and the existing producer/consumer gates is narrower than introducing another retry mechanism, and preserves the no-replay exclusions.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 13cb0bafd53c.

Labels

Label justifications:

  • P1: The linked report establishes a broken agent workflow where completed tool work receives a generic provider warning instead of a final answer.
  • 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 (linked_artifact): The supplied final-head execution record and inspected HTTP/WebSocket harness exercise actual transport clients through the changed projector and finalization owners, observing one write, tool-free recovery, one final payload, and preserved history; deployed-channel outage testing is outside this bounded internal-reliability proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied final-head execution record and inspected HTTP/WebSocket harness exercise actual transport clients through the changed projector and finalization owners, observing one write, tool-free recovery, one final payload, and preserved history; deployed-channel outage testing is outside this bounded internal-reliability proof.

Evidence

What I checked:

Likely related people:

  • VACInc: 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 (4 earlier review cycles)
  • reviewed 2026-09-05T10:09:00.408Z sha eca331f :: blocked before merge. :: [P1] Carry assistant-reported failures through the payload gate
  • reviewed 2026-09-05T13:45:38.444Z sha 09c5591 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-06T14:10:16.771Z sha 5808e6a :: needs maintainer review before merge. :: none
  • reviewed 2026-09-06T14:17:01.720Z sha 5808e6a :: needs maintainer review before merge. :: none

@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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 5, 2026
roboclaw-bot and others added 7 commits September 6, 2026 13:59
Classify transport-level WebSocket failures at the provider boundary and carry completed-assistant failures through the canonical terminal outcome policy. Permanent close codes and timeout observations remain fail-closed.

Worked on by:
- @VACInc

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

OpenClaw-Publication: dfe624ba-e8f9-4b4b-b100-7d095034170a

Co-authored-by: VACInc <[email protected]>
Use the validated settled-turn recovery context as the provider-warning gate regardless of whether the provider failure was thrown or returned as an assistant error.

Worked on by:
- @VACInc

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

OpenClaw-Publication: 7444a256-821a-41c7-9444-ebdc6714d3e2

Co-authored-by: VACInc <[email protected]>
Exercise the real failed assistant through the shared attempt projector, terminal preparation, and tool-free finalization after HTTP and WebSocket failures. Preserve the completed tool and transcript exactly once.

Worked on by:
- @VACInc

Co-authored-by: VACInc <[email protected]>
Give the structured permanent-close marker precedence over retry-looking text in the existing terminal-error guard. Preserve refusal and no-replay behavior for ordinary retries and settled-turn finalization.

Worked on by:
- @VACInc

Co-authored-by: VACInc <[email protected]>
Keep the same transport-failure assistant, transcript and settled-tool evidence while following the three-argument execution, settled and prompt contract introduced on main.

Worked on by:
- @VACInc

Co-authored-by: VACInc <[email protected]>
@roboclaw-bot
roboclaw-bot force-pushed the openclaw/openclaw-openclaw-vacinc-issue-138959 branch from 09c5591 to 5808e6a Compare September 6, 2026 14:00
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

Please review candidate 5808e6a. The previous payload-gate P1 and actual-assistant HTTP/WebSocket composition coverage are addressed. The related permanent-close disposition now takes precedence in the existing terminal-error guard, including retry-looking reason text; the fixture follows the current upstream three-argument projector API.

The PR body now distinguishes preserved pre-refresh local evidence from current-head validation. Fresh hosted CI is running at https://github.com/openclaw/openclaw/actions/runs/34037838739. Local cooldown and stale dependency limitations are disclosed; no policies or package pins were weakened.

Review only: no merge, auto-merge, or autofix requested.

@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 6, 2026
@VACInc

VACInc commented Sep 6, 2026

Copy link
Copy Markdown
Member

Related follow-up: #140335 has merged into main as 9a9b92322d7.

It fixes a separate liveness gap: the built-in model-stream watchdog remains armed while its consumer is paused, and ChatGPT Responses WebSocket progress reaches the signal observed by that watchdog.

#138985 remains the fix for transport-error classification and eligible final-answer recovery after tools settle. These changes are complementary, not replacements. #140335 does not broaden finalization eligibility or authorize replaying settled tools.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 7, 2026
* fix(agent): recover settled turns after websocket failures

Classify transport-level WebSocket failures at the provider boundary and carry completed-assistant failures through the canonical terminal outcome policy. Permanent close codes and timeout observations remain fail-closed.

Worked on by:
- @VACInc

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

* fix: recover final answers after WebSocket disconnects

Worked on by:
- @VACInc

OpenClaw-Publication: dfe624ba-e8f9-4b4b-b100-7d095034170a

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

* fix(agent): finalize assistant-reported transport failures

Use the validated settled-turn recovery context as the provider-warning gate regardless of whether the provider failure was thrown or returned as an assistant error.

Worked on by:
- @VACInc

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

* Publish openclaw/openclaw-openclaw-vacinc-issue-138959

Worked on by:
- @VACInc

OpenClaw-Publication: 7444a256-821a-41c7-9444-ebdc6714d3e2

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

* test(agent): prove WebSocket finalization without replay

Exercise the real failed assistant through the shared attempt projector, terminal preparation, and tool-free finalization after HTTP and WebSocket failures. Preserve the completed tool and transcript exactly once.

Worked on by:
- @VACInc

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

* fix(agent): honor permanent WebSocket close disposition

Give the structured permanent-close marker precedence over retry-looking text in the existing terminal-error guard. Preserve refusal and no-replay behavior for ordinary retries and settled-turn finalization.

Worked on by:
- @VACInc

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

* test(agent): adapt settled-turn fixture to current result API

Keep the same transport-failure assistant, transcript and settled-tool evidence while following the three-argument execution, settled and prompt contract introduced on main.

Worked on by:
- @VACInc

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

---------

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

VACInc commented Sep 7, 2026

Copy link
Copy Markdown
Member

Related transcript-state repair #138984 has now merged as b0ae5b6.

It addresses atomic history publication, reset-crossing amplification, and selected-reader context. It does not replace the WebSocket liveness or final-answer recovery work tracked here. Similar visible stalls or stale answers can have different owners; these fixes remain complementary.

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 P1 High-priority user-facing bug, regression, or broken workflow. 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

Development

Successfully merging this pull request may close these issues.

[Bug]: WebSocket error classification prevents final-answer recovery after tools settle

2 participants