Skip to content

fix(agents): preserve sanitized stream cancellation - #110427

Merged
steipete merged 3 commits into
openclaw:mainfrom
zenglingbiao:fix/compaction-retry-abortable-backoff
Jul 18, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
zenglingbiao:fix/compaction-retry-abortable-backoff

Conversation

@zenglingbiao

@zenglingbiao zenglingbiao commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Centralize best-effort reader cancellation for guarded OpenAI-compatible response streams. Successful JSON-to-SSE and SSE sanitizer wrappers now preserve intentional downstream cancellation when an upstream source's cancellation algorithm rejects.

Problem

Web Streams forwards an underlying source's cancellation failure through reader.cancel(). These two sanitizer wrappers returned that secondary teardown failure, so the OpenAI SDK's awaited iterator cleanup could escape or mask the consumer's intended cancellation.

Canceling an already-closed stream resolves normally; the relevant failure case is a rejecting underlying cancellation algorithm.

Fix

  • Add one provider-transport-local cancelReaderBestEffort helper with the teardown invariant documented at its owner boundary.
  • Reuse it across all eight existing best-effort reader-cancellation sites while preserving each call site's awaited or fire-and-forget ordering.
  • Add production-path regression coverage for both successful JSON-to-SSE synthesis and SSE sanitization.

Evidence

  • Before-fail: removing the two sanitizer quiet-cancel calls made both new cases reject in both agent test projects.
  • After-pass: cancellation regressions passed 4/4.
  • Provider transport tests passed 96/96; integration passed 1/1.
  • Targeted format, lint, and diff checks passed.
  • Fresh structured autoreview reported no actionable findings at 0.98 confidence.
  • Exact merge-head proof: Node 24 passed provider transport, integration, and workspace-baseline tests 155/155; hosted CI run 29662071511 passed at 2598a07542f9643ad2f98ea1d051b8d164fc6a81.

No config, request, routing, SSRF, provider-selection, protocol, or normal stream-consumption behavior changes.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Jul 18, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jul 18, 2026
@clawsweeper

clawsweeper Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 18, 2026, 5:45 PM ET / 21:45 UTC.

Summary
The PR introduces a shared best-effort reader-cancellation helper and tests JSON-to-SSE and SSE cleanup when upstream cancellation rejects.

PR surface: Source +9, Tests +52. Total +61 across 2 files.

Reproducibility: no. high-confidence live reproduction is provided. The source path and focused test clearly model a rejecting upstream ReadableStream cancellation, but the reported runtime condition has not been demonstrated after the fix in a real setup.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: serialized state: src/agents/provider-transport-fetch.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof from a real setup is added.

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

Rank-up moves:

  • [P1] Add redacted real-runtime evidence that a rejecting upstream cancellation does not reject downstream cancellation.
  • Update the PR body with that evidence; if a fresh review does not trigger, ask a maintainer to comment @clawsweeper re-review.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body and tests show the intended mocked rejection path, but no after-fix terminal output, logs, recording, or live runtime artifact demonstrates the changed behavior; add redacted evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] Merging without a redacted real-runtime demonstration leaves the intended protection against an actual rejecting stream cancellation unproven; the current evidence is a focused mock-based test only.

Maintainer options:

  1. Decide the mitigation before merge
    Keep the shared cleanup helper and add redacted terminal output, runtime logs, or a reproducible live stream artifact showing that a rejecting source cancellation does not reject downstream cancellation while normal stream cleanup still completes.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] The only remaining gate is contributor-owned real behavior proof; no narrow automated repair can establish the contributor's runtime scenario.

Security
Cleared: The two-file diff changes only local stream-cleanup control flow and focused tests; it adds no dependency, workflow, secret, permission, or supply-chain surface.

Review details

Best possible solution:

Keep the shared cleanup helper and add redacted terminal output, runtime logs, or a reproducible live stream artifact showing that a rejecting source cancellation does not reject downstream cancellation while normal stream cleanup still completes.

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

