fix: codex real token usage + resolve codex outside the daemon PATH#145
Merged
Conversation
Two fixes surfaced by the live subscription smoke (both previously showed as zeros / not-installed on a real machine): - Usage: codex's turn/completed carries NO token usage (verified against @openai/codex 0.144.1). It arrives on the separate thread/tokenUsage/updated notification (tokenUsage.last). Capture that per turn and fold it into turn_done — inputTokens excludes cache reads (claude convention: last.inputTokens - last.cachedInputTokens), cache reads and outputTokens mapped through. Smoke now reports real in=12474/out=8 instead of 0/0. - Resolution: codex is a Node-managed binary, and the daemon often runs with a PATH that omits the user's nvm / npm-global bin (systemd/launchd service, or a shell that never sourced nvm) — so a clearly-installed codex showed as unavailable. After PATH, scan the standard per-user Node bin dirs (nvm versions newest-first, NVM_BIN/VOLTA_HOME/ npm_config_prefix, ~/.npm-global, ~/.local/bin). New source: 'node-bin'. Verified live: codex resolves with an EMPTY daemon PATH. Tests: fake-codex emits the real tokenUsage.last notification; C1 asserts the cache-excluded usage; resolution test adds the node-bin-fallback case and isolates HOME so the machine's own codex can't leak into the no-codex assertion.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #145 +/- ##
==========================================
+ Coverage 82.82% 82.86% +0.03%
==========================================
Files 104 104
Lines 17734 17775 +41
==========================================
+ Hits 14688 14729 +41
Misses 3046 3046
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
… vars) codecov patch gap was the nodeBinDirs scanning. Add tests for the nvm newest-version-first glob, each version-manager env source (NVM_BIN / VOLTA_HOME / npm_config_prefix), and export compareNodeVersionsDesc to unit-test its ordering + equal-version tie. resolve.ts + index.ts now 100% line coverage.
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.
What
Two bugs the live ChatGPT-subscription smoke exposed — both make codex look broken on a real machine, neither is catchable offline:
Usage was always zero. codex's
turn/completedcarries no token usage (confirmed by probing@openai/codex@0.144.1live). Usage arrives on the separatethread/tokenUsage/updatednotification, withtokenUsage.lastbeing the just-finished turn's counts. The provider now captures that per turn and folds it intoturn_done, matching the claude convention (inputTokens= new tokens, cache reads excluded:last.inputTokens - last.cachedInputTokens; cache reads and output mapped through). Smoke went fromin=0 out=0toin=12474 out=8.codex resolved to "not installed" when it plainly was. codex is a Node-managed binary, and the daemon frequently runs with a PATH that omits the user's nvm / npm-global bin (a systemd/launchd service, or a shell that never sourced nvm — exactly this machine). After PATH, resolution now scans the standard per-user Node bin dirs (nvm versions newest-first,
NVM_BIN/VOLTA_HOME/npm_config_prefix,~/.npm-global,~/.local/bin), newsource: "node-bin". Verified live: codex resolves with an empty daemon PATH.Tests
fake-codexnow emits the realtokenUsage.lastnotification (and itsturn/completedno longer carries the fictional usage field). C1 asserts the cache-excluded numbers. The resolution test adds the node-bin-fallback case and isolatesHOMEso the machine's own codex can't leak into the "no codex → null" assertion.bun run test,typecheck,lintgreen; both fixes confirmed against real codex.🤖 Generated with Claude Code