Skip to content

fix(googlechat): cancel unread auth response bodies before release - #115873

Merged
steipete merged 1 commit into
openclaw:mainfrom
Yigtwxx:fix/googlechat-auth-cancel-unread-body
Aug 1, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
Yigtwxx:fix/googlechat-auth-cancel-unread-body

Conversation

@Yigtwxx

@Yigtwxx Yigtwxx commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #111290, as offered in review there.

What Problem This Solves

Fixes an issue where a Google Chat operator whose auth endpoint returns an oversized response would leave a live HTTP response body unread and uncancelled when the SSRF dispatcher is released, holding the socket open until the runtime gets around to it.

Nothing errors and nothing is logged — the request fails with the expected size error, and the leak sits behind it.

Why This Change Was Made

#111290 established the invariant for this extension and documented it at the api.ts guard site: release() does not cancel streams, so a status-only response has to be cancelled explicitly before release.

The auth transport has its own guard site, and it was not covered by that change. readGoogleAuthResponseBytes inspects content-length first:

const contentLengthHeader = response.headers.get("content-length");
if (contentLengthHeader) {
  const contentLength = parseMediaContentLength(contentLengthHeader);
  if (contentLength !== null && contentLength > MAX_GOOGLE_AUTH_RESPONSE_BYTES) {
    throw new Error(`Google auth response exceeds ${MAX_GOOGLE_AUTH_RESPONSE_BYTES} bytes.`);
  }
}

const reader = response.body?.getReader();

The throw happens before getReader(), so on that path the stream is never touched and the finally releases the dispatcher with the body still unread. This is the same shape as the one just fixed, reached by a different route: there the body is unread because the response is status-only, here because the guard rejected it early.

The fix mirrors the merged one exactly — same predicate, same non-awaited cancellation, same reasoning about the tee'd-capture deadlock — so both guard sites in this extension now read alike.

Note this is only reachable through the size guard's own rejection path, so the fix is narrow by construction: a response that is read normally is untouched.

User Impact

An oversized auth response no longer leaves its body open when the dispatcher is released; the socket is torn down at the same point it already is on every other path. Normal auth responses are unaffected.

Evidence

Added extensions/googlechat/src/google-auth.fetchok.transport.test.ts, following the harness #111290 landed: a real loopback server, the real fetchWithSsrFGuard, and the real release — the wrapper only records what release() observes and then delegates, so the assertions run against closeDispatcher → waitForDispatcherClose rather than a stub.

Both directions are covered, and the control case is the point: the site does not leak generally, only on the throw-before-read path.

case release() observes, before after
content-length: 1048577 { bodyIsNull: false, bodyUsed: false } { bodyIsNull: false, bodyUsed: true }
normal response (control) { bodyIsNull: false, bodyUsed: true } unchanged

Against the unfixed source the first case fails with exactly that difference:

- Expected
+ Received
-   "bodyUsed": true,
+   "bodyUsed": false,

Test Files  1 failed (1)
     Tests  1 failed | 1 passed (2)

The control case passes before and after, so the test is measuring the leak rather than the request path.

After the fix, the whole extension suite is green:

node scripts/run-vitest.mjs run --config test/vitest/vitest.extension-messaging.config.ts \
  extensions/googlechat/src/

Test Files  28 passed (28)
     Tests  285 passed (285)

oxfmt --check is clean on both touched files.

AI-assisted: written and verified with an AI coding agent; the failing-test-first measurement, the control case, and the suite run above were reviewed by me.

@openclaw-barnacle openclaw-barnacle Bot added channel: googlechat Channel integration: googlechat size: S labels Jul 29, 2026
@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 29, 2026
@clawsweeper

clawsweeper Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 31, 2026, 9:04 PM ET / August 1, 2026, 01:04 UTC.

ClawSweeper review

What this changes

The PR cancels an unread Google OAuth response body when the auth transport rejects an oversized response before reading it, and adds a loopback regression test.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

This PR remains necessary: current main still releases the guarded Google auth dispatcher after an oversized content-length rejection without cancelling the untouched response stream. The patch mirrors the already-merged Google Chat response-lifecycle fix at the distinct auth transport boundary, has focused loopback proof, and introduces no discrete correctness finding.

Priority: P2
Reviewed head: 9134cee6191aaffd29f2cc1bb5f3f60f55ac5f32

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-consistent repair with strong transport-level proof and no supported correctness findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body provides before/after output and a committed loopback transport test that runs the real guarded fetch and dispatcher release; it also reports a passing Google Chat extension suite. The proof concerns a non-visual transport lifecycle, so terminal evidence is appropriate.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body provides before/after output and a committed loopback transport test that runs the real guarded fetch and dispatcher release; it also reports a passing Google Chat extension suite. The proof concerns a non-visual transport lifecycle, so terminal evidence is appropriate.
Evidence reviewed 6 items Current-main defect: The auth transport calls readGoogleAuthResponseBytes(response) and always calls release() in finally; the size guard throws before response.body.getReader(), leaving the response body unused on that path.
Shared lifecycle contract: fetchWithSsrFGuard returns a release callback that closes the pinned dispatcher, while redirect handling separately cancels response bodies before closing the dispatcher; dispatcher release is not a substitute for consuming or cancelling a returned response stream.
Existing sibling pattern: The merged Google Chat API wrapper already cancels an unread body before release and documents why cancellation is intentionally non-awaited when debug capture may tee the stream; this PR applies that established invariant to the separate auth transport.
Findings None None.
Security None None.

How this fits together

Google Chat authentication uses google-auth-library through a plugin-local fetch implementation that applies OpenClaw's SSRF guard and then buffers the response within a fixed size limit. The guarded fetch returns both the HTTP response and a dispatcher-release callback, so the auth transport must settle an unread response body before it releases that dispatcher.

flowchart LR
  A[Google auth library request] --> B[Google Chat auth transport]
  B --> C[SSRF-guarded fetch]
  C --> D[Response size guard]
  D -->|accepted| E[Read and buffer body]
  D -->|oversized| F[Cancel unread body]
  E --> G[Release dispatcher]
  F --> G
Loading

Before merge

  • Complete next step (P2) - No mechanical repair is indicated; this proof-positive, focused PR needs ordinary maintainer review rather than a ClawSweeper repair job.
Agent review details

Security

None.

PR surface

Source +6, Tests +86. Total +92 across 2 files.

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

Review metrics

None.

Technical review

Best possible solution:

Merge the focused auth-transport lifecycle repair so every Google Chat guarded-response path either reads or starts cancelling a response body before dispatcher release.

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

Yes, source-reproducible: an oversized declared response makes readGoogleAuthResponseBytes throw before it obtains a reader, while the enclosing finally releases the dispatcher. The proposed loopback test directly measures that pre-release body state, but was not run in this read-only checkout because dependencies are absent.

Is this the best way to solve the issue?

Yes. Cancelling only when bodyUsed is false at the owner boundary before release() matches the current Google Chat API wrapper and preserves normally consumed responses without adding a second lifecycle path.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: The PR repairs a bounded Google Chat auth transport resource-lifecycle bug without evidence of a broad outage or security bypass.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body provides before/after output and a committed loopback transport test that runs the real guarded fetch and dispatcher release; it also reports a passing Google Chat extension suite. The proof concerns a non-visual transport lifecycle, so terminal evidence is appropriate.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides before/after output and a committed loopback transport test that runs the real guarded fetch and dispatcher release; it also reports a passing Google Chat extension suite. The proof concerns a non-visual transport lifecycle, so terminal evidence is appropriate.

Evidence

What I checked:

  • Current-main defect: The auth transport calls readGoogleAuthResponseBytes(response) and always calls release() in finally; the size guard throws before response.body.getReader(), leaving the response body unused on that path. (extensions/googlechat/src/google-auth.runtime.ts:417, 65717fd3be89)
  • Shared lifecycle contract: fetchWithSsrFGuard returns a release callback that closes the pinned dispatcher, while redirect handling separately cancels response bodies before closing the dispatcher; dispatcher release is not a substitute for consuming or cancelling a returned response stream. (src/infra/net/fetch-guard.ts:702, 65717fd3be89)
  • Existing sibling pattern: The merged Google Chat API wrapper already cancels an unread body before release and documents why cancellation is intentionally non-awaited when debug capture may tee the stream; this PR applies that established invariant to the separate auth transport. (extensions/googlechat/src/api.ts:88, 65717fd3be89)
  • Patch and regression coverage: The proposed change gates cancellation on !response.bodyUsed before release, and its loopback test exercises the real guarded fetch and release callback for both the oversized early-rejection path and a normally read control response. (extensions/googlechat/src/google-auth.fetchok.transport.test.ts, 9134cee6191a)
  • Feature history: The current auth-fetch block traces through the bounded-auth-transport work, and the PR head is the only local commit adding this auth-path cancellation. The previous merged Google Chat API fix is related but covers the separate status-only API response wrapper. (extensions/googlechat/src/google-auth.runtime.ts:413, 9134cee6191a)
  • Current-main inclusion check: The PR head is not an ancestor of current main, so the auth-path repair is not already implemented there. The local partial clone could not retrieve deeper historical blobs or live GitHub data because network resolution failed, but this does not undermine the direct current-source comparison. (extensions/googlechat/src/google-auth.runtime.ts:435, 65717fd3be89)

