Skip to content

Fix Cursor input normalization and CLI cache token accounting - #37

Open
Wang Siyuan (Wangmerlyn) wants to merge 1 commit into
microsoft:mainfrom
Wangmerlyn:codex/fix-cli-cache-accounting
Open

Wang Siyuan (Wangmerlyn) wants to merge 1 commit into
microsoft:mainfrom
Wangmerlyn:codex/fix-cli-cache-accounting

Conversation

@Wangmerlyn

Copy link
Copy Markdown

Cursor CLI results report cacheReadTokens, and Codex turns can report cache_write_input_tokens. Argus currently drops these fields, turning reported cache counts (including an explicit zero) into unknown ledger values.

Preserve both fields through the existing alias parser. Cursor also reports uncached input separately from cache reads/writes, so normalize its terminal result to Argus's inclusive input count. For example, a recorded result with inputTokens=7361, cacheReadTokens=23040, and cacheWriteTokens=0 becomes total input 30401 with cached input 23040. Adding only the cache alias would incorrectly discount fresh input when a model has a configured price.

Cursor terminal usage covers the current CLI invocation, including its followups. Mark that source separately so resumed sessions retain each invocation's full usage instead of subtracting the prior invocation. Canonical input aliases retain their existing precedence, omitted cache fields remain unknown, and raw events remain unchanged.

Protocol evidence: Cursor's CLI token explanation and official token-usage contract. Inspection of the installed official CLI 2026.09.28-64d2043 confirms that turnEnded subtracts both caches from provider input and that the terminal usage accumulator is local to the print invocation. The two positive Cursor payloads in the tests are sanitized recorded results. Positive cache writes and the known-model pricing selection are synthetic regression cases.

Validation:

  • Before the fix, the initial 12 regression cases produced 10 failures / 2 passes. A second canonical-input precedence case was then added.
  • 188 tests passed across cache parsing, usage, pricing, cost control, adapter accounting, and Grok/Pi/OpenCode regressions. Tests cover explicit zeros, missing fields, cache reads larger than fresh input, writes, ledger readback, resumed Cursor calls, and translation-failure accounting.
  • uv run --python 3.11 --frozen --with pytest --with ruff python -m ruff check argus_skill tests and git diff --check passed.
  • Two independent read-only reviews found no actionable issues. All verification was offline; no new paid model calls were made.

The price catalog, subscription billing, historical reconciliation, and Cursor trust/model-effort integration require separate changes. This PR fixes the demonstrated token-accounting path.

@Wangmerlyn

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

1 participant