Skip to content

Port upstream 0.66.0: Chutes quota classification and enrichment - #639

Closed
Finesssee wants to merge 1 commit into
port/upstream-0.66.0from
port/micro-0.66.0-chutes-quota-parity
Closed

Finesssee wants to merge 1 commit into
port/upstream-0.66.0from
port/micro-0.66.0-chutes-quota-parity

Conversation

@Finesssee

Copy link
Copy Markdown
Collaborator

Summary

Chutes now reads quotas the way upstream's bundled chutes.js does (row #28i, commit 6db17eeb, cutover "preserving" behaviors). Before, it requested only users/me/subscription_usage and put the first two quota-shaped objects it found into primary/secondary in traversal order, with a fixed Chutes API login method.

  • Lane classification. Rolling (4-hour) and monthly are picked by payload key (rolling, fourhour, ... / monthly, subscription, billing_period, ...), then by label (rolling|4h|4 h|4-hour|four hour|four-hour / month|billing|subscription), then by window length (240 min / >= 40320 min). Payload-keyed lanes default to 240 / 43200 minutes; other windows fill the remaining lane in order.
  • Key matching. Payload keys are matched case- and punctuation-insensitively against upstream's full key lists (limit, used, remaining, percent, reset, unit, label, window, plan, active, status). Numeric strings such as "$1,500" are accepted.
  • Enrichment. When rolling or monthly is still missing, users/me/quotas and then users/me/quota_usage/{chute_id|chuteId|id} are requested and merged (usage fields win). Everything except a 401/403 is best effort; a rejected key stays fatal.
  • Endpoint. CHUTES_API_URL is HTTPS-only (existing providers::validated_https_url) and now keeps its path and query on every request (previously Url::join dropped a base path such as /proxy). Requests send Accept: application/json.
  • Identity. Login method is the plan name; otherwise No active subscription (active false or a free/inactive/cancelled/expired status) or No usage data (no windows and active unknown). Renewal comes from explicit subscription reset keys.
  • Errors. Non-2xx is Chutes usage API error: HTTP <code>; a body that is not a JSON object or array is a parse error.
  • Structure. providers/chutes/mod.rs (provider and HTTP flow), parse.rs (payload parsing), tests.rs.

Upstream reference

  • Release: v0.66.0, "bundled plugin cutover" bullet (Chutes "preserving quota details and endpoint validation"); commit 6db17eeb. The cutover itself is SKIP (QuickJS/JavaScriptCore engine); only the preserved behavior is ported.
  • Tag-pinned sources (?ref=v0.66.0): Sources/CodexBarCore/Resources/Plugins/chutes.ts (chutesParse, chutesQuota, chutesSnapshot, fetchUsage), Sources/CodexBarCore/Providers/Chutes/ChutesSettingsReader.swift, ChutesProviderDescriptor.swift, Tests/CodexBarTests/ChutesProviderTests.swift.

Ported / Deferred

Ported: everything listed above, with the upstream fixtures from ChutesProviderTests.swift (active subscription, no-active fallback to quotas/quota_usage/0, wrapped data list, partial fill of rolling from quotas, no-data snapshot, distinct equal windows, large/very large/fractional amounts, unrepresentable durations, percent 1 stays 1, normalized aliases, best-effort enrichment with 403/500, base path and query, invalid JSON, 401).

Intentional differences from upstream, kept because local behavior is deliberate:

  • Fractional percent (deferred). Upstream rescales percent values below 1 ("0.25" becomes 25). Local keeps whole percents (chutes: same ambiguous 0..=1 fraction rescale heuristic as #407 (real 1% becomes 100%) #408: a real 1% must not become 100%; existing test usage_percent_half_stays_half), so 0.5 stays 0.5. The upstream test "fractions" case uses "25" here.
  • Epoch guard. Reset values below 1e9 are quota counts, not epochs (existing local rule; upstream accepts any positive number). Strings must be RFC 3339 or epoch numbers.
  • Renewal. Only explicit subscription reset keys set the renewal date. Upstream also falls back to the monthly window's reset; SubscriptionMetadata is documented as independent of quota resets, and the monthly window already shows its own reset.
  • No duplicate lane. Upstream's fallback filter compares windows including the synthetic label, so a rolling-only payload can repeat the rolling window as the secondary. Local excludes a window that came from the same source object as a selected lane.
  • No window at all. UsageSnapshot requires a primary window, so an absent 4-hour lane is an informational No quota reported row instead of the previous fake 0% quota.
  • Cancellation. Upstream re-throws a cancelled transport during enrichment; a cancelled refresh here drops the future, so no separate branch exists.
  • Parse error text. ProviderError::Parse renders as Parse error: Chutes usage response is not valid JSON rather than upstream's Chutes usage parse error: invalid JSON.

Validation

Toolchain cargo +1.98.0, per-slug target dir.

  • cargo +1.98.0 fmt --all: clean.
  • cargo +1.98.0 clippy --workspace --all-targets -- -D warnings: pass.
  • cargo +1.98.0 test -p codexbar chutes -- --test-threads=4: 37 passed, 0 failed.
  • cargo +1.98.0 test -p codexbar provider_id -- --test-threads=4: 18 passed, 0 failed.
  • Full cargo test -p codexbar and the Tauri crate tests were not run: only rust/src/providers/chutes/ changed, no shared code.

Affected areas

  • Provider (Chutes) fetch and parsing
  • Settings, tray, float bar, frontend: not changed (existing window and label rendering only)

UI proof

Pending: coordinator will capture CUA proof on a fresh build (window placement of the 4-hour and monthly lanes, informational primary row).

@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: 2174906e-c7b9-4589-8b84-aece86b5c188

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

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

CUA proof (PR #639): BLOCKED, assertions not verifiable with this kit

Build commit: 7e94241 (PR head) plus uncommitted proof-only patches (see proof-only.patch):

  • rust/src/logging.rs config_root() honors CODEXBAR_PROOF_CONFIG_ROOT.
  • proof_harness.rs seed parser accepts providerId "chutes".

Commands: bash launch.sh trayPanel, bash launch.sh settings:providers; driven with cua-driver call list_windows / get_window_state / click --screenshot-out-file.

Observed: the log confirms proof-harness: seeded provider snapshot for 'chutes', but Chutes needs https so the real fetch to https://127.0.0.1:9 fails. The tray card and the Settings > Providers row then show the fetch error ("Network error: error sending request for url (https://127.0.0.1:9/users/me/subscription_usage)", row status "Error ... 0%") instead of the seeded snapshot. No quota lanes rendered.

# Assertion Result
1 trayPanel shows Chutes card, no other providers' identities PARTIAL: Chutes card shown, but only with a network error
2 "4-hour quota" 40%, "40/100 requests"; "Monthly quota" 25%, "250/1000 credits"; plan Pro NOT VERIFIED (error card shadows seed)
3 Rolling lane first, monthly second NOT VERIFIED
4 settings:providers Chutes lanes/labels NOT VERIFIED (row shows Error)
5 Theme auto, webview dark PASS (dark in both surfaces)

This is a proof-kit limitation (seed does not survive the failed refresh in the UI), not evidence of a PR regression. Also, the Settings > Providers Codex pane displayed a real personal account email despite the isolated config, so those screenshots were discarded. Only unit tests cover the classification/enrichment path. Screenshots kept: none (shots\ is empty).

@Finesssee

Finesssee commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator Author

CUA proof (rerun): PR #639

Build commit: 7e942412906fc6447f112458db752701faad16f2 (PR head, verified unchanged before the run) plus uncommitted proof-only patches (never committed; see proof-only.patch):

  • Cargo.toml / Cargo.lock: [patch.crates-io] dirs proof shim for profile isolation (CODEXBAR_PROOF_HOME).
  • rust/src/providers/chutes/mod.rs: .danger_accept_invalid_certs(true) on the Chutes client so the real fetch path can reach a self-signed local HTTPS mock. No seed, no other logic change.

Data path: real fetch against a local mock (https://127.0.0.1:18639) using the fixtures of the PR test partial_subscription_usage_fills_the_missing_rolling_window (/users/me/subscription_usage returns only a monthly lane, /users/me/quotas returns the rolling_window). Dummy API key, isolated profile, only Chutes enabled, theme auto.

Commands: bash launch.sh trayPanel, then bash launch.sh settings:providers; driven with cua-driver call list_windows / get_window_state / click / --screenshot-out-file (CLI only).

# Assertion Result
0 No real email/account from the machine visible PASS (Codex pane shows "No Codex accounts found"; no personal data in any kept screenshot)
1 trayPanel shows only a Chutes card PASS
2 Rolling lane 40% used and Monthly 25% used, plan Pro, rolling first, monthly second, none duplicated or swapped PASS ("4-hour quota" 40% used, then "Monthly quota" 25% used, plan "Pro"). The raw "40/100 requests" and "250/1000 credits" strings are not rendered by the UI, so only percentages were checked
3 Mock log has GET /users/me/subscription_usage and GET /users/me/quotas, both bearer-present PASS (equal counts of both, all bearer-present)
4 settings:providers, Chutes selected, same lanes and values PASS (Plan Pro; 40% and 25% in the same order; both quota toggles checked). Settings uses generic labels "Session"/"Weekly" for the two bars
5 Theme auto, webview dark PASS (settings.json theme: "auto", both surfaces dark)

Observations, not asserted:

  • The Settings bars show reset text like "Resets in 26392d 8h". This comes from the mock fixture timestamps, not verified against real data.
  • While a surface was open the app fetched Chutes continuously (about 5800 request pairs within roughly 3 minutes across the two launches, per requests-final.log). Not compared against the base branch, so it is unknown whether the PR affects this or it is a proof-mode artifact.

Screenshots (local, not committed), in %LOCALAPPDATA%\Win-CodexBar\port-audit\proof\639\shots\: tray.png, settings-providers.png (Codex row, empty), settings-chutes.png; logs requests-tray.log, requests-final.log.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Port review: Chutes quota classification and enrichment (#639, GAP-36)

Reviewed the branch diff 7e942412 vs port/upstream-0.66.0 against the 0.66.0 manifest spec for row 28i (upstream chutes.js at v0.66.0: chutesParse / chutesQuota / chutesSnapshot), plus the PR body and the existing proof/validation comments.

What I checked:

  • Enrichment flow: fetch_usage_snapshot reads GET users/me/subscription_usage, then calls GET users/me/quotas and per-quota GET users/me/quota_usage/{id} only when the rolling or monthly lane is still missing. Auth rejection (401/403) on enrichment is fatal; every other failure logs at debug and keeps the subscription result — matches the spec's "auth rejection and cancellation stay fatal; best effort otherwise". A cancelled refresh drops the future, so cancellation needs no separate handling.
  • Classification: rolling/monthly selection by payload keys (rolling, rolling4h, fourhour, ... / monthly, subscriptionusage, billingperiod, ...), then label regex (rolling/4h/4-hour vs month/billing/subscription), then window minutes (240 for rolling; >= 40320 for monthly), with defaults 240/43200 applied when the payload gives none. Keys are matched case- and punctuation-insensitively (normalized to alphanumerics), as upstream does.
  • Fallback windows: unselected quota windows fill primary/secondary in traversal order (secondary index shifts when rolling is absent). An absent rolling lane becomes an informational "No quota reported" primary instead of a fabricated 0% bar.
  • Fraction guard (chutes: same ambiguous 0..=1 fraction rescale heuristic as #407 (real 1% becomes 100%) #408): PERCENT_USED_KEYS values are clamped 0..=100 and never treated as 0..=1 fractions; usage_percent: 1 renders 1%, not 100% — test fractional_usage_percent_is_not_scaled covers it. Renewal comes only from subscription-level reset keys; quota-level resets are never treated as subscription renewal (Only an explicit subscription date counts).
  • Plan/active: plan from planname/plan/tier/..., active from boolean keys or status text (free/inactive/cancel/none/expired → false), No active subscription / No usage data login-method strings match the spec.
  • Wire shape: requests carry Bearer + Accept: application/json to {base}/users/me/... with the configured path/query kept; non-2xx (except auth) is Chutes usage API error: HTTP <n>; JSON body must be an object or array else parse failure.
  • Tests: 28 tests in tests.rs (754 lines) cover the classification matrix, enrichment merge, quota-id lookup, fraction guard, epoch-vs-count date disambiguation, window-minute parsing (minutes/hours/days/seconds/text), and the fallback ordering.
  • Existing evidence at this head: PR body records fmt/clippy clean + chutes 37 passed / provider_id 18 passed; the CUA rerun comment (2026-09-30) shows a real-fetch mock proof with rolling 40% then monthly 25%, plan Pro, and both endpoints hit with the bearer present.

Result: no findings. The port matches the upstream semantics on the wire shape, the enrichment policy, the classification order and the fraction/renewal guards. All three files stay under the 1000-line cap (mod.rs 225, parse.rs 667, tests.rs 754). No dependency, locale, bridge or frontend change.

One observation carried from the proof comment (not a defect): the app polls Chutes continuously while a surface is open (~5800 request pairs in ~3 minutes under the proof harness). It was not compared against the base branch, so it is unknown whether the PR affects it — worth a look before release if the polling cadence matters.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

UI proof (browser-use)

Combined build of integrate/v0.70.0-ports at ddd85594 (all 40 port PRs and the follow-ups). Debug desktop build in proof mode, isolated config/data dirs, driven by browser-use over the WebView2 DevTools protocol with DOM events only (no mouse or keyboard input, no focus changes). All data is synthetic: local mock servers for L1, a seeded usage snapshot plus synthetic local logs for L2.

Scenario Check Result
L1 tray (mock servers) #639 Chutes: 4-hour quota 40% before Monthly quota 25%, plan Pro PASS
L1 mock request logs #639 Chutes mock: subscription_usage + quotas, every request carries the bearer PASS

Every surface also passed the privacy check (no email-like text, account e-mail nodes or profile paths in the DOM) and theme auto rendered dark on the tray flyout, float bar and settings windows.

Validation at ddd85594: cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test -p codexbar (3567 passed, 0 failed) and cargo test -p codexbar-desktop-tauri (606 passed, 0 failed). Screenshots were captured for each scenario and kept with the local proof kit.

@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