Skip to content

fix(chutes): cancel userinfo error response body before returning null - #109677

Merged
steipete merged 1 commit into
openclaw:mainfrom
wangmiao0668000666:fix/chutes-userinfo-body-cancel
Jul 17, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
wangmiao0668000666:fix/chutes-userinfo-body-cancel

Conversation

@wangmiao0668000666

Copy link
Copy Markdown
Contributor

What Problem This Solves

The bundled Chutes OAuth plugin leaks an HTTP connection every time the userinfo probe returns a non-2xx response. fetchChutesUserInfo (extensions/chutes/oauth.ts:131) did if (!response.ok) { return null; } without consuming or cancelling response.body, so the underlying connection stays attached until the server's idle timeout reaps it. The userinfo probe runs on every login / token exchange and fails in normal operation (IdP throttling, transient 5xx, or tokens without profile scope), so repeated login or probe attempts accumulate half-open connections.

The core helper copy (src/agents/chutes-oauth.ts) received exactly this fix in 6467c19 ("fix(chutes): cancel userinfo error bodies"), but the extension copy — the file the bundled plugin actually loads via extensions/chutes/index.ts:16 — was left behind. This PR ports the same cancel to the extension sibling.

Why This Change Was Made

Adds await response.body?.cancel().catch(() => undefined); before return null on the non-ok userinfo path. Cancelling the unread body releases the connection immediately instead of waiting for idle timeout, and the .catch(() => undefined) keeps a broken stream from changing the established "failed userinfo resolves to null" contract.

This mirrors the merged error-body cancel pattern from #109196 (reef guard denial), #109071 (GitHub Copilot catalog error streams), and #109007 (Telegram getChat), and matches the core sibling fix 6467c19. No new abstraction: the plugin SDK exposes no shared cancel helper, each fixed surface keeps the same inline one-liner, and extensions cannot import src/** internals.

The other non-ok path in the same file — token exchange via assertOkOrThrowProviderError (extensions/chutes/oauth.ts:172) — already consumes the error body through the bounded, redacted provider error reader (#97808, #103569), so it needs no change. Scope stays on the userinfo early return: 2 production lines.

User Impact

  • Failed Chutes userinfo probes no longer pin HTTP connections until idle timeout; repeated login/probe attempts stop accumulating sockets.
  • Login behavior is otherwise unchanged: a failed userinfo lookup still resolves to null, and issued tokens are kept without profile enrichment.

Evidence

Code path (source verified)

Layer File Line Behavior
Plugin entry extensions/chutes/index.ts 16 bundled plugin imports loginChutes from this file
Login flow extensions/chutes/oauth.ts 194 exchangeChutesCodeForTokens awaits fetchChutesUserInfo (optional enrichment; errors swallowed unless caller aborted)
Probe extensions/chutes/oauth.ts 124-130 fetch(CHUTES_USERINFO_ENDPOINT) with bearer token
Bug (before) extensions/chutes/oauth.ts 131-133 non-ok → return null with body unread → connection held until idle timeout
Fix (after) extensions/chutes/oauth.ts 131-135 non-ok → await response.body?.cancel().catch(() => undefined) → return null
Unaffected sibling path extensions/chutes/oauth.ts 172 token exchange non-ok goes through assertOkOrThrowProviderError, which reads the error body under the provider cap

Regression test — cancel observed through the production login flow

extensions/chutes/oauth.test.ts gains "cancels the userinfo error response body when profile lookup fails": the stubbed fetch returns a 200 token response, then a 503 Response whose body is a real ReadableStream with a cancel() tracker. The test drives the production wrapper loginChutes → exchangeChutesCodeForTokens → fetchChutesUserInfo and asserts the stream was cancelled, while the issued credentials survive without email/accountId enrichment.

Control-red

Same test against the unfixed source (the two production lines reverted): Tests 1 failed | 6 skipped (7) — the new test fails at expect(canceled).toBe(true) because nothing cancels the stream on the unfixed path. With the fix: Tests 7 passed (7).

Test suite

$ node scripts/run-vitest.mjs run extensions/chutes/oauth.test.ts
 Test Files  1 passed (1)
      Tests  7 passed (7)

Lint / typecheck / whitespace

$ node scripts/run-oxlint.mjs extensions/chutes/oauth.ts extensions/chutes/oauth.test.ts
(exit 0, no findings)
$ node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.extensions.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/extensions-test.tsbuildinfo
(exit 0, no errors)
$ git diff --check origin/main
(clean)

What was not tested

  • Live Chutes IdP behavior — no credentials available; the regression test uses a real ReadableStream body, which exercises the same response.body.cancel() path a wire response would.
  • The core src/agents/chutes-oauth.ts copy — already fixed in 6467c19 with its own regression test; this PR only brings the extension sibling to parity.

AI-assisted; reviewed before submission.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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 17, 2026
@clawsweeper

clawsweeper Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 17, 2026, 1:45 AM ET / 05:45 UTC.

Summary
The PR cancels a non-success Chutes userinfo response body before returning null and adds regression coverage through the bundled plugin login flow.

PR surface: Source +2, Tests +41. Total +43 across 2 files.

Reproducibility: no. high-confidence real HTTP reproduction is supplied. Current source and the constructed-stream regression clearly expose the unread-body path, but a loopback or live stalled response is still needed to verify transport cleanup.

Review metrics: none identified.

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 loopback or live HTTP output that observes prompt peer connection closure after a stalled userinfo error response.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR proves cancellation only with a stubbed fetch and constructed stream; before merge, add a redacted loopback or live HTTP run showing the stalled non-success response closes promptly, then update the PR body to trigger review or ask a maintainer for @clawsweeper re-review.

Risk before merge

  • [P1] The constructed-stream test proves that cancel() is invoked, but it does not demonstrate that a real stalled HTTP response releases the peer connection or transport resources as claimed.

Maintainer options:

  1. Decide the mitigation before merge
    Keep the owner-local cancellation and regression test, then add redacted loopback HTTP proof showing that a stalled non-2xx userinfo response closes promptly while login still returns the issued credentials without profile enrichment.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] No code repair is identified; the contributor needs to supply real HTTP behavior proof, which an automated patch worker cannot create on their behalf.

Security
Cleared: The focused Fetch response cleanup and test change introduces no concrete security or supply-chain concern.

Review details

Best possible solution:

Keep the owner-local cancellation and regression test, then add redacted loopback HTTP proof showing that a stalled non-2xx userinfo response closes promptly while login still returns the issued credentials without profile enrichment.

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

No high-confidence real HTTP reproduction is supplied. Current source and the constructed-stream regression clearly expose the unread-body path, but a loopback or live stalled response is still needed to verify transport cleanup.

Is this the best way to solve the issue?

Yes, the inline cancellation is the narrowest maintainable fix because the bundled plugin owns this code and cannot import core internals; merge readiness still depends on real HTTP proof rather than another implementation change.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add P2: This is a normal-priority resource-lifecycle bug in an optional provider login path with limited blast radius and preserved user-facing behavior.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR proves cancellation only with a stubbed fetch and constructed stream; before merge, add a redacted loopback or live HTTP run showing the stalled non-success response closes promptly, then update the PR body to trigger review or ask a maintainer for @clawsweeper re-review.

Label justifications:

  • P2: This is a normal-priority resource-lifecycle bug in an optional provider login path with limited blast radius and preserved user-facing behavior.
  • 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 proves cancellation only with a stubbed fetch and constructed stream; before merge, add a redacted loopback or live HTTP run showing the stalled non-success response closes promptly, then update the PR body to trigger review or ask a maintainer for @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +2, Tests +41. Total +43 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 2 0 +2
Tests 1 41 0 +41
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 43 0 +43

What I checked:

  • Current-main gap: At current main, the bundled plugin's userinfo non-success branch returns null without consuming or cancelling the response body, so the requested cleanup is not already implemented. (extensions/chutes/oauth.ts:131, 630b16805c3f)
  • Focused implementation: The PR adds a guarded body cancellation while preserving the established optional-profile failure result, and the regression test verifies that issued credentials remain usable without profile enrichment. (extensions/chutes/oauth.ts:132, 68d9d9b1c7de)
  • Runtime contract: Undici's official documentation warns that Node response bodies should always be consumed or cancelled to avoid excessive connection usage, reduced reuse, stalls, or deadlocks. (github.com)
  • Sibling precedent: The PR follows the same cancellation behavior already applied to the core Chutes userinfo helper in commit 6467c19 and to other recently merged non-success Fetch paths. (src/agents/chutes-oauth.ts, 6467c1962a)
  • Proof limitation: The PR explicitly says it did not exercise a live Chutes endpoint; its supplied behavioral evidence uses a fetch stub and constructed Response, without a loopback or live HTTP peer demonstrating socket or stream closure. (extensions/chutes/oauth.test.ts:273, 68d9d9b1c7de)

Likely related people:

  • ZOOWH: Their merged work routed bundled and core Chutes token failures through the current bounded, redacted provider-error boundary and touched both files central to this PR. (role: recent Chutes OAuth contributor; confidence: high; commits: 61893247ec7d; files: extensions/chutes/oauth.ts, extensions/chutes/oauth.test.ts, src/agents/chutes-oauth.ts)
  • Pick-cat: Their merged Chutes OAuth work established bounded reads and cancellation for token error responses, making them relevant to response-body ownership in this provider. (role: earlier Chutes error-body contributor; confidence: medium; commits: 9949f6bd8500; files: src/agents/chutes-oauth.ts, src/agents/chutes-oauth.flow.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.

@steipete steipete self-assigned this Jul 17, 2026
@steipete
steipete merged commit 538263b into openclaw:main Jul 17, 2026
120 of 126 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: chutes P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants