Skip to content

fix(chatgpt): read the usage window as used_percent too in the gate rewrite - #6463

Closed
lcxhh521 wants to merge 1 commit into
lidge-jun:devfrom
lcxhh521:fix/chatgpt-gate-used-percent
Closed

lcxhh521 wants to merge 1 commit into
lidge-jun:devfrom
lcxhh521:fix/chatgpt-gate-used-percent

Conversation

@lcxhh521

@lcxhh521 lcxhh521 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

unlockRateLimitGate (src/chatgpt/app-server-shim/gate-rewrite.ts) reads every gate field in both spellings it can arrive in: rate_limit/rateLimit, limit_reached/limitReached, spend_control/spendControlReached, rate_limit_reached_type/rateLimitReachedType. The usage window was the one exception: only the JSON-RPC usedPercent counted as plain-quota evidence.

A web usage snapshot (/backend-api/wham/usage) spells the window used_percent. Since the flags open only with plain-quota evidence, a genuinely exhausted snapshot never showed the plain quota as the reason and its rate_limit flags stayed closed. This PR counts both spellings. Below 100%, or with a reached spend control, the flags still stay as the server sent them.

  • On dev the only caller is the app-server RPC path, whose payloads use usedPercent, so its behaviour does not change.
  • The snake_case shape matters to the send-unblock intercept in feat(chatgpt): local-CA send-unblock intercept, stacked on #6361 (split from #5947) #6365, which runs this same rewrite over the web usage snapshot. Merging the current dev with that intercept makes its "exhausted usage snapshot opens the gate" tests fail without this line.

Verification

  • bun run typecheck, bun run structure:check, bun run privacy:scan: pass.
  • bun test ./tests/clients/desktop-app-server-shim.test.ts ./tests/clients/desktop-app-server-shim-launcher.test.ts ./tests/clients/desktop-chatgpt-config.test.ts: 43 pass, 0 fail.
  • New tests call unlockRateLimitGate on a web-shaped snapshot: used_percent: 100 opens the flags and leaves the window as sent; used_percent: 42 stays closed; a reached spend_control keeps them closed at 100%. Removing the new line fails the first one.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed. (structure/clients/chatgpt-desktop.md names both spellings.)
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. (No auth or credential code; the change only widens which payload field counts as quota evidence, and every non-quota restriction still keeps the gate closed.)

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • Required local validation passed; commands, results, and any full-suite exception are documented.

  • I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • Bug Fixes
    • Usage snapshots with used_percent now correctly identify exhausted quotas and open rate-limit gates when no other blocking condition applies.
  • Documentation
    • Clarified how quota usage fields are represented in RPC messages and web usage snapshots.

…ewrite

`unlockRateLimitGate` reads every gate field in both spellings it arrives in: rate_limit and
rateLimit, limit_reached and limitReached, spend_control and spendControlReached,
rate_limit_reached_type and rateLimitReachedType. The usage window was the exception: only the
JSON-RPC `usedPercent` counted as plain-quota evidence. A web usage snapshot spells it
`used_percent`, so a genuinely exhausted snapshot never showed the plain quota as the reason and
its flags stayed closed. Both spellings now count; below 100% and with a reached spend control
the flags still stay as sent.

On dev the only caller is the app-server RPC path, whose payloads use `usedPercent`, so its
behaviour is unchanged. The web snapshot shape matters to the send-unblock intercept, which runs
the same rewrite over `/backend-api/wham/usage`.
@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 93739acc-ee71-4f7e-8f8b-4ddfdb80d324

📥 Commits

Reviewing files that changed from the base of the PR and between e0af52c and 683e8d6.

📒 Files selected for processing (3)
  • src/chatgpt/app-server-shim/gate-rewrite.ts
  • structure/clients/chatgpt-desktop.md
  • tests/clients/desktop-app-server-shim.test.ts

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


📝 Walkthrough

Walkthrough

unlockRateLimitGate now recognizes used_percent as well as usedPercent when checking for exhausted quota usage. Tests cover snake_case snapshots at and below 100%, and when spend control has been reached. Documentation records the field spellings.

Changes

Quota gate usage detection

Layer / File(s) Summary
Usage detection and validation
src/chatgpt/app-server-shim/gate-rewrite.ts, tests/clients/desktop-app-server-shim.test.ts, structure/clients/chatgpt-desktop.md
The gate rewrite treats used_percent >= 100 as exhausted alongside usedPercent >= 100. Tests cover usage at and below 100%, and the reached spend-control condition. Documentation identifies the spellings used in RPC messages and web snapshots.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 683e8

The change adds snake_case quota handling while preserving existing gate protections, and tests cover the helper’s threshold behavior. The upstream notification shape is not established in the repository, but no concrete merge-blocking issue is evidenced; this appears mergeable after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 683e8

The change recognizes another spelling of quota usage without adding a new caller or credential access. Spend-control and other explicit restrictions still prevent gate opening. Remaining uncertainty concerns upstream message shapes, not an established security regression.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The established effect is modification of quota flags and ordinaryUsageAllowed within an accepted app-server message. No new cross-service caller, credential authority, or independently attackable production endpoint is established by this change.

Trust Boundaries and Controls

  • observed — A preflight scan detects spend-control and non-plain reached-type restrictions anywhere in the payload. New snake_case exhaustion evidence cannot override these explicit blockers when opening rate-limit flags or ordinaryUsageAllowed.

Resilience and Maintainability Implications

  • observed — The documented failure-containment contract preserves a line after a rewrite exception and switches to raw passthrough after framing or rewrite machinery failure. This PR changes exhaustion recognition, not that recovery contract.
🚥 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. (1 skipped: 1 … 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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: supporting the snake_case used_percent usage-window field in the ChatGPT gate rewrite.
Full details: Docstring Coverage

Explanation

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. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Oct 2, 2026
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

✅ READY

  • all PR quality gates passed; the review readiness checklist is complete.

Review readiness checklist

  • ✅ Required local validation passed; commands, results, and any full-suite exception are documented.
  • ✅ I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ✅ My PR is ready for review.

✅ 4/4 boxes ticked.

This pull request is already Ready for Review.
The review-ready label marks this PR as ready; review automation runs independently.
Maintainers: @lidge-jun @Ingwannu

@github-actions
github-actions Bot marked this pull request as ready for review October 2, 2026 15:35
@lcxhh521

lcxhh521 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

robin-bially pushed a commit to robin-bially/opencodex that referenced this pull request Oct 3, 2026
…un#6463)

Read used_percent as exhaustion evidence alongside usedPercent.
Preserve usage values and existing spend-control and non-quota blockers.

Carries lidge-jun#6463 by @lcxhh521.

Co-authored-by: lcxhh521 <59329914+lcxhh521@users.noreply.github.com>
@lcxhh521

lcxhh521 commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Closing as landed on dev via f5572a0. Thanks @lidge-jun for carrying it and keeping the credit.

@lcxhh521 lcxhh521 closed this Oct 3, 2026
lcxhh521 added a commit to lcxhh521/opencodex that referenced this pull request Oct 3, 2026
Brings the branch level with dev (100 commits) and resolves four conflicts:
- `src/cli/chatgpt-command.ts`: dev's carry of lidge-jun#6453 checks the discovered bundle's trust before
  either relaunch path. It now runs after the intercept listener probe and the shim's binary
  resolution, and before the restore watcher guard, so the intercept relaunch is validated too.
  An intercept-only launch reports "launch ChatGPT" rather than "launch the shim".
- `src/chatgpt/app-server-shim/gate-rewrite.ts`: dev's carry of lidge-jun#6463 makes the same
  `used_percent` change; only the comment differed, and dev's wording is kept.
- `structure/config.md` and the ChatGPT desktop guide: our `chatgptDesktop` fields alongside
  dev's `claudeCode.subagentModelForce` text and restore trust paragraphs.

The command-child fixture from lidge-jun#6453 now stubs the intercept status and watcher modules, so its
status and restore scenarios never probe this machine's listener, launchd agent, keychain or
running proxy. A new scenario covers restore refusing while the watcher is loaded. The
desktop-unblock layout entries share lines, which keeps `tests/fixtures/test-layout-expected.json`
under the 2000-line ratchet as dev's packed entries already do.
lcxhh521 added a commit to lcxhh521/opencodex that referenced this pull request Oct 3, 2026
Brings the branch level with dev (100 commits) and resolves four conflicts:
- `src/cli/chatgpt-command.ts`: dev's bundle trust check before either relaunch path (0358e72,
  from lidge-jun#6453) now runs after the intercept listener probe and the shim's binary resolution, and
  before the restore watcher guard, so the intercept relaunch is validated too. An intercept-only
  launch reports "launch ChatGPT" rather than "launch the shim".
- `src/chatgpt/app-server-shim/gate-rewrite.ts`: dev already has the same `used_percent` change
  (f5572a0, from lidge-jun#6463); only the comment differed, and dev's wording is kept.
- `structure/config.md` and the ChatGPT desktop guide: our `chatgptDesktop` fields alongside
  dev's `claudeCode.subagentModelForce` text and restore trust paragraphs.

The bundle-trust command-child fixture now stubs the intercept status and watcher modules, so its
status and restore scenarios never probe this machine's listener, launchd agent, keychain or
running proxy. A new scenario covers restore refusing while the watcher is loaded. The
desktop-unblock layout entries share lines, which keeps `tests/fixtures/test-layout-expected.json`
under the 2000-line ratchet as dev's packed entries already do.
@lidge-jun lidge-jun mentioned this pull request Oct 4, 2026
3 tasks done
@lcxhh521
lcxhh521 deleted the fix/chatgpt-gate-used-percent branch October 5, 2026 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working review-ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant