Skip to content

Fix Codex usage collector with current app-server - #7829

Closed
BestSithInEU wants to merge 3 commits into
omacom:quattrofrom
BestSithInEU:fix/codex-app-server-compat
Closed

BestSithInEU wants to merge 3 commits into
omacom:quattrofrom
BestSithInEU:fix/codex-app-server-compat

Conversation

@BestSithInEU

Copy link
Copy Markdown

Summary

Fix the Codex usage collector for current Codex CLI versions.

Codex CLI 0.149.0 no longer accepts untrusted as an --ask-for-approval value. The collector therefore exited before responding to the app-server initialize request and reported:

  • Codex limits unavailable
  • initialize

Use the supported non-interactive never policy instead.

Also prefer the Codex-specific entry in rateLimitsByLimitId.codex, while retaining the existing rateLimits fallback for older app-server responses.

Verification

  • Ran test/shell.d/agent-usage-codex-scanner-test.sh
  • All focused collector tests passed
  • Ran git diff --check
  • Tested the patched collector against Codex CLI 0.149.0 with an authenticated account
  • Confirmed it returned the account tier and current rate-limit window instead of the initialization error

The regression test now verifies:

  • the collector launches Codex with -a never
  • the Codex-specific rate-limit bucket takes precedence
  • the legacy single-bucket response remains supported

Copilot AI balanced review requested due to automatic review settings August 22, 2026 23:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Codex usage collection for current CLI and app-server responses.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Changes:

  • Uses the supported never approval policy.
  • Prefers Codex-specific limits with legacy fallback.
  • Updates the collector regression fixture.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
bin/omarchy-agent-usage-codex Updates CLI arguments and rate-limit selection.
test/shell.d/agent-usage-codex-scanner-test.sh Tests current arguments and Codex-specific limits.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +37 to +38
rateLimitsByLimitId: {
codex: {
Batuhan Edgüer and others added 2 commits August 23, 2026 04:59
Preferring rateLimitsByLimitId.codex on presence alone drops real numbers. The app-server's own schema marks every field of RateLimitSnapshot optional, so a codex bucket of {"limitId": "codex", "planType": null, "primary": null, "secondary": null} is valid and truthy, and it beat a populated rateLimits. limit_window() then discarded both windows and the panel hid its limits section, with usageStatusText empty so no error card explained the gap.

Choosing on content rather than presence keeps the Codex-specific bucket wherever it actually carries a window and falls through to rateLimits otherwise, which codex-cli 0.149.0 still marks required and undeprecated.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed on a disposable Omarchy worker with codex-cli 0.149.0 installed, and independently by Codex at xhigh reasoning.

The approval policy change is right. On 0.149.0 the CLI rejects untrusted with [possible values: on-request, never], and both remaining values start app-server and complete the handshake — I ran both. The collector only ever sends initialize, initialized, account/read and account/rateLimits/read, and never opens a conversation, so no approval can be requested and the policy is inert for this workload. never and on-request are equally safe here.

The schema claim does not hold, though the change itself is harmless. rateLimitsByLimitId is an addition, not a rename. Asking 0.149.0 for its own protocol schema with codex app-server generate-json-schema gives, in GetAccountRateLimitsResponse:

  • rateLimits — required, not nullable, not deprecated, described as "Backward-compatible single-bucket view; mirrors the historical payload."
  • rateLimitsByLimitId — optional and nullable, "Multi-bucket view keyed by metered limit_id (for example, codex)."

Both are the same RateLimitSnapshot type, so the two shapes are interchangeable downstream and there is no mismatch risk for planType, primary or secondary. Reading the Codex bucket first is defensible as future-proofing, but it is not what fixes #7648: the one-line policy change alone restores the panel, which I confirmed by running the collector with only -a changed.

One defect, now fixed on your branch. RateLimitSnapshot has no required fields, so {"limitId": "codex", "planType": null, "primary": null, "secondary": null} is a valid response. That dict is non-empty and therefore truthy, so it won the or chain and suppressed a populated rateLimits. limit_window() then dropped both windows and the panel hid its limits section entirely, with usageStatusText empty — no error card, just a Codex tab showing a plan name and nothing under it. Against a stub serving that shape, the branch returned limits: [] where the plain -a fix returned the real window.

9571085 chooses on content rather than presence: the Codex bucket is used wherever it actually carries a primary or secondary, and rateLimits otherwise. Your existing assertions all still pass, and the new one covering the null-window bucket fails without the collector change.

One thing for the maintainer rather than for you. The stub's [[ " $* " == *" -a never "* ]] guard pins one of the two valid policies, so this test fails against #7649 and #7770, which chose on-request. That is consistent with your own production line and I have not touched it, but it means the test and the collector have to be taken together. Codex also noted the guard flattens argv through $*, so a single argument containing -a never would satisfy it — cosmetic, since nothing constructs the argv that way.

Tests ran on the worker through the shell-test wrapper, never on the review machine: 22 passed, 0 failed. Codex at xhigh reported the same null-bucket defect and agreed that nothing in the repository establishes the wire format; its independence is not currently guaranteed, since it can read the reviewing session's own files. It contributed the $* observation, which I had not reasoned about. It could not settle the schema question from the repository alone — that came from the installed 0.149.0 binary on the worker.

Waiting on the maintainer, who is choosing between six pull requests for this one line.

@omarchybot

Copy link
Copy Markdown
Collaborator

#7649 is merged (4cd8a08) and makes this same fix: the collector now launches app-server with -a on-request instead of the retired untrusted, with the launch arguments asserted in the collector test.

Closing as superseded. The second half of this PR — preferring the Codex-specific rateLimitsByLimitId bucket — isn't in #7649; #7725 covers that ground more fully, so it's being handled there.

@omarchybot omarchybot closed this Aug 25, 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.

3 participants