From 112be0bd74ce327788613f4f8f92e8b7c92447c7 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 7 Sep 2026 01:24:23 +0000 Subject: [PATCH] Sort JSON schema object keys for consistent Cargo and Bazel output (#43325) ## Why JSON schema exports should be identical across Cargo and Bazel builds. ## What changed Recursively sort object keys before writing app-server protocol JSON schemas, while preserving array order. GitOrigin-RevId: 740c846062f7bae18790e9cf4f30734289ae3056 --- codex-rs/app-server-protocol/src/export.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/codex-rs/app-server-protocol/src/export.rs b/codex-rs/app-server-protocol/src/export.rs index d68bd1e2c5..4123b3f189 100644 --- a/codex-rs/app-server-protocol/src/export.rs +++ b/codex-rs/app-server-protocol/src/export.rs @@ -25,7 +25,6 @@ use anyhow::Result; use anyhow::anyhow; use codex_history::RolloutLine; use schemars::schema_for; -use serde::Serialize; use serde_json::Map; use serde_json::Value; use std::collections::BTreeMap; @@ -1571,8 +1570,11 @@ where write_json_schema_with_return::(out_dir, name) } -fn write_pretty_json(path: PathBuf, value: &impl Serialize) -> Result<()> { - let json = serde_json::to_vec_pretty(value) +fn write_pretty_json(path: PathBuf, value: &Value) -> Result<()> { + let mut value = value.clone(); + // Keep Cargo and Bazel output identical without changing meaningful array order. + value.sort_all_objects(); + let json = serde_json::to_vec_pretty(&value) .with_context(|| format!("Failed to serialize JSON schema to {}", path.display()))?; fs::write(&path, json).with_context(|| format!("Failed to write {}", path.display()))?; Ok(())