Skip to content

Commit e2b8a35

Browse files
committed
fix(supervisor): complete stream-first configuration startup
Signed-off-by: Piotr Mlocek <pmlocek@nvidia.com>
1 parent 4f082a5 commit e2b8a35

13 files changed

Lines changed: 1019 additions & 167 deletions

File tree

‎architecture/gateway.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,9 @@ process-local supervisor registry. A future HA implementation can resolve the
642642
gateway that owns a session and forward the same typed message without changing
643643
mutation handlers.
644644

645-
Current supervisors apply stream snapshots directly. Previous-revision
645+
Current supervisors establish the stream before gateway-owned runtime
646+
initialization, apply bootstrap and live snapshots directly, and persist only
647+
compact component observations from their results. Previous-revision
646648
supervisors retain polling as a rollout fallback, and owner reconciliation
647649
repairs missed or failed delivery from current database state. Snapshot build,
648650
fanout, or enqueue failure cannot fail a mutation that already committed.

‎architecture/sandbox.md‎

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,21 @@ only when the set is already empty; any other outcome fails the spawn.
2323

2424
## Startup Flow
2525

26-
1. The compute runtime starts the workload with sandbox identity, callback
26+
1. The compute runtime starts the supervisor with sandbox identity, callback
2727
endpoint, TLS or secret material, image metadata, and initial command.
28-
2. The supervisor loads policy and runtime settings from local files or the
29-
gateway, depending on mode.
30-
3. It prepares filesystem access, process restrictions, network namespace
28+
2. In gateway-backed mode, the supervisor opens `ConnectSupervisor` and
29+
receives the complete desired-state bootstrap. Standalone mode reads its
30+
explicit local files without opening a gateway session.
31+
3. It installs policy, settings, middleware, and provider state from that
32+
authoritative source.
33+
4. It prepares filesystem access, process restrictions, network namespace
3134
routing, trust stores, and provider credential resolution.
32-
4. It launches the persisted canonical main-process argv and retains its PTY
35+
5. It starts the policy proxy and local SSH server, then launches the persisted
36+
canonical main-process argv and retains its PTY
3337
or pipes in the main-session multiplexer.
34-
5. It starts the policy proxy and local SSH server.
35-
6. It opens a supervisor session back to the gateway for connect, exec, file
36-
sync, config polling, and log push.
38+
6. After runtime endpoints are ready, it reports bootstrap application and
39+
keeps the session open for desired-state delivery, connect, exec, file sync,
40+
and log push.
3741

3842
## Isolation Layers
3943

@@ -201,10 +205,9 @@ the registry. Public custom-CA PEM travels with the stable registration.
201205

202206
The slots live in a supervisor-owned `ExtensionCredentialStore` shared by every
203207
gateway connection the supervisor opens, so the registry's clients and the
204-
polling loop that rotates them observe the same credentials. Configuration
205-
polling runs far more frequently than credentials expire, so the loop rotates
206-
only when a credential is missing or has passed four fifths of its lifetime,
207-
and bounds its sleep by the soonest rotation deadline.
208+
configuration loop that rotates them observe the same credentials. The loop
209+
rotates only when a credential is missing or has passed four fifths of its
210+
lifetime, and bounds its sleep by the soonest rotation deadline.
208211

209212
Middleware cannot observe injected credentials, introduce credential
210213
placeholders, or mutate supervisor-owned credential, routing, or framing
@@ -487,6 +490,10 @@ Revision 2 supervisors require a complete bootstrap. The gateway uses the same
487490
bounded 45-second construction window as other snapshot builds and rejects the
488491
connection when construction fails. Revision 1 compatibility sessions retain
489492
the optional one-second bootstrap budget and use polling when it expires.
493+
The revision 2 supervisor opens the stream and consumes the bootstrap before it
494+
constructs gateway-owned policy, provider state, networking, or the workload.
495+
It reports bootstrap results after those components, the workload, and relay
496+
endpoints are ready.
490497
These payloads describe the latest effective state rather than
491498
the mutation that produced it. The gateway assigns ordering sequences within
492499
each session and component, while each snapshot retains its own content
@@ -496,7 +503,8 @@ Bootstrap components are independent read projections, not one atomic database
496503
snapshot. The sandbox configuration carries the provider-environment revision
497504
it was built against. The gateway retries bootstrap construction when that
498505
revision does not match the provider snapshot. Later component updates and
499-
polling repair changes committed while the other projections were being built.
506+
owner reconciliation repair changes committed while the other projections
507+
were being built.
500508

501509
Configuration delivery goes through a gateway-owned routing boundary rather
502510
than exposing local supervisor channels to mutation handlers. The current
@@ -506,12 +514,15 @@ without changing publishers. Provider payloads can contain
506514
credentials, so the gateway does not persist or render complete stream
507515
messages in logs.
508516

