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
@@ -61,6 +61,7 @@ fn parses_user_message_with_text_and_two_images() {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected user message turn item");
|
||||
@@ -110,6 +111,7 @@ fn skips_local_image_label_text() {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected user message turn item");
|
||||
@@ -142,6 +144,7 @@ fn parses_assistant_message_input_text_for_backward_compatibility() {
|
||||
.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected assistant message turn item");
|
||||
@@ -191,6 +194,7 @@ fn skips_unnamed_image_label_text() {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected user message turn item");
|
||||
@@ -223,7 +227,7 @@ fn skips_user_instructions_and_env() {
|
||||
text: "# AGENTS.md instructions for test_directory\n\n<INSTRUCTIONS>\ntest_text\n</INSTRUCTIONS>".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
},
|
||||
metadata: None,},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
role: "user".to_string(),
|
||||
@@ -231,7 +235,7 @@ fn skips_user_instructions_and_env() {
|
||||
text: "<environment_context>test_text</environment_context>".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
},
|
||||
metadata: None,},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
role: "user".to_string(),
|
||||
@@ -239,7 +243,7 @@ fn skips_user_instructions_and_env() {
|
||||
text: "# AGENTS.md instructions for test_directory\n\n<INSTRUCTIONS>\ntest_text\n</INSTRUCTIONS>".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
},
|
||||
metadata: None,},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
role: "user".to_string(),
|
||||
@@ -248,7 +252,7 @@ fn skips_user_instructions_and_env() {
|
||||
.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
},
|
||||
metadata: None,},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
role: "user".to_string(),
|
||||
@@ -256,7 +260,7 @@ fn skips_user_instructions_and_env() {
|
||||
text: "<user_shell_command>echo 42</user_shell_command>".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
},
|
||||
metadata: None,},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
role: "user".to_string(),
|
||||
@@ -271,7 +275,7 @@ fn skips_user_instructions_and_env() {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
},
|
||||
metadata: None,},
|
||||
];
|
||||
|
||||
for item in items {
|
||||
@@ -321,7 +325,7 @@ fn parses_hook_prompt_and_hides_other_contextual_fragments() {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
};
|
||||
metadata: None,};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected hook prompt turn item");
|
||||
|
||||
@@ -353,6 +357,7 @@ fn internal_model_context_does_not_parse_as_visible_turn_item() {
|
||||
.render(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
assert!(parse_turn_item(&item).is_none());
|
||||
@@ -367,6 +372,7 @@ fn parses_agent_message() {
|
||||
text: "Hello from Codex".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected agent message turn item");
|
||||
@@ -398,6 +404,7 @@ fn parses_reasoning_summary_and_raw_content() {
|
||||
text: "raw details".to_string(),
|
||||
}]),
|
||||
encrypted_content: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected reasoning turn item");
|
||||
@@ -430,6 +437,7 @@ fn parses_reasoning_including_raw_content() {
|
||||
},
|
||||
]),
|
||||
encrypted_content: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected reasoning turn item");
|
||||
@@ -455,6 +463,7 @@ fn parses_web_search_call() {
|
||||
query: Some("weather".to_string()),
|
||||
queries: None,
|
||||
}),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected web search turn item");
|
||||
@@ -483,6 +492,7 @@ fn parses_web_search_open_page_call() {
|
||||
action: Some(WebSearchAction::OpenPage {
|
||||
url: Some("https://example.com".to_string()),
|
||||
}),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected web search turn item");
|
||||
@@ -511,6 +521,7 @@ fn parses_web_search_find_in_page_call() {
|
||||
url: Some("https://example.com".to_string()),
|
||||
pattern: Some("needle".to_string()),
|
||||
}),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected web search turn item");
|
||||
@@ -537,6 +548,7 @@ fn parses_partial_web_search_call_without_action_as_other() {
|
||||
id: Some("ws_partial".to_string()),
|
||||
status: Some("in_progress".to_string()),
|
||||
action: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected web search turn item");
|
||||
|
||||
Reference in New Issue
Block a user