Track executor registrations across connection refresh and recovery (#46555)

## Why

An executor can renew its registration while retaining its Noise identity. Connection refresh must distinguish registrations even when their keys match, and a stale registry lookup must not retire a session that recovery has already renewed.

## What changed

- Track the installed session's registration and expose it through `Environment::cached_executor_registration_id()` without connecting. Publish registration changes only when the new connection is installed.
- Require both registration and executor key to match before refresh reuses a session. Retry stale lookups and prevent recovery from installing a connection after retirement.
- Pin session recovery to the original Noise key while allowing registration renewal to preserve the session and running processes.
- Expose `CodexThread::active_turn_environment_selections()` so hosts can authorize steering against the active turn's selections, including starting and failed environments, independently of later settings updates.

## Testing

Add regression coverage for registration replacement, renewal with a running process, stale refresh lookups, missing sessions, and rejection of changed Noise keys. Extend active-turn tests to check selection snapshots across settings updates, deferred startup, and turn completion.

GitOrigin-RevId: 4395bc6c57f137691887e6585f52dcc5b958101c
This commit is contained in:
viyatb-oai
2026-09-19 01:27:02 +00:00
committed by copyberry
parent a633ebc124
commit 328feb0c29
9 changed files with 445 additions and 30 deletions
+20
View File
@@ -291,6 +291,8 @@ struct Inner {
struct ConnectionState {
status: ConnectionStatus,
// Publish registration renewal together with the recovered transport.
executor_registration_id: Option<String>,
active_process_starts: usize,
environment_connection_state_tx: watch::Sender<EnvironmentConnectionState>,
}
@@ -347,6 +349,7 @@ pub struct ExecServerClient {
/// `timeout_for_error` keeps diagnostics tied to the caller's configured
/// budget after readiness has consumed part of that budget.
pub(crate) struct NoiseInitializeContext {
pub(crate) executor_registration_id: String,
pub(crate) span: tracing::Span,
pub(crate) timeout_for_error: Duration,
}
@@ -598,6 +601,11 @@ impl LazyRemoteExecServerClient {
.filter(|client| !client.is_disconnected())
}
pub(crate) fn cached_executor_registration_id(&self) -> Option<String> {
self.cached_client()
.and_then(|client| client.executor_registration_id())
}
fn cached_client(&self) -> Option<ExecServerClient> {
self.current_client
.lock()
@@ -693,6 +701,15 @@ pub enum ExecServerError {
}
impl ExecServerClient {
fn executor_registration_id(&self) -> Option<String> {
self.inner
.connection
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.executor_registration_id
.clone()
}
fn attach_environment_connection_state(
&self,
state_tx: watch::Sender<EnvironmentConnectionState>,
@@ -1216,6 +1233,9 @@ impl ExecServerClient {
let inner = Arc::new(Inner {
connection: StdMutex::new(ConnectionState {
status: ConnectionStatus::Connected(Arc::clone(&rpc_client)),
executor_registration_id: noise_context
.as_ref()
.map(|context| context.executor_registration_id.clone()),
active_process_starts: 0,
environment_connection_state_tx: watch::channel(
EnvironmentConnectionState::Connected,