Skip to content

Commit b132c1a

Browse files
pimlockclaude
andcommitted
refactor(supervisor): trim the streamed configuration apply path
- Convert a delivered sandbox configuration snapshot through the polling projection, as provider environment snapshots already are, so both paths share defaults and validation. The conversion lists every response field, so a new one cannot be missed. - Drop the per-component sequence watermarks. The gateway sends at most one update per component in order and replaces unsent ones, so the stream never carries an older sequence. - Test that the deferred loopback connector holds relay connects until the boundary connector is installed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Piotr Mlocek <pmlocek@nvidia.com>
1 parent 7f81df0 commit b132c1a

3 files changed

Lines changed: 63 additions & 60 deletions

File tree

‎crates/openshell-core/src/grpc_client.rs‎

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,31 +1368,29 @@ fn settings_poll_result(inner: crate::proto::GetSandboxConfigResponse) -> Settin
13681368
}
13691369
}
13701370

1371+
/// Delivered snapshots go through the polling projection, so both paths
1372+
/// apply the same defaults and validation.
13711373
impl From<crate::proto::SandboxConfigSnapshot> for SettingsPollResult {
1372-
fn from(inner: crate::proto::SandboxConfigSnapshot) -> Self {
1373-
Self {
1374-
configuration_instance_id: inner.configuration_instance_id,
1375-
configuration_admitted: inner.configuration_admitted,
1376-
configuration_error: inner.configuration_error,
1377-
policy: inner.policy,
1378-
version: inner.version,
1379-
policy_hash: inner.policy_hash,
1380-
config_revision: inner.config_revision,
1381-
settings_revision: inner.settings_revision,
1382-
policy_source: PolicySource::try_from(inner.policy_source)
1383-
.unwrap_or(PolicySource::Unspecified),
1384-
settings: inner.settings,
1385-
global_policy_version: inner.global_policy_version,
1386-
provider_env_revision: inner.provider_env_revision,
1387-
provider_attachment_epoch: inner.provider_attachment_epoch,
1388-
supervisor_middleware_services: inner.supervisor_middleware_services,
1389-
workspace: inner.workspace,
1390-
policy_validation_failure_mode: inner
1391-
.policy_validation_failure_mode
1392-
.parse()
1393-
.unwrap_or_default(),
1394-
extension_authentication_enabled: inner.extension_authentication_enabled,
1395-
}
1374+
fn from(snapshot: crate::proto::SandboxConfigSnapshot) -> Self {
1375+
settings_poll_result(crate::proto::GetSandboxConfigResponse {
1376+
policy: snapshot.policy,
1377+
version: snapshot.version,
1378+
policy_hash: snapshot.policy_hash,
1379+
settings: snapshot.settings,
1380+
config_revision: snapshot.config_revision,
1381+
policy_source: snapshot.policy_source,
1382+
global_policy_version: snapshot.global_policy_version,
1383+
provider_env_revision: snapshot.provider_env_revision,
1384+
supervisor_middleware_services: snapshot.supervisor_middleware_services,
1385+
workspace: snapshot.workspace,
1386+
policy_validation_failure_mode: snapshot.policy_validation_failure_mode,
1387+
extension_authentication_enabled: snapshot.extension_authentication_enabled,
1388+
configuration_admitted: snapshot.configuration_admitted,
1389+
provider_attachment_epoch: snapshot.provider_attachment_epoch,
1390+
configuration_instance_id: snapshot.configuration_instance_id,
1391+
configuration_error: snapshot.configuration_error,
1392+
settings_revision: snapshot.settings_revision,
1393+
})
13961394
}
13971395
}
13981396

‎crates/openshell-supervisor-process/src/delegated.rs‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,46 @@ pub async fn finalize_main_process_exit(endpoint: &str, sandbox_id: &str, instan
385385
#[cfg(test)]
386386
mod tests {
387387
use super::*;
388+
use std::sync::atomic::AtomicUsize;
389+
390+
#[derive(Default)]
391+
struct CountingConnector {
392+
connects: AtomicUsize,
393+
}
394+
395+
#[async_trait::async_trait]
396+
impl BoundaryLoopbackConnector for CountingConnector {
397+
async fn connect(
398+
&self,
399+
_target: LoopbackTarget,
400+
) -> Result<BoundaryDuplexStream, BackendError> {
401+
self.connects.fetch_add(1, Ordering::SeqCst);
402+
Ok(Box::new(tokio::io::duplex(8).0))
403+
}
404+
}
405+
406+
#[tokio::test]
407+
async fn deferred_loopback_waits_for_the_boundary_connector() {
408+
let deferred = Arc::new(DeferredLoopbackConnector::default());
409+
let target = LoopbackTarget::new(std::net::Ipv4Addr::LOCALHOST.into(), 22).unwrap();
410+
let pending = tokio::spawn({
411+
let deferred = Arc::clone(&deferred);
412+
let target = target.clone();
413+
async move { deferred.connect(target).await.map(|_| ()) }
414+
});
415+
for _ in 0..10 {
416+
tokio::task::yield_now().await;
417+
}
418+
assert!(!pending.is_finished(), "connect waits until install");
419+
420+
let connector = Arc::new(CountingConnector::default());
421+
deferred
422+
.install(Arc::<CountingConnector>::clone(&connector))
423+
.await;
424+
pending.await.unwrap().unwrap();
425+
deferred.connect(target).await.unwrap();
426+
assert_eq!(connector.connects.load(Ordering::SeqCst), 2);
427+
}
388428

389429
#[tokio::test]
390430
async fn expected_post_exit_attachment_is_preserved_for_remote_main() {

‎crates/openshell-supervisor-process/src/supervisor_session.rs‎

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
//! selection — it has no protocol awareness of the bytes flowing through.
1212
1313
use std::net::IpAddr;
14+
use std::sync::Arc;
1415
use std::sync::atomic::{AtomicBool, Ordering};
15-
use std::sync::{Arc, Mutex};
1616
use std::time::Duration;
1717

1818
use openshell_core::grpc_client::SettingsPollResult;
@@ -100,12 +100,6 @@ impl PreparedSupervisorSession {
100100
}
101101
}
102102

103-
#[derive(Default)]
104-
struct ConfigSequenceWatermarks {
105-
sandbox_config: u64,
106-
provider_environment: u64,
107-
}
108-
109103
/// Revision token the gateway correlates with a sandbox configuration result.
110104
pub fn sandbox_config_revision(snapshot: &SettingsPollResult) -> ConfigSnapshotRevision {
111105
ConfigSnapshotRevision {
@@ -1095,7 +1089,6 @@ async fn run_prepared_session(
10951089
.await
10961090
.map_err(|_| "failed to queue configuration bootstrap result")?;
10971091
}
1098-
let config_sequences = Arc::new(Mutex::new(ConfigSequenceWatermarks::default()));
10991092
if let Some(updates) = &config.config_apply_updates {
11001093
updates.send_replace(prepared.config_apply_enabled);
11011094
}
@@ -1150,7 +1143,6 @@ async fn run_prepared_session(
11501143
tx: &tx,
11511144
terminating: &config.terminating,
11521145
config_apply_tx,
1153-
config_sequences: &config_sequences,
11541146
ready_tx: &config.ready_tx,
11551147
runtime_ready: &config.runtime_ready,
11561148
};
@@ -1285,7 +1277,6 @@ struct GatewayMessageContext<'a> {
12851277
tx: &'a mpsc::Sender<SupervisorMessage>,
12861278
terminating: &'a Arc<AtomicBool>,
12871279
config_apply_tx: Option<&'a mpsc::Sender<ConfigApplyRequest>>,
1288-
config_sequences: &'a Arc<Mutex<ConfigSequenceWatermarks>>,
12891280
ready_tx: &'a watch::Sender<bool>,
12901281
runtime_ready: &'a Arc<AtomicBool>,
12911282
}
@@ -1331,25 +1322,6 @@ fn handle_gateway_message(msg: &GatewayMessage, context: &GatewayMessageContext<
13311322
let invalid_update = update.update_id.is_empty()
13321323
|| update.component_sequence == 0
13331324
|| update.component.is_none();
1334-
let stale_sequence = if invalid_update {
1335-
false
1336-
} else {
1337-
let mut watermarks = context.config_sequences.lock().unwrap();
1338-
let watermark = if matches!(
1339-
update.component,
1340-
Some(config_update::Component::ProviderEnvironment(_))
1341-
) {
1342-
&mut watermarks.provider_environment
1343-
} else {
1344-
&mut watermarks.sandbox_config
1345-
};
1346-
if update.component_sequence <= *watermark {
1347-
true
1348-
} else {
1349-
*watermark = update.component_sequence;
1350-
false
1351-
}
1352-
};
13531325
tokio::spawn(async move {
13541326
let result = if invalid_update {
13551327
unapplied_update(
@@ -1358,13 +1330,6 @@ fn handle_gateway_message(msg: &GatewayMessage, context: &GatewayMessageContext<
13581330
"invalid_update",
13591331
"configuration update identity, sequence, and component are required",
13601332
)
1361-
} else if stale_sequence {
1362-
unapplied_update(
1363-
update,
1364-
ConfigApplyOutcome::IgnoredStale,
1365-
"stale_sequence",
1366-
"configuration update sequence is stale",
1367-
)
13681333
} else {
13691334
apply_update(&apply_tx, update).await
13701335
};

0 commit comments

Comments
 (0)