Skip to content

Commit ea6c689

Browse files
committed
feat(supervisor): stage gateway configuration snapshot delivery
Signed-off-by: Piotr Mlocek <pmlocek@nvidia.com>
1 parent 0569c3a commit ea6c689

24 files changed

Lines changed: 4413 additions & 1164 deletions

File tree

‎architecture/gateway.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,24 @@ successful create therefore yields an immediately usable provider; failures roll
654654
back the provider record. Service-account JSON and private keys remain gateway-side
655655
refresh bootstrap material; sandboxes receive minted access tokens instead.
656656

657+
## Supervisor configuration routing
658+
659+
Committed configuration mutations publish component and scope identifiers,
660+
never configuration payloads, to a bounded coalescing scheduler. The scheduler
661+
builds the latest full snapshot for each affected active sandbox. An async
662+
router owns session lookup, message sizing, sequence allocation, and enqueue.
663+
Its local implementation uses the process-local supervisor registry. A future
664+
HA implementation can resolve the gateway that owns a session and forward the
665+
same typed message without changing mutation handlers.
666+
667+
Polling remains authoritative during the first rollout stage. Snapshot build,
668+
fanout, or enqueue failure cannot fail a mutation that already committed.
669+
Provider snapshots may contain credentials and must not be
670+
persisted or included in logs.
671+
672+
See [sandbox configuration delivery](sandbox.md#supervisor-configuration-delivery)
673+
for bootstrap, revision, and supervisor application semantics.
674+
657675
## Supervisor Relay
658676

659677
Sandbox workloads maintain an outbound supervisor session to the gateway. This

‎architecture/sandbox.md‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,44 @@ the structured 403 and authors the narrowest rule. Mechanistically mapping L7
473473
would either over-broaden rules or require path-templating logic that rots
474474
quickly.
475475

476+
## Supervisor Configuration Delivery
477+
478+
The gateway and supervisor must implement the same internal supervisor protocol
479+
revision. The gateway includes a configuration bootstrap when it accepts a
480+
`ConnectSupervisor` session and can send complete component replacements on the
481+
same stream after policy, settings, or provider state changes.
482+
Bootstrap construction does not gate the session while polling remains
483+
authoritative. These payloads describe the latest effective state rather than
484+
the mutation that produced it. The gateway assigns ordering sequences within
485+
each session and component, while each snapshot retains its own content
486+
revision.
487+
488+
Bootstrap components are independent read projections, not one atomic database
489+
snapshot. The sandbox configuration carries the provider-environment revision
490+
it was built against. The gateway retries bootstrap construction when that
491+
revision does not match the provider snapshot. Later component updates and
492+
polling repair changes committed while the other projections were being built.
493+
494+
Configuration delivery goes through a gateway-owned routing boundary rather
495+
than exposing local supervisor channels to mutation handlers. The current
496+
implementation routes only to a supervisor connected to the same gateway
497+
process. The asynchronous router contract can resolve a remote owner later
498+
without changing publishers. Provider payloads can contain
499+
credentials, so the gateway does not persist or render complete stream
500+
messages in logs.
501+
502+
The supervisor currently parses and ignores stream-delivered configuration.
503+
Polling remains the only path that changes runtime state and repairs dropped or
504+
unavailable delivery. The gateway serializes construction per sandbox and
505+
component, and coalesces repeated mutations into the latest full snapshot. An
506+
enqueue result means only that the local stream queue accepted the message. A
507+
bounded scope fanout scheduler coalesces repeated workspace and global changes.
508+
Snapshot construction has a deadline, and the gateway rejects encoded stream
509+
messages that approach the transport decoder limit. A
510+
later migration will apply these payloads directly and acknowledge their exact
511+
revisions before removing supervisor polling. At that point, the gateway will
512+
require a valid bootstrap before marking a session ready.
513+
476514
## Policy Revision Acknowledgement
477515

478516
When the supervisor loads a sandbox-scoped policy from the gateway, it retains

‎crates/openshell-core/src/proto/mod.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,10 @@ pub fn all_workspaces_selector() -> WorkspaceSelector {
9494
)),
9595
}
9696
}
97+
98+
/// Exact protocol revision required between a gateway and its supervisor.
99+
///
100+
/// The supervisor stream is an internal, version-locked deployment contract.
101+
/// Bump this when either peer can no longer honor the previous stream
102+
/// semantics.
103+
pub const SUPERVISOR_PROTOCOL_REVISION: u32 = 1;