Likely related people:

  • Peter Steinberger: Current-main blame attributes the auth-fetch lifecycle block to a recent broad routing refactor, and history includes multiple Google Chat auth transport refactors. (role: recent area contributor; confidence: high; commits: 4645d4a4879a, 1ecef82da8a8; files: extensions/googlechat/src/google-auth.runtime.ts)
  • QiuYuang: History identifies the bounded Google auth transporter fetch work that established the size-limit path this patch repairs. (role: introduced bounded auth transport behavior; confidence: high; commits: 9d1a75df2d8d; files: extensions/googlechat/src/google-auth.runtime.ts)
  • Vincent Koc: Earlier history shows Google auth transport isolation and hardening work in the same module lineage. (role: earlier auth transport contributor; confidence: medium; commits: b31c001a2b51, 6d6845ea9d23; files: extensions/googlechat/src/google-auth.runtime.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-29T13:07:31.050Z sha a40485126d6676fee9c3127335220e34cc398495 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-29T13:24:42.780Z sha 5017eade81c148abc2ebc744f80ff1b5a2bf90b0 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-29T16:51:39.665Z sha 9134cee :: needs maintainer review before merge. :: none
  • reviewed July 31, 2026, 9:04 PM ET / August 1, 2026, 01:04 UTC sha unknown :: needs maintainer review before merge. :: none

@Yigtwxx
Yigtwxx force-pushed the fix/googlechat-auth-cancel-unread-body branch from a404851 to 5017ead Compare July 29, 2026 13:20
@Yigtwxx

Yigtwxx commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Refreshed onto current main as 5017eade81c — that was the one open item on the before-merge list.

The branch was 60 commits behind. Nothing upstream had touched either file (git log <head>..origin/main -- extensions/googlechat/src/google-auth.runtime.ts extensions/googlechat/src/google-auth.fetchok.transport.test.ts is empty), the rebase preserved the diff byte for byte (2 files, +92 either side), and the extension suite is green on the refreshed head:

node scripts/run-vitest.mjs run --config test/vitest/vitest.extension-messaging.config.ts \
  extensions/googlechat/src/

Test Files  28 passed (28)
     Tests  285 passed (285)

No changes to the patch itself.

The size guard in readGoogleAuthResponseBytes inspects content-length and
throws before it reaches response.body.getReader(), so an oversized auth
response leaves the stream untouched and the finally block releases the
dispatcher without cancelling it.

This is the same shape openclaw#111290 just fixed in api.ts, applied to the auth
transport's own guard site.
@Yigtwxx
Yigtwxx force-pushed the fix/googlechat-auth-cancel-unread-body branch from 5017ead to 9134cee Compare July 29, 2026 16:44
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Landing verification for original contributor head 9134cee6191aaffd29f2cc1bb5f3f60f55ac5f32:

  • Traced the complete Google Chat auth owner, OAuth callers, existing API-transport sibling, guarded-fetch dispatcher release, and actual Undici dependency. The currently shipped auth owner rejects oversized content-length before acquiring its reader, then releases the dispatcher without consuming/canceling its body. Undici explicitly requires consuming or canceling bodies to prevent connection leaks and stalled requests.
  • Executed the real google-auth-library Gaxios auth path against a real localhost HTTP server and the real SSRF-guard dispatcher. Oversized responses now enter dispatcher release with { bodyIsNull: false, bodyUsed: true }; successful fully read responses remain unchanged with the same release observation. A separate actual ReadableStream probe confirmed cancellation flips bodyUsed synchronously without awaiting a potentially stalled cancellation.
  • OPENCLAW_VITEST_MAX_WORKERS=1 node /Users/steipete/Projects/openclaw/scripts/run-vitest.mjs extensions/googlechat/src/google-auth.fetchok.transport.test.ts — 2/2 passed.
  • Fresh structured Codex autoreview at xhigh effort: clean, confidence 0.94. Exact-head hosted CI run 30472163779 and Workflow Sanity run 30472163707 are green.
  • Proof gap: no real Google OAuth endpoint or operator credentials were used; the actual auth transport/dispatcher boundary was exercised with live loopback HTTP instead.

Owner-boundary fix is six production lines and matches the Google Chat API sibling and guarded redirect cleanup; no config, security policy, timeout, or public API changed.

@steipete
steipete merged commit 9dfbf6a into openclaw:main Aug 1, 2026
135 checks passed
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

sunlit-deng pushed a commit to sunlit-deng/openclaw that referenced this pull request Aug 1, 2026
* commit '441d6ab254df14fb6939a8a261f474904ff9c500': (388 commits)
  fix(qqbot): ignore blank app id fallbacks (openclaw#109460)
  fix(feishu): consume implicit reply targets across media delivery (openclaw#117196)
  fix(exec): preserve approved command output when sessions resume (openclaw#117177)
  fix(qa): use public subagent fanout evidence (openclaw#116832)
  fix(googlechat): cancel unread auth response bodies before release (openclaw#115873)
  fix(queue): prevent cron saturation from starving hook dispatch (openclaw#116666)
  fix(gateway): sessions.steer retry no longer interrupts an active run when replaying a cached idempotency key (openclaw#116969)
  fix(irc): config validation rejects documented channels.irc.configWrites key (openclaw#112392)
  fix(mistral): keep terminal error branch lint-clean
  fix(onboard): stop a full reset from resetting the default workspace when the config is unreadable (openclaw#114110)
  refactor(i18n): remove unused Apple contradiction report (openclaw#117182)
  fix(google): stop scraping Gemini CLI OAuth credentials (openclaw#117167)
  perf: count large histories before Gateway prewarm (openclaw#117118)
  fix(signal): restore provider-safe original attachment filenames (openclaw#115107)
  refactor(channels): unify setup ownership across bundled channels (openclaw#117188)
  fix: allow gateway service commands for named profiles (openclaw#116314)
  fix(plugins): invalidate bundled artifact locations after metadata refresh (openclaw#117041)
  fix(ollama): honor model requests and pull completion contracts (openclaw#117171)
  fix(agents): prevent fallback after stale lifecycle abort (openclaw#117168)
  fix(telegram): confirm polling before long poll (openclaw#116970)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
…penclaw#115873)

The size guard in readGoogleAuthResponseBytes inspects content-length and
throws before it reaches response.body.getReader(), so an oversized auth
response leaves the stream untouched and the finally block releases the
dispatcher without cancelling it.

This is the same shape openclaw#111290 just fixed in api.ts, applied to the auth
transport's own guard site.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
* commit 'ae4e662145b6aa162777cdb1c011b3f04ddd230d': (388 commits)
  fix(qqbot): ignore blank app id fallbacks (openclaw#109460)
  fix(feishu): consume implicit reply targets across media delivery (openclaw#117196)
  fix(exec): preserve approved command output when sessions resume (openclaw#117177)
  fix(qa): use public subagent fanout evidence (openclaw#116832)
  fix(googlechat): cancel unread auth response bodies before release (openclaw#115873)
  fix(queue): prevent cron saturation from starving hook dispatch (openclaw#116666)
  fix(gateway): sessions.steer retry no longer interrupts an active run when replaying a cached idempotency key (openclaw#116969)
  fix(irc): config validation rejects documented channels.irc.configWrites key (openclaw#112392)
  fix(mistral): keep terminal error branch lint-clean
  fix(onboard): stop a full reset from resetting the default workspace when the config is unreadable (openclaw#114110)
  refactor(i18n): remove unused Apple contradiction report (openclaw#117182)
  fix(google): stop scraping Gemini CLI OAuth credentials (openclaw#117167)
  perf: count large histories before Gateway prewarm (openclaw#117118)
  fix(signal): restore provider-safe original attachment filenames (openclaw#115107)
  refactor(channels): unify setup ownership across bundled channels (openclaw#117188)
  fix: allow gateway service commands for named profiles (openclaw#116314)
  fix(plugins): invalidate bundled artifact locations after metadata refresh (openclaw#117041)
  fix(ollama): honor model requests and pull completion contracts (openclaw#117171)
  fix(agents): prevent fallback after stale lifecycle abort (openclaw#117168)
  fix(telegram): confirm polling before long poll (openclaw#116970)
  ...
@Yigtwxx
Yigtwxx deleted the fix/googlechat-auth-cancel-unread-body branch August 2, 2026 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

2 participants