Skip to content

Populate PromptResponse.usage from Codex token usage#210

Closed
simonrosenberg wants to merge 1 commit into
zed-industries:mainfrom
simonrosenberg:fix-acp-prompt-usage-telemetry
Closed

Populate PromptResponse.usage from Codex token usage#210
simonrosenberg wants to merge 1 commit into
zed-industries:mainfrom
simonrosenberg:fix-acp-prompt-usage-telemetry

Conversation

@simonrosenberg

@simonrosenberg simonrosenberg commented Mar 26, 2026

Copy link
Copy Markdown

Summary

This wires Codex token usage through to ACP prompt responses instead of dropping it at turn completion.

Specifically:

  • return a full PromptResponse from the ACP prompt path
  • populate PromptResponse.usage from Codex token counts
  • compute PromptResponse.usage as a per-turn delta from cumulative token usage
  • fix UsageUpdate.used to report cumulative tokens currently in context, not only the latest API call
  • add a regression test covering sequential turns

Resolves #165
Resolves #99

Why

codex-acp currently emits bare PromptResponse::new(stop_reason) responses, so ACP clients never receive per-turn token usage even though upstream Codex already exposes token counts.

This breaks telemetry in ACP clients and benchmarks that rely on PromptResponse.usage.

Scope

This PR intentionally does not populate UsageUpdate.cost.
That remains a separate issue because the adapter does not appear to receive an authoritative cumulative cost signal from upstream Codex today.

Tracked separately in #209.

Testing

Added a targeted regression test for:

  • first turn usage population
  • second turn delta calculation
  • cumulative UsageUpdate.used

I could not run cargo test locally in this environment because cargo is not installed on this machine.

@simonrosenberg simonrosenberg marked this pull request as draft March 26, 2026 16:19
@simonrosenberg

Copy link
Copy Markdown
Author

This PR also resolves #99 — it populates PromptResponse.usage with per-turn token counts from Codex, which is the data requested there.

@benbrandt

Copy link
Copy Markdown
Member

Hi thanks for taking the time to dig in!
Development is moving to agentclientprotocol/codex-acp. The new adapter is built on the new Codex App Server, and we are pooling implementation and maintenance work across teams there. If this is still needed, please open a PR for that one. Thanks!

@benbrandt benbrandt closed this Jun 23, 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

2 participants