Repository navigation
📊 feat: Preserve Response Accounting and History - #17599
Conversation
014c38b to
374b07c
Compare
374b07c to
b8ba493
Compare
b8ba493 to
2f35174
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Missing production integration leaves retrieval, continuation, tool results, and cumulative accounting incomplete, while accounting merges can incorrectly report partially covered costs as complete.
6 open issues
Preserve partial coverage across multi-segment composition · New Connect response reference resolution and continuation paths · New Integrate cumulative usage across resumed executions · New Forward tool completion events to streaming and JSON handlers · New Preserve model provenance before contextualizing usage · New Wire accounting snapshots into responses and storage · New
What changed in this PR
Adds Responses API helpers intended to preserve stored output history and cumulative usage across continuations, while distinguishing complete accounting from unavailable data.
Changes:
- Adds accounting collection, billing quotes, and segment-composition helpers.
- Adds response-reference resolution, history selection, and message-projection utilities.
- Extends terminal response builders and tool-completion handlers, with focused regression tests.
| File | Description |
|---|---|
packages/api/src/agents/responses/service.ts |
Adds completion handling, accounting parameters, and background-request validation. |
packages/api/src/agents/responses/segments.ts |
Adds saved-prefix composition and cumulative usage merging. |
packages/api/src/agents/responses/segments.spec.ts |
Tests segment history, identity, usage, and accounting preservation. |
packages/api/src/agents/responses/persistence.ts |
Adds response resolution, ancestry selection, and stored-message projection. |
packages/api/src/agents/responses/persistence.spec.ts |
Tests persistence references, history branches, and tool-result projection. |
packages/api/src/agents/responses/index.ts |
Exports persistence and accounting helpers. |
packages/api/src/agents/responses/handlers.ts |
Adds terminal accounting metadata and stored-response flags. |
packages/api/src/agents/responses/clientTools.ts |
Updates comments describing stored tool-history behavior. |
packages/api/src/agents/responses/accounting.ts |
Adds usage provenance, billing quotes, and coverage tracking. |
packages/api/src/agents/responses/accounting.spec.ts |
Tests pricing, provenance, deduplication, and unavailable accounting. |
packages/api/src/agents/responses/__tests__/service.test.ts |
Tests consistent terminal accounting metadata in JSON and SSE. |
Review effort: Balanced
2f35174 to
0c67e1e
Compare
0c67e1e to
5f82166
Compare
5f82166 to
252cc5f
Compare
|
Lighthouse CI failed. The last 80 log lines contain the measured budgets and assertion failures. |
7ebf027 to
db50d58
Compare
db50d58 to
6a664b2
Compare
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6a664b2c18
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 46a4184dec
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
4c1af23 to
207d9bc
Compare
207d9bc to
8075c9d
Compare
8075c9d to
8764d82
Compare
8764d82 to
cf36b38
Compare
cf36b38 to
4067667
Compare
4067667 to
672ed05
Compare
672ed05 to
6f6763b
Compare
6f6763b to
1444f4a
Compare
1444f4a to
4c26053
Compare


Summary
Stored foreground Responses could not be continued or retrieved by their returned response IDs, and saving discarded tool results and message ancestry. Completion also omitted accounting and reported
store: falseeven after successful writes. Connect the foreground controller to a typed history, persistence and terminal lifecycle so JSON, SSE and retrieved responses carry the saved turn and its accounting.How it works
The foreground controller resolves an owned previous reply or conversation, preserves message ancestry and completed tool results, and records usage/accounting with the saved turn. JSON, SSE and retrieved Responses agree on the persisted result. Optional save failures preserve the generated answer with store: false; history lookup failures do not silently start a new conversation.
Type of change
Testing
Tested environments/configuration: Local macOS with CI Node.js 24.22.1, MongoDB replica-set fixtures and the actual execution host, SDK history formatter and Responses event handlers.
Automated tests:
Screenshots / recordings
No standalone UI change.
Risk / compatibility
Terminal publication waits for provider drain, trailing writes and requested storage. Legacy conversation-ID continuations remain supported. Caller-executed tools retain their explicit replay contract. Optional accounting never fabricates a complete amount from partial coverage, and historical calls retain their recorded quotes rather than being repriced.
Checklist