Repository navigation
fix(reef): provider error streams remain open after guard denial - #109196
Conversation
…unread-error-body
|
Codex review: needs maintainer review before merge. Reviewed July 16, 2026, 2:11 PM ET / 18:11 UTC. Summary 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 follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Next step before merge
Security Review detailsBest 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 changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +2, Tests +22. Total +24 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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
Review history (1 earlier review cycle)
|
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.
…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]>
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.
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.
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.
…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]>
…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]>
…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.
…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]>
…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]>
…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.
…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]>
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
guard_failurebut failed because the response body was not cancelled.main,node scripts/run-vitest.mjs extensions/reef/protocol/guard.test.tspassed with 19 tests passed and 2 skipped.503response. Each adapter issued one request, returneddeny/guard_failure, and the server observedpeerClosed=true../node_modules/.bin/oxfmt --check extensions/reef/protocol/guard-adapters.ts extensions/reef/protocol/guard.test.tspassed../node_modules/.bin/oxlint extensions/reef/protocol/guard-adapters.ts extensions/reef/protocol/guard.test.tspassed.mainstill does not cover the Reef response-cleanup contribution.