Skip to content

Port upstream 0.66.0: back off forbidden Cursor cost requests for six hours - #636

Closed
Finesssee wants to merge 2 commits into
port/upstream-0.66.0from
port/micro-0.66.0-cursor-cost-403-cooldown
Closed

Finesssee wants to merge 2 commits into
port/upstream-0.66.0from
port/micro-0.66.0-cursor-cost-403-cooldown

Conversation

@Finesssee

Copy link
Copy Markdown
Collaborator

Summary

  • A 403 from POST https://cursor.com/api/dashboard/get-filtered-usage-events is now a typed cost-only rejection (TokenCostError::CostRequestForbidden) instead of ProviderError::AuthRequired. It never touches the usage session or the validated app-session cache; quota usage and the local-CSV fallback are unchanged.
  • After one 403 the events request is skipped for six hours for that credential. The state is in memory only and keyed by a SHA-256 fingerprint of the Cookie header (raw cookies are never stored), so a new cookie or account retries immediately and a restart clears it. Timeouts and other failures (401, 5xx, parse errors) keep the normal per-refresh cadence and start no cooldown. A later successful events response clears the entry.
  • The events POST now sends Origin: https://cursor.com (upstream documents it as a CSRF requirement for these POST endpoints).
  • The cooldown is a process-wide store (cost_cooldown.rs) because the shell builds a fresh provider for every refresh. It is bounded to 32 credentials and prunes expired entries. The clock is injectable for tests.
  • CursorApi now holds its base URL (default https://cursor.com) so the existing mockito approach can drive it; production behavior is unchanged.

Upstream reference

Ported / Deferred

Ported: typed 403, six-hour in-memory cooldown scoped per credential, Origin header, timeout and transient failures keep the normal cadence, quota session and CSV fallback untouched, restart clears state.

Deferred:

  • Manual and menu-open refresh bypass. FetchContext has no force signal (checked rust/src/core/provider.rs; the shell's force flag in commands/providers.rs only reaches the refresh lock, not the provider). Adding one is cross-provider plumbing, which this PR avoids. Until then only a changed credential or a restart recovers early; codexbar CLI runs are separate processes and always retry.
  • max(cadence, 6 h). Win-CodexBar's slowest refresh interval is 30 minutes, so the six-hour floor is always the binding term and a constant is used; the provider does not know the cadence.
  • Scope beyond the credential. Upstream also scopes the deadline by history window, timezone, and provider configuration revision. Win-CodexBar's events window (default_since) is fixed, so the credential fingerprint is the only scope here. Note a rotating cookie value (same account, new token) retries early, which is the previous behavior.

Validation

Toolchain cargo +1.98.0, process-local target dir.

  • cargo +1.98.0 fmt --all: clean.
  • cargo +1.98.0 clippy --workspace --all-targets -- -D warnings: pass, no warnings.
  • cargo +1.98.0 test -p codexbar cursor: 62 passed, 0 failed. New tests:
    • cost_cooldown::tests (5): six-hour boundary (6 h - 1 s cooling, 6 h not), per-credential isolation, clear, bounded map with expired-entry pruning, fingerprint hides the cookie.
    • token_cost::tests (4, mockito): 403 maps to CostRequestForbidden (not AuthRequired), 401 stays AuthRequired, 503 stays a generic failure, the request carries Origin equal to the base URL.
    • cursor::tests (5, mockito, injected clock): 403 events + 200 usage-summary gives exactly one events request across two fetches inside the window with identical usage and cost output; retried at exactly the six-hour mark; a different Cookie retries immediately while the first stays parked; 503 starts no cooldown (two events requests); a successful response after the window ends the cooldown.
  • Shared code not touched (core, settings, cost_scanner); full cargo test -p codexbar not run.

Affected areas

Rust backend, Cursor provider only (rust/src/providers/cursor/{api,mod,token_cost,cost_cooldown}.rs). No Tauri shell, frontend, settings, dependency, or wire-shape changes beyond the documented Origin header.

UI proof

Not applicable (no UI surface changes).

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: d7ac81f5-a3fe-4ffd-b18e-50093efc5762

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • 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.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Reviewed by Codex gpt-6-luna (xhigh); verified and validated by Claude

Adversarial review of #636 (Cursor cost 403 cooldown) against upstream v0.66.0 (CursorUsageEventsFetcher, UsageStore+TokenCost, docs/cursor.md):

  • P3, rust/src/providers/cursor/cost_cooldown.rs:54: when the cooldown map was full, a second 403 for a credential that was already tracked (two in-flight fetches for the same cookie) evicted the credential with the oldest deadline, ending another account's active cooldown early. Fix: evict only when inserting a new key; deterministic regression test added. Status: fixed.

No other defects found: 403 is typed and does not invalidate the session, 401/503 start no cooldown, the cookie is only stored as a SHA-256 fingerprint, no lock is held across an await, and the Origin header matches upstream. The manual/menu-open bypass and the wider scope keys stay deferred as the PR body says (needs a force signal in FetchContext; main worker's call).

Commands run: cargo +1.98.0 fmt --all --check (clean), cargo +1.98.0 clippy --workspace --all-targets -- -D warnings (clean), cargo test -p codexbar --lib providers::cursor (57 passed). No UI surface, so no proof needed.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Adversarial validation (Claude Opus 5.5) passed at 24db68a

Scope: GAP-32, the Cursor cost 403 cooldown, plus the codex-2 review fix in 24db68a.

  • Base is port/upstream-0.66.0 (b585d48, also the merge base).
  • Two commits, fast-forward only: f5fff8f and its child 24db68a. No force pushes.
  • Touches only rust/src/providers/cursor/. All four files are under 1000 lines.

Compared with upstream v0.66.0 (CursorUsageEventsFetcher.swift, UsageStore+TokenCost.swift, docs/cursor.md):

  • A 403 maps to CostRequestForbidden. It does not become AuthRequired, does not invalidate the usage session and leaves the CSV fallback alone.
  • 401 stays AuthRequired. 5xx and timeouts start no cooldown.
  • The cooldown is 6 h, kept in memory and scoped to the credential through a SHA-256 fingerprint, so the raw cookie is never stored. A success clears it.
  • Origin matches the base URL.
  • No lock is held across an await.
  • The review fix is real. Traced by hand, refreshing_an_existing_cooldown_does_not_evict_another_credential would fail on f5fff8f's record_forbidden: re-recording a tracked credential in a full map evicts "oldest" and leaves 31 entries. It passes at this SHA.
  • Disclosed deferrals in the PR body (not counted as defects):
    • Manual and menu-open refreshes do not bypass the cooldown. I confirmed FetchContext carries no force signal.
    • The scope does not include history window or timezone.

Checks run at this SHA (toolchain 1.98.0, isolated target dir):

  • cargo +1.98.0 fmt --all --check: clean.
  • cargo +1.98.0 clippy --workspace --all-targets -- -D warnings: clean.
  • cargo +1.98.0 test -p codexbar: 2175 passed, 0 failed, 1 ignored. Every providers::cursor test passes, including the 6 cooldown and 10 provider mockito and unit tests.
  • cargo +1.98.0 test -p codexbar-desktop-tauri: 461 passed, 1 failed.
    • The failing test is commands::tests::bootstrap_payload_exposes_every_provider_variant (catalog 79 vs 78).
    • The failure comes from the base and depends on the host. On this base, get_bootstrap_state() calls Settings::load(), so the test reads the local user profile. One deprecated provider enabled there adds a catalog entry.
    • The same failure shows up on every branch based on b585d48.
    • This PR does not touch the shell crate.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Shipped in v0.70.0: this PR's head is included in main via #735 (merge commit 9d0a37a). Closing as integrated.

@Finesssee Finesssee closed this Oct 3, 2026
junglesub-bot Bot pushed a commit to junglesub/Win-CodexBar that referenced this pull request Oct 4, 2026
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