feat(core): store turn_id on ResponseItem metadata#28360
Open
owenlin0 wants to merge 3 commits into
Open
Conversation
1537199 to
e5daf04
Compare
b4ee3c1 to
3e26c3d
Compare
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.
993ed6a to
9b81c0f
Compare
9b81c0f to
0b66f2b
Compare
pakrym-oai
reviewed
Jun 15, 2026
|
|
||
| impl ResponseItemMetadata { | ||
| /// Returns the non-empty turn ID carried by this metadata, if present. | ||
| pub(crate) fn turn_id(&self) -> Option<&str> { |
Collaborator
There was a problem hiding this comment.
too many turn_id/set_turn_id_if_missing helpers everywhere.
pakrym-oai
reviewed
Jun 15, 2026
| "<token_budget>\nThread id {thread_id}.\nCurrent context window 1.\nYou have {EFFECTIVE_CONTEXT_WINDOW} tokens left in this context window.\n</token_budget>" | ||
| )] | ||
| ); | ||
| let follow_up_body = requests[2].body_json(); |
Collaborator
There was a problem hiding this comment.
This test is unrelated to your feature. revert?
pakrym-oai
reviewed
Jun 15, 2026
| communication: InterAgentCommunication, | ||
| mut communication: InterAgentCommunication, | ||
| ) { | ||
| communication.set_turn_id_if_missing(&turn_context.sub_id); |
Collaborator
There was a problem hiding this comment.
you are calling prepare_conversation_items_for_history below
pakrym-oai
reviewed
Jun 15, 2026
| message_item("second"), | ||
| ]); | ||
| let mut first_user = message_item("hello"); | ||
| first_user.set_turn_id_if_missing("turn-123"); |
Collaborator
There was a problem hiding this comment.
can the test churn be reduced?
Collaborator
There was a problem hiding this comment.
this seems like an unrelated test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR is a followup to the mechanical plumbing PR that added
metadataonResponseItem: #28355, and starts assigningmetadata.turn_idto Responses API items created during a turn.The goal is that items are stably associated with the
turn_idthat introduced them, even when using stateless HTTP or resending context to ResponsesAPI onthread/resumewhen using websockets.What changed
metadata.turn_idon streamed output items, recorded conversation items, initial context, inter-agent communication items, and compaction trigger/input/summary items when missing.Validation
just fmtcargo check -p codex-core -p codex-protocol -p codex-app-server-protocol