509-
The supervisor applies stream-delivered configuration through the same runtime
510-
primitives used by the compatibility poller. It reports the requested and
517+
The supervisor applies bootstrap and live stream snapshots through shared
518+
component runtime primitives. It reports the requested and
511519
active revisions plus a component-specific outcome on `ConnectSupervisor`.
512520
Sandbox-scoped policy results update only the matching policy-history row, so a
513521
late result cannot mark a newer revision loaded. Explicit local policy remains
514-
authoritative and produces a retained-local-override result.
522+
authoritative and produces a retained-local-override result. Other component
523+
results persist only compact observed state: requested and active revisions,
524+
outcome, effective source, observation time, and a bounded sanitized error.
525+
Delivered snapshots, including provider credentials, are never persisted.
515526

516527
The gateway keeps one update in flight per session and component. It replaces
517528
the pending snapshot when newer desired state arrives, validates the update ID,
@@ -522,10 +533,11 @@ revisions suppress unchanged delivery, while failed or timed-out delivery is
522533
retried from current database state. Reconnect discards session delivery state
523534
and starts with a fresh bootstrap.
524535

525-
Polling remains available during the mixed-version rollout. The gateway
526-
serializes construction per sandbox and component, and coalesces repeated
527-
mutations into the latest full snapshot. An enqueue result means only that the
528-
local stream queue accepted the message. A bounded scope fanout scheduler
536+
Revision 2 does not poll configuration fetch APIs. Polling remains available
537+
only to revision 1 and revision 0 supervisors during the mixed-version rollout.
538+
The gateway serializes construction per sandbox and component, and coalesces
539+
repeated mutations into the latest full snapshot. An enqueue result means only
540+
that the local stream queue accepted the message. A bounded scope fanout scheduler
529541
coalesces repeated workspace and global changes,
530542
and semaphores sized from the database pool bound delivery workers and snapshot
531543
builds. Fanout waits for worker capacity before admitting each recipient, so a
@@ -546,12 +558,11 @@ If policy construction fails, it reports the captured revision as `FAILED` with
546558
the original construction error. It never infers revision identity by comparing
547559
policy structure.
548560

549-
This holds even when the initial policy is enriched with baseline paths during
550-
startup: the enriched revision the supervisor synced back to the gateway is the
551-
revision it acknowledges, so a successfully constructed initial policy never
552-
remains `Pending`. If the first poll returns a different revision, the supervisor
553-
processes it through the normal reload path instead of treating it as already
554-
loaded.
561+
Image-specific policy discovery and baseline enrichment can require one initial
562+
gateway synchronization. The supervisor commits that repair before runtime
563+
initialization, discards the mutation response, and reconnects so it installs
564+
only the fresh authoritative stream bootstrap. Compatibility supervisors retain
565+
the earlier enrichment and first-poll reconciliation path.
555566

556567
A newer sandbox-scoped revision can carry the same non-empty effective policy
557568
hash as the currently loaded revision, for example when provenance changes
@@ -562,23 +573,23 @@ reconciliation succeeds. Global policies, local overrides, equal or older
562573
versions, and different hashes do not use this shortcut. Success telemetry is
563574
emitted only after the gateway accepts the resulting loaded-status report.
564575

565-
Policy status delivery uses a FIFO background worker. Retryable delivery
566-
failures retain the ordered update and retry with capped exponential backoff;
567-
terminal errors are logged and discarded. The outbox is nonblocking and does
568-
not discard updates because of a fixed queue capacity, so status endpoint
569-
outages cannot block policy polling, enforcement, settings, or provider
570-
refreshes and cannot permanently lose the initial acknowledgement.
576+
Revision 2 policy status is recorded from the correlated stream result. The
577+
retained reporting RPC uses the same domain helper for compatibility
578+
supervisors. Retryable legacy status delivery uses a FIFO background worker so
579+
status endpoint outages do not block enforcement.
571580

572581
Only sandbox-scoped revisions (`PolicySource::Sandbox`, version greater than
573582
zero) are acknowledged. Global policies and local-file development policies do
574583
not use the sandbox revision API and produce no acknowledgement. When explicit
575584
local Rego and data files are configured, the supervisor continues polling the
576-
gateway for settings and provider refreshes but never replaces the local OPA
577-
engine with a gateway policy revision.
585+
gateway for settings and provider refreshes only on the compatibility path; a
586+
revision 2 supervisor receives those components on the stream and never
587+
replaces the local OPA engine with a gateway policy revision.
578588

579589
## Failure Behavior
580590

581-
- If gateway config polling fails, the sandbox keeps its last-known-good policy.
591+
- If a compatibility configuration poll fails, the sandbox keeps its
592+
last-known-good policy.
582593
- If a live policy or middleware-registry update is invalid, the supervisor
583594
rejects the combined update and keeps the current runtime pair.
584595
- If an operator-run middleware call fails, the selected config's `on_error`

0 commit comments

Comments
 (0)