Skip to content

Skip the Codex app-server probe when there are no credentials - #13106

Closed
surim0n wants to merge 2 commits into
omacom:quattrofrom
surim0n:fix/codex-auth-gate
Closed

surim0n wants to merge 2 commits into
omacom:quattrofrom
surim0n:fix/codex-auth-gate

Conversation

@surim0n

@surim0n surim0n commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Every agents-panel refresh runs omarchy-agent-usage-codex, which starts codex app-server to read rate limits — and starting it makes Codex sync its plugin list, a git fetch of github.com/openai/plugins.git per refresh plus a ~/.codex/.tmp/git-* folder each time (~680 accumulated in a week in the report)
  • Without ~/.codex/auth.json (or a CODEX_API_KEY/OPENAI_API_KEY env login) account/read can only fail, so for anyone who has Codex installed but isn't authenticated the spawn is pure side effect
  • The collector now checks for credentials before spawning the app-server and returns the usual "Run codex login" help text instead

This deliberately leaves the enabled-providers question (ship disabled vs opt-in) to a maintainer decision; this PR removes the unavoidable no-op spawn.

Fixes #13051

Test plan

  • bash test/shell.d/agent-usage-codex-scanner-test.sh — new assertion: with no auth.json the collector never invokes codex (verified via CODEX_ARGS_FILE capture) and reports Codex limits unavailable. Existing fixtures now carry an auth.json so the RPC path is still exercised end to end.
  • Network audit shows no github.com/openai/plugins.git fetches from the agents panel on a machine without Codex auth

Starting `codex app-server` to read rate limits makes Codex sync its
plugin list — a git fetch of github.com/openai/plugins.git on every
refresh, plus a ~/.codex/.tmp/git-* folder each time (680 collected in a
week in the report). Without ~/.codex/auth.json (or a CODEX_API_KEY /
OPENAI_API_KEY env login) account/read can only fail anyway, so the
probe is pure side effect.

Fixes omacom#13051
@llstrk

llstrk commented Sep 25, 2026

Copy link
Copy Markdown

Automated AI review

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

Verified: With Codex's default file credential store, a missing $CODEX_HOME/auth.json means no login, and the collector now returns before starting codex app-server. Local Codex, pi, omp and opencode usage stats are still reported. For these users the skipped probe loses nothing: account/rateLimits/read can only return an authentication error. The new test assertion fails on the base collector and passes on this head.

The credential check also has false negatives (logged-in users treated as logged out) and false positives (variables that do not log in the app-server), described below.

Logged-in users without auth.json lose their rate limits

The check at bin/omarchy-agent-usage-codex:529-536 treats "no auth.json and no API-key variable" as "not logged in". At Codex rust-v0.156.1, two supported login paths leave no auth.json:

  • cli_auth_credentials_store = "keyring" or "auto" in config.toml. Saving credentials to the keyring deletes auth.json (login/src/auth/storage.rs#L300-L310).
  • A CODEX_ACCESS_TOKEN login, which Codex reads before its persistent store and which uses the Codex backend, so rate limits are readable.

Collector output with a stub codex that answers as a logged-in app-server (synthetic, --limits-only):

Case Base This PR
auth.json present 2 limits, plan shown 2 limits, plan shown
no auth.json (keyring/auto store) 2 limits, plan shown no limits, "Codex limits unavailable"
no auth.json, CODEX_ACCESS_TOKEN set 2 limits, plan shown no limits, "Codex limits unavailable"

Impact: These users lose their 5-hour and weekly meters and are told to run codex login. In keyring mode that does not help, because a new login again saves to the keyring and deletes auth.json. The file store is the default, so most users are unaffected.

Suggested change: Apply the auth.json shortcut only when the configured store is file (read cli_auth_credentials_store from $CODEX_HOME/config.toml, for example with tomllib, and fall through to the probe for keyring/auto). Treat a non-empty CODEX_ACCESS_TOKEN as a possible login.

OPENAI_API_KEY and CODEX_API_KEY do not log in codex app-server

At rust-v0.156.1 the app-server builds its auth manager with the environment API key disabled (app-server/src/lib.rs#L805-L808), and login resolution never reads OPENAI_API_KEY. Rate limits also need a Codex-backend login: an API key gets "chatgpt authentication required to read rate limits" (account_processor.rs#L1107-L1121).

no auth.json + OPENAI_API_KEY or CODEX_API_KEY exported
  -> check passes, app-server starts on every refresh
  -> no Codex login, so no remote plugin catalog
  -> curated plugin repo sync runs (the reported side effect)
  -> rateLimits/read fails, no limits shown

Impact: Users with no Codex login who export either variable in the desktop session keep the plugin-repository contact the PR aims to remove, with nothing gained. This matches base behavior, so it is not a regression, but it narrows the fix for a common developer setup.

Suggested change: Drop the CODEX_API_KEY and OPENAI_API_KEY exceptions (and add CODEX_ACCESS_TOKEN as above).

Optional test improvement: The new no-credentials case inherits OPENAI_API_KEY and CODEX_API_KEY from the caller. With either variable set, the test fails falsely ("Codex collector does not spawn app-server without credentials"). Prefixing the call with env -u OPENAI_API_KEY -u CODEX_API_KEY made it pass in the same environment.


Review information

Test scope: Source review of the pinned head and base, and of Codex CLI source at tag rust-v0.156.1 (the PR does not state which Codex version was tested; other versions may differ). Sandboxed runs with no network: the scanner test on base and head, and direct collector runs against a stub codex whose replies follow the rust-v0.156.1 source. Not tested: a live Codex binary, a real keyring or login, or a network audit.

AI process: Opus 5.5 Medium coordination and synthesis, independent Opus 5.5 Xhigh and GPT 6 Sol Xhigh technical assessments, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@surim0n

surim0n commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

Good catches, fixed in 7b2bbd8. The gate now reads cli_auth_credentials_store from config.toml and only short-circuits under the default file store; keyring/auto fall through to the probe. CODEX_ACCESS_TOKEN counts as a possible login. The OPENAI_API_KEY/CODEX_API_KEY exceptions are dropped since they do not log in the app-server. Tests cover keyring, access token, API-key-only and the plain no-credentials case, with the inherited variables unset.

@llstrk

llstrk commented Sep 27, 2026

Copy link
Copy Markdown

Automated AI review

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

Follow-up to the earlier review, checked at 7b2bbd8b. The author's reply describes the changes.

Verified: All three earlier points are resolved.

New in this round: the new config.toml read can crash the collector, the parser misses some store settings, and two open PRs have tests that will need an auth.json fixture.

Earlier point Status at 7b2bbd8b
Keyring/auto store and CODEX_ACCESS_TOKEN users lose their rate limits Resolved
OPENAI_API_KEY/CODEX_API_KEY exceptions keep the app-server spawn Resolved
Optional test improvement: the no-credentials test inherits API-key variables Resolved

Collector runs with a stub codex that answers as logged in, --limits-only, no auth.json:

Case Previous head bfbba368 This head
cli_auth_credentials_store = "keyring" or "auto" skip, no limits probe, 2 limits
CODEX_ACCESS_TOKEN set skip, no limits probe, 2 limits
only OPENAI_API_KEY or only CODEX_API_KEY set probe skip, "Codex limits unavailable"
no config, no token skip skip, "Codex limits unavailable"

The earlier source claims still hold at the latest Codex release, rust-v0.157.1. The app-server still disables the environment API key, and saving to the keyring still deletes auth.json. The head test file passes 25/25, including with all three variables exported. Each new case fails against a collector variant that lacks the behaviour it tests.

Documentation: The PR description still lists CODEX_API_KEY/OPENAI_API_KEY as logins, which no longer matches the code after 7b2bbd8b. Updating the description to drop them would keep it accurate.

An unreadable or non-UTF-8 config.toml crashes the collector

config_toml.read_text() at bin/omarchy-agent-usage-codex:539 has no error handling and no explicit encoding, and no caller catches the exception. It runs whenever codex is on PATH and config.toml exists, even when auth.json exists.

config.toml (auth.json present) Base and bfbba368 This head
mode 000 exit 0, full record exit 1, PermissionError, empty stdout
contains byte 0xE9 (LANG=C.UTF-8) exit 0, full record exit 1, UnicodeDecodeError, empty stdout

The mode 000 case fails the same way in full-scan mode.

Impact: omarchy-agent-usage-update treats the missing JSON as "codex collector failed" and keeps the previous codex.json. On a first run it writes none. The Codex tab then stops updating entirely, local token stats included, where base and bfbba368 still printed a full record. Such a file is unlikely, but the failure is out of proportion to it.

Suggested change: Guard the read and fall through to the probe on any error other than a missing file. A variant that opens the file in binary mode, parses it with tomllib and probes on any exception passed the head test file (25/25) and fixed these cases. It also fixed the three syntax cases below (single-quoted value, quoted key, key inside a table). That variant was written during the review; it is not from the PR.

The line regex misses some ways of setting the store

The regex only matches a double-quoted value with a bare key, in $CODEX_HOME/config.toml only.

  • Logged-in users treated as logged out (the earlier finding, in narrower configurations):
    • Confirmed by run: cli_auth_credentials_store = 'keyring', a valid TOML literal string that Codex's own test fixtures use, and a quoted key ("cli_auth_credentials_store" = "keyring").
    • From source only: a store set in /etc/codex/config.toml when the user file does not set it, or enforced by /etc/codex/requirements.toml (or the legacy /etc/codex/managed_config.toml). Both apply at rust-v0.156.1 and rust-v0.157.1, and a requirement overrides the user setting.
  • Probe still runs without a Codex login (same as base, so not a regression, but the plugin sync stays):
    • Confirmed by run: the key inside a TOML table, for example after a [projects."..."] header. Codex does not read that as the top-level setting.
    • "ephemeral": the collector probes (run), and by source a fresh app-server has no login under that store.

Impact: The first group loses the 5-hour and weekly meters and is told to run codex login. The second group keeps the refresh-time plugin sync the PR aims to remove. Both groups need unusual configurations.

Suggested change: Parse the file with tomllib and read only the top-level key, as in the variant above. Optionally, also read /etc/codex/config.toml when the user file does not set the key, and fall through to the probe when /etc/codex/requirements.toml or /etc/codex/managed_config.toml exists.

Optional test improvement: No test covers auto, and none sets only CODEX_API_KEY. A collector variant that checks == "keyring" in place of != "file" passes the current tests, and so does one that re-adds the CODEX_API_KEY exception.

Interaction with open PRs #13109 and #13102

Both PRs append tests whose fixtures have no auth.json and expect the collector to probe codex:

In each pair, whichever PR lands second needs one auth.json line per affected fixture. #13109 and #13102 both append their tests at the same point in the test file, so their merges will also conflict textually.


Review information

Test scope: Fresh follow-up review of head 7b2bbd8b against bfbba368 and the base. Sources read: this PR's code and tests, and the Codex CLI source at rust-v0.156.1 and rust-v0.157.1. Sandboxed runs with no network: the scanner test files, a collector matrix and per-case variant runs against a stub codex whose replies are synthetic, and this head combined with #13109 and with #13102. Not tested: a live Codex binary, a real keyring or login, a network audit, and the /etc/codex and requirements layers.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@dhh

dhh commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Thank you! Brought in with your authorship in #14049. Adapted to check credentials in each account's own home, report "Waiting for auth" for a signed-out home, and read the credentials-store setting with tomllib.

@dhh dhh closed this Oct 2, 2026
dhh added a commit that referenced this pull request Oct 3, 2026
…ommunity PRs (#14049)

* Read Codex app-server replies from the raw fd (#13703)

* Resolve Codex through mise which instead of running the lazy launcher (#13109)

* Skip the Codex app-server probe when there are no credentials (#13106)

Adapted: credentials are checked in the home being probed rather than in
the CODEX_HOME environment variable, since each registered account is
probed in its own home, so a signed-out secondary account isn't hidden
behind the primary's login. A home without credentials reports "Waiting
for auth" like any other signed-out home. The credentials store setting is
read with tomllib, so a single-quoted value counts too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Show the Codex CLI's own error when its app-server dies (#8977)

Detect an app-server that exits or stops answering, and report the end of
its stderr instead of a bare RPC method name. Rebased onto the raw-fd
reply reader; the switch from "-a on-request" to "-a never" is left out,
keeping the current approval flags.

* Count pi sessions when HOME is a git checkout (#13209)

* Count only OpenAI-backed native sessions as Codex usage (#12032)

* Deduplicate Pi usage across forked sessions (#8602)

* Skip unchanged native Codex token snapshots (#10531)

* Count omp and pi profile sessions in the agent usage collectors (#9546)

`omp --profile=<name>` (and pi's equivalent) relocates the whole agent
tree under <base>/profiles/<name>/. The Claude and Codex collectors only
ever scanned <base>/agent/sessions, so a subscription driven entirely
through a profile was invisible to the agents panel: no tokens by day, no
tokens by model, no prompt or session counts.

Discover the profile roots alongside the default one. Sessions are keyed
by file path, so a profile adds sessions instead of double-counting the
default root, and a missing or unreadable profiles directory leaves the
existing behavior untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014zFbJcDEEpV5BAmsH6kAB3

* Skip unrelated Codex session lines before JSON parsing (#12803)

Adapted: session_meta lines also pass the pre-filter, since the provider
filter from #12032 reads them to skip rollouts served by a non-OpenAI
provider.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Read only the Codex session files that changed since the last scan (#12595)

Native Codex rollouts keep per-file totals between runs, replayed while a
file's mtime and size are unchanged. Rebased onto the session_meta
provider filter, snapshot dedup, and line pre-filter, which now live in
the per-file reader. pi and omp sessions are left out of the per-file
cache: a forked pi session repeats its parent's messages, so they are
deduplicated across the whole tree on every scan.

* Count streamed Claude messages by their highest-output usage line (#10606)

Claude Code writes a streamed assistant response as several transcript
lines that share one message id, one per content block. Each line
carries a usage object. The first line's output_tokens is a placeholder,
often 1, and the last line has the real count. Input and cache fields
usually match across the lines.

The scanner dedupes by message id and keeps the first line it sees, so
it under-counts output tokens. On a machine with 2,577 transcripts it
reported 39.0M output tokens against 60.1M used, a 35% shortfall. Input
and both cache fields differed by under 0.01%.

Keep the line with the highest output count, with the last one scanned
winning a tie. The whole line is kept because a response can fall back
to another model mid-stream. Those lines are separate snapshots with
different cache figures and a different model, and taking a maximum per
field across them over-counts cache tokens and credits the wrong model.

The zero-usage check now runs before dedup, so a zero-usage first line
no longer claims a message id and hides a later line with real usage.

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: GPT-6 Astra <noreply@openai.com>

* Index Claude transcripts so the agents refresh reads only what was appended (#8313)

omarchy-agent-usage-claude re-parsed every line of every transcript under
~/.claude/projects on each refresh: no mtime cutoff, no memory of the last
pass. The agents widget is on by default and ticks every 15 minutes, so the
cost grew for the life of the machine. After one month here that was 803
files, 640 MB, 127k lines and 57k JSON parses per tick, about 1 core-second,
pushed through the page cache every quarter hour forever.

Keep a per-file index next to the scan cache: the unique usage records
already parsed out of each transcript and the byte offset they end at. A
file whose size and mtime match is not opened; a file that grew is read
from the stored offset; a file that shrank or was rewritten is read from
the start. --force drops the index and rescans from scratch.

The summary is built from the indexed records in the same directory order
the walk always used. That matters: when a resumed session carries earlier
messages, the same message id appears in two files with different usage,
and the first file visited wins. 91 ids differed on this machine; sorting
the walk moved one model's output total by 25k tokens. Output is now
byte-identical to the previous scan on a frozen copy of the corpus, cold,
warm, and after an append.

Warm refresh: 1.0 s -> 0.10 s of CPU, of which the scan itself is 70 ms;
the index for this corpus is 2.9 MB.

Adapted:
- Rebased onto #10606: the highest-output rule for streamed messages now
  lives where the index parses records, and decides between files too.
- The index records the timezone it was written in, and a change rereads
  every transcript, since its records hold local days.
- A file only counts as appended to when its inode and the hash of what
  was already read still match, so a transcript replaced by a larger one,
  or rewritten in place, is read from the start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Label a Claude Team seat by its subscription, not its rate-limit tier (#11109)

The collector built the plan label from the OAuth rateLimitTier first, so a
Team premium seat, which runs on default_claude_max_5x, showed in the agents
panel as "Max 5x". Lead with subscriptionType and keep the multiplier as its
qualifier: Max still reads "Max 5x", a Team seat reads "Team 5x".

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Label the Claude plan from the profile the CLI refreshes (#7225)

Adapted: the profile is found the same way current_account_id() finds it,
now shared as profile_path(): ~/.claude.json for the default home, the
home's own .claude.json otherwise. The original fell back to ~/.claude.json
for any home without CLAUDE_CONFIG_DIR set, so a secondary account read the
primary's tier. The profile's tier also keeps the subscription in the label,
so a Team seat stays "Team" (#11109).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Call a lapsed Claude access token paused, not signed out (#8093)

* Refresh Claude usage after the clock moves backwards (#9956)

* Bound unreadable Claude transcript warnings (#12414)

* Count Claude usage from opencode v2 sessions (#13894)

* Reload agent usage records when an inotify watch fails to rearm (#10067)

* Reload agent usage records after each update run instead of on a timer

Rather than #10067's two-minute timer per record, reload every record when
the omarchy-agent-usage-update process exits, the moment its files can have
been replaced. A reload that finds a file unchanged keeps its record, so the
panel isn't stirred up by identical data. The grep test now runs the QML
functions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Show the agent status when the trouble line has no help text (#8497)

* Clear stale agent login guidance after a successful probe (#8892)

* Clear the Grok login hint after a successful probe

#8892 cleared the default login hint after a successful probe in the
Claude and Codex collectors; Grok's collector had the same stale hint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Read Fireworks credentials from pi's auth.json (#7455)

The Fireworks collector skipped pi, Omarchy's default agent, when
walking its credential ladder, so a machine signed in to Fireworks only
through pi (/login fireworks) never showed the tab. Insert the key pi
stores in $PI_CODING_AGENT_DIR/auth.json (default ~/.pi/agent) between
the firectl auth.ini and the opencode fallback.

pi keys can be literals, $ENV_VAR/${ENV_VAR} references, or !command
shell lookups. The collector resolves the first two; command lookups
stay pi-only and are skipped rather than sent to the API verbatim.

* Call a lapsed Grok access token paused, not signed out

Grok's access token lives six hours and Grok mints a new one from its
refresh token whenever it starts, so a lapsed one is routine. Reporting
it as an expired sign-in made the panel offer Sign-in required several
times a day, sending people through grok login for nothing. With a
refresh token present it now reads as paused, like Claude's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Keep showing Grok's last limits while it sits idle

While Grok hasn't run, nothing on the machine has spent its allowance,
so with a refresh token on hand the last numbers still stand: they show
as current rather than dimmed under a status line. A weekly window that
reset in the meantime starts over at 0%, a whole number of weeks on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Ask for a Grok sign-in once its refresh token is past 30 days

A refresh token older than Grok's 30-day sign-in can't renew anything,
so the panel offers Sign-in required again instead of showing the last
limits as current. With nothing cached yet it says to start Grok, rather
than showing an empty section without a word.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Check both ends of what the Claude index read before resuming a transcript

A transcript rewritten in place could grow and change only after its
first kilobytes, and the index took it for an append. It now compares
the last kilobytes before the resume point too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Simplify the agent usage collectors

- Codex: pass the forced-scan choice down instead of a module global, make
  the per-file reader's cache arguments required, shrink the cache record
  check, and drop guards for shapes that can't occur: an empty launcher
  path, realpath raising, mise itself being a lazy launcher, multi-line
  `mise which` output, and probing without a temp file for stderr.
- Claude: decide an append by the digest of both ends of what was read
  alone; the inode and mtime checks it made redundant are gone.
- Snapshot: the device id falls back to the hostname, which always exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Share fixture setup in the agent usage scanner tests

Every fixture home lives under one scratch directory with a single cleanup
trap, instead of a trap rewritten with a longer list for each new home, and
the Codex test builds its signed-in homes with one helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Treat a replaced Claude transcript as new even when its ends match

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Probe Codex without its error text when there's no temporary space

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: tossbaws <17258053+tossbaws@users.noreply.github.com>
Co-authored-by: surim0n <suritech@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: anonwurcod <anonwurcod@proton.me>
Co-authored-by: Kevin Rajan <7121943+kvnloo@users.noreply.github.com>
Co-authored-by: Nate Ashby <nate.ashby11@gmail.com>
Co-authored-by: Aris Gysel <aris.gysel@me.com>
Co-authored-by: Brams <76213579+Brams-s@users.noreply.github.com>
Co-authored-by: This_Is_NPC <gabrielfollone27@gmail.com>
Co-authored-by: sanjyay <102979855+sanjyay@users.noreply.github.com>
Co-authored-by: PapistProtocol <12738904+PapistProtocol@users.noreply.github.com>
Co-authored-by: steez <stevedimakos97@gmail.com>
Co-authored-by: GPT-6 Astra <noreply@openai.com>
Co-authored-by: Ryan Yogan <ryanyogan@gmail.com>
Co-authored-by: Oli Denton <41393837+omdenton@users.noreply.github.com>
Co-authored-by: Igor Kramar <i@ikramar.ru>
Co-authored-by: Martin Eidensten <martin@meibe.se>
Co-authored-by: Romain Perron <rdj.perron@gmail.com>
Co-authored-by: Omarchy Contributor <contributor@users.noreply.github.com>
Co-authored-by: manuaudio <manu@arimaka.com>
Co-authored-by: Tyler South <tsouth2@gmail.com>
Co-authored-by: whathek <Hek846@users.noreply.github.com>
Co-authored-by: Ty Richards <me@tyrichards.com>
sgruendel pushed a commit to sgruendel/omarchy that referenced this pull request Oct 3, 2026
…ommunity PRs (omacom#14049)

* Read Codex app-server replies from the raw fd (omacom#13703)

* Resolve Codex through mise which instead of running the lazy launcher (omacom#13109)

* Skip the Codex app-server probe when there are no credentials (omacom#13106)

Adapted: credentials are checked in the home being probed rather than in
the CODEX_HOME environment variable, since each registered account is
probed in its own home, so a signed-out secondary account isn't hidden
behind the primary's login. A home without credentials reports "Waiting
for auth" like any other signed-out home. The credentials store setting is
read with tomllib, so a single-quoted value counts too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Show the Codex CLI's own error when its app-server dies (omacom#8977)

Detect an app-server that exits or stops answering, and report the end of
its stderr instead of a bare RPC method name. Rebased onto the raw-fd
reply reader; the switch from "-a on-request" to "-a never" is left out,
keeping the current approval flags.

* Count pi sessions when HOME is a git checkout (omacom#13209)

* Count only OpenAI-backed native sessions as Codex usage (omacom#12032)

* Deduplicate Pi usage across forked sessions (omacom#8602)

* Skip unchanged native Codex token snapshots (omacom#10531)

* Count omp and pi profile sessions in the agent usage collectors (omacom#9546)

`omp --profile=<name>` (and pi's equivalent) relocates the whole agent
tree under <base>/profiles/<name>/. The Claude and Codex collectors only
ever scanned <base>/agent/sessions, so a subscription driven entirely
through a profile was invisible to the agents panel: no tokens by day, no
tokens by model, no prompt or session counts.

Discover the profile roots alongside the default one. Sessions are keyed
by file path, so a profile adds sessions instead of double-counting the
default root, and a missing or unreadable profiles directory leaves the
existing behavior untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014zFbJcDEEpV5BAmsH6kAB3

* Skip unrelated Codex session lines before JSON parsing (omacom#12803)

Adapted: session_meta lines also pass the pre-filter, since the provider
filter from omacom#12032 reads them to skip rollouts served by a non-OpenAI
provider.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Read only the Codex session files that changed since the last scan (omacom#12595)

Native Codex rollouts keep per-file totals between runs, replayed while a
file's mtime and size are unchanged. Rebased onto the session_meta
provider filter, snapshot dedup, and line pre-filter, which now live in
the per-file reader. pi and omp sessions are left out of the per-file
cache: a forked pi session repeats its parent's messages, so they are
deduplicated across the whole tree on every scan.

* Count streamed Claude messages by their highest-output usage line (omacom#10606)

Claude Code writes a streamed assistant response as several transcript
lines that share one message id, one per content block. Each line
carries a usage object. The first line's output_tokens is a placeholder,
often 1, and the last line has the real count. Input and cache fields
usually match across the lines.

The scanner dedupes by message id and keeps the first line it sees, so
it under-counts output tokens. On a machine with 2,577 transcripts it
reported 39.0M output tokens against 60.1M used, a 35% shortfall. Input
and both cache fields differed by under 0.01%.

Keep the line with the highest output count, with the last one scanned
winning a tie. The whole line is kept because a response can fall back
to another model mid-stream. Those lines are separate snapshots with
different cache figures and a different model, and taking a maximum per
field across them over-counts cache tokens and credits the wrong model.

The zero-usage check now runs before dedup, so a zero-usage first line
no longer claims a message id and hides a later line with real usage.

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: GPT-6 Astra <noreply@openai.com>

* Index Claude transcripts so the agents refresh reads only what was appended (omacom#8313)

omarchy-agent-usage-claude re-parsed every line of every transcript under
~/.claude/projects on each refresh: no mtime cutoff, no memory of the last
pass. The agents widget is on by default and ticks every 15 minutes, so the
cost grew for the life of the machine. After one month here that was 803
files, 640 MB, 127k lines and 57k JSON parses per tick, about 1 core-second,
pushed through the page cache every quarter hour forever.

Keep a per-file index next to the scan cache: the unique usage records
already parsed out of each transcript and the byte offset they end at. A
file whose size and mtime match is not opened; a file that grew is read
from the stored offset; a file that shrank or was rewritten is read from
the start. --force drops the index and rescans from scratch.

The summary is built from the indexed records in the same directory order
the walk always used. That matters: when a resumed session carries earlier
messages, the same message id appears in two files with different usage,
and the first file visited wins. 91 ids differed on this machine; sorting
the walk moved one model's output total by 25k tokens. Output is now
byte-identical to the previous scan on a frozen copy of the corpus, cold,
warm, and after an append.

Warm refresh: 1.0 s -> 0.10 s of CPU, of which the scan itself is 70 ms;
the index for this corpus is 2.9 MB.

Adapted:
- Rebased onto omacom#10606: the highest-output rule for streamed messages now
  lives where the index parses records, and decides between files too.
- The index records the timezone it was written in, and a change rereads
  every transcript, since its records hold local days.
- A file only counts as appended to when its inode and the hash of what
  was already read still match, so a transcript replaced by a larger one,
  or rewritten in place, is read from the start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Label a Claude Team seat by its subscription, not its rate-limit tier (omacom#11109)

The collector built the plan label from the OAuth rateLimitTier first, so a
Team premium seat, which runs on default_claude_max_5x, showed in the agents
panel as "Max 5x". Lead with subscriptionType and keep the multiplier as its
qualifier: Max still reads "Max 5x", a Team seat reads "Team 5x".

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Label the Claude plan from the profile the CLI refreshes (omacom#7225)

Adapted: the profile is found the same way current_account_id() finds it,
now shared as profile_path(): ~/.claude.json for the default home, the
home's own .claude.json otherwise. The original fell back to ~/.claude.json
for any home without CLAUDE_CONFIG_DIR set, so a secondary account read the
primary's tier. The profile's tier also keeps the subscription in the label,
so a Team seat stays "Team" (omacom#11109).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Call a lapsed Claude access token paused, not signed out (omacom#8093)

* Refresh Claude usage after the clock moves backwards (omacom#9956)

* Bound unreadable Claude transcript warnings (omacom#12414)

* Count Claude usage from opencode v2 sessions (omacom#13894)

* Reload agent usage records when an inotify watch fails to rearm (omacom#10067)

* Reload agent usage records after each update run instead of on a timer

Rather than omacom#10067's two-minute timer per record, reload every record when
the omarchy-agent-usage-update process exits, the moment its files can have
been replaced. A reload that finds a file unchanged keeps its record, so the
panel isn't stirred up by identical data. The grep test now runs the QML
functions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Show the agent status when the trouble line has no help text (omacom#8497)

* Clear stale agent login guidance after a successful probe (omacom#8892)

* Clear the Grok login hint after a successful probe

omacom#8892 cleared the default login hint after a successful probe in the
Claude and Codex collectors; Grok's collector had the same stale hint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Read Fireworks credentials from pi's auth.json (omacom#7455)

The Fireworks collector skipped pi, Omarchy's default agent, when
walking its credential ladder, so a machine signed in to Fireworks only
through pi (/login fireworks) never showed the tab. Insert the key pi
stores in $PI_CODING_AGENT_DIR/auth.json (default ~/.pi/agent) between
the firectl auth.ini and the opencode fallback.

pi keys can be literals, $ENV_VAR/${ENV_VAR} references, or !command
shell lookups. The collector resolves the first two; command lookups
stay pi-only and are skipped rather than sent to the API verbatim.

* Call a lapsed Grok access token paused, not signed out

Grok's access token lives six hours and Grok mints a new one from its
refresh token whenever it starts, so a lapsed one is routine. Reporting
it as an expired sign-in made the panel offer Sign-in required several
times a day, sending people through grok login for nothing. With a
refresh token present it now reads as paused, like Claude's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Keep showing Grok's last limits while it sits idle

While Grok hasn't run, nothing on the machine has spent its allowance,
so with a refresh token on hand the last numbers still stand: they show
as current rather than dimmed under a status line. A weekly window that
reset in the meantime starts over at 0%, a whole number of weeks on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Ask for a Grok sign-in once its refresh token is past 30 days

A refresh token older than Grok's 30-day sign-in can't renew anything,
so the panel offers Sign-in required again instead of showing the last
limits as current. With nothing cached yet it says to start Grok, rather
than showing an empty section without a word.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Check both ends of what the Claude index read before resuming a transcript

A transcript rewritten in place could grow and change only after its
first kilobytes, and the index took it for an append. It now compares
the last kilobytes before the resume point too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Simplify the agent usage collectors

- Codex: pass the forced-scan choice down instead of a module global, make
  the per-file reader's cache arguments required, shrink the cache record
  check, and drop guards for shapes that can't occur: an empty launcher
  path, realpath raising, mise itself being a lazy launcher, multi-line
  `mise which` output, and probing without a temp file for stderr.
- Claude: decide an append by the digest of both ends of what was read
  alone; the inode and mtime checks it made redundant are gone.
- Snapshot: the device id falls back to the hostname, which always exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Share fixture setup in the agent usage scanner tests

Every fixture home lives under one scratch directory with a single cleanup
trap, instead of a trap rewritten with a longer list for each new home, and
the Codex test builds its signed-in homes with one helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Treat a replaced Claude transcript as new even when its ends match

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Probe Codex without its error text when there's no temporary space

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: tossbaws <17258053+tossbaws@users.noreply.github.com>
Co-authored-by: surim0n <suritech@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: anonwurcod <anonwurcod@proton.me>
Co-authored-by: Kevin Rajan <7121943+kvnloo@users.noreply.github.com>
Co-authored-by: Nate Ashby <nate.ashby11@gmail.com>
Co-authored-by: Aris Gysel <aris.gysel@me.com>
Co-authored-by: Brams <76213579+Brams-s@users.noreply.github.com>
Co-authored-by: This_Is_NPC <gabrielfollone27@gmail.com>
Co-authored-by: sanjyay <102979855+sanjyay@users.noreply.github.com>
Co-authored-by: PapistProtocol <12738904+PapistProtocol@users.noreply.github.com>
Co-authored-by: steez <stevedimakos97@gmail.com>
Co-authored-by: GPT-6 Astra <noreply@openai.com>
Co-authored-by: Ryan Yogan <ryanyogan@gmail.com>
Co-authored-by: Oli Denton <41393837+omdenton@users.noreply.github.com>
Co-authored-by: Igor Kramar <i@ikramar.ru>
Co-authored-by: Martin Eidensten <martin@meibe.se>
Co-authored-by: Romain Perron <rdj.perron@gmail.com>
Co-authored-by: Omarchy Contributor <contributor@users.noreply.github.com>
Co-authored-by: manuaudio <manu@arimaka.com>
Co-authored-by: Tyler South <tsouth2@gmail.com>
Co-authored-by: whathek <Hek846@users.noreply.github.com>
Co-authored-by: Ty Richards <me@tyrichards.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agents panel runs every provider's collector by default; the Codex collector causes repeated network fetches

4 participants