mirror of
https://github.com/openai/codex.git
synced 2026-11-10 21:00:47 +00:00
Include code-mode tool names in Responses Lite metadata (#35271)
## What changed - Add `code_mode_tool_names` to Responses Lite turn metadata, mapping each normalized code-mode identifier to its structured `ToolName`. - Reserve the metadata key against client overrides and omit it from metadata exposed to external MCP servers. - Keep non-Lite requests and the legacy top-level client metadata unchanged. ## Testing - Cover HTTP and WebSocket Responses Lite requests, including switching from a non-Lite model. - Verify reserved-key handling and external MCP metadata filtering. GitOrigin-RevId: b678afba13d57a91e26f5895aa37238fbb4cb276
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use super::*;
|
||||
|
||||
use crate::responses_metadata::CODE_MODE_TOOL_NAMES_KEY;
|
||||
use crate::responses_metadata::CodexResponsesRequestKind;
|
||||
use crate::responses_metadata::CompactionTurnMetadata;
|
||||
use crate::responses_metadata::INSTALLATION_ID_KEY;
|
||||
@@ -9,6 +10,7 @@ use codex_analytics::CompactionImplementation;
|
||||
use codex_analytics::CompactionPhase;
|
||||
use codex_analytics::CompactionReason;
|
||||
use codex_analytics::CompactionTrigger;
|
||||
use codex_protocol::ToolName;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::openai_models::ReasoningEffort as ReasoningEffortConfig;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
@@ -542,6 +544,10 @@ fn turn_metadata_state_ignores_client_reserved_metadata_before_start() {
|
||||
/*enforce_managed_network*/ false,
|
||||
);
|
||||
state.set_responsesapi_client_metadata(HashMap::from([
|
||||
(
|
||||
CODE_MODE_TOOL_NAMES_KEY.to_string(),
|
||||
"client-supplied".to_string(),
|
||||
),
|
||||
(
|
||||
"turn_started_at_unix_ms".to_string(),
|
||||
"client-supplied".to_string(),
|
||||
@@ -560,6 +566,7 @@ fn turn_metadata_state_ignores_client_reserved_metadata_before_start() {
|
||||
let header = test_turn_metadata_header(&state);
|
||||
let json: Value = serde_json::from_str(&header).expect("json");
|
||||
|
||||
assert!(json.get(CODE_MODE_TOOL_NAMES_KEY).is_none());
|
||||
assert!(json.get("turn_started_at_unix_ms").is_none());
|
||||
assert!(json.get("forked_from_thread_id").is_none());
|
||||
assert!(json.get("parent_thread_id").is_none());
|
||||
@@ -628,6 +635,10 @@ fn turn_metadata_state_merges_client_metadata_without_replacing_reserved_fields(
|
||||
"client-supplied".to_string(),
|
||||
),
|
||||
("subagent_kind".to_string(), "client-supplied".to_string()),
|
||||
(
|
||||
CODE_MODE_TOOL_NAMES_KEY.to_string(),
|
||||
"client-supplied".to_string(),
|
||||
),
|
||||
("turn_id".to_string(), "client-supplied".to_string()),
|
||||
(WINDOW_ID_KEY.to_string(), "client-supplied".to_string()),
|
||||
("thread_source".to_string(), "client-supplied".to_string()),
|
||||
@@ -638,6 +649,13 @@ fn turn_metadata_state_merges_client_metadata_without_replacing_reserved_fields(
|
||||
),
|
||||
]));
|
||||
state.set_turn_started_at_unix_ms(/*turn_started_at_unix_ms*/ 1_700_000_000_123);
|
||||
state.set_code_mode_tool_names(BTreeMap::from([
|
||||
("exec_command".to_string(), ToolName::plain("exec_command")),
|
||||
(
|
||||
"mcp__calendar__lookup".to_string(),
|
||||
ToolName::namespaced("mcp__calendar", "lookup"),
|
||||
),
|
||||
]));
|
||||
|
||||
let header = test_turn_metadata_header(&state);
|
||||
assert!(header.is_ascii());
|
||||
@@ -651,6 +669,19 @@ fn turn_metadata_state_merges_client_metadata_without_replacing_reserved_fields(
|
||||
assert_eq!(json["reasoning_effort"].as_str(), Some("client-supplied"));
|
||||
assert_eq!(json["session_id"].as_str(), Some("session-a"));
|
||||
assert_eq!(json["thread_id"].as_str(), Some("thread-a"));
|
||||
assert_eq!(
|
||||
json[CODE_MODE_TOOL_NAMES_KEY],
|
||||
serde_json::json!({
|
||||
"exec_command": {
|
||||
"name": "exec_command",
|
||||
"namespace": null,
|
||||
},
|
||||
"mcp__calendar__lookup": {
|
||||
"name": "lookup",
|
||||
"namespace": "mcp__calendar",
|
||||
},
|
||||
})
|
||||
);
|
||||
assert!(json.get(INSTALLATION_ID_KEY).is_none());
|
||||
assert!(json.get("x-codex-installation-id").is_none());
|
||||
assert!(json.get("x-codex-parent-thread-id").is_none());
|
||||
@@ -695,6 +726,7 @@ fn turn_metadata_state_merges_client_metadata_without_replacing_reserved_fields(
|
||||
.expect("turn metadata should be present");
|
||||
assert_eq!(meta["model"].as_str(), Some("gpt-5.4"));
|
||||
assert_eq!(meta["reasoning_effort"].as_str(), Some("high"));
|
||||
assert!(meta.get(CODE_MODE_TOOL_NAMES_KEY).is_none());
|
||||
assert!(meta.get(WINDOW_ID_KEY).is_none());
|
||||
assert_eq!(state.workspace_kind().as_deref(), Some("projectless"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user