No high-confidence live reproduction is provided. The source path and focused test clearly model a rejecting upstream ReadableStream cancellation, but the reported runtime condition has not been demonstrated after the fix in a real setup.

Is this the best way to solve the issue?

Yes, subject to real behavior proof. A single helper makes the cleanup-only error policy explicit and avoids leaving sanitizer and capped-response wrappers with divergent cancellation semantics.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.

Label justifications:

  • P2: This is a bounded agent-stream reliability fix with limited blast radius and no demonstrated active user outage.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body and tests show the intended mocked rejection path, but no after-fix terminal output, logs, recording, or live runtime artifact demonstrates the changed behavior; add redacted evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +9, Tests +52. Total +61 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 17 8 +9
Tests 1 52 0 +52
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 69 8 +61

What I checked:

  • Centralized cleanup behavior: The branch adds cancelReaderBestEffort, which suppresses rejection only for reader-cancellation cleanup and applies it to capped-response and sanitized JSON/SSE wrapper paths. (src/agents/provider-transport-fetch.ts:99, 2598a07542f9)
  • Focused regression coverage: The added parameterized test makes the upstream stream's cancel hook reject, then verifies both JSON-to-SSE synthesis and SSE sanitization still let downstream response.body.cancel() resolve and release the fetch guard. (src/agents/provider-transport-fetch.test.ts:1326, 2598a07542f9)
  • Prior review continuity: The latest completed ClawSweeper review found no code defect and retained one merge gate: contributor-supplied after-fix real behavior proof. The supplied context does not show new real-runtime evidence after that review. (23b59e007b19)

Likely related people:

  • steipete: Authored the branch commit that preserved sanitized-stream cancellation and integrated the shared cleanup helper now under review. (role: recent area contributor; confidence: medium; commits: 23b59e007b19, 2598a07542f9; files: src/agents/provider-transport-fetch.ts, src/agents/provider-transport-fetch.test.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.
Review history (7 earlier review cycles)
  • reviewed 2026-07-18T05:14:48.348Z sha 7f64c70f39871fe6e9e569628c1dab8d03b36796 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T06:08:41.223Z sha 7f64c70f39871fe6e9e569628c1dab8d03b36796 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T06:50:56.927Z sha 7f64c70f39871fe6e9e569628c1dab8d03b36796 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T16:03:03.708Z sha d964b2f :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T16:32:49.074Z sha d964b2f :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T16:39:35.421Z sha d964b2f :: needs real behavior proof before merge. :: [P2] Preserve rejected cancellation results
  • reviewed 2026-07-18T21:21:21.755Z sha 23b59e0 :: needs real behavior proof before merge. :: none

@zenglingbiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 18, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jul 18, 2026
@zenglingbiao
zenglingbiao force-pushed the fix/compaction-retry-abortable-backoff branch from 7f64c70 to d964b2f Compare July 18, 2026 15:59
@zenglingbiao zenglingbiao changed the title fix(compaction): make retry backoff abortable with caller signal fix(agents): add .catch() to reader.cancel() to prevent unhandled rejection Jul 18, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 18, 2026
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 18, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Jul 18, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jul 18, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Jul 18, 2026
@steipete steipete changed the title fix(agents): add .catch() to reader.cancel() to prevent unhandled rejection fix(agents): preserve sanitized stream cancellation Jul 18, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 18, 2026
@steipete
steipete merged commit 490ab26 into openclaw:main Jul 18, 2026
133 of 134 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 19, 2026
* fix(agents): add .catch() to reader.cancel() to prevent unhandled rejection

* fix(agents): preserve sanitized stream cancellation

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

---------

Co-authored-by: Peter Steinberger <[email protected]>
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
* fix(agents): add .catch() to reader.cancel() to prevent unhandled rejection

* fix(agents): preserve sanitized stream cancellation

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

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants