Skip to content

Close rejected optional OpenCode billing requests - #26236

Merged
nwparker merged 1 commit into
mainfrom
nwparker/perf-opencode-billing-request-lifetime
Oct 8, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/perf-opencode-billing-request-lifetime

Conversation

@nwparker

@nwparker nwparker commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

A failed optional OpenCode billing check now closes its network request while still showing the valid quota result.

What Changed

Abort the optional billing request's existing controller when its HTTP response is rejected. It returns the same disabled balance result. Successful billing-body parsing keeps its five-second deadline; quota and workspace requests retain their independent deadlines.

Why

After rejected billing headers arrive, this path returns without reading the body and clears its only deadline. A stalled rejected body therefore leaves a physical Chromium request open even though the quota check and cookie cleanup have finished. The request already owns a controller, so a one-line abort closes that lifetime without closing the shared Session or changing cookies/proxy configuration.

The complete public fetcher and real Session cookie/proxy helper were exercised in windowless Electron 43.7.5 against a controlled HTTPS service. Three successive checks with valid quota and 1 KiB stalled billing failures retained three physical response owners before, including after forced GC and 5.5 seconds beyond the billing deadline; the fix retained zero and closed each in under 1 ms. All cookie jars were empty after each call. This demonstrates resource lifetime, not live OpenCode outage frequency, throughput, total memory or the reported Codex typing pause.

Linked Issue

Maintainer performance audit; no pre-existing linked issue.

Visual Proof

N/A — valid quota, balance errors and interactions are unchanged.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

The existing valid-quota/optional-billing regression now checks request ownership, unread rejected bodies and cookie cleanup. The rejection assertion fails before the fix; successful unsupported billing consumes its body without aborting. All 61 rate-limit test files / 828 tests pass, with one existing skip. Node typecheck, two-file changed-code quality, formatting and fresh Electron build pass. Combined with the other 31 audit changes, all 831 rate-limit tests, full typecheck and the 102-file changed-code quality gate pass.

Eleven paired native controls preserve full normalized results, request counts, cookie/proxy helper calls and empty cookies: normal 7.5 USD balance, finite rejection, malformed/truncated billing, actual five-second timeout, failed/malformed quota, balance-only status and small stalled billing failures. The native proof used the default DIRECT proxy branch; configured proxies were not physically exercised, and proxy code is unchanged. Only service URLs and isolated probe partitions/certificate trust were controlled; no real account/API. An initial HTTP redirect rejected before requests was discarded. Probe apps, HTTPS server and all connections were closed afterward.

Review

Independently reviewed: this controller belongs only to the optional billing attempt, and later workspaces create new controllers. Existing Session cookie cleanup remains in finally; no global connection teardown, cache, remote wire or platform-specific behavior change. Local credential execution and folder/SSH workspace behavior are unchanged.

Agent skill upstream boundary

  • Not applicable

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Visual proof is N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform and SSH/remote impact considered
  • Relevant tests, typecheck, quality checks and build pass; all required selected hosted checks pass

Hosted followthrough: the first run failed in an unchanged Bash trap test after its five-second native command deadline and in nine unchanged Windows boundary tests. The failed Windows tests’ literal import closures exclude this PR’s OpenCode files. The complete Bash suite passes locally (37 cases). The single failed-jobs-only rerun passed with the source unchanged, including Windows packaging and the Node 24 shard; the final verification job passed. This does not establish the cause of the first failures. No timeout or readiness changes were made.

@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 04de4f49-f0db-4eb6-befd-dcc3581ee85d
📥 Commits

Reviewing files that changed from the base of the PR and between 76d1b7b and 752657f.

📒 Files selected for processing (2)
  • src/main/rate-limits/opencode-go-usage-fetcher.test.ts
  • src/main/rate-limits/opencode-go-usage-fetcher.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

The optional billing request now aborts when it receives a non-OK response, before returning a refresh-failed balance. The test captures the request’s AbortSignal and checks its aborted state, response-body reads, and cookie clearing.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 75265

Rejected optional billing requests are now cancelled while retaining the disabled result and existing successful-response behavior. No actionable merge risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the main change: aborting rejected optional OpenCode billing requests.
Description check ✅ Passed The description covers the required explanation, change, rationale, testing, visual-proof status, review, and checklist sections. It provides detailed test results and addresses compatibility consider…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker merged commit ad0a5ad into main Oct 8, 2026
50 of 53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant