Skip to content

fix(github-copilot): cancel unread device-flow error bodies before throwing - #112268

Merged
steipete merged 2 commits into
openclaw:mainfrom
xydt-juyaohui:fix/copilot-cancel-device-flow-non-ok-body
Aug 2, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
xydt-juyaohui:fix/copilot-cancel-device-flow-non-ok-body

Conversation

@xydt-juyaohui

@xydt-juyaohui xydt-juyaohui commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

When GitHub Copilot device-code or access-token requests return a non-OK response with an unread streaming body, postGitHubDeviceFlowForm throws immediately and then closes the SSRF-guarded dispatcher in finally. Dispatcher release waits for the still-open response, unnecessarily delaying the existing HTTP error.

Why This Change Was Made

Cancel the unread response body at its owning device-flow helper before throwing, so the existing release closes promptly. Both /login/device/code and /login/oauth/access_token share this owner. The HTTP error labels, successful JSON reads, OAuth polling behavior, SSRF policy, and public provider configuration remain unchanged.

Original fix and both device-flow regression tests: @xydt-juyaohui. Maintainer follow-up reduced the lifecycle explanation to one precise owner-boundary comment.

User Impact

Copilot sign-in reports upstream non-OK HTTP failures without waiting on an unread, never-ending response body. Successful device authorization and token polling continue through their existing paths.

Evidence

Focused actual plugin suite:

OPENCLAW_VITEST_FS_MODULE_CACHE_PATH=/private/tmp/openclaw-vitest-pr-112268-s23-840c42eb node scripts/run-vitest.mjs extensions/github-copilot/login.test.ts

Result: 1 file passed; 14 tests passed, including both new unread-body cancellation regressions and unchanged device/token HTTP error labels.

Real localhost HTTP/Undici proof used the production fetchWithSsrFGuard against an ephemeral 127.0.0.1 server that returned HTTP 503, streamed a partial JSON body, and intentionally never completed the response. Comparing the existing release-only path with cancel-before-release:

  • /login/device/code: 100.9 ms → 3.0 ms; HTTP status remained 503; response.bodyUsed changed from false to true.
  • /login/oauth/access_token: 100.5 ms → 0.8 ms; HTTP status remained 503; response.bodyUsed changed from false to true.

A separate real localhost HTTP 200 run used production fetchWithSsrFGuard and readProviderJsonResponse; all five actual response shapes were consumed unchanged: device code, authorization_pending, slow_down, access_denied, and authorized token.

The localhost fixtures prove the production guarded HTTP transport and response-body lifecycle; the focused plugin suite proves the public device-flow HTTP errors and polling behavior. No external GitHub OAuth service or live account was used.

@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 24, 2026
@clawsweeper

clawsweeper Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 2, 2026, 7:24 AM ET / 11:24 UTC.

ClawSweeper review

What this changes

This PR cancels unread GitHub Copilot device-flow error response streams before releasing the guarded HTTP dispatcher, with regressions for both device-code and access-token failures.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

The patch addresses a real current-main lifecycle gap at the device-flow helper: non-OK responses are thrown before their body is consumed, then the guarded dispatcher is released. The PR cancels that unread body at the owning boundary, preserves existing error text and successful polling, and supplies focused tests plus real localhost guarded-transport proof. No discrete repair finding remains; this should proceed through normal exact-head maintainer merge review.

