Skip to content

fix(usage): retain gateway coverage and separate quota from consumption - #249

Draft
nullStack65 wants to merge 1 commit into
release/native-0.1.10from
fix/clo-1348-usage-coverage
Draft

nullStack65 wants to merge 1 commit into
release/native-0.1.10from
fix/clo-1348-usage-coverage

Conversation

@nullStack65

Copy link
Copy Markdown
Owner

Problem

Usage discarded balance-only gateway cards and made an established gateway outage look like an origin that had never served quotas. Tokens and cost also lacked a clear account of what the quota source actually measures.

Change

The existing Magpie adapter now retains balance, last, lastServedAt, timestamps and display-only cards for providers without a driver mapping. Web and mobile show unavailable, stale and provider-limited coverage, including explicit messages for missing fields and missing OpenCode or Antigravity/Gemini rows. Discovery origins, fleet defaults, opt-out and refresh routes stay on the existing release behavior.

Usage names three separate parts: measured transcript consumption, subscription quota, and provider-reported or model-priced cost. Reported and estimated amounts follow the existing transcript-source deduplication. The quota endpoint provides no token or billed-cost totals, so no gateway consumption is added. Direct and gateway routes retain the explicit transcript-only, unattributed coverage label.

Scope

Remaining Usage coverage and accounting scope for the shared Magpie-backed Usage issue. Includes the unavailable-provider gap and older-client decoder case tracked there. Additive wire fields; no access-scope change or data migration.

Prior Art

Extends the existing quota reader and pooled Limits presentation. Uses the existing source-fingerprint ownership for transcript deduplication and forward-compatible schemas for additive metadata. Gateway request correlation remains unavailable because this endpoint provides no consumption records or matching request IDs.

Verification

Candidate: c5efcdccae910040f39aeb9b1ebd935136eea39e, based on release commit 39b0a57d62a66f39efe777d45e4623ba9c6d1e5c.

  • The required changed-file check was run against origin/release/native-0.1.10. Formatting, lint and GraphQL checks pass; all 340 targeted tests in nine files and nine affected React Compiler checks pass.
  • Consumer typechecking reports nine errors in unchanged apps/web/src/components/Sidebar.logic.test.ts and apps/web/src/components/bots/botOrgTree.test.ts (thread-standing fixture shape and inferred thread identity). The scoped server typecheck passes. The failing files and referenced thread-standing types are outside this diff.
  • Knip reports two unchanged release-version helper files and five unchanged exports in the output gate, remote delegation and secret-redaction modules. The overall changed-file command remains nonzero; these unrelated findings are preserved. After running the checks, the documented one-shot local hook override was used to publish this draft; CI and the review gate remain active.
  • The QA feature-map check passes. Web/mobile catalogs include the new Usage messages with English fallback. A bounded secret-pattern scan of the diff and new compatibility fixture is clean.

Compatibility tests use the relevant decoder semantics inspected at v0.1.9 (24e77473ecf41bc1f7142529c7911c1c1aae1d76). The legacy config decoder rejects kind: magpie; the existing capability filter removes that config for an old client. Added accounting fields are ignored, supported quota sources ignore the extra metadata, and unknown quota-source variants are skipped. This is schema evidence, without a running old-client session.

This draft still needs the integrated Usage flow on real web/desktop/mobile clients, before/after app captures, and a pinned rendered-screen comparison on fleet targets after the normal rollout. Local Chromium component tests cover balance-only cards and the source-outage view. No service was restarted or candidate deployed, and no fleet-live closeout is claimed. The parent owns review, merge eligibility and rollout; the author will not merge this PR.

Deploy: fleet

Model: gpt-6.1-sol
Task: fix
Agent: Usage implementation
Harness: Codex/T3

Keep provider-limited cards and established gateway failures in the existing quota reader. Expose absent upstream fields and separate transcript token and cost accounting from subscription quota across clients, with additive legacy-compatible metadata.

