From 313d736bc7cdc9d5888c13a0ef3c60fc88749803 Mon Sep 17 00:00:00 2001 From: celia-oai Date: Thu, 21 May 2026 11:06:11 -0700 Subject: [PATCH 1/6] changes --- codex-rs/tools/src/json_schema.rs | 166 ++++++++++++++++++++++++ codex-rs/tools/src/json_schema_tests.rs | 90 +++++++++++++ 2 files changed, 256 insertions(+) diff --git a/codex-rs/tools/src/json_schema.rs b/codex-rs/tools/src/json_schema.rs index 83733ffb7b4..02936d52d11 100644 --- a/codex-rs/tools/src/json_schema.rs +++ b/codex-rs/tools/src/json_schema.rs @@ -160,6 +160,7 @@ pub fn parse_tool_input_schema(input_schema: &JsonValue) -> Result Result bool { + compact_normalized_schema_len(value) <= MAX_COMPACT_TOOL_SCHEMA_BYTES +} + +fn compact_normalized_schema_len(value: &JsonValue) -> usize { + serde_json::from_value::(value.clone()) + .and_then(|schema| serde_json::to_vec(&schema)) + .map(|json| json.len()) + .unwrap_or(0) +} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum DefinitionTraversal { Include, @@ -214,6 +256,130 @@ fn for_each_schema_child( } } +fn strip_schema_descriptions(value: &mut JsonValue) { + match value { + JsonValue::Array(values) => { + for value in values { + strip_schema_descriptions(value); + } + } + JsonValue::Object(map) => { + map.remove("description"); + for_each_schema_child_mut(map, DefinitionTraversal::Include, &mut |value| { + strip_schema_descriptions(value); + }); + } + _ => {} + } +} + +fn for_each_schema_child_mut( + map: &mut serde_json::Map, + definition_traversal: DefinitionTraversal, + visitor: &mut impl FnMut(&mut JsonValue), +) { + if let Some(properties) = map.get_mut("properties") + && let Some(properties_map) = properties.as_object_mut() + { + for value in properties_map.values_mut() { + visitor(value); + } + } + + for key in SCHEMA_CHILD_KEYS { + if let Some(value) = map.get_mut(key) { + visitor(value); + } + } + + if let Some(additional_properties) = map.get_mut("additionalProperties") + && !matches!(additional_properties, JsonValue::Bool(_)) + { + visitor(additional_properties); + } + + if definition_traversal == DefinitionTraversal::Include { + for key in DEFINITION_TABLE_KEYS { + if let Some(definitions) = map.get_mut(key) + && let Some(definitions_map) = definitions.as_object_mut() + { + for value in definitions_map.values_mut() { + visitor(value); + } + } + } + } +} + +/// Replace local definition refs with empty schemas before dropping root +/// definition tables, so downstream behavior does not depend on how a schema +/// parser handles refs to missing definitions. +fn drop_schema_definitions(value: &mut JsonValue) { + rewrite_definition_refs_to_empty_schemas(value); + + let JsonValue::Object(map) = value else { + return; + }; + + for key in DEFINITION_TABLE_KEYS { + map.remove(key); + } +} + +fn rewrite_definition_refs_to_empty_schemas(value: &mut JsonValue) { + match value { + JsonValue::Array(values) => { + for value in values { + rewrite_definition_refs_to_empty_schemas(value); + } + } + JsonValue::Object(map) => { + if map + .get("$ref") + .and_then(JsonValue::as_str) + .and_then(parse_local_definition_ref) + .is_some() + { + *value = json!({}); + return; + } + + for_each_schema_child_mut(map, DefinitionTraversal::Skip, &mut |value| { + rewrite_definition_refs_to_empty_schemas(value); + }); + } + _ => {} + } +} + +fn collapse_deep_schema_objects(value: &mut JsonValue, depth: usize) { + match value { + JsonValue::Array(values) => { + for value in values { + collapse_deep_schema_objects(value, depth); + } + } + JsonValue::Object(map) => { + if depth >= MAX_COMPACT_TOOL_SCHEMA_DEPTH && is_complex_schema_object(map) { + *value = json!({}); + return; + } + + for_each_schema_child_mut(map, DefinitionTraversal::Skip, &mut |value| { + collapse_deep_schema_objects(value, depth + 1); + }); + } + _ => {} + } +} + +fn is_complex_schema_object(map: &serde_json::Map) -> bool { + SCHEMA_CHILD_KEYS.iter().any(|key| map.contains_key(*key)) + || map.contains_key("properties") + || map.contains_key("additionalProperties") + || map.contains_key("$ref") +} + /// Sanitize a JSON Schema (as serde_json::Value) so it can fit our limited /// schema representation. This function: /// - Ensures every typed schema object has a `"type"` when required. diff --git a/codex-rs/tools/src/json_schema_tests.rs b/codex-rs/tools/src/json_schema_tests.rs index 90ddcc4529c..e3a032aaf98 100644 --- a/codex-rs/tools/src/json_schema_tests.rs +++ b/codex-rs/tools/src/json_schema_tests.rs @@ -779,6 +779,96 @@ fn parse_tool_input_schema_preserves_explicit_enum_type_union() { ); } +#[test] +fn parse_large_tool_input_schema_drops_definitions() { + let many_properties = (0..300) + .map(|index| { + ( + format!("field_{index:03}"), + serde_json::json!({ "type": "string" }), + ) + }) + .collect::>(); + + let schema = parse_tool_input_schema(&serde_json::json!({ + "type": "object", + "description": "x".repeat(4_500), + "properties": { + "metadata": { + "$ref": "#/$defs/metadata" + } + }, + "$defs": { + "metadata": { + "type": "object", + "description": "metadata object", + "properties": many_properties + } + } + })) + .expect("parse schema"); + + assert_eq!( + schema, + JsonSchema::object( + BTreeMap::from([( + "metadata".to_string(), + JsonSchema { + schema_ref: Some("#/$defs/metadata".to_string()), + ..Default::default() + }, + )]), + /*required*/ None, + /*additional_properties*/ None, + ) + ); +} + +#[test] +fn parse_large_tool_input_schema_collapses_deep_nested_shapes() { + let many_properties = (0..300) + .map(|index| { + ( + format!("field_{index:03}"), + serde_json::json!({ "type": "string" }), + ) + }) + .collect::>(); + + let schema = parse_tool_input_schema(&serde_json::json!({ + "type": "object", + "description": "x".repeat(4_500), + "properties": { + "event": { + "type": "object", + "properties": { + "recurrence": { + "type": "object", + "properties": many_properties + } + } + } + } + })) + .expect("parse schema"); + + assert_eq!( + schema, + JsonSchema::object( + BTreeMap::from([( + "event".to_string(), + JsonSchema::object( + BTreeMap::from([("recurrence".to_string(), JsonSchema::default())]), + /*required*/ None, + /*additional_properties*/ None, + ) + )]), + /*required*/ None, + /*additional_properties*/ None, + ) + ); +} + #[test] fn parse_tool_input_schema_preserves_string_enum_constraints() { // Example schema shape: From 69959457e0d2b9b2b14bb2faf4e6d5f44ba69c24 Mon Sep 17 00:00:00 2001 From: celia-oai Date: Thu, 21 May 2026 12:24:49 -0700 Subject: [PATCH 2/6] changes --- codex-rs/tools/src/json_schema_tests.rs | 308 ++++++++++++++++++++---- 1 file changed, 266 insertions(+), 42 deletions(-) diff --git a/codex-rs/tools/src/json_schema_tests.rs b/codex-rs/tools/src/json_schema_tests.rs index e3a032aaf98..ec27037644e 100644 --- a/codex-rs/tools/src/json_schema_tests.rs +++ b/codex-rs/tools/src/json_schema_tests.rs @@ -779,17 +779,19 @@ fn parse_tool_input_schema_preserves_explicit_enum_type_union() { ); } -#[test] -fn parse_large_tool_input_schema_drops_definitions() { - let many_properties = (0..300) +fn many_string_properties(count: usize) -> serde_json::Map { + (0..count) .map(|index| { ( format!("field_{index:03}"), serde_json::json!({ "type": "string" }), ) }) - .collect::>(); + .collect() +} +#[test] +fn parse_large_tool_input_schema_stops_after_descriptions_when_under_budget() { let schema = parse_tool_input_schema(&serde_json::json!({ "type": "object", "description": "x".repeat(4_500), @@ -800,72 +802,294 @@ fn parse_large_tool_input_schema_drops_definitions() { }, "$defs": { "metadata": { - "type": "object", - "description": "metadata object", - "properties": many_properties + "type": "string", + "description": "Metadata value" } } })) .expect("parse schema"); assert_eq!( - schema, - JsonSchema::object( - BTreeMap::from([( - "metadata".to_string(), - JsonSchema { - schema_ref: Some("#/$defs/metadata".to_string()), - ..Default::default() - }, - )]), - /*required*/ None, - /*additional_properties*/ None, - ) + serde_json::to_value(schema).expect("serialize schema"), + serde_json::json!({ + "type": "object", + "properties": { + "metadata": { + "$ref": "#/$defs/metadata" + } + }, + "$defs": { + "metadata": { + "type": "string" + } + } + }) ); } #[test] -fn parse_large_tool_input_schema_collapses_deep_nested_shapes() { - let many_properties = (0..300) - .map(|index| { - ( - format!("field_{index:03}"), - serde_json::json!({ "type": "string" }), - ) - }) - .collect::>(); - +fn parse_large_tool_input_schema_stops_after_dropping_root_definitions_when_under_budget() { let schema = parse_tool_input_schema(&serde_json::json!({ "type": "object", "description": "x".repeat(4_500), "properties": { "event": { "type": "object", + "description": "Calendar event", "properties": { "recurrence": { "type": "object", - "properties": many_properties + "description": "Recurrence settings", + "properties": { + "pattern": { + "type": "string", + "description": "Recurrence pattern" + } + } } } + }, + "metadata": { + "$ref": "#/$defs/metadata" + } + }, + "$defs": { + "metadata": { + "type": "object", + "description": "metadata object", + "properties": many_string_properties(300) } } })) .expect("parse schema"); + assert_eq!( + serde_json::to_value(schema).expect("serialize schema"), + serde_json::json!({ + "type": "object", + "properties": { + "event": { + "type": "object", + "properties": { + "recurrence": { + "type": "object", + "properties": { + "pattern": { + "type": "string" + } + } + } + } + }, + "metadata": { + "$ref": "#/$defs/metadata" + } + } + }) + ); +} + +#[test] +fn parse_large_tool_input_schema_strips_descriptions_without_removing_description_property() { + let schema = parse_tool_input_schema(&serde_json::json!({ + "type": "object", + "description": "x".repeat(4_500), + "properties": { + "description": { + "type": "string", + "description": "User-facing description value" + }, + "metadata": { + "type": "object", + "description": "Metadata object", + "properties": { + "label": { + "type": "string", + "description": "Metadata label" + } + } + }, + "tags": { + "type": "array", + "description": "Tag list", + "items": { + "type": "string", + "description": "Tag value" + } + }, + "extras": { + "type": "object", + "additionalProperties": { + "type": "string", + "description": "Extra value" + } + }, + "choice": { + "description": "Choice value", + "anyOf": [ + { + "type": "string", + "description": "String choice" + }, + { + "type": "number", + "description": "Number choice" + } + ] + } + } + })) + .expect("parse schema"); + + assert_eq!( + serde_json::to_value(schema).expect("serialize schema"), + serde_json::json!({ + "type": "object", + "properties": { + "choice": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "number" + } + ] + }, + "description": { + "type": "string" + }, + "extras": { + "type": "object", + "properties": {}, + "additionalProperties": { + "type": "string" + } + }, + "metadata": { + "type": "object", + "properties": { + "label": { + "type": "string" + } + } + }, + "tags": { + "type": "array", + "items": { + "type": "string" + } + } + } + }) + ); +} + +#[test] +fn collapse_deep_schema_objects_traverses_schema_children() { + let mut schema = serde_json::json!({ + "type": "object", + "properties": { + "object_parent": { + "type": "object", + "properties": { + "complex": { + "type": "object", + "properties": { + "leaf": { "type": "string" } + } + }, + "scalar": { + "type": "string" + } + } + }, + "array_parent": { + "type": "array", + "items": { + "type": "object", + "properties": { + "leaf": { "type": "string" } + } + } + }, + "map_parent": { + "type": "object", + "additionalProperties": { + "type": "object", + "properties": { + "leaf": { "type": "string" } + } + } + }, + "union_parent": { + "anyOf": [ + { + "type": "object", + "properties": { + "leaf": { "type": "string" } + } + }, + { "type": "string" } + ], + "oneOf": [ + { + "type": "object", + "properties": { + "leaf": { "type": "string" } + } + } + ], + "allOf": [ + { + "type": "object", + "properties": { + "leaf": { "type": "string" } + } + } + ] + } + } + }); + + super::collapse_deep_schema_objects(&mut schema, /*depth*/ 0); + assert_eq!( schema, - JsonSchema::object( - BTreeMap::from([( - "event".to_string(), - JsonSchema::object( - BTreeMap::from([("recurrence".to_string(), JsonSchema::default())]), - /*required*/ None, - /*additional_properties*/ None, - ) - )]), - /*required*/ None, - /*additional_properties*/ None, - ) + serde_json::json!({ + "type": "object", + "properties": { + "object_parent": { + "type": "object", + "properties": { + "complex": {}, + "scalar": { + "type": "string" + } + } + }, + "array_parent": { + "type": "array", + "items": {} + }, + "map_parent": { + "type": "object", + "additionalProperties": {} + }, + "union_parent": { + "anyOf": [ + {}, + { "type": "string" } + ], + "oneOf": [ + {} + ], + "allOf": [ + {} + ] + } + } + }) ); } From bb30e63aa75a57828dda79aec636f6082409e03e Mon Sep 17 00:00:00 2001 From: celia-oai Date: Thu, 21 May 2026 13:41:59 -0700 Subject: [PATCH 3/6] comment --- codex-rs/tools/src/json_schema_tests.rs | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/codex-rs/tools/src/json_schema_tests.rs b/codex-rs/tools/src/json_schema_tests.rs index ec27037644e..6750b70bca9 100644 --- a/codex-rs/tools/src/json_schema_tests.rs +++ b/codex-rs/tools/src/json_schema_tests.rs @@ -985,6 +985,51 @@ fn parse_large_tool_input_schema_strips_descriptions_without_removing_descriptio ); } +#[test] +fn parse_large_tool_input_schema_preserves_object_enum_literal_descriptions() { + let schema = parse_tool_input_schema(&serde_json::json!({ + "type": "object", + "description": "x".repeat(4_500), + "properties": { + "choice": { + "enum": [ + { + "description": "first literal", + "id": 1 + }, + { + "description": "second literal", + "id": 2 + } + ] + } + } + })) + .expect("parse schema"); + + assert_eq!( + serde_json::to_value(schema).expect("serialize schema"), + serde_json::json!({ + "type": "object", + "properties": { + "choice": { + "type": "string", + "enum": [ + { + "description": "first literal", + "id": 1 + }, + { + "description": "second literal", + "id": 2 + } + ] + } + } + }) + ); +} + #[test] fn collapse_deep_schema_objects_traverses_schema_children() { let mut schema = serde_json::json!({ From d377d461f5090b1dbe913990976c3d630e4d0adf Mon Sep 17 00:00:00 2001 From: celia-oai Date: Thu, 21 May 2026 13:47:04 -0700 Subject: [PATCH 4/6] changes --- codex-rs/tools/src/json_schema.rs | 51 ++++---- codex-rs/tools/src/json_schema_tests.rs | 154 +++++++++++++++++++++++- 2 files changed, 179 insertions(+), 26 deletions(-) diff --git a/codex-rs/tools/src/json_schema.rs b/codex-rs/tools/src/json_schema.rs index 02936d52d11..4d21b4e905e 100644 --- a/codex-rs/tools/src/json_schema.rs +++ b/codex-rs/tools/src/json_schema.rs @@ -273,6 +273,27 @@ fn strip_schema_descriptions(value: &mut JsonValue) { } } +fn visit_schema_objects( + value: &JsonValue, + definition_traversal: DefinitionTraversal, + visitor: &mut impl FnMut(&JsonValue), +) { + match value { + JsonValue::Array(values) => { + for value in values { + visit_schema_objects(value, definition_traversal, visitor); + } + } + JsonValue::Object(map) => { + visitor(value); + for_each_schema_child(map, definition_traversal, &mut |value| { + visit_schema_objects(value, definition_traversal, visitor); + }); + } + _ => {} + } +} + fn for_each_schema_child_mut( map: &mut serde_json::Map, definition_traversal: DefinitionTraversal, @@ -565,37 +586,19 @@ fn collect_reachable_definitions(value: &JsonValue) -> BTreeSet) { - match value { - JsonValue::Array(values) => { - for value in values { - collect_refs_outside_definitions(value, refs); - } - } - JsonValue::Object(map) => { + visit_schema_objects(value, DefinitionTraversal::Skip, &mut |value| { + if let JsonValue::Object(map) = value { collect_ref_from_map(map, refs); - for_each_schema_child(map, DefinitionTraversal::Skip, &mut |value| { - collect_refs_outside_definitions(value, refs); - }); } - _ => {} - } + }); } fn collect_refs(value: &JsonValue, refs: &mut Vec) { - match value { - JsonValue::Array(values) => { - for value in values { - collect_refs(value, refs); - } - } - JsonValue::Object(map) => { + visit_schema_objects(value, DefinitionTraversal::Include, &mut |value| { + if let JsonValue::Object(map) = value { collect_ref_from_map(map, refs); - for value in map.values() { - collect_refs(value, refs); - } } - _ => {} - } + }); } fn collect_ref_from_map( diff --git a/codex-rs/tools/src/json_schema_tests.rs b/codex-rs/tools/src/json_schema_tests.rs index 6750b70bca9..64be6a2bbd8 100644 --- a/codex-rs/tools/src/json_schema_tests.rs +++ b/codex-rs/tools/src/json_schema_tests.rs @@ -827,6 +827,58 @@ fn parse_large_tool_input_schema_stops_after_descriptions_when_under_budget() { ); } +#[test] +fn parse_large_tool_input_schema_ignores_dropped_metadata_for_budget() { + let schema = parse_tool_input_schema(&serde_json::json!({ + "type": "object", + "properties": { + "event": { + "type": "object", + "title": "Calendar event", + "properties": { + "recurrence": { + "type": "object", + "examples": [ + { + "payload": "x".repeat(4_500) + } + ], + "properties": { + "pattern": { + "type": "string", + "title": "Recurrence pattern" + } + } + } + } + } + } + })) + .expect("parse schema"); + + assert_eq!( + serde_json::to_value(schema).expect("serialize schema"), + serde_json::json!({ + "type": "object", + "properties": { + "event": { + "type": "object", + "properties": { + "recurrence": { + "type": "object", + "properties": { + "pattern": { + "type": "string" + } + } + } + } + } + } + }) + ); +} + #[test] fn parse_large_tool_input_schema_stops_after_dropping_root_definitions_when_under_budget() { let schema = parse_tool_input_schema(&serde_json::json!({ @@ -881,8 +933,106 @@ fn parse_large_tool_input_schema_stops_after_dropping_root_definitions_when_unde } } }, - "metadata": { - "$ref": "#/$defs/metadata" + "metadata": {} + } + }) + ); +} + +#[test] +fn parse_large_tool_input_schema_rewrites_root_definition_ref_before_dropping_definitions() { + let schema = parse_tool_input_schema(&serde_json::json!({ + "$ref": "#/$defs/Arguments", + "$defs": { + "Arguments": { + "type": "object", + "properties": many_string_properties(300), + "required": ["property_1"] + } + } + })) + .expect("parse schema"); + + assert_eq!(schema, JsonSchema::default()); +} + +#[test] +fn parse_large_tool_input_schema_rewrites_nested_definition_refs_before_dropping_definitions() { + let schema = parse_tool_input_schema(&serde_json::json!({ + "type": "object", + "description": "x".repeat(4_500), + "properties": { + "container": { + "type": "object", + "properties": { + "user": { + "$ref": "#/$defs/User" + } + } + }, + "list": { + "type": "array", + "items": { + "$ref": "#/$defs/User" + } + }, + "map": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/User" + } + }, + "choice": { + "anyOf": [ + { + "$ref": "#/$defs/User" + }, + { + "$ref": "#/definitions/Legacy" + } + ] + } + }, + "$defs": { + "User": { + "type": "object", + "properties": many_string_properties(300) + } + }, + "definitions": { + "Legacy": { + "type": "object", + "properties": many_string_properties(300) + } + } + })) + .expect("parse schema"); + + assert_eq!( + serde_json::to_value(schema).expect("serialize schema"), + serde_json::json!({ + "type": "object", + "properties": { + "choice": { + "anyOf": [ + {}, + {} + ] + }, + "container": { + "type": "object", + "properties": { + "user": {} + } + }, + "list": { + "type": "array", + "items": {} + }, + "map": { + "type": "object", + "properties": {}, + "additionalProperties": {} } } }) From 20a851d5c66a76b905a49f3ef013b59739dc18eb Mon Sep 17 00:00:00 2001 From: celia-oai Date: Thu, 21 May 2026 15:02:49 -0700 Subject: [PATCH 5/6] changes --- codex-rs/tools/src/json_schema.rs | 51 ++++++------ codex-rs/tools/src/json_schema_tests.rs | 100 ------------------------ 2 files changed, 24 insertions(+), 127 deletions(-) diff --git a/codex-rs/tools/src/json_schema.rs b/codex-rs/tools/src/json_schema.rs index 4d21b4e905e..02936d52d11 100644 --- a/codex-rs/tools/src/json_schema.rs +++ b/codex-rs/tools/src/json_schema.rs @@ -273,27 +273,6 @@ fn strip_schema_descriptions(value: &mut JsonValue) { } } -fn visit_schema_objects( - value: &JsonValue, - definition_traversal: DefinitionTraversal, - visitor: &mut impl FnMut(&JsonValue), -) { - match value { - JsonValue::Array(values) => { - for value in values { - visit_schema_objects(value, definition_traversal, visitor); - } - } - JsonValue::Object(map) => { - visitor(value); - for_each_schema_child(map, definition_traversal, &mut |value| { - visit_schema_objects(value, definition_traversal, visitor); - }); - } - _ => {} - } -} - fn for_each_schema_child_mut( map: &mut serde_json::Map, definition_traversal: DefinitionTraversal, @@ -586,19 +565,37 @@ fn collect_reachable_definitions(value: &JsonValue) -> BTreeSet) { - visit_schema_objects(value, DefinitionTraversal::Skip, &mut |value| { - if let JsonValue::Object(map) = value { + match value { + JsonValue::Array(values) => { + for value in values { + collect_refs_outside_definitions(value, refs); + } + } + JsonValue::Object(map) => { collect_ref_from_map(map, refs); + for_each_schema_child(map, DefinitionTraversal::Skip, &mut |value| { + collect_refs_outside_definitions(value, refs); + }); } - }); + _ => {} + } } fn collect_refs(value: &JsonValue, refs: &mut Vec) { - visit_schema_objects(value, DefinitionTraversal::Include, &mut |value| { - if let JsonValue::Object(map) = value { + match value { + JsonValue::Array(values) => { + for value in values { + collect_refs(value, refs); + } + } + JsonValue::Object(map) => { collect_ref_from_map(map, refs); + for value in map.values() { + collect_refs(value, refs); + } } - }); + _ => {} + } } fn collect_ref_from_map( diff --git a/codex-rs/tools/src/json_schema_tests.rs b/codex-rs/tools/src/json_schema_tests.rs index 64be6a2bbd8..5ec99fa6d4a 100644 --- a/codex-rs/tools/src/json_schema_tests.rs +++ b/codex-rs/tools/src/json_schema_tests.rs @@ -939,106 +939,6 @@ fn parse_large_tool_input_schema_stops_after_dropping_root_definitions_when_unde ); } -#[test] -fn parse_large_tool_input_schema_rewrites_root_definition_ref_before_dropping_definitions() { - let schema = parse_tool_input_schema(&serde_json::json!({ - "$ref": "#/$defs/Arguments", - "$defs": { - "Arguments": { - "type": "object", - "properties": many_string_properties(300), - "required": ["property_1"] - } - } - })) - .expect("parse schema"); - - assert_eq!(schema, JsonSchema::default()); -} - -#[test] -fn parse_large_tool_input_schema_rewrites_nested_definition_refs_before_dropping_definitions() { - let schema = parse_tool_input_schema(&serde_json::json!({ - "type": "object", - "description": "x".repeat(4_500), - "properties": { - "container": { - "type": "object", - "properties": { - "user": { - "$ref": "#/$defs/User" - } - } - }, - "list": { - "type": "array", - "items": { - "$ref": "#/$defs/User" - } - }, - "map": { - "type": "object", - "additionalProperties": { - "$ref": "#/$defs/User" - } - }, - "choice": { - "anyOf": [ - { - "$ref": "#/$defs/User" - }, - { - "$ref": "#/definitions/Legacy" - } - ] - } - }, - "$defs": { - "User": { - "type": "object", - "properties": many_string_properties(300) - } - }, - "definitions": { - "Legacy": { - "type": "object", - "properties": many_string_properties(300) - } - } - })) - .expect("parse schema"); - - assert_eq!( - serde_json::to_value(schema).expect("serialize schema"), - serde_json::json!({ - "type": "object", - "properties": { - "choice": { - "anyOf": [ - {}, - {} - ] - }, - "container": { - "type": "object", - "properties": { - "user": {} - } - }, - "list": { - "type": "array", - "items": {} - }, - "map": { - "type": "object", - "properties": {}, - "additionalProperties": {} - } - } - }) - ); -} - #[test] fn parse_large_tool_input_schema_strips_descriptions_without_removing_description_property() { let schema = parse_tool_input_schema(&serde_json::json!({ From f553d8f6b05674d4398bd7cc2e722e1574251733 Mon Sep 17 00:00:00 2001 From: celia-oai Date: Thu, 21 May 2026 17:09:07 -0700 Subject: [PATCH 6/6] Changes --- codex-rs/tools/src/json_schema_tests.rs | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/codex-rs/tools/src/json_schema_tests.rs b/codex-rs/tools/src/json_schema_tests.rs index 5ec99fa6d4a..52b30138c11 100644 --- a/codex-rs/tools/src/json_schema_tests.rs +++ b/codex-rs/tools/src/json_schema_tests.rs @@ -909,7 +909,7 @@ fn parse_large_tool_input_schema_stops_after_dropping_root_definitions_when_unde "metadata": { "type": "object", "description": "metadata object", - "properties": many_string_properties(300) + "properties": many_string_properties(/*count*/ 300) } } })) @@ -1126,22 +1126,6 @@ fn collapse_deep_schema_objects_traverses_schema_children() { } }, { "type": "string" } - ], - "oneOf": [ - { - "type": "object", - "properties": { - "leaf": { "type": "string" } - } - } - ], - "allOf": [ - { - "type": "object", - "properties": { - "leaf": { "type": "string" } - } - } ] } } @@ -1175,12 +1159,6 @@ fn collapse_deep_schema_objects_traverses_schema_children() { "anyOf": [ {}, { "type": "string" } - ], - "oneOf": [ - {} - ], - "allOf": [ - {} ] } }