From 154433c8f0e0a98131a92699e761cf34b30344ce Mon Sep 17 00:00:00 2001 From: Owen Lin Date: Wed, 8 Jul 2026 11:35:42 -0700 Subject: [PATCH] chore(protocol): use UUIDv7 for generated item IDs (#31524) ## Description Use UUIDv7 for item IDs generated locally in `codex-protocol`. This covers user messages, agent messages, hook prompts, and context compaction items. These IDs are generated once and carried through item lifecycle, so this only changes the UUID version. It keeps generated item IDs consistent with thread and turn IDs. --- codex-rs/protocol/src/items.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/codex-rs/protocol/src/items.rs b/codex-rs/protocol/src/items.rs index 8fb2e4bb99..a65bd970df 100644 --- a/codex-rs/protocol/src/items.rs +++ b/codex-rs/protocol/src/items.rs @@ -409,11 +409,13 @@ pub struct ContextCompactionItem { pub id: String, } +fn new_item_id() -> String { + uuid::Uuid::now_v7().to_string() +} + impl ContextCompactionItem { pub fn new() -> Self { - Self { - id: uuid::Uuid::new_v4().to_string(), - } + Self { id: new_item_id() } } } @@ -426,7 +428,7 @@ impl Default for ContextCompactionItem { impl UserMessageItem { pub fn new(content: &[UserInput]) -> Self { Self { - id: uuid::Uuid::new_v4().to_string(), + id: new_item_id(), client_id: None, content: content.to_vec(), } @@ -528,9 +530,7 @@ fn trim_trailing_default_image_details( impl HookPromptItem { pub fn from_fragments(id: Option<&String>, fragments: Vec) -> Self { Self { - id: id - .cloned() - .unwrap_or_else(|| uuid::Uuid::new_v4().to_string()), + id: id.cloned().unwrap_or_else(new_item_id), fragments, } } @@ -560,7 +560,7 @@ pub fn build_hook_prompt_message(fragments: &[HookPromptFragment]) -> Option Option Self { Self { - id: uuid::Uuid::new_v4().to_string(), + id: new_item_id(), content: content.to_vec(), phase: None, memory_citation: None,