Keep rollout trace terminal sessions distinct when process IDs are reused (#56011)

## Why

Runtime process handles are recyclable and thread-local. Using them as terminal session identities can merge separate commands or associate `write_stdin` operations with the wrong exec.

## What changed

- Give each exec a distinct terminal session and track the latest session for each thread-local process handle.
- Record the exec selected by `write_stdin` at runtime and use it to correct session membership during replay, including when dispatch is delayed until a handle is reused.
- Fall back to the latest session for the thread and handle when replaying older traces without runtime target events.

## Testing

Extend reducer coverage for process ID reuse across threads and successive execs, stdin session membership, and delayed runtime target resolution.

GitOrigin-RevId: 330c6fd26a4eebdef03ae600a030dc76920e0dd9
This commit is contained in:
cassirer-openai
2026-10-21 23:13:31 +00:00
committed by copyberry
parent 082900149c
commit deede7201d
8 changed files with 306 additions and 165 deletions
@@ -996,6 +996,15 @@ impl UnifiedExecProcessManager {
} = self
.prepare_process_handles(process_id, &locked_process)
.await?;
context
.session
.services
.rollout_thread_trace
.record_stdin_target(
&context.step_context.turn.sub_id,
&context.call_id,
&call_id,
);
let remote_exited =
process.has_exited() && output.drain_policy == OutputDrainPolicy::WaitForOutputClosure;
// A write racing with remote exit still collects the final output.