Skip to content

fix(reef): provider error streams remain open after guard denial - #109196

Merged
steipete merged 2 commits into
openclaw:mainfrom
zhangguiping-xydt:fix/problem-batch-e20ce49214c7-3-reef-guard-unread-error-body
Jul 16, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
zhangguiping-xydt:fix/problem-batch-e20ce49214c7-3-reef-guard-unread-error-body

Conversation

@zhangguiping-xydt

@zhangguiping-xydt zhangguiping-xydt commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor
Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.

What Problem This Solves

Fixes an issue where Reef guard classification could leave a provider HTTP stream open when OpenAI or Anthropic returned non-success headers and then stalled the response body. Reef already denied the message fail-closed, but the rejected provider connection could remain alive.

Why This Change Was Made

Both production guard adapters now cancel every non-success response body before preserving the existing HTTP error and fail-closed verdict. Successful response parsing, provider payloads, schemas, and timeout behavior are unchanged.

User Impact

Reef users still receive a deny decision when a guard provider fails, while stalled provider error streams are released promptly instead of retaining HTTP resources.

Evidence

  • Added a regression covering both OpenAI and Anthropic non-success response ownership. Before the fix, both cases returned guard_failure but failed because the response body was not cancelled.
  • After updating the PR branch from current main, node scripts/run-vitest.mjs extensions/reef/protocol/guard.test.ts passed with 19 tests passed and 2 skipped.
  • A fresh real loopback HTTP proof called both production guard adapters against providers that returned a partial stalled 503 response. Each adapter issued one request, returned deny / guard_failure, and the server observed peerClosed=true.
  • ./node_modules/.bin/oxfmt --check extensions/reef/protocol/guard-adapters.ts extensions/reef/protocol/guard.test.ts passed.
  • ./node_modules/.bin/oxlint extensions/reef/protocol/guard-adapters.ts extensions/reef/protocol/guard.test.ts passed.
  • The branch update incorporated the upstream fix for the unrelated Knip dependency-check baseline; a fresh upstream check confirmed current main still does not cover the Reef response-cleanup contribution.

@openclaw-barnacle openclaw-barnacle Bot added channel: reef Channel integration: reef size: XS labels Jul 16, 2026
@clawsweeper

clawsweeper Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 16, 2026, 2:11 PM ET / 18:11 UTC.

Summary
This PR cancels OpenAI and Anthropic Reef guard response bodies on non-success HTTP responses and adds regression coverage for both adapters.

PR surface: Source +2, Tests +22. Total +24 across 2 files.

Reproducibility: yes. at source level: return a partial non-success provider response whose body remains open, then invoke either production adapter; the existing path reaches guard_failure without consuming that body. The PR's loopback proof reports the corresponding peer-close observation after the fix.

Review metrics: none identified.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

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

Rank-up moves:

  • none.

Next step before merge

  • [P2] This active implementation PR has no actionable patch finding requiring a separate repair job; it should continue through ordinary maintainer review and exact-head merge gates.

Security
Cleared: The focused response-cleanup and regression-test changes introduce no concrete authorization, credential, dependency, workflow, or supply-chain concern.

Review details

Best possible solution:

Keep cleanup in each Reef adapter's non-success response branch, preserving the current fail-closed verdict while explicitly releasing the adapter-owned Fetch body before returning.

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

Yes at source level: return a partial non-success provider response whose body remains open, then invoke either production adapter; the existing path reaches guard_failure without consuming that body. The PR's loopback proof reports the corresponding peer-close observation after the fix.

Is this the best way to solve the issue?

Yes. The adapters own these Fetch responses, so cancelling at their non-success early exits is narrower and safer than draining a potentially stalled body or changing shared timeout behavior.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add P2: This fixes a bounded production HTTP resource leak after Reef already reaches the correct fail-closed decision.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix loopback HTTP proof for both production adapters, including the deny result and server-observed peer closure for stalled partial 503 responses.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides after-fix loopback HTTP proof for both production adapters, including the deny result and server-observed peer closure for stalled partial 503 responses.

