← Back to Pull requests

fix(usage): let an active weekly_scoped cap outvote the all-models window #1537

Open
unknown opened this pull request with 278 lines diff across 3 files
View on GitHub
unknown unknown commented on Sep 18, 2026 20:49 UTC
Author

Problem

parse_usage resolves the weekly dimension from the top-level seven_day object (or a weekly_all limits[] entry) and never looks at limits[] entries of kind weekly_scoped — the per-model weekly caps the API now reports.

Live payload observed 2026-09-18 on a Team account (tokens and identifiers omitted):

| window | percent | is_active |
|---|---|---|
| seven_day / weekly_all | 44 | false |
| weekly_scoped · scope.model.display_name = "Fable" | 74 | true |

The daemon reported 44 % weekly for an account whose binding constraint was the 74 % Fable cap. For a Fable-heavy operator the account exhausts ~30 pp before any weekly trigger can fire.

Change

After the existing dimension() resolution, scan limits[] for weekly_scoped entries that are active (is_active true or absent; explicit false skipped) and, if the highest such fraction is strictly greater than the resolved weekly fraction, take that entry's (fraction, resets_at, severity) instead. dimension(), the session dimension, and UsageReport are unchanged. No new dependencies.

Rationale for max-not-replace: weekly_all aggregates every model, so a scoped cap can only be the binding limit when it is above the aggregate; when it is below, the aggregate still binds.

Tests

Four new unit tests in src/usage.rs::tests, using the observed payload shape:

  • weekly_scoped_higher_than_weekly_all_wins — 0.74 and the scoped resets_at win; session unaffected

  • weekly_scoped_lower_than_weekly_all_is_ignored — 10 % scoped leaves 0.44

  • inactive_weekly_scoped_is_ignored — 90 % scoped with is_active: false leaves 0.44

  • no_limits_array_still_parses — top-level objects only (regression guard)
  • cargo test --locked: 2389 passed, 0 failed, 14 ignored. cargo clippy --locked --all-targets -- -D warnings and cargo fmt --check clean.

    Verified against a live daemon: after swapping in the patched binary the same account reads 74–81 % weekly in sessiometer status, matching Claude Code's own /usage Fable bar.

    Not in scope

    Whether the scoped cap should be surfaced separately in status (a second weekly column) — this PR only makes the existing weekly dimension honest.

    Diff: 278 lines (+208 / -70) across 3 files Reviewer: alexey-pelykh Review duration: 94229m
    All Vouch review confidence checks passed
    Residual risk 0.26 = Change Risk (0.47) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 278 lines diff across 3 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.337
    Real PR Conversation Timeline
    1 comments
    "Review active on #1537"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 46.6% (MEDIUM) · Higher = larger blast radius
    46.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.7% · Lower = rushed or shallow review
    44.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.8% · Safe to merge
    25.8%