Skip to content

fix(gateway): install/manage OpenShell gateway service for reboot persistence - #6907

Closed
jibin7jose wants to merge 1 commit into
NVIDIA:mainfrom
jibin7jose:fix-issue-6903
Closed

jibin7jose wants to merge 1 commit into
NVIDIA:mainfrom
jibin7jose:fix-issue-6903

Conversation

@jibin7jose

@jibin7jose jibin7jose commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implemented reboot persistence for the OpenShell gateway by adding a NemoClaw-managed systemd user service, environment handling, and related tests.

Related Issue

Fixes #6903

Changes

  • Added detection of existing OpenShell gateway service.
  • Created nemoclaw-openshell-gateway.service unit in user systemd config.
  • Implemented environment file creation for the gateway.
  • Updated install script to stage and enable the service.
  • Added uninstall logic to disable and remove the service and its env file.
  • Added unit tests for detection and uninstall behavior.
  • Updated documentation task tracking.

DCO

Signed-off-by: Jibin7Jose [email protected]

@copy-pr-bot

copy-pr-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds Linux systemd user-service staging for the NemoClaw-managed OpenShell gateway, selects and starts the available gateway service during onboarding, writes its environment file, and integrates service preservation or removal into uninstall behavior.

Changes

NemoClaw gateway service lifecycle

Layer / File(s) Summary
Stage NemoClaw gateway service
scripts/install-openshell.sh, scripts/nemoclaw-openshell-gateway.service
The installer stages a generated Linux systemd user unit for the installed gateway binary unless an upstream unit already exists.
Start and configure gateway
src/lib/onboard/docker-driver-gateway-service.ts, src/lib/onboard/docker-driver-gateway-env.ts, src/lib/onboard/docker-driver-gateway-service.test.ts
Onboarding detects the available service, writes the corresponding environment file, starts the selected unit, and validates NemoClaw detection and uninstall commands.
Uninstall gateway service
src/lib/domain/uninstall/plan.ts, src/lib/actions/uninstall/run-plan.ts
Uninstall planning and execution preserve or remove the NemoClaw service together with OpenShell binaries based on keepOpenShell.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • NVIDIA/NemoClaw#6905: Implements related NemoClaw-managed OpenShell gateway systemd lifecycle handling.

Suggested labels: bug-fix, area: install, area: onboarding

Suggested reviewers: ericksoa, cv

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: installing and managing the gateway service for reboot persistence.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@jibin7jose jibin7jose changed the title fix(gateway): install/manage OpenShell gateway service for reboot per… fix(gateway): install/manage OpenShell gateway service for reboot persistence Jul 15, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/lib/actions/uninstall/run-plan.ts (1)

943-955: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Keep mode still removes the gateway state dir
removePath(paths.gatewayLocalStateDir, runtime) deletes ~/.local/state/nemoclaw/openshell-docker-gateway/gateway.env even when keepOpenShell is set. Skip that cleanup in keep mode, or the retained service will fail on its next start.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/actions/uninstall/run-plan.ts` around lines 943 - 955, Update the
cleanup flow around removePath(paths.gatewayLocalStateDir, runtime) so
gatewayLocalStateDir is preserved when options.keepOpenShell is true. Continue
removing it in the non-keep path, while leaving the other state and
configuration cleanup behavior unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/nemoclaw-openshell-gateway.service`:
- Line 6: Update the service template’s EnvironmentFile to use a substitution
for the gateway environment path instead of hard-coding $HOME/.local/state, and
ensure staging replaces that placeholder with the same env_dir/gateway.env
location used when writing the gateway environment, including XDG_STATE_HOME
overrides.
- Around line 1-2: Add the project-required SPDX license header at the beginning
of the openshell gateway service unit, before the [Unit] section, while
preserving the existing Description and service configuration.
- Around line 11-12: Update the service installation/setup flow associated with
WantedBy=default.target to manage and validate user lingering, ensuring the user
manager starts after a headless reboot and the gateway remains available without
login. Use loginctl to verify the target user’s Linger state and enable
lingering when needed, or explicitly narrow the documented lifecycle if
lingering is not supported.

In `@src/lib/onboard/docker-driver-gateway-service.ts`:
- Around line 122-129: Update the cleanup sequence around runSystemctlUser and
the fs.rmSync calls: disable and stop the service first, remove the unit and
environment files via getNemoclawGatewayUserServicePath and
getNemoclawGatewayEnvFilePath, then invoke runSystemctlUser(["daemon-reload"], {
env, spawnSyncImpl }) after both deletions.
- Around line 125-130: Update the test setup around the cleanup calls in the
relevant onboarding test to inject an rmSync mock alongside spawnSyncImpl, and
replace direct fs.rmSync usage with that injected dependency. Assert that rmSync
receives the gateway service and environment-file paths with force enabled,
ensuring no real user-service files are deleted.

---

Outside diff comments:
In `@src/lib/actions/uninstall/run-plan.ts`:
- Around line 943-955: Update the cleanup flow around
removePath(paths.gatewayLocalStateDir, runtime) so gatewayLocalStateDir is
preserved when options.keepOpenShell is true. Continue removing it in the
non-keep path, while leaving the other state and configuration cleanup behavior
unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: f990c4d2-7aa2-48ee-8deb-0dbfccc4a1ee

📥 Commits

Reviewing files that changed from the base of the PR and between 5b67372 and a9d7131.

📒 Files selected for processing (7)
  • scripts/install-openshell.sh
  • scripts/nemoclaw-openshell-gateway.service
  • src/lib/actions/uninstall/run-plan.ts
  • src/lib/domain/uninstall/plan.ts
  • src/lib/onboard/docker-driver-gateway-env.ts
  • src/lib/onboard/docker-driver-gateway-service.test.ts
  • src/lib/onboard/docker-driver-gateway-service.ts

Comment on lines +1 to +2
[Unit]
Description=OpenShell Docker-driver gateway (NemoClaw-managed)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add the required SPDX header.

Proposed fix
+# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0
+
 [Unit]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[Unit]
Description=OpenShell Docker-driver gateway (NemoClaw-managed)
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
[Unit]
Description=OpenShell Docker-driver gateway (NemoClaw-managed)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/nemoclaw-openshell-gateway.service` around lines 1 - 2, Add the
project-required SPDX license header at the beginning of the openshell gateway
service unit, before the [Unit] section, while preserving the existing
Description and service configuration.

Source: Coding guidelines

After=network.target

[Service]
EnvironmentFile=%h/.local/state/nemoclaw/openshell-docker-gateway/gateway.env

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Keep the unit’s environment-file path aligned with XDG state.

This hard-codes $HOME/.local/state, but staging and onboarding write under $XDG_STATE_HOME when set. In that configuration, systemd reads a missing or stale file instead of the newly written gateway environment. Parameterize EnvironmentFile in the template and substitute the same env_dir/gateway.env path during staging.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/nemoclaw-openshell-gateway.service` at line 6, Update the service
template’s EnvironmentFile to use a substitution for the gateway environment
path instead of hard-coding $HOME/.local/state, and ensure staging replaces that
placeholder with the same env_dir/gateway.env location used when writing the
gateway environment, including XDG_STATE_HOME overrides.

Comment on lines +11 to +12
[Install]
WantedBy=default.target

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Enable lingering or this does not provide reboot persistence.

systemctl --user enable only starts this unit when the user manager runs; after reboot, that normally requires login unless lingering is enabled. A headless reboot therefore leaves the gateway down, contrary to the stated objective. Manage and validate user lingering, or explicitly narrow the supported lifecycle.

#!/bin/sh
loginctl show-user "$USER" -p Linger
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/nemoclaw-openshell-gateway.service` around lines 11 - 12, Update the
service installation/setup flow associated with WantedBy=default.target to
manage and validate user lingering, ensuring the user manager starts after a
headless reboot and the gateway remains available without login. Use loginctl to
verify the target user’s Linger state and enable lingering when needed, or
explicitly narrow the documented lifecycle if lingering is not supported.

Comment on lines +122 to +129
runSystemctlUser(["disable", "--now", NEMOCLAW_GATEWAY_USER_SERVICE], { env, spawnSyncImpl });
runSystemctlUser(["daemon-reload"], { env, spawnSyncImpl });

try {
fs.rmSync(getNemoclawGatewayUserServicePath(opts), { force: true });
} catch {}
try {
fs.rmSync(getNemoclawGatewayEnvFilePath(opts), { force: true });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reload systemd after deleting the unit.

daemon-reload runs before the unit file is removed, leaving the current user manager with the deleted definition loaded. Disable/stop, remove the unit and env file, then reload.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/onboard/docker-driver-gateway-service.ts` around lines 122 - 129,
Update the cleanup sequence around runSystemctlUser and the fs.rmSync calls:
disable and stop the service first, remove the unit and environment files via
getNemoclawGatewayUserServicePath and getNemoclawGatewayEnvFilePath, then invoke
runSystemctlUser(["daemon-reload"], { env, spawnSyncImpl }) after both
deletions.

Comment on lines +125 to +130
try {
fs.rmSync(getNemoclawGatewayUserServicePath(opts), { force: true });
} catch {}
try {
fs.rmSync(getNemoclawGatewayEnvFilePath(opts), { force: true });
} catch {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Do not let the unit test delete real user-service files.

The new test injects existsSync: () => true, so these direct fs.rmSync calls remove files beneath the developer’s actual home directory. Inject rmSync alongside spawnSyncImpl and assert the requested paths instead.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/onboard/docker-driver-gateway-service.ts` around lines 125 - 130,
Update the test setup around the cleanup calls in the relevant onboarding test
to inject an rmSync mock alongside spawnSyncImpl, and replace direct fs.rmSync
usage with that injected dependency. Assert that rmSync receives the gateway
service and environment-file paths with force enabled, ensuring no real
user-service files are deleted.

@github-actions

github-actions Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

PR Review Advisor — Blocking findings reported

Advisor assessment: Blockers require maintainer review
Next action: Review the blockers below.
Findings: 3 blockers · 0 warnings · 0 suggestions

Model lanes

  • GPT-5.6 Terra (primary): Failed after a partial review · low confidence · 3 blockers · 0 warnings · 0 suggestions
  • Nemotron 3 Ultra (second opinion): Failed after a partial review · low confidence · 0 blockers · 1 warning · 0 suggestions

Nemotron output stays in workflow artifacts and does not change the assessment above.

E2E guidance

Advisory only. E2E / PR Gate selects and runs jobs independently.

Recommended E2E: cloud-onboard, onboard-repair, onboard-resume

Blockers

PRA-1 Blocker — Use the configured XDG state directory in the staged service

  • Location: scripts/nemoclaw-openshell-gateway.service:6
  • Category: scope
  • Problem: The installer derives the gateway environment directory from XDG_STATE_HOME, and onboarding writes the environment file through the same configurable location, but the staged systemd unit always reads %h/.local/state/nemoclaw/openshell-docker-gateway/gateway.env. On hosts with XDG_STATE_HOME set, the service starts without the generated gateway configuration.
  • Impact: The persisted gateway can fail to start correctly after reboot or run with missing required Docker-driver, TLS, bind-address, and authentication configuration, defeating the reboot-persistence behavior this patch adds.
  • Fix: Make the systemd unit and the installer/onboarding environment-file writer use one consistent supported path; either constrain this service to the default state location or generate the unit's EnvironmentFile path from the selected XDG state directory with systemd-safe escaping.
  • Verification: Read the unit EnvironmentFile value alongside stage_nemoclaw_gateway_service and getNemoclawGatewayEnvFilePath, then trace a run with XDG_STATE_HOME=/tmp/nemoclaw-state to confirm the written and consumed paths match.
  • Test coverage: Add a checked-in installer or integration-level regression that sets XDG_STATE_HOME and asserts the staged unit EnvironmentFile path equals the path used to write gateway.env.
  • Evidence: scripts/install-openshell.sh stage_nemoclaw_gateway_service defines env_dir as ${XDG_STATE_HOME:-$HOME/.local/state}/nemoclaw/openshell-docker-gateway. src/lib/onboard/docker-driver-gateway-service.ts getNemoclawGatewayEnvFilePath honors XDG_STATE_HOME. scripts/nemoclaw-openshell-gateway.service:6 hard-codes %h/.local/state/nemoclaw/openshell-docker-gateway/gateway.env.

PRA-2 Blocker — Document or remediate the user-service boot boundary

  • Location: scripts/nemoclaw-openshell-gateway.service:12
  • Category: acceptance
  • Problem: The new unit is a systemd user service enabled under default.target, but the patch neither enables lingering nor tells users that it will start only once the user manager exists. Thus a reboot before user login does not meet the stated durable post-reboot startup behavior on systems without user lingering.
  • Impact: A fresh supported Linux installation can still have no reachable gateway after reboot until the user logs in or manually configures lingering, so status and sandbox recovery remain unavailable during the stated reboot scenario.
  • Fix: Choose and document the supported boot model: request explicit approval to enable lingering, emit clear remediation for configuring it, or explicitly document first-login startup and provide the supported non-systemd/WSL/container fallback.
  • Verification: Inspect the staged [Install] user unit and installer/onboarding paths for loginctl handling, user-visible remediation, or lifecycle documentation; then verify the documented behavior against a reboot before any user session.
  • Test coverage: Add checked-in coverage asserting the selected user-service boot policy is surfaced (for example, the required lingering remediation when no persistent user manager is configured) and document the resulting reboot behavior.
  • Evidence: Issue Install and uninstall a managed OpenShell gateway service for reboot persistence #6903 Constraints and Non-goals require explicit approval, clear remediation, or documentation if boot autostart requires loginctl enable-linger. Issue Install and uninstall a managed OpenShell gateway service for reboot persistence #6903 Acceptance Criteria require reboot validation without manual recovery and docs for the lifecycle model. scripts/nemoclaw-openshell-gateway.service:12 uses WantedBy=default.target for a user unit. The changed installer and onboarding code contain no loginctl invocation, remediation output, or documentation update.

PRA-3 Blocker — Use one ownership detector for staging and onboarding

  • Location: scripts/install-openshell.sh:753
  • Category: correctness
  • Problem: Installer staging treats any `systemctl --user list-unit-files openshell-gateway.service` result as an upstream service and skips the NemoClaw unit. Onboarding only recognizes upstream services at three system installation paths, and otherwise only recognizes the NemoClaw unit. A user-local or externally supervised openshell-gateway.service therefore causes installer staging to be skipped while onboarding starts neither persistent service.
  • Impact: The affected install has no durable managed gateway path and falls back to a transient standalone process, reintroducing the post-reboot outage this change is intended to fix; it also leaves external-supervisor ownership undefined.
  • Fix: Define one shared, trust-aware ownership contract for upstream, NemoClaw-owned, and external user services, and make installer staging and onboarding selection follow it. Preserve the no-competing-authority rule while giving unsupported/external service cases explicit remediation.
  • Verification: Compare `systemctl --user list-unit-files openshell-gateway.service` in stage_nemoclaw_gateway_service with hasOpenShellGatewayUserService's three filesystem paths, then trace a host with only ~/.config/systemd/user/openshell-gateway.service.
  • Test coverage: Add a regression covering a user-local/external openshell-gateway.service and assert either a supported persistent authority is selected or onboarding emits the documented remediation rather than silently using standalone fallback.
  • Evidence: scripts/install-openshell.sh stage_nemoclaw_gateway_service skips staging whenever `systemctl --user list-unit-files openshell-gateway.service` returns a line. src/lib/onboard/docker-driver-gateway-service.ts hasOpenShellGatewayUserService checks only /usr/local/lib/systemd/user, /usr/lib/systemd/user, and /lib/systemd/user. Issue Install and uninstall a managed OpenShell gateway service for reboot persistence #6903 requires avoiding a competing owner when an upstream service or explicit external supervisor is present and requires a durable startup path.

Workflow run details

This automated review informs maintainers. Warnings and suggestions do not require a response. A maintainer decides whether to merge.

@jibin7jose jibin7jose closed this Jul 15, 2026
@jibin7jose
jibin7jose deleted the fix-issue-6903 branch July 15, 2026 06:54
@wscurran wscurran added area: install Install, setup, prerequisites, or uninstall flow area: sandbox OpenShell sandbox lifecycle, runtime, config, or recovery area: security Security controls, permissions, secrets, or hardening bug-fix PR fixes a bug or regression platform: linux Affects non-Ubuntu Linux environments labels Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: install Install, setup, prerequisites, or uninstall flow area: sandbox OpenShell sandbox lifecycle, runtime, config, or recovery area: security Security controls, permissions, secrets, or hardening bug-fix PR fixes a bug or regression platform: linux Affects non-Ubuntu Linux environments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Install and uninstall a managed OpenShell gateway service for reboot persistence

2 participants