Give Guardian classifications distinct turn identities (#41385)

## What changed

- Generate a UUIDv7 turn ID for each Guardian classification and preserve it across retries.
- Record the owning turn as `parent_turn_id` and propagate its trusted `root_turn_id` when known, including through the tool lifecycle extension API.
- Omit ambiguous or unknown root lineage and keep classification identities distinct when reusing Guardian sessions and WebSocket connections.

## Testing

- Cover classification metadata across retries, connection reuse, concurrent samples, auth refresh, and consecutive owning turns.

GitOrigin-RevId: 78757f2ad031844e4b545802f634c678a9ee2298
This commit is contained in:
Eddie Chen authored and copyberry committed 2026-08-28 18:23:47 +00:00
1 parent e4d0ba4e92
commit 60fc699560
11 files changed
+221 -62

No files matched your search

@@ -136,6 +136,7 @@ enum RecordedToolLifecycle {
Start {
call_id: String,
tool_name: codex_tools::ToolName,
root_turn_id: Option<String>,
},
Finish {
call_id: String,
@@ -157,6 +158,7 @@ impl codex_extension_api::ToolLifecycleContributor for ToolLifecycleRecorder {
let record = RecordedToolLifecycle::Start {
call_id: input.call_id.to_string(),
tool_name: input.tool_name.clone(),
root_turn_id: input.root_turn_id.map(str::to_owned),
};
Box::pin(async move {
records
@@ -640,6 +642,8 @@ fn post_tool_use_feedback_output_keeps_code_mode_result_typed() {
#[tokio::test]
async fn dispatch_uses_canonical_tool_names_for_lifecycle_contributors() -> anyhow::Result<()> {
let (mut session, turn) = crate::session::tests::make_session_and_context().await;
turn.turn_metadata_state
.set_root_turn_id("root-turn".to_string());
let records = Arc::new(std::sync::Mutex::new(Vec::new()));
let mut builder = codex_extension_api::ExtensionRegistryBuilder::<crate::config::Config>::new();
builder.tool_lifecycle_contributor(Arc::new(ToolLifecycleRecorder {
@@ -672,6 +676,7 @@ async fn dispatch_uses_canonical_tool_names_for_lifecycle_contributors() -> anyh
/*terminal_outcome_reached*/ None,
)
.await?;
turn.turn_metadata_state.mark_root_turn_ambiguous();
let err = match registry
.dispatch_any_with_terminal_outcome(
test_invocation(
@@ -693,6 +698,7 @@ async fn dispatch_uses_canonical_tool_names_for_lifecycle_contributors() -> anyh
RecordedToolLifecycle::Start {
call_id: "ok-call".to_string(),
tool_name: ok_tool.clone().with_default_namespace(),
root_turn_id: Some("root-turn".to_string()),
},
RecordedToolLifecycle::Finish {
call_id: "ok-call".to_string(),
@@ -702,6 +708,7 @@ async fn dispatch_uses_canonical_tool_names_for_lifecycle_contributors() -> anyh
RecordedToolLifecycle::Start {
call_id: "failing-call".to_string(),
tool_name: failing_tool.clone(),
root_turn_id: None,
},
RecordedToolLifecycle::Finish {
call_id: "failing-call".to_string(),