[codex] add account usage API#15
Merged
Merged
Conversation
- Treat JSON-RPC error replies on the optional usage/account reads as absent fields and propagate transport failures instead of swallowing them after killing the child. - Skip messages that carry a method (notifications and server-initiated requests) when matching responses by id. - Capture a bounded stderr tail and attach it to app-server errors. - Add a per-request timeout to AccountUsageRequest (default 10s). - Share the default executable name through a crate constant. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- Send params {} on account/read; the real app-server rejects the
request without it, leaving Account permanently nil.
- Replace the per-request read goroutines with a single long-lived
reader, removing a data race on the shared bufio.Reader.
- Skip messages that carry a method when matching responses by id.
- Treat JSON-RPC error replies on the optional reads as absent fields
and propagate transport failures instead of swallowing them.
- Capture stderr through the bounded, mutex-guarded tail buffer.
- Accept string-encoded numbers in rate-limit window fields, matching
the core decoder and observed payloads.
- Add AccountUsageRequest.Timeout (default 10s), reuse the
defaultExecutable constant and the runner's env merge convention.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add timeoutMs to the getAccountUsage options, mapped to the core per-request JSON-RPC timeout (default 10s). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- Add AccountUsageRequest.timeout (seconds), mapped to the core per-request JSON-RPC timeout (default 10s). - Raise CodexcwError (kind "process") when the account usage result is missing, matching the Node binding, and unwrap outcomes through _result_or_raise. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a separate account-usage API across all codexcw surfaces:
GetAccountUsage(ctx, AccountUsageRequest)get_account_usage(AccountUsageRequest)getAccountUsage()get_account_usage()andcodexcw.aio.get_account_usage()The helper talks to
codex app-server --stdio, reads account rate limits, token usage, and account metadata, and accepts executable/env overrides withCODEX_HOMEdefaulting to~/.codexwhen absent.Details
null.CODEXCW_LIVE_CODEX=1for real Codex validation./fastrecipe viaservice_tier="priority".Validation
Normal checks:
go test ./...cargo test --workspacenpm testuv run pytestgit diff --checkmarkdownlint-cli2,lychee, andgitleaksLive checks against the real local Codex executable:
CODEXCW_LIVE_CODEX=1 go test . -run TestLiveGetAccountUsageAndFastMode -vCODEXCW_LIVE_CODEX=1 cargo test -p codexcw live_account_usage_and_fast_mode -- --nocaptureCODEXCW_LIVE_CODEX=1 node --test --test-name-pattern 'live getAccountUsage' "__test__/**/*.test.mjs"CODEXCW_LIVE_CODEX=1 uv run pytest tests/test_smoke.py -k live_get_account_usage_and_fast_mode -q