Model: gpt-6.1-sol
Task: fix
Agent: Usage implementation
Harness: Codex/T3
@nullStack65

Copy link
Copy Markdown
Owner Author

Note

🤖 gpt-6.1-sol responding on behalf of nullStack65

Source review: changes-required at c5efcdccae910040f39aeb9b1ebd935136eea39e. Two important findings are reproduced below. This is the single full review round; the PR stays draft and fleet acceptance remains outside this review.

{
  "disposition": "changes-required",
  "reviewed_base": "1d87e8030dda52d154c763b204ee147d4737bc9a",
  "reviewed_head": "c5efcdccae910040f39aeb9b1ebd935136eea39e",
  "merge_base": "39b0a57d62a66f39efe777d45e4623ba9c6d1e5c",
  "reviewer": "gpt-6.1-sol / Codex / T3",
  "author_session": "thread:delegated-task:command:mcp:3b7de01d-7d18-46fe-b00c-0a7f431b9d80:delegate-task:00c27b22-f5b8-4ee4-8460-68fa64b79d9c",
  "author_session_source": "CLO-1348 CTO writer-confirmation comment 3afe0c23-5229-4fce-b342-db5343601350",
  "reviewer_session": "01a229eb-2d96-7fc1-895d-e1cc8765080a",
  "fresh_context": true,
  "review_kind": "full",
  "round_id": "thread:delegated-task:command%3Amcp%3A9d4f7918-731a-4a31-8e59-e0148918269a%3Adelegate-task%3Aclo-1348-review-pr249-c5efcdcc",
  "intent_source": "https://linear.app/closura/issue/CLO-1348; issue description and all available comments (pagination exhausted), including stop report e4b8d8cd and result 0c23aa1c",
  "intent": [
    "CLO-1348 done-when 1: Every configured provider and route is accounted for, including pooled quotas, aliases, direct/fallback routes, Antigravity and OpenCode. Verify which upstream fields actually exist. Expose explicit unavailable/stale/provider-limited states and last successful refresh where appropriate.",
    "CLO-1348 done-when 2: Provider, model, route and account identity are normalized without exposing cross-founder data. Distinguish measured consumption, subscription quota, and billed or estimated cost. Deduplicate usage recorded by both T3 and Magpie. Preserve coverage labels for any direct usage that has no gateway observation."
  ],
  "prior_findings": [],
  "findings": [
    {
      "id": "F1",
      "severity": "important",
      "outcome": "open",
      "file": "packages/shared/src/usageMerge.ts",
      "line": 456,
      "summary": "The new dollar split treats each bucket.costSource as a record-level partition. UsageAggregator groups the same provider/model/day (or hour) before returning buckets; resolveCostSource marks any mixture of provider-reported and model-priced records as modelPriced. Reproduced through the current UsageAggregator -> mergeUsage -> usageAccountingMessages: one $2 reported record plus one $1 estimated record in the same bucket yields total $3, providerReportedUsd=0 and modelPricedUsd=3; the UI says \"Not provided provider-reported usage value; $3.00 model-priced estimate.\" Carry the separate dollar amounts through aggregation (or mark mixed amounts unknown) instead of assigning the whole mixed bucket to the estimate. The new test uses separate models, so it misses this case."
    },
    {
      "id": "F2",
      "severity": "important",
      "outcome": "open",
      "file": "apps/server/src/usage/magpieQuotas.ts",
      "line": 329,
      "summary": "The new gatewayCards retain provider but discard the account id/alias needed to associate balance, last and lastServedAt with a seat. gatewayCoverageMessages renders only that provider and those fields into a Set (packages/shared/src/usageLimitsCopy.ts:58), so distinct seats can collapse. Reproduced by reading a synthetic gateway response with two Claude seats, aliases seat-a/seat-b, different quota windows (0%/50%), and equal timestamps/last flags: accounts retains both labels, gatewayCards loses both identities, and the shared coverage function emits exactly one anonymous \"claude: Available...\" line. When values differ it emits anonymous lines that still cannot be tied to the corresponding account. Preserve a safe stable account key and display label on these cards and use it in the presentation/deduplication; this affects the shared web/desktop/mobile coverage display."
    }
  ],
  "evidence": [
    "Live PR API checked at entry and again after verification: exact reviewed_head matches; base branch release/native-0.1.10; draft=true. Reviewed only the patch against merge-base/parent 39b0a57d62a66f39efe777d45e4623ba9c6d1e5c; no re-review of the merged discovery change or upstream-only changes.",
    "Obligation: read the controlling issue and all comments, including the source-boundary stop and later allowance/result. Checked field retention, missing-provider states, source outage/recovery, quota-versus-consumption separation, cost provenance, transcript deduplication and direct-route labels.",
    "Repository: read pinned AGENTS.md and testing rules; reviewed changed source/contracts, tests, shared copy, web/mobile consumers, translation additions and the updated Usage feature map. Existing reader is extended; no second reader, service or rollout layer added. git diff --check passes; worktree clean before and after verification.",
    "Operational proof on the pinned candidate in the existing clean checkout, Node 26.13.1: vp test run apps/server/src/serverSettings.test.ts apps/server/src/usage/UsageLimitSources.test.ts apps/server/src/usage/UsageService.test.ts apps/server/src/usage/magpieQuotas.test.ts apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx packages/contracts/src/usageCompatibility.test.ts packages/shared/src/usageLimits.test.ts packages/shared/src/usageMerge.test.ts scripts/feature-map.test.ts => 9 files passed, 342 tests passed, exit 0 (91.60 seconds). This is the observed rerun count, not a restatement of the PR claim of 340.",
    "Adversarial checks: balance=$0 and last=false survive; unmapped provider retains driver=null and provider-limited display; known discovered gateway survives failed cached/manual reads with last-success/card metadata and recovers; first-time non-gateways remain dropped. Existing discovery origins, fleet loopback defaults, opt-out and manual-refresh behavior remain covered by passing affected tests. No quota balance/percentage is added to token or cost totals; source ownership/deduplication precedes the cost sums; transcript-only/unattributed labels remain.",
    "Affected surfaces: web Usage and desktop web wrapper consume the new shared messages; mobile uses the same helpers. Server quota decode and older-client config shaping were inspected. Inspected v0.1.9 decoder source at 24e77473ecf41bc1f7142529c7911c1c1aae1d76 and reran schema compatibility/settings capability-filter tests: additive fields ignored, unsupported snapshot variants skipped, Magpie config filtered from old clients. No new rejection introduced by the additive fields was found in this source review.",
    "Two additional read-only Node probes against current exported production functions produced the F1/F2 results above; synthetic data only. No source edits, commits, pushes, rebases, ready/merge operation, dev-server launch or fleet action."
  ],
  "limitations": [
    "No integrated live Usage screen was compared with a live gateway; no running-server source outage was exercised. Chromium component tests are not full app/fleet acceptance.",
    "Older-client verification is decoder/schema-only, not a running v0.1.9 mixed-client session. No fleet rollout, exact deployed-build parity, before/after app captures or fleet-live receipt verified or claimed.",
    "Did not rerun the full changed-file check, consumer typecheck, Knip or React Compiler checks. The disclosed pre-existing Knip/typecheck/browser failures and one-shot hook override are not findings of this review; no new failure appeared in the affected tests run here.",
    "CI readback showed two queued checks and four skipped checks; not a green-CI or merge-readiness claim. PR remains draft. Implementation/acceptance and CLO-1348 remain with the delegating owner.",
    "Author-session identity is retained from the controlling issue; reviewer-session identity is observed from this native runtime. T3 issue-link UI returned \"Issues cannot be browsed for this project yet\"; durable issue comments remain the return path."
  ]
}

This branch has not been deployed

No deployments
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