Label justifications:

  • P2: This fixes a bounded production HTTP resource leak after Reef already reaches the correct fail-closed decision.
  • 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 (live_output): The PR body provides after-fix loopback HTTP proof for both production adapters, including the deny result and server-observed peer closure for stalled partial 503 responses.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix loopback HTTP proof for both production adapters, including the deny result and server-observed peer closure for stalled partial 503 responses.
Evidence reviewed

PR surface:

Source +2, Tests +22. Total +24 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 2 0 +2
Tests 1 33 11 +22
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 35 11 +24

What I checked:

  • Response ownership: Both adapters currently reject non-success responses before consuming their bodies; the patch cancels each body at that exact early-exit point while preserving the existing error and fail-closed result. (extensions/reef/protocol/guard-adapters.ts:61, 05fd7b4d2db9)
  • Sibling coverage: The parameterized regression exercises both OpenAI and Anthropic adapters, verifies the existing deny/guard_failure outcome, and confirms the response stream's cancellation callback runs. (extensions/reef/protocol/guard.test.ts:168, 05fd7b4d2db9)
  • Real behavior proof: The PR body reports a loopback HTTP run against both production adapters using partial stalled 503 responses; both returned deny/guard_failure and the server observed peerClosed=true. (extensions/reef/protocol/guard-adapters.ts:61, 05fd7b4d2db9)
  • Stream cancellation contract: The Streams standard defines cancellation as immediately closing the readable stream, discarding queued chunks, and invoking the underlying source's cancellation mechanism, matching the intended connection cleanup. (streams.spec.whatwg.org)
  • Extension ownership boundary: The scoped extension policy keeps vendor-specific runtime behavior inside the owning plugin; changing the Reef guard adapters rather than core follows that boundary. (raw.githubusercontent.com) (extensions/AGENTS.md:1, 7133305bac6a)

Likely related people:

  • steipete: The available repository ownership evidence identifies this account for the ownership rules, but the inaccessible local git-history path prevents a stronger Reef-specific attribution; route with low confidence. (raw.githubusercontent.com) (role: adjacent owner; confidence: low; files: extensions/reef/protocol/guard-adapters.ts, extensions/reef/protocol/guard.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 (1 earlier review cycle)
  • reviewed 2026-07-16T17:01:21.708Z sha 05fd7b4 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Jul 16, 2026
@steipete
steipete merged commit 2cd2363 into openclaw:main Jul 16, 2026
120 of 125 checks passed
Monkey-wusky added a commit to Monkey-wusky/openclaw that referenced this pull request Jul 17, 2026
When the Cloudflare docs search API returns a non-OK status,
fetchDocsSearch threw without cancelling the response body.
This could leave the underlying connection open until GC.

Cancel the body before throwing, matching the pattern established
in reef guard adapters (openclaw#109196) and fetchOpenRouterModels.
steipete added a commit that referenced this pull request Jul 17, 2026
…ng (#109519)

* fix(googlechat): cancel non-OK cert fetch response body before throwing

When fetchChatCerts receives a non-OK response from the Google Chat
cert endpoint, it throws without cancelling the response body.
Cancel the body before throwing, matching the pattern established
in reef guard adapters (#109196) and fetchOpenRouterModels.

* test(googlechat): cover cert response cancellation

Co-authored-by: 毛宇豪0668001457 <[email protected]>

* test(googlechat): satisfy strict call-order types

Co-authored-by: 毛宇豪0668001457 <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
steipete pushed a commit to Monkey-wusky/openclaw that referenced this pull request Jul 17, 2026
When the Cloudflare docs search API returns a non-OK status,
fetchDocsSearch threw without cancelling the response body.
This could leave the underlying connection open until GC.

Cancel the body before throwing, matching the pattern established
in reef guard adapters (openclaw#109196) and fetchOpenRouterModels.
steipete pushed a commit that referenced this pull request Jul 17, 2026
When the Cloudflare docs search API returns a non-OK status,
fetchDocsSearch threw without cancelling the response body.
This could leave the underlying connection open until GC.

Cancel the body before throwing, matching the pattern established
in reef guard adapters (#109196) and fetchOpenRouterModels.
steipete pushed a commit to Monkey-wusky/openclaw that referenced this pull request Jul 17, 2026
When fetchClawRouterUsage receives a non-OK response, it throws
without cancelling the response body.  The finally block calls
release() which cleans up the dispatcher, but the unconsumed
body stays open.

Cancel the body before throwing, matching the pattern in
guard-adapters (openclaw#109196) and fetchOpenRouterModels.
steipete added a commit that referenced this pull request Jul 17, 2026
…109525)

* fix(clawrouter): cancel non-OK usage response body before throwing

When fetchClawRouterUsage receives a non-OK response, it throws
without cancelling the response body.  The finally block calls
release() which cleans up the dispatcher, but the unconsumed
body stays open.

Cancel the body before throwing, matching the pattern in
guard-adapters (#109196) and fetchOpenRouterModels.

* test: use explicit ClawRouter placeholder token

---------

Co-authored-by: Peter Steinberger <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 17, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 17, 2026
…ng (openclaw#109519)

* fix(googlechat): cancel non-OK cert fetch response body before throwing

When fetchChatCerts receives a non-OK response from the Google Chat
cert endpoint, it throws without cancelling the response body.
Cancel the body before throwing, matching the pattern established
in reef guard adapters (openclaw#109196) and fetchOpenRouterModels.

* test(googlechat): cover cert response cancellation

Co-authored-by: 毛宇豪0668001457 <[email protected]>

* test(googlechat): satisfy strict call-order types

Co-authored-by: 毛宇豪0668001457 <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 17, 2026
…aw#109508)

When the Cloudflare docs search API returns a non-OK status,
fetchDocsSearch threw without cancelling the response body.
This could leave the underlying connection open until GC.

Cancel the body before throwing, matching the pattern established
in reef guard adapters (openclaw#109196) and fetchOpenRouterModels.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 18, 2026
…penclaw#109525)

* fix(clawrouter): cancel non-OK usage response body before throwing

When fetchClawRouterUsage receives a non-OK response, it throws
without cancelling the response body.  The finally block calls
release() which cleans up the dispatcher, but the unconsumed
body stays open.

Cancel the body before throwing, matching the pattern in
guard-adapters (openclaw#109196) and fetchOpenRouterModels.

* test: use explicit ClawRouter placeholder token

---------

Co-authored-by: Peter Steinberger <[email protected]>
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…ng (openclaw#109519)

* fix(googlechat): cancel non-OK cert fetch response body before throwing

When fetchChatCerts receives a non-OK response from the Google Chat
cert endpoint, it throws without cancelling the response body.
Cancel the body before throwing, matching the pattern established
in reef guard adapters (openclaw#109196) and fetchOpenRouterModels.

* test(googlechat): cover cert response cancellation

Co-authored-by: 毛宇豪0668001457 <[email protected]>

* test(googlechat): satisfy strict call-order types

Co-authored-by: 毛宇豪0668001457 <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…aw#109508)

When the Cloudflare docs search API returns a non-OK status,
fetchDocsSearch threw without cancelling the response body.
This could leave the underlying connection open until GC.

Cancel the body before throwing, matching the pattern established
in reef guard adapters (openclaw#109196) and fetchOpenRouterModels.
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…penclaw#109525)

* fix(clawrouter): cancel non-OK usage response body before throwing

When fetchClawRouterUsage receives a non-OK response, it throws
without cancelling the response body.  The finally block calls
release() which cleans up the dispatcher, but the unconsumed
body stays open.

Cancel the body before throwing, matching the pattern in
guard-adapters (openclaw#109196) and fetchOpenRouterModels.

* test: use explicit ClawRouter placeholder token

---------

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

channel: reef Channel integration: reef 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: XS 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.

2 participants