Record host-confirmed Code Mode wait targets in rollout traces (#61338)

## Why

Inferring wait targets from request arguments can abort trace replay on malformed arguments and link waits to cells the host never resolved.

## What changed

Record an explicit `CodeCellWaitTargetResolved` event when the host confirms a live cell, and expose its runtime handle as `resolved_wait_runtime_cell_id` on the tool call. Build cell wait links from these observations, preserving links while cell source is pending and preventing late confirmations from linking to recycled handles after thread resume.

Older traces no longer infer wait links from request arguments, so an empty `wait_tool_call_ids` list does not establish that nobody waited on a cell.

## Testing

Extend dispatch and replay tests to cover live, missing, and invalid wait targets, pending cell source, legacy traces, and runtime handle reuse across threads and resume.

GitOrigin-RevId: 0f13b291c197c5487258b6ce36276cf1f19e2b6d
This commit is contained in:
tongzhou wang
2026-11-13 18:43:21 +00:00
committed by copyberry
parent c79dfb1d9c
commit 9d12d007b2
10 changed files with 238 additions and 93 deletions
@@ -154,11 +154,23 @@ impl CodeModeWaitHandler {
FunctionCallError::RespondToModel(error)
})?;
if let codex_code_mode::WaitOutcome::LiveCell(response) = &wait_response {
// Dispatch already records failed waits. Re-parsing {"cell_id": 5} during
// replay used to abort the whole trace, and even a valid string can name
// a closed cell. Only the host can confirm which cell this wait reached.
let runtime_cell_id = match response {
RuntimeResponse::Yielded { cell_id, .. }
| RuntimeResponse::Terminated { cell_id, .. }
| RuntimeResponse::Result { cell_id, .. } => cell_id,
};
let cell_trace = exec
.session
.services
.rollout_thread_trace
.code_cell_trace_context(
exec.turn.sub_id.as_str(),
runtime_cell_id.as_str(),
);
cell_trace.record_wait_target(&call_id);
tracing::Span::current().record("cell.id", trace_id(runtime_cell_id.as_str()));
telemetry.cell_id = Some(runtime_cell_id.to_string());
exec.session
@@ -174,14 +186,7 @@ impl CodeModeWaitHandler {
.unwrap_or_default(),
},
);
exec.session
.services
.rollout_thread_trace
.code_cell_trace_context(
exec.turn.sub_id.as_str(),
runtime_cell_id.as_str(),
)
.record_ended(response);
cell_trace.record_ended(response);
exec.session
.services
.code_mode_service