Skip to content

fix(api): close upload bodies on retry preflight failures - #1136

Merged
steipete merged 2 commits into
mainfrom
fix/retry-request-body-cleanup
Sep 15, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/retry-request-body-cleanup

Conversation

@steipete

Copy link
Copy Markdown
Collaborator

The Google API retry transport left upload bodies open when the circuit breaker rejected a request or retry buffering failed. Files and streams attached to those requests could remain open even after http.Client.Do returned an error.

Close circuit-rejected bodies immediately and close consumed input bodies on every buffering exit. Dispatched streaming bodies remain owned by the underlying transport, and the original errors and retry behavior are preserved.

Validation:

  • A new http.Client regression reproduced all three leaks before the fix: open circuit, read failure, and replay-buffer overflow each closed the body zero times.
  • The same regressions pass after the fix, alongside existing replay and streaming-body tests.
  • Full local make ci passed (all Go tests, lint/deadcode, docs, generated skills, and Docker version checks).
  • go test -race ./internal/googleapi ./internal/discoveryapi ./internal/input ./internal/timeparse ./internal/sheetsa1 ./internal/sheetsdimension passed.
  • Independent review of the final candidate is scoped-clean at P0–P2.

This is synthetic HTTP/resource-lifecycle proof; no live Google account or API mutation is involved. Includes an automation guide note and an Unreleased changelog entry.

@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. 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. labels Sep 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed September 15, 2026, 2:13 AM ET / 06:13 UTC (Revision 2).

ClawSweeper review

What this changes

The PR closes upload bodies when retry preflight fails, adds three resource-lifecycle regression cases, and documents the behavior.

Merge readiness

⛔ Needs changes before merge - 2 items remain

The fix remains necessary on current main and v0.40.0. The resource cleanup is correct; the prior changelog feedback is only partially resolved.

Priority: P2
Reviewed head: 53676f3c85b3948b3764a6b4135b5aea0bef15df

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, technically sound repair with targeted regression coverage and one remaining release-note requirement.
Proof confidence 🌊 off-meta tidepool Not applicable: The collaborator-authored PR is exempt from ordinary contributor proof. Its reported synthetic http.Client regressions exercise retry preflight cleanup with tracked bodies and a mocked base; they are supplemental tests, not live Google proof, and no authority boundary changes.
Patch quality 🐚 platinum hermit (4/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The collaborator-authored PR is exempt from ordinary contributor proof. Its reported synthetic http.Client regressions exercise retry preflight cleanup with tracked bodies and a mocked base; they are supplemental tests, not live Google proof, and no authority boundary changes.
Evidence reviewed 7 items Applicable repository policy: Read the full root AGENTS.md. No nested AGENTS.md files or maintainer-notes directory were found. The policy explicitly requires Unreleased references and contributor thanks.
Current main still leaks rejected bodies: Circuit rejection returns without closing the request body; buffering read and size errors return before the existing success-only Close.
Latest release retains the same failure paths: The v0.40.0 transport has the same circuit rejection and buffering cleanup omissions; this PR is not redundant with the latest release.
Findings 1 actionable finding [P3] Add the remaining contributor credit to the changelog
Security None None.

How this fits together

Google API requests pass through a retry transport before reaching the authenticated HTTP transport. It checks the circuit breaker and prepares replayable bodies, then either returns an error or dispatches the request.

flowchart TD
 A[Google API request and upload body] --> B[Circuit breaker check]
 B -->|Rejected| C[Close body and return error]
 B -->|Allowed| D[Prepare replayable body]
 D -->|Buffering fails| C
 D -->|Ready or streaming| E[Authenticated HTTP transport]
 E --> F[Response or retry]
Loading

Before merge

  • Add the remaining contributor credit to the changelog (P3) - The follow-up adds the PR reference, but the contributor-thanks portion of the previous finding remains unresolved. Root AGENTS.md requires both for Unreleased entries. Add credit for @steipete to complete the release-note attribution.
  • Complete next step (P2) - Add contributor thanks for @steipete to the existing Unreleased changelog entry.

Findings

  • [P3] Add the remaining contributor credit to the changelog — CHANGELOG.md:5
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test delta Production +8/-2 lines; tests +88/-0 lines The small cleanup change has focused coverage for all three reported rejection paths.

Technical review

Best possible solution:

Keep cleanup at the retry transport's pre-dispatch exits while preserving streaming ownership, replay behavior, and release-note attribution.

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

Yes, from source: circuit rejection and buffering errors return before closing the original body on main. The added regression cases cover these paths; this review did not execute tests.

Is this the best way to solve the issue?

Yes. Closing rejected bodies and deferring cleanup only after buffering begins is a narrow repair that preserves streaming and replay semantics.

Full review comments:

  • [P3] Add the remaining contributor credit to the changelog — CHANGELOG.md:5
    The follow-up adds the PR reference, but the contributor-thanks portion of the previous finding remains unresolved. Root AGENTS.md requires both for Unreleased entries. Add credit for @steipete to complete the release-note attribution.
    Confidence: 0.99

Overall correctness: patch is correct
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against ae5eefa0309d.

Labels

Label justifications:

  • P2: This repairs bounded upload-resource leaks on API request failures without changing normal request behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The collaborator-authored PR is exempt from ordinary contributor proof. Its reported synthetic http.Client regressions exercise retry preflight cleanup with tracked bodies and a mocked base; they are supplemental tests, not live Google proof, and no authority boundary changes.

Evidence

Acceptance criteria:

  • [P1] git diff --check.
  • [P1] git diff -- CHANGELOG.md.

What I checked:

  • Applicable repository policy: Read the full root AGENTS.md. No nested AGENTS.md files or maintainer-notes directory were found. The policy explicitly requires Unreleased references and contributor thanks. (AGENTS.md:37, 53676f3c85b3)
  • Current main still leaks rejected bodies: Circuit rejection returns without closing the request body; buffering read and size errors return before the existing success-only Close. (internal/googleapi/transport.go:78, ae5eefa0309d)
  • Latest release retains the same failure paths: The v0.40.0 transport has the same circuit rejection and buffering cleanup omissions; this PR is not redundant with the latest release. (internal/googleapi/transport.go:78, a3065f53c38f)
  • Cleanup preserves transport ownership: The deferred Close captures the original body before replacement. Existing GetBody requests and large or unknown-length streaming bodies bypass buffering; dispatched bodies retain underlying-transport ownership. (internal/googleapi/transport.go:318, 53676f3c85b3)
  • Focused regression coverage: Three cases use http.Client.Do with tracked bodies and a rejecting mock base transport: open circuit, reader failure, and buffer overflow. Each asserts one Close and no dispatch. The body reports before/after results, make ci, and race tests; these were not executed during this read-only review. (internal/googleapi/transport_body_test.go:26, 53676f3c85b3)
  • Prior feedback partially addressed: The supplied completed-review projection requested a reference and contributor thanks. The follow-up commit adds only the reference; CHANGELOG.md line 5 still lacks contributor credit. (CHANGELOG.md:5, 53676f3c85b3)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Complete the contributor credit in the Unreleased entry.

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 (1 earlier review cycle)
  • reviewed 2026-09-15T06:03:32.376Z sha 5824421 :: needs changes before merge. :: [P3] Add the required changelog reference and contributor credit

@steipete
steipete merged commit 469b823 into main Sep 15, 2026
12 checks passed
@steipete

Copy link
Copy Markdown
Collaborator Author

Landed as 469b823.

The shared retry transport now closes upload bodies on circuit rejection, replay-buffer read errors, and replay-buffer overflow. Dispatched streams remain owned by the underlying transport, with retry and error behavior preserved.

Verification:

  • Before the fix, go test ./internal/googleapi -run TestRetryTransportClosesRejectedRequestBody -count=1 reproduced all three leaks: zero closes instead of one.
  • After the fix, the regression, existing replay/streaming tests, and full make ci passed.
  • go test -race ./internal/googleapi ./internal/discoveryapi ./internal/input ./internal/timeparse ./internal/sheetsa1 ./internal/sheetsdimension passed.
  • Final independent P0–P2 review was scoped-clean.
  • GitHub CI passed for exact head 53676f3c85b3948b3764a6b4135b5aea0bef15df: https://github.com/openclaw/gogcli/actions/runs/34935789685 (Linux, Windows, minimum Go, macOS CGO, and tracking worker).

Proof used synthetic request bodies through http.Client; no live Google API operation was performed. The change includes regression tests, automation documentation, and an Unreleased changelog entry.

Maintainer review: the changelog now references this PR. The remaining P3 request for self-credit is inapplicable because this was found during a maintainer code audit, with no external reporter or contributor.

@steipete
steipete deleted the fix/retry-request-body-cleanup branch September 15, 2026 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant