Preserve rollout tracing across sub-agent reloads (#57615)

## Why

Reloading an evicted sub-agent disabled its rollout tracing, leaving later turns out of the trace. Replacement Code Mode sessions could also reuse cell IDs from earlier sessions.

## What changed

- Reattach reloaded children to the root rollout trace and emit `ThreadResumed` without duplicating `ThreadStarted`.
- Reopen existing threads during replay, preserving their identity and history while clearing stale runtime cell and terminal process mappings.
- Allocate Code Mode cell generations across sessions for both gRPC and stdio hosts to prevent ID reuse after reload.
- Record an aborted trace when session startup fails before the session loop begins.

## Testing

Add regression coverage for child eviction and reload, including a failed reload, continued inference tracing, distinct cell IDs, and preserved mail and follow-up context. Extend replay tests for history preservation and reused runtime handles, and host tests for cell IDs across session replacement and reconnection.

GitOrigin-RevId: 6c146c04b5cda9295afb7d973c0d5474b363a822
This commit is contained in:
cassirer-openai
2026-10-28 01:29:34 +00:00
committed by copyberry
parent c0e88f3c04
commit 68b67f0ff4
19 changed files with 367 additions and 100 deletions
@@ -5,6 +5,7 @@ use std::sync::Mutex;
use std::sync::PoisonError;
use std::sync::Weak;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::AtomicU64;
use std::sync::atomic::Ordering;
use std::time::Duration;
@@ -67,6 +68,8 @@ fn inject_span_traceparent<T>(request: &mut tonic::Request<T>, span: &tracing::S
#[derive(Clone)]
pub struct GrpcCodeModeSessionProvider {
transport: Arc<SharedTransport>,
// Reloaded threads share this counter rather than reusing a cell namespace.
next_generation: Arc<AtomicU64>,
}
impl GrpcCodeModeSessionProvider {
@@ -94,6 +97,7 @@ impl GrpcCodeModeSessionProvider {
fn from_transport(transport: SharedTransport) -> Self {
Self {
transport: Arc::new(transport),
next_generation: Arc::new(AtomicU64::new(1)),
}
}