Priority: P2
Reviewed head: c46096d847f65cefb7db55c0774dc6a8beb0e821

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, owner-boundary repair with strong real transport proof, regression coverage for both call paths, and no supported correctness or security concern.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body provides after-fix localhost evidence using production fetchWithSsrFGuard against never-ending error responses, with measured release-latency improvement and focused plugin regressions; no private external OAuth account was needed.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body provides after-fix localhost evidence using production fetchWithSsrFGuard against never-ending error responses, with measured release-latency improvement and focused plugin regressions; no private external OAuth account was needed.
Evidence reviewed 6 items Current-main defect boundary: On current main, the shared helper throws immediately for a non-OK response and only then reaches its finally block, which awaits the guarded transport release; the non-success body is not otherwise consumed in that branch.
Guarded transport contract: The guarded fetch implementation defines release as a one-time cleanup that closes the supplied dispatcher, so response-body cleanup belongs before the helper's finally release rather than in a caller.
Patch and regression scope: The PR head adds awaited best-effort cancellation only on the non-OK branch and adds separate cancellation regressions for the device-code and access-token paths; the success JSON path and provider-facing error labels remain unchanged.
Findings None None.
Security None None.

How this fits together

The GitHub Copilot plugin posts device-flow forms through OpenClaw's SSRF-guarded HTTP transport. The helper either parses a successful provider response for the login/polling flow or releases its dispatcher and reports the upstream HTTP failure.

flowchart LR
  A[Operator starts Copilot login] --> B[Device-flow form request]
  B --> C[SSRF-guarded HTTP response]
  C --> D{HTTP successful?}
  D -->|No| E[Cancel unread response stream]
  E --> F[Release dispatcher and report error]
  D -->|Yes| G[Parse JSON and continue polling]
Loading

Before merge

  • Complete next step (P2) - No mechanical repair remains for an automation worker; use normal exact-head maintainer review and the repository merge gates.
Agent review details

Security

None.

PR surface

Source +2, Tests +63. Total +65 across 2 files.

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

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: extensions/github-copilot/login.test.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Merge the narrow owner-boundary repair after the normal exact-head rebase/check refresh, retaining the existing success parser, polling behavior, SSRF policy, and public provider configuration unchanged.

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

Yes. Current main shows the non-OK branch throws without consuming the response body before the finally block releases the dispatcher, and the PR supplies a concrete localhost guarded-transport reproduction using a never-ending error stream.

Is this the best way to solve the issue?

Yes. Cancelling at postGitHubDeviceFlowForm is the narrowest maintainable repair because that helper owns both device-flow endpoints, the unread response, and the subsequent dispatcher release.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded GitHub Copilot sign-in failure-path latency fix with focused provider impact rather than a broad runtime or security regression.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • 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 localhost evidence using production fetchWithSsrFGuard against never-ending error responses, with measured release-latency improvement and focused plugin regressions; no private external OAuth account was needed.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix localhost evidence using production fetchWithSsrFGuard against never-ending error responses, with measured release-latency improvement and focused plugin regressions; no private external OAuth account was needed.

Evidence

What I checked:

  • Current-main defect boundary: On current main, the shared helper throws immediately for a non-OK response and only then reaches its finally block, which awaits the guarded transport release; the non-success body is not otherwise consumed in that branch. (extensions/github-copilot/login.ts:163, 3629aeeef959)
  • Guarded transport contract: The guarded fetch implementation defines release as a one-time cleanup that closes the supplied dispatcher, so response-body cleanup belongs before the helper's finally release rather than in a caller. (src/infra/net/fetch-guard.ts:507, 3629aeeef959)
  • Patch and regression scope: The PR head adds awaited best-effort cancellation only on the non-OK branch and adds separate cancellation regressions for the device-code and access-token paths; the success JSON path and provider-facing error labels remain unchanged. (extensions/github-copilot/login.ts:164, c46096d847f6)
  • Established lifecycle pattern: Current repository history includes merged provider/channel fixes that cancel unread non-success response bodies before throwing, including the qqbot direct-upload repair cited by this PR; this is an established owner-boundary pattern rather than a new transport policy. (extensions/qqbot/src, 17643f3850)
  • Real behavior proof: The PR body records production guarded-transport localhost runs against deliberately non-terminating HTTP 503 bodies: device-code release latency fell from 100.9 ms to 3.0 ms and access-token latency from 100.5 ms to 0.8 ms, while status handling remained unchanged. It also records a focused 14-test plugin suite and HTTP 200 response-shape coverage. (extensions/github-copilot/login.test.ts, c46096d847f6)
  • Exact-head provenance: The current PR head is c46096d, a maintainer-authored follow-up that only clarifies the response-release ordering; the branch is not contained in current main and no release tag contains the PR commits, so this remains an open merge candidate rather than an implemented-on-main close. (extensions/github-copilot/login.ts:164, c46096d847f6)