‎crates/openshell-server/src/compute/mod.rs‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,18 @@ impl ComputeRuntime {
989989
}
990990
})?;
991991

992+
if let Err(status) = Box::pin(crate::grpc::policy::initialize_policy_history(
993+
self.store.as_ref(),
994+
&sandbox,
995+
crate::grpc::policy::InitialPolicyHistoryStatus::Pending,
996+
))
997+
.await
998+
{
999+
let _ = self.store.delete(Sandbox::object_type(), &sandbox_id).await;
1000+
self.sandbox_index.remove_sandbox(&sandbox_id);
1001+
return Err(status);
1002+
}
1003+
9921004
if let Some(token) = sandbox_token
9931005
&& let Some(spec) = driver_sandbox.spec.as_mut()
9941006
{
@@ -1026,6 +1038,10 @@ impl ComputeRuntime {
10261038
Ok(sandbox)
10271039
}
10281040
Err(status) if status.code() == Code::AlreadyExists => {
1041+
let _ = self
1042+
.store
1043+
.delete_by_scope(POLICY_OBJECT_TYPE, sandbox.object_id())
1044+
.await;
10291045
let _ = self
10301046
.store
10311047
.delete(Sandbox::object_type(), sandbox.object_id())
@@ -1034,6 +1050,10 @@ impl ComputeRuntime {
10341050
Err(Status::already_exists("sandbox already exists"))
10351051
}
10361052
Err(status) if status.code() == Code::FailedPrecondition => {
1053+
let _ = self
1054+
.store
1055+
.delete_by_scope(POLICY_OBJECT_TYPE, sandbox.object_id())
1056+
.await;
10371057
let _ = self
10381058
.store
10391059
.delete(Sandbox::object_type(), sandbox.object_id())
@@ -1042,6 +1062,10 @@ impl ComputeRuntime {
10421062
Err(Status::failed_precondition(status.message().to_string()))
10431063
}
10441064
Err(err) => {
1065+
let _ = self
1066+
.store
1067+
.delete_by_scope(POLICY_OBJECT_TYPE, sandbox.object_id())
1068+
.await;
10451069
let _ = self
10461070
.store
10471071
.delete(Sandbox::object_type(), sandbox.object_id())
@@ -4938,6 +4962,7 @@ pub async fn new_test_runtime_with_driver(
49384962
#[cfg(test)]
49394963
mod tests {
49404964
use super::*;
4965+
use crate::policy_store::PolicyStoreExt;
49414966
use futures::stream;
49424967
use openshell_core::proto::compute::v1::{
49434968
CreateSandboxResponse, DeleteSandboxResponse, GetCapabilitiesResponse, GetSandboxRequest,
@@ -11240,6 +11265,36 @@ mod tests {
1124011265
);
1124111266
}
1124211267

11268+
#[tokio::test]
11269+
async fn create_sandbox_persists_initial_policy_revision() {
11270+
let runtime = test_runtime(Arc::new(TestDriver::default())).await;
11271+
let mut sandbox = sandbox_record(
11272+
"sb-initial-policy",
11273+
"initial-policy",
11274+
SandboxPhase::Provisioning,
11275+
);
11276+
let policy = openshell_core::proto::SandboxPolicy::default();
11277+
sandbox.spec = Some(SandboxSpec {
11278+
policy: Some(policy.clone()),
11279+
..Default::default()
11280+
});
11281+
11282+
runtime.create_sandbox(sandbox, None, false).await.unwrap();
11283+
11284+
let revision = runtime
11285+
.store
11286+
.get_latest_policy("sb-initial-policy")
11287+
.await
11288+
.unwrap()
11289+
.expect("initial policy revision");
11290+
assert_eq!(revision.version, 1);
11291+
assert_eq!(
11292+
revision.policy_hash,
11293+
crate::grpc::policy::deterministic_policy_hash(&policy)
11294+
);
11295+
assert_eq!(revision.status, "pending");
11296+
}
11297+
1124311298
#[tokio::test]
1124411299
async fn created_sandbox_is_immediately_visible_to_label_selectors() {
1124511300
let runtime = test_runtime(Arc::new(TestDriver::default())).await;

0 commit comments

Comments
 (0)