Skip to content

Populate PromptResponse.usage from Codex token usage#210

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

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
Copy link
Copy Markdown

@simonrosenberg simonrosenberg commented Mar 26, 2026

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant