Repository navigation
feat(gateway): explicit shutdown disposition to retain running sandboxes (Connect S5) - #44
Conversation
…s on request A graceful gateway shutdown always ran the sandbox stop sweep, so an embedded host that restarts its gateway (Connect's runtime restart) could never re-adopt a live sandbox: the sweep's stop terminates the boundary and a later attach is rejected as terminal. Re-adoption only worked after SIGKILL. Add a separate shutdown disposition, independent of the driver's gateway_manages_lifecycle capability (which also gates startup reconciliation and must stay on for re-adoption): - stop-running-sandboxes (default): today's stop sweep, unchanged. - retain-running-sandboxes: skip only the stop sweep. Listener shutdown, the managed driver process shutdown and all other cleanup still run. Sources: --shutdown-disposition / OPENSHELL_GATEWAY_SHUTDOWN_DISPOSITION, or --shutdown-disposition-file / OPENSHELL_GATEWAY_SHUTDOWN_DISPOSITION_FILE, read when the shutdown signal arrives so a host can choose per shutdown; a configured file is the only source. Anything but an exact known token (unset, unknown, missing/unreadable/oversized file) selects the stop sweep, with a CK_gateway_shutdown_disposition_fallback warning. Every graceful shutdown emits one bounded CK_gateway_shutdown_disposition receipt with mode, source and the retained running-intent sandbox count. Tests: unit coverage for the default sweep, unknown values, retain skipping only the sweep (driver process still stopped, intent kept), file resolution at shutdown time and CLI/env parsing. The Docker E2E gains a graceful-SIGTERM retain variant: the container, its StartedAt and running intent survive, the next gateway reaches Ready and exec through a generation-2 handover, and removing the file makes the next graceful stop sweep the sandbox. Connect S5 (shutdown half); stacked on #42; separate from ai-openshell#471. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
raghusubramanyam
left a comment
There was a problem hiding this comment.
[vega]
Conformance: CONDITIONAL PASS (source-clean at 64fc5dcf; combined D1b contract gated on Connect ai-openshell#472 fixes + live WP-6 H6 runtime receipt)
Head SHA: 64fc5dcf9712642ad4d7ba71135ca4700c930ba6 (stacked on #42 @6efaf294) | Objective / Bar: D1b shutdown-disposition contract (OpenShell half, reviewed jointly with lightforgedev/aegis-connect-phoenix#472 @d773a67c); live WP-6 H6 run remains the runtime gate.
Cross-Repo D1b Contract Check (OpenShell#44 + aegis-connect-phoenix#472)
- Env var & token handshake:
OPENSHELL_GATEWAY_SHUTDOWN_DISPOSITION_FILE(cli.rs:166) matches Connectprocess.ex:361; exact tokensretain-running-sandboxes/stop-running-sandboxes(shutdown_disposition.rs:47-48) match Connectprocess.ex:31-32. - Signal-time resolution & fail-closed fallback:
lib.rs:1049resolves aftershutdown_signal().awaitandlistener_task.await. When a disposition file is configured it is the sole source — missing, unreadable, directory, >64 B, non-UTF-8, or non-exact tokens all resolve toStopRunningSandboxeswithCK_gateway_shutdown_disposition_fallback(shutdown_disposition.rs:129-181,lib.rs:1050-1058). - Scope isolation:
gateway_manages_lifecycleis untouched (compute/mod.rs:2807, 2942); no genericskip_cleanupflag exists; retain skips onlystop_persisted_sandboxes_on_shutdown()while still shutting down the listener, settinggateway_shutting_down, terminating the manageddriver_process, and propagating cleanup errors (compute/mod.rs:2716-2780). - Exit-status propagation: Sweep errors return
Errfromcleanup_on_shutdown->run_server(lib.rs:1063) ->cli::run(cli.rs:700), exiting non-zero as Connect's explicit-stop wrapper requires. - Foreign-sandbox boundary:
stop_persisted_sandboxes_on_shutdown()queries onlyself.store(list_persisted_sandbox_ids), never Docker directly, so sandboxes owned by other Gateways/runs on the same Docker engine are untouched. - Companion PR status:
lightforgedev/aegis-connect-phoenix#472(d773a67c) has 4 smallREQUEST_CHANGESitems in its new:stopping/RunOwnedCleanup/terminate/2paths (separate comment posted on ai-openshell#472).
Findings
- Required now: None in
OpenShell#44source at64fc5dcf. Remaining gates before merge/integrated-D1 closure: (1) resolve Connect ai-openshell#472 review items so the one D1b contract is clean on both sides, and (2) exact-head WP-6 H6 receipt (plus merge ordering: merge#42first and retarget#44tolightforge-main). - Track next (non-blocking):
- VM and Kubernetes drivers were not exercised in retain mode (documented in PR; for drivers with
gateway_manages_lifecycle == false, the sweep was already a no-op). - On a failed stop sweep (
sweep_ok=false),CK_gateway_shutdown_dispositionlogsretained=0even if some sandboxes failed to stop (compute/mod.rs:2727);sweep_ok=falsealready flags failure, so cosmetic only. - Connect's Gateway wrapper discards child stderr (
2>/dev/null), so in packaged Connect runsCK_gateway_shutdown_dispositionis only observable if Gateway logging is routed to a file/sink; Connect emits its ownCK_gateway_shutdown_disposition_selected.
- VM and Kubernetes drivers were not exercised in retain mode (documented in PR; for drivers with
Ownership / Reuse
| Capability | Existing owner/module@head | Decision | Evidence |
|---|---|---|---|
| Gateway shutdown disposition parsing/resolution | OpenShell:crates/openshell-server (64fc5dcf, on #42 6efaf294) |
new (narrow module in owning server crate) |
No existing disposition parser; cleanly separated from gateway_manages_lifecycle |
| Graceful shutdown compute cleanup | OpenShell:crates/openshell-server/src/compute/mod.rs@64fc5dcf |
extend |
Extends ComputeRuntime::cleanup_on_shutdown in place without duplicating driver teardown |
| Docker graceful retain + re-adopt E2E | OpenShell:e2e/rust/tests/docker_gateway_restart_readopt.rs@64fc5dcf |
extend |
Extends #42's Docker re-adopt suite with ManagedGateway::terminate (no SIGKILL escalation) |
Validation
- Independently verified at exact head
64fc5dcf9712642ad4d7ba71135ca4700c930ba6:git diff --check 6efaf2943e7218850b49d8fab24a00fef66c4ef6...HEAD: cleancargo fmt --all -- --checkand(cd e2e/rust && cargo fmt --check): cleancargo clippy -p openshell-server --all-targets -- -D warnings: cleancargo test -p openshell-server --lib -- shutdown_disposition cleanup_on_shutdown command_reads_shutdown_disposition: 9 passed, 0 failed
- Author-reported Docker E2E (
e2e/rust/tests/docker_gateway_restart_readopt.rs,e2e/with-docker-gateway.sh): 2/2 passed twice (graceful SIGTERM retain + generationSome(1)->Some(2)re-adopt + missing-file fallback sweep, plus#42SIGKILL test); inspected test code — no stubs/mocks replacing Docker/Gateway boundaries. - CI status: no GitHub Actions check runs reported on
64fc5dcf(unknown / none configured). - Integrated runtime E2E: live WP-6 H6 run with
#42+#43+#44+ Connect#472remains open.
Blast Radius
crates/openshell-server/src/{cli.rs, lib.rs, compute/mod.rs, shutdown_disposition.rs},e2e/rust/src/harness/gateway.rs,e2e/rust/tests/docker_gateway_restart_readopt.rs. Zero changes to sandbox/supervisor crates orgateway_manages_lifecyclestartup reconciliation.
Simplification
- Clean: compact 302-line module (including unit tests) with no speculative config schema or TOML churn.
|
[hugo] Conformance: CONDITIONAL PASS Findings:
Ownership/reuse:
Validation:
Blast radius: server CLI, shutdown resolution, compute cleanup, and Docker restart harness only; supervisor/security policy paths unchanged. Simplification: one bounded disposition parser and one branch in existing cleanup; no generic skip-cleanup mode. |
WP-6 H6 live runtime receipt: run
|
| Repo | Pin |
|---|---|
Connect integration integration/wp6-agy-h6b2 |
64fa3f38 = ai-openshell#472 a57e3609 + ai-openshell#474 52f1ebb2 + ai-openshell#461 af0133d4 |
OpenShell closure integration/wp6-agy-h6 |
e2e20ace = #42 6efaf294 + #43 f72b22d8 + #44 64fc5dcf. Images: gateway f31ba45a, sandbox 720f7bbd, supervisor 63dd0bd0 |
| Shell | b08afb13 |
| Phoenix | e89345f7 |
| global-e2e control | dcee6fe1 |
| SDK linux-arm64 | 09de4309 (sha256 520f4a9a…) |
The SDK differs from attempts 2 and 3, which used 2642ce34. That binary predates SDK ai-openshell#160 --lane, while Shell D-070 calls session-start --lane connect. h6c is kept as the record of that pin skew.
Diagnostics on: AEGIS_CONNECT_GATEWAY_DIAGNOSTIC_LOG=1, OPENSHELL_LOG_LEVEL=debug. Run with native-run/run-native-gates.sh --diag --restarts 3 (aegis-api-phoenix#3900).
| Gate | Result |
|---|---|
| 1 inputs | passed: pins equal the checkouts, artifact SHA-256 values match, 0 FIFO wrappers, umask 022 |
| accept | passed: runtime-setup, bootstrap, first-session, restart-session; mind smoke post-enroll and post-restart |
| D1 restart re-adoption, 3 restarts | passed: same sandbox container 53f47c46 and StartedAt 21:00:04.395Z across all restarts; supervisor generation 2→3→4→5, advancing by exactly one each time; a distinct healthy sidecar per restart; Ready, and exec rc=0 after each restart |
| D1b shutdown disposition | CK_gateway_shutdown_disposition_selected mode=retain-running-sandboxes reason=runtime_restart on all 5 Gateway stops (preflight, accept and 3 proof restarts); no sweep |
| ai-openshell#471 | passed: first_session_passed, no sandbox_session_not_registered, no policy-generation stale close |
| ai-openshell#474 diagnostic log | home/logs/gateway.log plus 3 rotations, each ≤1.05 MB (bounded), mode 0600; 4 [redacted] substitutions; 0 hits from a credential-pattern scan (Authorization/Cookie/Bearer/token/secret/password, JWT, sk-, ghp_, PEM); no CK_gateway_output_log_unavailable; readiness unchanged |
| 5 down | down result=verified, rc=0; no namespace containers or volumes left; custody-unproven agent/identity volumes kept (ai-openshell#85); 0 lingering wrappers |
Receipts are private (0600) on the build host under out/wp6-agy-20261127h6d/ (inputs.txt, accept.log, restart/restart-proof-receipt.json, 471-receipt.json, postdown-receipt.txt, restart/gateway.log*).
|
[hugo] Conformance: PASS The D1b runtime gate is closed by WP-6 H6d No required finding remains. GitHub reports no CI/check runs; prior exact-head local suites plus H6d satisfy this cross-repository contract's evidence bar. Merge sequencing: after #42 and #43 merge, retarget #44 to Comment-only review: no approval, merge, or label change performed. |
Summary
Connect S5 (shutdown half); companion to OpenShell #42; separate from ai-openshell#471 (lightforgedev/aegis-connect-phoenix#471, supervisor-network tunnel staleness).
Stacked on #42 (
fix/gateway-restart-readopt, head6efaf294). Review and merge #42 first.A graceful gateway shutdown always ran the sandbox stop sweep (
cleanup_on_shutdowncallsstop_persisted_sandboxes_on_shutdown). The sweep's driver stop sends TerminateBoundary, so a later gateway can never re-adopt the sandbox: attach fails with "sandbox session is terminal". #42 proved re-adoption only after SIGKILL. Connect's runtime restart is graceful, so it always lost its sandboxes (WP-6 run H5).Contract (Hugo, S5 option 1)
ShutdownDisposition(crates/openshell-server/src/shutdown_disposition.rs):stop-running-sandboxes(default) orretain-running-sandboxesgateway_manages_lifecyclecompute/mod.rs,start_persisted_sandboxes)skip_cleanupcleanup_on_shutdown(disposition): retain does not callstop_persisted_sandboxes_on_shutdown. Listener shutdown,gateway_shutting_down, the managed driver process shutdown and the error merge are unchangedCK_gateway_shutdown_dispositionline per graceful shutdown:mode,source(default/static/file),retained(running-intent count), andsweep_okfor the sweepCK_gateway_shutdown_disposition_fallbackwarning withreasonSources:
--shutdown-disposition/OPENSHELL_GATEWAY_SHUTDOWN_DISPOSITION: a static value.--shutdown-disposition-file/OPENSHELL_GATEWAY_SHUTDOWN_DISPOSITION_FILE: read when the shutdown signal arrives, so a host can choose for each shutdown. Connect needs this because one Gateway process can end either way: runtime restart (retain) or explicit Stop (sweep). When a file is configured it is the only source; a missing file sweeps and never falls back to the static value.No TOML key was added: Connect pins
gateway.tomlwith a content receipt, so it passes the file through the environment.Tests
Unit (
cargo test -p openshell-server: 1766 lib tests pass, 8 ignored, 0 failed; all other test targets pass). New tests (9):shutdown_disposition::tests(5): missing defaults to sweep; exact parsing; unknown static values sweep ("",retain, upper-case,skip-cleanup, a trailing suffix); the file is read at resolve time (missing, then retain, then stop); unknown, non-UTF-8, oversized or directory files sweep.compute::tests(3):cleanup_on_shutdown_default_disposition_runs_stop_sweep(default sweep unchanged);cleanup_on_shutdown_unknown_disposition_runs_stop_sweep;cleanup_on_shutdown_retain_skips_only_the_stop_sweep(0 driver stops, persisted Ready/Provisioning intent kept, the managed driver child still terminated, retained count 2).cli::tests::command_reads_shutdown_disposition_from_flags_and_env(1).shutdown_stops_running_intent_without_changing_persisted_phaseand the others) pass unchanged.Docker E2E (
e2e/rust/tests/docker_gateway_restart_readopt.rs, local Docker Desktop arm64,e2e/with-docker-gateway.sh): 2 passed, 0 failed,E2E_EXIT=0.docker_gateway_graceful_retain_restart_readopts_live_sandbox:--shutdown-disposition-fileset to retain.ManagedGateway::terminatenever escalates to SIGKILL.mode="retain-running-sandboxes" source="file" retained=1.StartedAt/RestartCount.CK_supervisor_handover_accepted previous_supervisor_generation=Some(1) supervisor_generation=Some(2).mode="stop-running-sandboxes" source="file" retained=0 sweep_ok=true, and the container stops. This is the E2E check that a missing disposition sweeps.local/readopt/{sandbox,supervisor}:allowlist, built from fix(docker): re-adopt live sandboxes across gateway restarts via supervisor generation handover #42 head6efaf294. This PR does not change sandbox or supervisor code, so those images match its sandbox/supervisor sources. The gateway and CLI were built from this branch.Gates:
cargo fmt --all -- --checkand e2ecargo fmt --checkare clean.cargo clippy -p openshell-server --all-targets -D warningsis clean, and so is clippy on the e2e lib plusdocker_gateway_restart_readopt. Other e2e test files have clippy lints from before this PR.git diff --checkis clean.Not in scope / unverified
gateway_manages_lifecycle, the sweep was already a no-op.🤖 Generated with Claude Code