Likely related people:

  • Sebastien Tardif: The locally available current-main blame/history baseline attributes the shared device-flow helper lines to this source snapshot, but the shallow/promisor history prevents a stronger feature-origin attribution. (role: current source-history carrier; confidence: low; commits: b300a0cfb3fe; files: extensions/github-copilot/login.ts)

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-07-21T11:47:16.422Z sha b4a2e49bc721bc7cdb330d87424c05dfa1e14ba4 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-29T23:22:44.888Z sha b4a2e49bc721bc7cdb330d87424c05dfa1e14ba4 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-01T11:32:31.457Z sha b4a2e49bc721bc7cdb330d87424c05dfa1e14ba4 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-02T11:17:23.439Z sha b4a2e49bc721bc7cdb330d87424c05dfa1e14ba4 :: needs maintainer review before merge. :: none

xydt-juyaohui and others added 2 commits August 2, 2026 03:56
…rowing

postGitHubDeviceFlowForm now drops the unread response stream before it
raises on a non-OK HTTP status. GitHub OAuth error responses ship a JSON
body (`{error, error_description}`) that this helper never consumes, so
the underlying fetch connection previously stayed open holding the
payload until the caller's release() ran, keeping the device-flow socket
half-drained on every 4xx/5xx.

Mirrors the recently-merged qqbot/kilocode/tlon fixes for the same
'cancel body before throwing' pattern (openclaw#110008, openclaw#109950, openclaw#112059).
@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. and removed 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. labels Aug 2, 2026
@steipete
steipete force-pushed the fix/copilot-cancel-device-flow-non-ok-body branch from b4a2e49 to c46096d Compare August 2, 2026 11:20
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 2, 2026

Copy link
Copy Markdown
Contributor

Maintainer verification on reviewed head c46096d847f65cefb7db55c0774dc6a8beb0e821:

  • Original contributor fix preserved; the Copilot device-flow owner now cancels unread HTTP error bodies before releasing its guarded dispatcher.
  • node scripts/run-vitest.mjs extensions/github-copilot/login.test.ts — 14/14 passed.
  • Actual production guarded-fetch requests against localhost streaming HTTP 503: device-code release 100.9 → 3.0 ms; access-token release 100.5 → 0.8 ms. Five real HTTP 200 OAuth response shapes remain unchanged.
  • Whole-branch plus full public-body Sol/xhigh review: no findings, confidence 0.98.
  • Exact-head CI run 30745537253, Workflow Sanity, and latest real-behavior proof are green.

No external OAuth service or live credential was used.

@steipete
steipete merged commit 096cd23 into openclaw:main Aug 2, 2026
89 of 91 checks passed
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
…rowing (openclaw#112268)

* fix(github-copilot): cancel unread device-flow error bodies before throwing

postGitHubDeviceFlowForm now drops the unread response stream before it
raises on a non-OK HTTP status. GitHub OAuth error responses ship a JSON
body (`{error, error_description}`) that this helper never consumes, so
the underlying fetch connection previously stayed open holding the
payload until the caller's release() ran, keeping the device-flow socket
half-drained on every 4xx/5xx.

Mirrors the recently-merged qqbot/kilocode/tlon fixes for the same
'cancel body before throwing' pattern (openclaw#110008, openclaw#109950, openclaw#112059).

* style(github-copilot): clarify response release ordering

---------

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

extensions: github-copilot P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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.

3 participants