Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
6283fd9
fix(installer): qualify existing OpenShell services
apurvvkumaria Aug 20, 2026
9a53a08
fix(installer): harden OpenShell coexistence checks
apurvvkumaria Aug 20, 2026
1d6bbb3
fix(installer): preserve gateway lifecycle boundaries
apurvvkumaria Aug 20, 2026
9729c70
Merge remote-tracking branch 'origin/main' into HEAD
apurvvkumaria Aug 20, 2026
98f7309
Merge remote-tracking branch 'origin/codex/issue-9705-openshell-coexi…
apurvvkumaria Aug 20, 2026
834a9e1
test(installer): verify preflight leaves home unchanged
apurvvkumaria Aug 20, 2026
3b37eca
fix(installer): stop unsafe gateway lifecycle changes
apurvvkumaria Aug 20, 2026
2ffdca2
test(installer): isolate user service fixtures
apurvvkumaria Aug 20, 2026
2f634fb
fix(installer): validate supervision before host changes
apurvvkumaria Aug 20, 2026
2bf4b30
fix(installer): preserve unavailable manager fallback
apurvvkumaria Aug 20, 2026
1088c78
Merge branch 'main' into codex/issue-9705-openshell-coexistence
cv Aug 20, 2026
d8ca52f
fix(onboard): validate gateway bind before discovery
cv Aug 20, 2026
862ccd2
test(e2e): expect gateway service discovery
cv Aug 20, 2026
99cdeb5
fix(installer): preserve gateway service qualification
apurvvkumaria Aug 20, 2026
5facf0f
Merge remote-tracking branch 'origin/main' into codex/issue-9705-open…
apurvvkumaria Aug 20, 2026
7d0ee33
fix(installer): qualify canonical custom-port services
apurvvkumaria Aug 20, 2026
c7a4abe
fix(installer): sanitize activation path diagnostics
apurvvkumaria Aug 20, 2026
529535a
test(installer): allow service parser in fixtures
apurvvkumaria Aug 20, 2026
2ea8bd0
fix(installer): harden gateway service identity
apurvvkumaria Aug 21, 2026
75c0cd4
merge: update gateway service identity branch
apurvvkumaria Aug 21, 2026
c30ba44
fix(onboard): bind gateway lifecycle identity
apurvvkumaria Aug 21, 2026
16a2011
Merge remote-tracking branch 'origin/main' into codex/issue-9705-open…
apurvvkumaria Aug 21, 2026
bec87d8
fix(onboard): harden Homebrew lifecycle boundary
apurvvkumaria Aug 21, 2026
900cdd2
test(onboard): wait for legacy gateway readiness
apurvvkumaria Aug 21, 2026
de9f6bd
fix(onboard): exclude gateway test fixture from build
apurvvkumaria Aug 21, 2026
f9cc065
test(onboard): bind gateway retirement fixtures
apurvvkumaria Aug 21, 2026
18ae901
ci(e2e): bind existing systemd user manager
apurvvkumaria Aug 21, 2026
4a8908f
merge(main): integrate current main
apurvvkumaria Aug 21, 2026
1f70f4c
Merge branch 'main' into codex/issue-9705-openshell-coexistence
cv Aug 21, 2026
53d8e5c
test(onboard): reuse gateway service fixtures
apurvvkumaria Aug 21, 2026
645e10c
Merge branch 'main' into codex/issue-9705-openshell-coexistence
cv Aug 21, 2026
6b19a0c
ci(e2e): preserve standalone GPU qualification
apurvvkumaria Aug 21, 2026
d9b4bb9
merge: resolve conflicts with main
github-actions[bot] Aug 21, 2026
14758ed
merge: integrate current main
apurvvkumaria Aug 21, 2026
a634456
merge(main): integrate rebuild config sealing
apurvvkumaria Aug 23, 2026
2e79ec1
test(installer): bound Station command fixtures
apurvvkumaria Aug 23, 2026
72e0726
test(uninstall): qualify packaged gateway fixture
apurvvkumaria Aug 23, 2026
fb2d1e4
fix(installer): qualify historical gateway upgrades
apurvvkumaria Aug 23, 2026
59127cd
test(e2e): expect staged service reload
apurvvkumaria Aug 23, 2026
cb65945
Merge remote-tracking branch 'origin/main' into codex/issue-9705-open…
apurvvkumaria Aug 23, 2026
ee4fa2c
fix(installer): qualify historical gateway upgrades
apurvvkumaria Aug 23, 2026
fbf5c45
fix(onboard): qualify user-owned system-local gateways
apurvvkumaria Aug 23, 2026
760c3a2
fix(onboard): classify systemd trust failures
apurvvkumaria Aug 23, 2026
35c0d17
fix(onboard): retain empty systemd metadata
apurvvkumaria Aug 23, 2026
8f776c9
test(uninstall): accept complete systemd metadata
apurvvkumaria Aug 23, 2026
a31a4dc
fix(onboard): handle systemd lifecycle races
apurvvkumaria Aug 23, 2026
6c43f85
test(e2e): align upgrade credential boundary
apurvvkumaria Aug 23, 2026
35a1365
Merge branch 'main' into codex/issue-9705-openshell-coexistence
cv Aug 23, 2026
9d4ebff
Merge branch 'main' into codex/issue-9705-openshell-coexistence
apurvvkumaria Aug 24, 2026
9171449
refactor(onboard): unify gateway identity sources
apurvvkumaria Aug 24, 2026
9e8548e
merge: integrate main into issue-9705 branch
apurvvkumaria Aug 24, 2026
b4b46ba
fix(onboard): support compiled unit identity
apurvvkumaria Aug 24, 2026
e19b1d2
merge: integrate main into issue-9705 branch
apurvvkumaria Aug 24, 2026
47cb886
merge: integrate current main
apurvvkumaria Aug 24, 2026
86722c0
Merge branch 'main' into codex/issue-9705-openshell-coexistence
cv Aug 24, 2026
fe61baf
Merge branch 'main' into codex/issue-9705-openshell-coexistence
cv Aug 24, 2026
0170db5
Merge branch 'main' into codex/issue-9705-openshell-coexistence
cv Aug 24, 2026
7b9758f
Merge branch 'main' into codex/issue-9705-openshell-coexistence
cv Aug 24, 2026
37d64a3
Merge branch 'main' into codex/issue-9705-openshell-coexistence
cv Aug 24, 2026
4111965
merge: integrate current main into issue 9705
apurvvkumaria Aug 25, 2026
c9b17eb
merge: integrate current main into issue 9705
apurvvkumaria Aug 25, 2026
600cd2e
test(install): align service identity fixtures
apurvvkumaria Aug 25, 2026
97045ea
merge: resolve conflicts with main
github-actions[bot] Aug 25, 2026
aef6eef
merge: resolve conflicts with main
github-actions[bot] Aug 26, 2026
0c5a661
merge: sync main into PR #9726
cv Aug 28, 2026
4471700
test: lower installer preflight budget
cv Aug 28, 2026
168b472
Merge branch 'main' into codex/issue-9705-openshell-coexistence
cv Aug 28, 2026
08e5851
ci: retrigger PR review advisor
cv Aug 28, 2026
bb4484c
merge: resolve conflicts with main
github-actions[bot] Aug 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/checks/vitest-project-overlap.mts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const INSTALLER_INTEGRATION_TESTS = new Set([
"test/install-clone-ref.test.ts",
"test/install-express-prompt.test.ts",
"test/install-express-wsl-ollama.test.ts",
"test/install-external-gateway-supervision.test.ts",
"test/install-forward-restore-diagnostics.test.ts",
"test/install-hermes-portable-active.test.ts",
"test/install-hermes-forward-restore.test.ts",
Expand Down
2 changes: 2 additions & 0 deletions scripts/install-openshell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ case "$ARCH" in
esac

info "Detected $OS_LABEL ($ARCH_LABEL)"
command -v strings >/dev/null 2>&1 \
|| fail "'strings' (from binutils) is required to install and verify OpenShell. Install it first (Debian/Ubuntu: sudo apt-get install -y binutils) and retry."

# Minimum version required for native messaging credential rewrite and
# round-trippable base policies: WebSocket text frames, provider-shaped
Expand Down
315 changes: 306 additions & 9 deletions scripts/install.sh

Large diffs are not rendered by default.

28 changes: 26 additions & 2 deletions src/lib/onboard/docker-driver-gateway-env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,32 @@ describe("buildDockerDriverGatewayEnv", () => {
});
});


describe("writeDockerGatewayDebEnvOverride", () => {
it("checks competing services before custom-port managed-service fallback (#9705)", () => {
const conflict = new Error("competing OpenShell gateway service");
const assertNoCompetingService = vi.fn(() => {
throw conflict;
});
const hasService = vi.fn();

expect(() =>
startPackageManagedDockerDriverGatewayWithEnvOverride({
assertNoCompetingOpenShellGatewayUserService: assertNoCompetingService,
clearDockerDriverGatewayRuntimeFiles: vi.fn(),
exitOnFailure: false,
gatewayEnv: { OPENSHELL_SERVER_PORT: "9090" },
gatewayName: "nemoclaw",
hasOpenShellGatewayUserService: hasService,
registerDockerDriverGatewayEndpoint: vi.fn(),
runCaptureOpenshell: vi.fn(),
skipSandboxBridgeReachability: false,
verifySandboxBridgeGatewayReachableOrExit: vi.fn(),
}),
).toThrow(conflict);

expect(assertNoCompetingService).toHaveBeenCalledWith(9090);
expect(hasService).not.toHaveBeenCalled();
});

it("rejects an env file swapped to a symlink after opening without writing its target", () => {
const tempHome = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-gateway-env-"));
Expand Down Expand Up @@ -244,7 +268,6 @@ describe("writeDockerGatewayDebEnvOverride", () => {
}
});


it("uses the provided HOME as the config root fallback when XDG_CONFIG_HOME is unset", () => {
const tempHome = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-gateway-env-home-"));
const envFile = path.join(tempHome, ".config", "openshell", "gateway.env");
Expand Down Expand Up @@ -289,6 +312,7 @@ describe("writeDockerGatewayDebEnvOverride", () => {
try {
await expect(
startPackageManagedDockerDriverGatewayWithEnvOverride({
assertNoCompetingOpenShellGatewayUserService: vi.fn(),
clearDockerDriverGatewayRuntimeFiles: vi.fn(),
env: homeEnv(tempHome),
exitOnFailure: false,
Expand Down
20 changes: 17 additions & 3 deletions src/lib/onboard/docker-driver-gateway-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from "./docker-driver-gateway-config";
import { buildDockerDriverGatewayLocalTlsEnv } from "./docker-driver-gateway-local-tls";
import {
assertNoCompetingOpenShellGatewayUserService,
getOpenShellGatewayManagedServiceLogCommand,
getOpenShellUserConfigHome,
hasOpenShellGatewayUserService,
Expand Down Expand Up @@ -82,6 +83,7 @@ export type PackageManagedDockerDriverGatewayWithEnvOverrideOptions = Omit<
PackageManagedDockerDriverGatewayOptions,
"prepareOpenShellGatewayUserServiceEnv"
> & {
assertNoCompetingOpenShellGatewayUserService?: (gatewayPort: number) => void;
env?: NodeJS.ProcessEnv;
gatewayEnv: Record<string, string>;
home?: string;
Expand Down Expand Up @@ -400,12 +402,24 @@ export function writeDockerGatewayDebEnvOverrideOrThrow(
export function startPackageManagedDockerDriverGatewayWithEnvOverride(
optionsWithEnv: PackageManagedDockerDriverGatewayWithEnvOverrideOptions,
): Promise<boolean> {
const { env: _env, gatewayEnv, home, ...options } = optionsWithEnv;
const {
assertNoCompetingOpenShellGatewayUserService: assertNoCompetingService,
env: _env,
gatewayEnv,
home,
...options
} = optionsWithEnv;
const env = optionsWithEnv.env ?? process.env;
const gatewayPort = Number(gatewayEnv.OPENSHELL_SERVER_PORT ?? GATEWAY_PORT);
if (gatewayPort !== DEFAULT_GATEWAY_PORT) return Promise.resolve(false);
assertDockerDriverGatewayAuthConfigSafe(gatewayEnv);
const effectiveHome = home ?? optionsWithEnv.env?.HOME ?? os.homedir();
if (gatewayPort === DEFAULT_GATEWAY_PORT) {
assertDockerDriverGatewayAuthConfigSafe(gatewayEnv);
}
(
assertNoCompetingService ??
((port) => assertNoCompetingOpenShellGatewayUserService(port, { env, home: effectiveHome }))
)(gatewayPort);
if (gatewayPort !== DEFAULT_GATEWAY_PORT) return Promise.resolve(false);
return startPackageManagedDockerDriverGateway({
...options,
hasOpenShellGatewayUserService:
Expand Down
223 changes: 218 additions & 5 deletions src/lib/onboard/docker-driver-gateway-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import path from "node:path";

import { sleepSeconds, waitUntilAsync } from "../core/wait";
import { isGatewayHealthy } from "../state/gateway";
import {
classifyOpenShellGatewayServiceMetadata,
COMPETING_OPENSHELL_GATEWAY_SERVICE_PROPERTIES,
type OpenShellGatewayServiceMetadataVerdict,
} from "./gateway/openshell-service-coexistence";
import { envInt } from "./env";
import {
createGatewayHealthWaitOptions,
Expand Down Expand Up @@ -372,13 +377,15 @@ function runCommand(
command: string,
args: string[],
opts: Required<Pick<OpenShellGatewayUserServiceOptions, "env" | "spawnSyncImpl">>,
timeout?: number,
): CommandResult {
try {
return commandResult(
opts.spawnSyncImpl(command, args, {
encoding: "utf-8",
env: opts.env,
stdio: ["ignore", "pipe", "pipe"],
...(timeout === undefined ? {} : { timeout }),
} satisfies SpawnSyncOptions),
command,
);
Expand Down Expand Up @@ -430,13 +437,21 @@ function commandResult(result: SpawnSyncLikeResult, command = "command"): Comman
function runSystemctlUser(
args: string[],
opts: Required<Pick<OpenShellGatewayUserServiceOptions, "env" | "spawnSyncImpl">>,
timeout?: number,
) {
return runCommand("systemctl", ["--user", ...args], {
...opts,
env: { ...opts.env, LC_ALL: "C" },
});
return runCommand(
"systemctl",
["--user", ...args],
{
...opts,
env: { ...opts.env, LC_ALL: "C" },
},
timeout,
);
}

const SYSTEMCTL_USER_INSPECTION_TIMEOUT_MS = 10_000;

const OPENSHELL_HOMEBREW_FORMULA_ABSENT = 65;
const OPENSHELL_HOMEBREW_FORMULA_REPAIR = 66;
const OPENSHELL_HOMEBREW_TRUST_FAILED = 67;
Expand Down Expand Up @@ -727,7 +742,7 @@ function userManagerLooksUnavailable(reason: string): boolean {
}

function findSystemdUserServiceActivationPath(
service: OpenShellGatewayUserServiceTarget,
service: Pick<OpenShellGatewayUserServiceTarget, "manager">,
home: string,
env: NodeJS.ProcessEnv,
existsSync: (filePath: string) => boolean,
Expand Down Expand Up @@ -881,6 +896,202 @@ function extractSystemdExecStartPath(execStart: string): string | null {
return path.normalize(candidates[0]);
}

function isSafeSystemdServiceName(serviceName: string): boolean {
return /^(?:[A-Za-z0-9_]|\\x[0-9A-Fa-f]{2})(?:[A-Za-z0-9_.@:-]|\\x[0-9A-Fa-f]{2})*\.service$/.test(
serviceName,
);
}

function parseActiveSystemdServiceNames(output: string): string[] | null {
const names: string[] = [];
for (const rawLine of output.split(/\r?\n/)) {
const line = rawLine.trim();
if (!line) continue;
const columns = line.split(/\s+/);
if (
columns.length < 4 ||
!isSafeSystemdServiceName(columns[0]) ||
!["active", "activating", "reloading", "deactivating"].includes(columns[2])
) {
return null;
}
names.push(columns[0]);
}
return names;
}

function parseEnabledSystemdServiceNames(output: string): string[] | null {
const names: string[] = [];
for (const rawLine of output.split(/\r?\n/)) {
const line = rawLine.trim();
if (!line) continue;
const columns = line.split(/\s+/);
if (
columns.length < 2 ||
columns.length > 3 ||
!isSafeSystemdServiceName(columns[0]) ||
(columns[1] !== "enabled" && columns[1] !== "enabled-runtime")
) {
return null;
}
names.push(columns[0]);
}
return names;
}

function assertNoCanonicalGatewayActivationPath(
gatewayPort: number,
opts: OpenShellGatewayUserServiceOptions,
): void {
if (gatewayPort !== 8080) return;
const env = opts.env ?? process.env;
const home = effectiveHome(opts.home, opts.env);
const activationPath = findSystemdUserServiceActivationPath(
{ manager: "systemd" },
home,
env,
opts.existsSync ?? fs.existsSync,
opts.lstatSync ?? fs.lstatSync,
opts.readdirSync ?? fs.readdirSync,
);
if (!activationPath) return;
throw new OpenShellGatewayServiceTrustError(
`OpenShell gateway user service activation path ${activationPath} can later claim port ${String(gatewayPort)}.`,
);
}

function assertCompetingServiceVerdictAllowed(
serviceName: string,
gatewayPort: number,
verdict: OpenShellGatewayServiceMetadataVerdict,
): void {
if (verdict === "unrelated" || verdict === "different-port") return;
if (verdict === "block-invalid-selected-port") {
throw new OpenShellGatewayServiceTrustError("The selected OpenShell gateway port is invalid.");
}
if (verdict === "block-malformed-metadata") {
throw new OpenShellGatewayServiceTrustError(
`Could not inspect same-user service ${serviceName} because systemd returned malformed metadata.`,
);
}
if (verdict === "block-ambiguous-executable") {
throw new OpenShellGatewayServiceTrustError(
`OpenShell gateway user service ${serviceName} has ambiguous executable metadata.`,
);
}
if (verdict === "block-untrusted-executable") {
throw new OpenShellGatewayServiceTrustError(
`OpenShell gateway user service ${serviceName} uses an untrusted executable.`,
);
}
if (verdict === "block-ambiguous-port") {
throw new OpenShellGatewayServiceTrustError(
`OpenShell gateway user service ${serviceName} has ambiguous port configuration and could claim selected port ${String(gatewayPort)}.`,
);
}
throw new OpenShellGatewayServiceTrustError(
`OpenShell gateway user service ${serviceName} can claim selected port ${String(gatewayPort)}. Stop or disable that independently managed service before continuing.`,
);
}

/** Refuse a noncanonical same-user service that can claim the selected gateway port. */
export function assertNoCompetingOpenShellGatewayUserService(
gatewayPort: number,
opts: OpenShellGatewayUserServiceOptions = {},
): void {
if (!Number.isSafeInteger(gatewayPort) || gatewayPort < 1 || gatewayPort > 65_535) {
throw new OpenShellGatewayServiceTrustError("The selected OpenShell gateway port is invalid.");
}
if ((opts.platform ?? process.platform) !== "linux") return;
const env = opts.env ?? process.env;
const commandExists = opts.commandExists ?? ((command) => defaultCommandExists(command, env));
if (!commandExists("systemctl")) {
assertNoCanonicalGatewayActivationPath(gatewayPort, opts);
return;
}
const commandOptions = { env, spawnSyncImpl: opts.spawnSyncImpl ?? spawnSync };
const active = runSystemctlUser(
[
"list-units",
"--type=service",
"--state=active,activating,reloading,deactivating",
"--no-legend",
"--plain",
"--no-pager",
],
commandOptions,
SYSTEMCTL_USER_INSPECTION_TIMEOUT_MS,
);
if (!active.ok) {
if (userManagerLooksUnavailable(active.reason ?? "")) {
assertNoCanonicalGatewayActivationPath(gatewayPort, opts);
return;
}
throw new OpenShellGatewayServiceTrustError(
"Could not inspect same-user OpenShell gateway services during active enumeration.",
);
}
const enabled = runSystemctlUser(
[
"list-unit-files",
"--type=service",
"--state=enabled,enabled-runtime",
"--no-legend",
"--plain",
"--no-pager",
],
commandOptions,
SYSTEMCTL_USER_INSPECTION_TIMEOUT_MS,
);
if (!enabled.ok) {
throw new OpenShellGatewayServiceTrustError(
"Could not inspect same-user OpenShell gateway services during enabled enumeration.",
);
}
const activeNames = parseActiveSystemdServiceNames(active.stdout ?? "");
const enabledNames = parseEnabledSystemdServiceNames(enabled.stdout ?? "");
if (!activeNames || !enabledNames) {
throw new OpenShellGatewayServiceTrustError(
"Could not inspect same-user OpenShell gateway services because systemd returned malformed service enumeration metadata.",
);
}
const canonicalNames = new Set([
`${OPENSHELL_GATEWAY_USER_SERVICE}.service`,
`${NEMOCLAW_OPENSHELL_GATEWAY_USER_SERVICE}.service`,
]);
const serviceNames = [...new Set([...activeNames, ...enabledNames])].filter(
(serviceName) => !canonicalNames.has(serviceName),
);
for (const serviceName of serviceNames) {
const metadata = runSystemctlUser(
[
"show",
serviceName,
...COMPETING_OPENSHELL_GATEWAY_SERVICE_PROPERTIES.map(
(property) => `--property=${property}`,
),
],
commandOptions,
SYSTEMCTL_USER_INSPECTION_TIMEOUT_MS,
);
Comment thread
apurvvkumaria marked this conversation as resolved.
Resolved
if (!metadata.ok) {
throw new OpenShellGatewayServiceTrustError(
"Could not inspect same-user OpenShell gateway services during service metadata query.",
);
}
const home = effectiveHome(opts.home, opts.env);
assertCompetingServiceVerdictAllowed(
serviceName,
gatewayPort,
classifyOpenShellGatewayServiceMetadata({
gatewayPort,
metadata: metadata.stdout ?? "",
trustedExecutablePaths: getNemoclawOpenShellGatewayUserServiceBinaryPaths(home, env),
}),
);
}
}

function validateSystemdServiceIdentity(
service: OpenShellGatewayUserServiceTarget,
opts: Required<Pick<OpenShellGatewayUserServiceOptions, "env" | "spawnSyncImpl">>,
Expand All @@ -890,6 +1101,7 @@ function validateSystemdServiceIdentity(
const result = runSystemctlUser(
["show", service.serviceName, "--property=FragmentPath", "--property=ExecStart"],
opts,
SYSTEMCTL_USER_INSPECTION_TIMEOUT_MS,
);
if (!result.ok) return { diagnostic: result.diagnostic, ok: false, reason: result.reason };
const properties = parseSystemctlShow(result.stdout ?? "", ["FragmentPath", "ExecStart"]);
Expand Down Expand Up @@ -1018,6 +1230,7 @@ export function getTrustedActiveOpenShellGatewayUserServiceIdentity(
"--property=MainPID",
],
{ env, spawnSyncImpl },
SYSTEMCTL_USER_INSPECTION_TIMEOUT_MS,
);
if (!result.ok) return null;
const properties = parseSystemctlShow(result.stdout ?? "", [
Expand Down
Loading
Loading