Skip to content

feat(core): store turn_id on ResponseItem metadata#28360

Merged
owenlin0 merged 2 commits into
mainfrom
owen/stamp_and_preserve_meta_turn_id
Jun 22, 2026
Merged

feat(core): store turn_id on ResponseItem metadata#28360
owenlin0 merged 2 commits into
mainfrom
owen/stamp_and_preserve_meta_turn_id

Conversation

@owenlin0

@owenlin0 owenlin0 commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR is a followup to #28355 and starts assigning internal_chat_message_metadata_passthrough.turn_id to durable Responses API items created during a turn.

The goal is that those items keep the turn_id that introduced them when Codex resends stateless HTTP context, reconstructs history for resume/fork paths, or reuses websocket response state.

What changed

  • Set internal_chat_message_metadata_passthrough.turn_id when missing as response items enter durable history, initial/replacement history, inter-agent communication history, and local compaction summaries.
  • Preserve existing item turn IDs instead of overwriting them during persistence, resume reconstruction, compaction, forked history, and websocket incremental reuse.
  • Keep compaction_trigger fieldless because it is a request control, not a durable response item.
  • Update focused history/request assertions and fixtures for stateless requests, websocket incrementals, compaction, thread injection, prompt debug, and related CI coverage.

@owenlin0 owenlin0 changed the title [codex] stamp Responses API item turn ids feat(core): store turn_id on ResponseItem metadata Jun 15, 2026
@owenlin0 owenlin0 force-pushed the owen/carry_responses_api_item_metadata branch from 1537199 to e5daf04 Compare June 15, 2026 17:59
@owenlin0 owenlin0 force-pushed the owen/stamp_and_preserve_meta_turn_id branch 3 times, most recently from b4ee3c1 to 3e26c3d Compare June 15, 2026 18:35
@owenlin0 owenlin0 marked this pull request as ready for review June 15, 2026 18:38
@owenlin0 owenlin0 requested a review from a team as a code owner June 15, 2026 18:38
owenlin0 added a commit that referenced this pull request Jun 15, 2026
## Description

This PR adds an optional `metadata` field to `ResponseItem` for
Responses API calls. Only mechanical plumbing, no actual values
populated and sent yet. Turns out just adding a new field to
`ResponseItem` has quite a large blast radius already.

This change is backwards compatible because `metadata` is optional and
omitted when absent, so existing response items and rollout history
without it still deserialize and requests that do not set it keep the
same wire shape. For provider compatibility, we strip out `metadata`
before non-OpenAI Responses requests so Azure and AWS Bedrock never see
this field.

My followup PR here will actually make use of it to start storing and
passing along `turn_id`: #28360

## What changed

- Added `ResponseItemMetadata` with optional `turn_id`, plus optional
`metadata` on Responses API item variants and inter-agent communication.
- Preserved item metadata through response-item rewrites such as
truncation, missing tool-output synthesis, compaction history
rebuilding, visible-history conversion, rollout/resume, and generated
app-server schemas/types.
- Strip item metadata from non-OpenAI Responses requests while
preserving it for OpenAI-shaped requests.
- Updated the mechanical fixture/test construction churn required by the
new optional field.
Base automatically changed from owen/carry_responses_api_item_metadata to main June 15, 2026 22:05
@owenlin0 owenlin0 force-pushed the owen/stamp_and_preserve_meta_turn_id branch 4 times, most recently from 9b81c0f to 0b66f2b Compare June 15, 2026 22:46
@owenlin0 owenlin0 requested a review from pakrym-oai June 15, 2026 22:53
Comment thread codex-rs/protocol/src/models.rs Outdated
Comment thread codex-rs/core/tests/suite/token_budget.rs Outdated
Comment thread codex-rs/core/src/session/mod.rs
Comment thread codex-rs/core/tests/suite/client_websockets.rs Outdated
@owenlin0 owenlin0 force-pushed the owen/stamp_and_preserve_meta_turn_id branch 3 times, most recently from fe3d386 to 65e1264 Compare June 22, 2026 18:37
@owenlin0 owenlin0 force-pushed the owen/stamp_and_preserve_meta_turn_id branch 4 times, most recently from bede56a to 3fc4d86 Compare June 22, 2026 19:09
owenlin0 added a commit that referenced this pull request Jun 22, 2026
owenlin0 added a commit that referenced this pull request Jun 22, 2026
owenlin0 added a commit that referenced this pull request Jun 22, 2026
@owenlin0 owenlin0 force-pushed the owen/stamp_and_preserve_meta_turn_id branch 3 times, most recently from e02b55c to b89b047 Compare June 22, 2026 21:37
@owenlin0 owenlin0 force-pushed the owen/stamp_and_preserve_meta_turn_id branch from b89b047 to 33ba9c8 Compare June 22, 2026 21:50
owenlin0 added a commit that referenced this pull request Jun 22, 2026
owenlin0 added a commit that referenced this pull request Jun 22, 2026
@owenlin0 owenlin0 force-pushed the owen/stamp_and_preserve_meta_turn_id branch from d021e1d to cbf9aee Compare June 22, 2026 22:08
owenlin0 added a commit that referenced this pull request Jun 22, 2026
@owenlin0 owenlin0 force-pushed the owen/stamp_and_preserve_meta_turn_id branch from cbf9aee to 1b7c621 Compare June 22, 2026 22:20
Comment thread codex-rs/core/tests/common/responses.rs Outdated
Comment thread codex-rs/core/tests/common/responses.rs Outdated
}

/// Returns the decoded request body without internal item transport metadata.
pub fn body_json(&self) -> Value {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fact that we are messing with request might be unexpected.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed body_json() back to the raw decoded request body and removed the request-body normalization.

Comment thread codex-rs/core/src/session/mod.rs Outdated
{
items.push(guardian_developer_message);
}
// Some callers insert initial context into prompt/replacement history without first

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

who does?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New context windows and compaction; tightened the comment.

owenlin0 added a commit that referenced this pull request Jun 22, 2026
@owenlin0 owenlin0 force-pushed the owen/stamp_and_preserve_meta_turn_id branch from 1b7c621 to 3560732 Compare June 22, 2026 22:37
Comment thread codex-rs/core/src/tools/handlers/extension_tools.rs Outdated
owenlin0 added a commit that referenced this pull request Jun 22, 2026
@owenlin0 owenlin0 force-pushed the owen/stamp_and_preserve_meta_turn_id branch from 3560732 to b1275cf Compare June 22, 2026 22:40
owenlin0 added a commit that referenced this pull request Jun 22, 2026
@owenlin0 owenlin0 force-pushed the owen/stamp_and_preserve_meta_turn_id branch from b1275cf to b0201bd Compare June 22, 2026 22:54
owenlin0 added a commit that referenced this pull request Jun 22, 2026
@owenlin0 owenlin0 force-pushed the owen/stamp_and_preserve_meta_turn_id branch from b0201bd to 54adfac Compare June 22, 2026 23:07
owenlin0 added a commit that referenced this pull request Jun 22, 2026
@owenlin0 owenlin0 force-pushed the owen/stamp_and_preserve_meta_turn_id branch from 54adfac to 616a5f3 Compare June 22, 2026 23:19
@owenlin0 owenlin0 force-pushed the owen/stamp_and_preserve_meta_turn_id branch from 616a5f3 to 8bf4791 Compare June 22, 2026 23:29
@owenlin0 owenlin0 merged commit 4a82ecc into main Jun 22, 2026
31 checks passed
@owenlin0 owenlin0 deleted the owen/stamp_and_preserve_meta_turn_id branch June 22, 2026 23:45
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants