Skip to content

Read Codex day totals from the account, and label each usage section's source - #12865

Open
berlonce wants to merge 3 commits into
omacom:quattrofrom
berlonce:codex-account-usage
Open

berlonce wants to merge 3 commits into
omacom:quattrofrom
berlonce:codex-account-usage

Conversation

@berlonce

@berlonce berlonce commented Sep 22, 2026 •

Copy link
Copy Markdown

Why

The Codex collector builds "Tokens by day" and today's total from session files stored on the machine running the panel. Codex usage from another computer, an SSH session, the desktop app, or the web never appears, so a subscription driven mostly from elsewhere shows a week of zeros while the weekly limit meter climbs.

The Codex app-server has an account/usage/read method that returns the daily token totals OpenAI records for the account itself, covering every device it is signed in on:

{"summary": {"lifetimeTokens": 1234567890, "peakDailyTokens": 12345678, "...": null},
 "dailyUsageBuckets": [{"startDate": "2026-09-19", "tokens": 23456789}, {"startDate": "2026-09-21", "tokens": 3456789}],
 "threadUsage": null}

Adopting it creates a second problem the panel has always had in milder form: limits describe the whole subscription, token counts describe one machine, and the column gives no sign of which is which. With account-wide days beside a locally scanned model split, the two populations now sit in the same tab.

What changed

Codex day totals come from the account. bin/omarchy-agent-usage-codex asks for account/usage/read in the session that already fetches account/rateLimits/read. When the answer carries dailyUsageBuckets, the record's recentDays, todayTotalTokens, and activeDates/activeDays come from those totals. Per-model usage still comes from local sessions, because the endpoint has no model split. An app-server predating the method answers method-not-found, and the collector keeps the local totals and the limits it already collected, with no change in output.

Every section header names its source. LIMITS and BALANCE are always · ACCOUNT; TOKENS BY DAY and TOKENS BY MODEL say · ACCOUNT, · THIS MACHINE, or · N MACHINES under synced aggregation. The label follows the record's "scope", so collectors that scan local sessions need no change and read THIS MACHINE, while Fireworks reads ACCOUNT from the scope it already declares. A collector may scope one family apart from the rest with "daysScope" or "modelUsageScope"; the Codex record declares "daysScope": "account" and nothing more, so its day totals are account-wide while its model split and prompt counts stay machine-local.

Synced aggregation merges per family, in any order. Snapshots carry both family scopes resolved beside the record-wide one older versions read. The merge keeps account and device populations apart per family and per date until the end: account figures collapse to their maximum, device figures add up, and the larger stands. Locally scanned model tokens and prompt counts from several machines therefore still add up under account day totals, identical account totals are never summed once per machine, a machine on a Codex too old for the usage method contributes a local share the account figure already covers without inflating it whichever snapshot is read first, and a lagging account figure falls back to the local share. Fully account-scoped records such as Fireworks deduplicate exactly as before.

shell/plugins/agents/README.md documents both.

Tests

  • test/shell.d/agent-usage-codex-scanner-test.sh: the fake app-server now answers unknown methods with an error like the real one. New checks cover the record staying machine-local without account usage, and account totals replacing the day rows while the model split stays local, active days union, and the two scopes are declared. 25 checks pass.
  • test/shell.d/agents-panel-test.sh: new checks evaluate the panel's scope-label helper, the record mapper, the snapshot writer, and the aggregation directly: each label, the unstated-scope default, the one-machine case, limits and balances never inheriting a synced label, per-family scope resolution, local model tokens and prompt counts adding up across machines under account day totals, account-beside-local merges giving the same answer in both orders, a lagging account figure yielding to the local share, and a fully account-scoped record still deduplicating. 45 checks pass.
  • ./test/cli passes. ./test/shell passes except for five files that also fail on a clean checkout here, needing an omarchy-pkgs checkout, omasnap, or a live compositor.
  • Verified in the running panel against Codex CLI 0.155.1 and a signed-in Claude Code: the Codex tab reads TOKENS BY DAY · ACCOUNT with totals matching the account, including tokens spent on another machine over SSH that the local scan could not see, beside TOKENS BY MODEL · THIS MACHINE; the Claude tab reads LIMITS · ACCOUNT over TOKENS BY DAY · THIS MACHINE.

Anthropic's OAuth usage endpoint returns utilization percentages only, with no daily token history, so Claude Code has no equivalent account-wide source to adopt. Its day and model rows stay local and now say so.

The Codex collector counted tokens by scanning session files on this
machine, so the day rows stayed at zero when the same subscription was
used over SSH, on another computer, or in a different client. The
app-server's account/usage/read call returns the daily token totals
OpenAI records for the whole account, so use those for today, the
seven-day rows, and the active-day list whenever the app-server offers
them. Per-model usage keeps coming from local sessions, since the
endpoint has no model split.

An older app-server answers the call with a method-not-found error and
the collector falls back to the local scan without touching the limits
it already collected. Records built from account totals declare
scope "account" so synced snapshots take the widest value instead of
summing one copy of the same numbers per machine.
Limits have always described the whole subscription while token counts
described the machine the panel runs on, and the two sit in one column
with nothing to tell them apart. Reading Codex day totals from the
account puts both populations inside a single tab, so every section
header now names its source: limits and balances are ACCOUNT, and day
and model totals say ACCOUNT, THIS MACHINE, or N MACHINES when synced
aggregation merged them.

A record's scope drives the label. Collectors that scan local sessions
need no change and read THIS MACHINE, Fireworks reads ACCOUNT from the
scope it already declares, and a collector whose model split is narrower
than its day totals says so with modelUsageScope, which is how the Codex
record keeps its locally scanned model breakdown honest.
@berlonce berlonce changed the title Take Codex day totals from the account's usage via the app-server Read Codex day totals from the account, and label each usage section's source Sep 22, 2026
@llstrk

llstrk commented Sep 22, 2026

Copy link
Copy Markdown

Two sync regressions were reproduced at 15eee012: local statistics are undercounted, and mixed account/local day totals depend on snapshot order.

Keep local model and activity statistics additive

The new record-wide scope: "account" in apply_account_usage() reaches Main.qml's aggregateSnapshots(), which applies maximum-value merging to every numeric family. providerSnapshot() also drops modelUsageScope. Consequently, independently scanned model tokens and prompt/session counts are deduplicated as though they were account replicas.

Synthetic sessions passed through the actual collector and extracted snapshot/aggregation functions:

Local statistic Machine A Machine B Baseline sum PR result
Same model: input tokens 60 20 80 60
Same model: output tokens 40 180 220 180
Model total 100 200 300 240
Today's prompts / sessions 1 / 1 1 / 1 2 / 2 1 / 1

Impact: With multiple synced machines using the account endpoint, the model section labelled 2 MACHINES under-reports their combined usage. Local all-time prompt/session counts are affected too.

Suggested change: Preserve and consume per-family scopes in snapshots and aggregation. Keep locally scanned model tokens and prompt/session counts additive, while deduplicating account-wide day totals. Preserve account-wide model deduplication for providers such as Fireworks.

Resolve account/local precedence independently of snapshot order

The supported method-not-found fallback produces device-scoped days. Combining that record with an account-scoped record for the same subscription alternates addition and maximum operations according to input order.

With a synthetic account total of 1,000 that already includes the fallback machine's 200 tokens:

Account first: max(0, 1000) + 200 = 1200
Local first:   max(0 + 200, 1000) = 1000
Expected account total:            1000

Impact: Mixed CLI versions or an unavailable optional usage endpoint can inflate both today's total and its chart row. The result changes with snapshot traversal order, not usage.

Suggested change: Resolve account-versus-local precedence per date before combining totals. Do not add a local subset to an account total covering it; retain addition when only local records are available. Test both orders, separately from the model-scope correction above.

Verified: Without sync, account buckets replace day totals while the model split remains local and receives the corresponding source label. Method-not-found preserves local totals and previously fetched limits. Homogeneous account day totals deduplicate correctly. Both changed test files pass, but do not exercise these failing snapshot/aggregation combinations.


Review information

Test scope: Pinned baseline/head collectors with synthetic session files and RPC replies, plus actual QML JavaScript snapshot, merge and mapping functions executed outside the UI. No live account queries or rendered-panel validation; account bucket timezone and freshness remain unverified.

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Automated AI review: Astra initial source inspection, independent Fable 5.1 High and Astra Xhigh technical reviews, followed by Astra synthesis and verification against saved targeted evidence.

…al stats

Marking the whole Codex record account-scoped once its day totals came
from the account made synced aggregation treat every number in it as a
replica: locally scanned model tokens and prompt counts from two machines
collapsed to the larger one instead of adding up. Mixing a machine on a
Codex old enough to lack the usage method with one that has it was worse,
since the merge alternated addition and maximum per snapshot, so today's
total depended on which snapshot happened to be read first.

The Codex record now scopes just its day totals with daysScope and stays
device-scoped otherwise. Snapshots carry both family scopes resolved
beside the record-wide one older versions read, and the merge keeps the
two populations apart per family and per date until the end: account
figures collapse to their maximum, device figures add up, and the larger
stands. That is order-independent, lets a lagging account figure fall
back to the local share, and leaves a fully account-scoped record such as
Fireworks deduplicated as before.
@berlonce

Copy link
Copy Markdown
Author

Thanks, both reproduced and fixed in e7a7a3d: the Codex record now scopes only its day totals, and the merge tallies account and device figures separately per family and per date, with tests for both orders.

@llstrk

llstrk commented Sep 23, 2026

Copy link
Copy Markdown

Verified: Both findings in the earlier review are resolved at e7a7a3dd for current-version aggregation. The reported fixes preserve per-family scopes in snapshots and combine account/device day totals independently of traversal order.

Synthetic comparisons through the actual collector account-override, snapshot-writer and aggregation functions:

Original condition 15eee012 e7a7a3dd
Local model input/output: 60/40 + 20/180 60/180 80/220
Today's local prompts/sessions: 1/1 + 1/1 1/1 2/2
Account 1,000 covering a local 200, account-first / local-first 1,200 / 1,000 1,000 / 1,000

Verified: The day-chart rows follow the same order-independent result, while fully account-scoped Fireworks-style replicas still deduplicate. No new actionable issue was established in this follow-up scope.


Review information

Test scope: Pinned original/head source inspection and synthetic function-level execution outside the UI. No live account queries, rendered-panel validation or stock-suite rerun. Account timezone/freshness and older readers consuming new snapshots are not covered by the resolution claim.

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Automated AI review: Astra initial inspection; independent Opus 5.5 High and GPT 6 Sol Xhigh technical assessments; Astra synthesis and verification against retained targeted evidence. Opus executed the synthetic comparisons; Sol independently reviewed source.

@omarchybot omarchybot added the enhancement New feature or request label Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants