Define and enforce one OpenShell gateway lifecycle authority on Brev
Parent epic: #6401
Downstream implementation repository: brevdev/nemoclaw-image.
Problem
The Brev image currently supervises an OpenShell gateway through a custom system service, while canonical NemoClaw onboarding recognizes its packaged user service or a standalone gateway. When canonical onboarding runs on that image, both layers can believe they own the same gateway state and port. One process can replace the live listener while the custom service immediately restarts, producing a persistent :8080 bind conflict and leaving neither lifecycle authoritative.
The broader #6401 migration cannot be considered complete while gateway ownership is implicit. Provider changes, re-onboarding, artifact mismatch, rebuild, recovery, or a VM restart must never create a second gateway authority.
Invariant
At every point, exactly one component owns the OpenShell gateway lifecycle. Canonical onboarding must either:
- manage the packaged canonical gateway service; or
- attach to an explicitly declared external supervisor through a supported public contract.
It must never silently fall back to a competing standalone gateway when external management was declared or detected.
Supported modes
NemoClaw-managed
- NemoClaw owns start, stop, restart, upgrade, recovery, and runtime identity.
- Brev may enable the packaged service at boot, including through user-service lingering, but does not add a second gateway implementation.
- Re-onboard and rebuild reuse the same gateway owner unless an explicit supported migration is requested.
Externally supervised
- A platform supervisor owns the gateway process.
- A versioned public configuration declares the endpoint, state location, expected service/runtime identity, and required capabilities without embedding Brev or GCP control-plane logic in core NemoClaw.
- NemoClaw validates and attaches to the gateway but never stops, replaces, or independently starts it.
- Missing, incompatible, ambiguous, or multiply owned state fails before provider, policy, sandbox, or registry effects.
Upstream NemoClaw work
- Define the public gateway-management mode and identity/capability contract used by profiles and automation.
- Make the gateway FSM handler enforce the declared owner before all effects and on resume.
- Prohibit standalone fallback when external supervision is declared.
- Expose redacted owner, attachment, reuse, drift, and conflict results through status, diagnostics, and machine events.
- Revalidate owner identity before re-onboard, rebuild, provider/model mutation, artifact fallback, recovery, and uninstall.
- Keep credentials out of persisted ownership metadata, process diagnostics, and machine events.
Downstream Brev work
- Choose one supported mode and remove the parallel lifecycle path.
- Prefer the packaged canonical service with boot-time user-service lingering where it satisfies the launchable requirements; otherwise implement the supported external-supervisor contract.
- Remove service behavior that independently recreates or re-registers a gateway behind canonical onboarding.
- Ensure the web UI invokes the canonical onboarding protocol and never performs gateway cutover directly.
Acceptance criteria
- [ ] A booted candidate Brev image has exactly one gateway listener and one declared lifecycle authority.
- [ ] Canonical onboarding, re-onboarding, provider changes, rebuild, and artifact fallback do not change authority implicitly.
- [ ] Externally supervised mode never invokes a standalone fallback.
- [ ] An unknown listener, mismatched identity, or multiple owners fails before any provider, policy, sandbox, or registry mutation.
- [ ] VM and service restarts recover the declared gateway without sandbox loss or restart-count growth.
- [ ] Status and read-only diagnostics identify the management mode and redacted owner identity.
- [ ] Failure-injection tests cover a competing listener, stale PID/state, service restart, and interruption during onboarding.
- [ ] No provider credential value is persisted or emitted as part of gateway ownership or diagnostics.
Dependencies and sequencing
- Design this contract alongside #6404 immediately.
- Implement the pre-effect ownership decision on the stable planning and transition boundaries from #6226 and #6227.
- Integrate durable resume/revalidation with #6228 rather than defining a second checkpoint format.
- Blocks the downstream cutover in #6405 and is required evidence for lifecycle parity in #6406.
- Image-level release proof belongs in #6409.
Proposed design decision (requesting maintainer acceptance)
Per the v0.0.88 disposition on PR #6842, the implementation is deferred until #6576, parent #6401, and profile #6404 record an accepted decision covering ownership, lifecycle, compatibility, security, and validation. This comment proposes that decision for the gateway-authority contract, scoped strictly inside the boundary the epic already states. If maintainers accept (or amend) it, needs: design can be resolved here and #6842 re-reviewed against it as the candidate implementation.
1. Ownership
- NemoClaw core owns the gateway-management contract: mode declaration parsing, authority resolution, the FSM pre-effect ownership check, attach/validate semantics, and redacted ownership reporting through status/diagnostics/machine events. This is the "NemoClaw owns lifecycle semantics" side of the #6401 boundary.
- The Brev deployment layer owns choosing exactly one supported mode per image and providing the supervisor unit when it chooses external supervision. It never ships a second gateway implementation or performs cutover behind canonical onboarding (per the epic's boundary and this issue's "Downstream Brev work").
- The declaration reaches core through the #6404 platform profile's declarative inputs ("gateway service endpoint/state location when operator-managed") — no GCP/Brev specifics enter core.
2. Lifecycle
- Exactly one authority per run. The owner is resolved and validated once, before any provider/policy/sandbox/registry effect, and bound to the run's plan/checkpoint (the stable boundaries from #6226/#6227, resume via #6228 — no second checkpoint format).
- Revalidation fails closed. Re-onboard, rebuild, provider/model mutation, artifact fallback, recovery, and uninstall revalidate the bound owner; a mismatch aborts before effects. Revalidation never silently selects a different authority — changing authority is an explicit operator migration.
- No implicit fallback. When external supervision is declared, standalone fallback is prohibited; failures route the operator to the platform supervisor.
- VM/service restarts recover the declared authority without sandbox loss or restart-count growth.
3. Compatibility
- v1 supported modes:
nemoclaw-managed(default; packaged canonical service; boot-time user-service lingering permitted) andexternally-supervisedwithkind: systemd-system | systemd-user. - Opaque/generic external supervisors are out of the v1 contract — rejected at declaration time rather than accepted and always failing at attach, because only systemd offers an authoritative listener-to-unit identity proof today (cgroup membership). The contract is versioned so a proven external-identity mechanism can be added later without a breaking change.
- Non-Brev platforms (DGX Spark) are unaffected: absent a declaration, behavior is
nemoclaw-managedas today.
4. Security
- Identity proof is structural, not nominal: the listening process must belong to the declared unit's cgroup; a same-binary process started outside the unit is rejected.
- Destructive cleanup (container/volume removal, registry clearing) is permitted only after positive resolution that NemoClaw owns the gateway — never in externally supervised mode, and never before the ownership check.
- No provider credential value is persisted in ownership metadata or emitted via status, diagnostics, or machine events; owner identity is redacted in all read paths.
- Gateway endpoints are constrained to numeric loopback per the SSRF guidance already reviewed on #6842.
5. Validation
Acceptance evidence follows this issue's checklist, with the review-identified paths made explicit:
- a regression test through the full preflight sequence proving no destructive branch executes under external supervision, including when reuse state is
missing; - a stable-authority test proving the bound owner cannot flip mid-run, with revalidation failing closed;
- failure injection: competing listener, stale PID/state, supervisor restart, interruption during onboarding;
- status/diagnostics assertions for mode + redacted owner; credential-absence assertions on persisted state and events;
- image-level release proof stays in #6409; downstream cutover remains #6405.
Non-goals (v1)
Generic third-party supervisor kinds without an identity proof; web-UI-driven gateway cutover; any Brev-specific packaging inside core; changes to DGX Spark behavior.
If any dimension above needs a different call (e.g., a stricter v1 mode set, or different revalidation boundaries), I'll align #6842 to whatever is recorded here.
Maintainer decision: accepted.
The proposed v1 design in the preceding comment is approved, with this issue’s invariant and acceptance criteria as the controlling scope. In particular:
- v1 supports
nemoclaw-managedandexternally-supervisedwithsystemd-systemorsystemd-useridentity proof; - the exact gateway name, port, owner, endpoint, supervisor identity, and capabilities are bound durably and revalidated before effects and on resume;
- external supervision has no implicit standalone fallback and must remain inert across onboarding, rebuild, recovery, stop, final-sandbox cleanup, and uninstall — including no host-process signals or legacy gateway-destroy behavior;
- status and read-only diagnostics expose only redacted, secret-free authority metadata;
- failure-injection and zero-effect tests are required at each destructive boundary, while image-level proof remains in #6409.
This design acceptance resolves the product-scope decision only; it is not approval of any implementation PR. Each implementation must still satisfy the complete lifecycle contract and normal merge gates.
Removing needs: design.
Completed on the NemoClaw boundary by #7246 and released in v0.0.95.
Downstream Brev Launchable adoption is tracked separately in brevdev/nemoclaw-image#91, with broader Launchable qualification tracked under #6405 and #6409. The downstream release cadence does not keep this NemoClaw implementation issue open.