Skip to content

Account for token usage from incomplete responses - #53670

Merged
copyberry[bot] merged 1 commit into
mainfrom
copyberry/codex-internal-to-codex-oss/bf1ee6df3912052ab7c19e1c6af8ad3dc4b07675
Oct 13, 2026
Merged

copyberry[bot] merged 1 commit into
mainfrom
copyberry/codex-internal-to-codex-oss/bf1ee6df3912052ab7c19e1c6af8ad3dc4b07675

Conversation

@copyberry

@copyberry copyberry Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Account for token usage from incomplete responses

Why

Terminal response.incomplete errors discard reported token usage. Counting that usage as a new context baseline can also double-count input and trigger unnecessary compaction on the next turn.

What changed

  • Carry the response ID and valid reported usage with incomplete-response errors.
  • Record usage for sampling and foreground compaction in cumulative totals, rollout records, budgets, and token-usage contributors without replacing the context baseline. Preserve the original terminal error, including when accounting exhausts the budget or cancellation races the error.
  • Charge incomplete background compaction requests to the rollout budget without publishing foreground token usage.
  • Ignore missing or malformed usage rather than estimating it.

Testing

Extend coverage for SSE and WebSocket incomplete responses, rollout usage records, compaction accounting, deferred token-count events, and token-usage contributors. Add regressions for unnecessary compaction on the next turn and background compaction publishing foreground usage.

## Why

Terminal `response.incomplete` errors discard reported token usage. Counting that usage as a new context baseline can also double-count input and trigger unnecessary compaction on the next turn.

## What changed

- Carry the response ID and valid reported usage with incomplete-response errors.
- Record usage for sampling and foreground compaction in cumulative totals, rollout records, budgets, and token-usage contributors without replacing the context baseline. Preserve the original terminal error, including when accounting exhausts the budget or cancellation races the error.
- Charge incomplete background compaction requests to the rollout budget without publishing foreground token usage.
- Ignore missing or malformed usage rather than estimating it.

## Testing

Extend coverage for SSE and WebSocket incomplete responses, rollout usage records, compaction accounting, deferred token-count events, and token-usage contributors. Add regressions for unnecessary compaction on the next turn and background compaction publishing foreground usage.

GitOrigin-RevId: bf1ee6df3912052ab7c19e1c6af8ad3dc4b07675
@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/bf1ee6df3912052ab7c19e1c6af8ad3dc4b07675 branch from 3a0b611 to 816fa70 Compare October 13, 2026 13:36
@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
πŸ“ Code Review πŸ”„ Running since 2026-10-13T13:36:36.939747Z 3a0b611 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with πŸ‘€ while any review is running, comments if it has suggestions, and reacts with πŸ‘ once all reviews finish with no findings.

@copyberry
copyberry Bot merged commit 816fa70 into main Oct 13, 2026
@copyberry
copyberry Bot deleted the copyberry/codex-internal-to-codex-oss/bf1ee6df3912052ab7c19e1c6af8ad3dc4b07675 branch October 13, 2026 13:36
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 13, 2026

This branch was successfully deployed

1 active deployment
issue-triage β€” 816fa702 Deployed Oct 13, 2026 by Aristide-Lab via Identify potential duplicates (open issues fallback) #55093
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants