mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
feat(core): add metadata field to ResponseItem (#28355)
## 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`: https://github.com/openai/codex/pull/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.
This commit is contained in:
committed by
GitHub
Unverified
parent
bef99f861b
commit
040dafa32d
@@ -298,6 +298,7 @@ async fn seed_guardian_parent_history(session: &Arc<Session>, turn: &Arc<TurnCon
|
||||
.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCall {
|
||||
id: None,
|
||||
@@ -305,12 +306,14 @@ async fn seed_guardian_parent_history(session: &Arc<Session>, turn: &Arc<TurnCon
|
||||
namespace: None,
|
||||
arguments: "{\"repo\":\"openai/codex\"}".to_string(),
|
||||
call_id: "call-1".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: "call-1".to_string(),
|
||||
output: codex_protocol::models::FunctionCallOutputPayload::from_text(
|
||||
"repo visibility: public".to_string(),
|
||||
),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -320,6 +323,7 @@ async fn seed_guardian_parent_history(session: &Arc<Session>, turn: &Arc<TurnCon
|
||||
.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
],
|
||||
)
|
||||
@@ -526,6 +530,7 @@ async fn build_guardian_prompt_delta_mode_preserves_original_numbering() -> anyh
|
||||
text: "Please also push the second docs fix.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -534,6 +539,7 @@ async fn build_guardian_prompt_delta_mode_preserves_original_numbering() -> anyh
|
||||
text: "I need approval for the second push.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
],
|
||||
)
|
||||
@@ -656,6 +662,7 @@ async fn build_guardian_prompt_stale_delta_version_falls_back_to_full_prompt() -
|
||||
text: "Compacted retained user request.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -664,6 +671,7 @@ async fn build_guardian_prompt_stale_delta_version_falls_back_to_full_prompt() -
|
||||
text: "Compacted summary of earlier guardian context.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
],
|
||||
/*reference_context_item*/ None,
|
||||
@@ -680,6 +688,7 @@ async fn build_guardian_prompt_stale_delta_version_falls_back_to_full_prompt() -
|
||||
text: "Please push after the compaction.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -688,6 +697,7 @@ async fn build_guardian_prompt_stale_delta_version_falls_back_to_full_prompt() -
|
||||
text: "I need approval for the post-compaction push.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
],
|
||||
)
|
||||
@@ -735,6 +745,7 @@ fn collect_guardian_transcript_entries_skips_contextual_user_messages() {
|
||||
text: "<environment_context>\n<cwd>/tmp</cwd>\n</environment_context>".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -743,6 +754,7 @@ fn collect_guardian_transcript_entries_skips_contextual_user_messages() {
|
||||
text: "hello".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -770,6 +782,7 @@ fn collect_guardian_transcript_entries_keeps_manual_approval_developer_message()
|
||||
text: "ordinary developer context".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -778,6 +791,7 @@ fn collect_guardian_transcript_entries_keeps_manual_approval_developer_message()
|
||||
text: approval_text.clone(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -802,6 +816,7 @@ fn collect_guardian_transcript_entries_includes_recent_tool_calls_and_output() {
|
||||
text: "check the repo".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCall {
|
||||
id: None,
|
||||
@@ -809,12 +824,14 @@ fn collect_guardian_transcript_entries_includes_recent_tool_calls_and_output() {
|
||||
namespace: None,
|
||||
arguments: "{\"path\":\"README.md\"}".to_string(),
|
||||
call_id: "call-1".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: "call-1".to_string(),
|
||||
output: codex_protocol::models::FunctionCallOutputPayload::from_text(
|
||||
"repo is public".to_string(),
|
||||
),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -823,6 +840,7 @@ fn collect_guardian_transcript_entries_includes_recent_tool_calls_and_output() {
|
||||
text: "I need to push a fix".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -1909,6 +1927,7 @@ async fn guardian_reuses_prompt_cache_key_and_appends_prior_reviews() -> anyhow:
|
||||
text: "Please push the second docs fix too.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -1917,6 +1936,7 @@ async fn guardian_reuses_prompt_cache_key_and_appends_prior_reviews() -> anyhow:
|
||||
text: "I need approval for the second docs fix.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
],
|
||||
)
|
||||
@@ -1954,6 +1974,7 @@ async fn guardian_reuses_prompt_cache_key_and_appends_prior_reviews() -> anyhow:
|
||||
text: "Please push the third docs fix too.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -1962,6 +1983,7 @@ async fn guardian_reuses_prompt_cache_key_and_appends_prior_reviews() -> anyhow:
|
||||
text: "I need approval for the third docs fix.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
],
|
||||
)
|
||||
@@ -2701,7 +2723,7 @@ async fn guardian_ephemeral_retry_preserves_parallel_trunk_and_fork_history() ->
|
||||
text: "Please inspect pending changes before pushing.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
},
|
||||
metadata: None,},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
role: "assistant".to_string(),
|
||||
@@ -2709,7 +2731,7 @@ async fn guardian_ephemeral_retry_preserves_parallel_trunk_and_fork_history() ->
|
||||
text: "I need approval to run git diff.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
},
|
||||
metadata: None,},
|
||||
],
|
||||
)
|
||||
.await;
|
||||
@@ -2768,7 +2790,7 @@ async fn guardian_ephemeral_retry_preserves_parallel_trunk_and_fork_history() ->
|
||||
text: "Now inspect whether pushing is safe.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
},
|
||||
metadata: None,},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
role: "assistant".to_string(),
|
||||
@@ -2776,7 +2798,7 @@ async fn guardian_ephemeral_retry_preserves_parallel_trunk_and_fork_history() ->
|
||||
text: "I need approval to push after the diff check.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
},
|
||||
metadata: None,},
|
||||
],
|
||||
)
|
||||
.await;
|
||||
|
||||
Reference in New Issue
Block a user