Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
aa865b5
fix(state): observe stale onboarding locks
jyaunches Sep 9, 2026
7f1d936
fix(state): unify onboarding lock recovery
jyaunches Sep 9, 2026
9a1bc85
merge(main): refresh onboarding lock recovery
jyaunches Sep 9, 2026
f518a36
fix(state): require complete onboarding lock identity
jyaunches Sep 9, 2026
424bdf0
merge(main): refresh lock identity validation
jyaunches Sep 9, 2026
3e6de7d
fix(state): bound onboarding lock inspection
jyaunches Sep 9, 2026
27f336b
merge(main): refresh onboarding lock inspection
jyaunches Sep 9, 2026
0fe5904
Merge remote-tracking branch 'origin/main' into codex/pr-10899-squashed
jyaunches Sep 9, 2026
1139fab
refactor(state): route migration through lock inspection
jyaunches Sep 9, 2026
8d3ab79
fix(state): harden onboarding lock ownership
jyaunches Sep 9, 2026
27a5077
test(state): provide stable macOS lock identity
jyaunches Sep 9, 2026
a561045
merge(main): refresh onboarding lock observation
jyaunches Sep 9, 2026
045b3e1
fix(onboard): release lock on handled signals
jyaunches Sep 9, 2026
34c55da
Merge remote-tracking branch 'refs/remotes/origin/main' into codex/pr…
jyaunches Sep 9, 2026
4b4688c
Merge remote-tracking branch 'refs/remotes/origin/main' into codex/pr…
jyaunches Sep 9, 2026
9928cf2
merge(main): consume gateway teardown test fix
jyaunches Sep 9, 2026
e732ec7
Merge remote-tracking branch 'origin/main' into codex/pr-10899-squashed
jyaunches Sep 9, 2026
0e44d06
Merge remote-tracking branch 'origin/main' into codex/pr-10899-squashed
jyaunches Sep 9, 2026
1ef1148
fix(onboard): cover lock cleanup during entry setup
jyaunches Sep 9, 2026
4e023b0
merge: refresh PR 11296 from main
jyaunches Sep 9, 2026
8ca55be
docs: document retained onboarding lock recovery
jyaunches Sep 9, 2026
d526fc6
merge: refresh PR 11296 from main
jyaunches Sep 9, 2026
6987d07
merge: refresh PR 11296 from main
jyaunches Sep 10, 2026
85794a4
test(onboard): budget subprocess exit coverage
jyaunches Sep 10, 2026
7963815
fix(onboard): preserve outer lifecycle lock
jyaunches Sep 10, 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
4 changes: 3 additions & 1 deletion docs/manage-sandboxes/uninstall-nemoclaw.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ Use the dedicated gateway state directory created for that port, not a shared or
Onboarding rejects relative overrides, the shared NemoClaw state root or its parents, and existing nonempty directories without valid NemoClaw-managed gateway configuration.
Let onboarding create the directory when possible. Every existing ancestor, from its containing directory to the filesystem root, must be a real directory owned by the current user or root and must not be group- or world-writable. If the state directory already exists, it must be an owner-controlled, non-symbolic-link directory with mode `0700`.
If onboarding stops immediately after reserving that directory, uninstall removes the marker-only reservation only while the selected gateway port is free. Gateway configuration, a runtime marker, or a PID file moves cleanup to the managed-gateway checks instead. A port-bound marked gateway with valid generated configuration can be retired after the port is free and a complete process scan proves that no live process claims its state; a listener or unproven process preserves the directory. Inspect and stop the listener or matching gateway process, then rerun uninstall after the port is free.
Onboarding holds an exclusive lifecycle lock from reservation through gateway initialization. If uninstall reports that onboarding owns the state directory, wait for onboarding to finish and rerun uninstall; the reservation is preserved.
Onboarding holds an exclusive lifecycle lock from reservation through gateway initialization.
If uninstall reports that onboarding owns the state directory while onboarding is active, wait for onboarding to finish and rerun uninstall; the reservation is preserved.
If the reported `onboard.lock` remains after onboarding ended abruptly, confirm that no NemoClaw onboarding process is active in any environment that shares the state root, remove only the reported lock, and rerun uninstall.
After successful managed cleanup, uninstall recursively removes that directory and all contents.
Portable cleanup and `--keep-openshell` preserve it.
</Warning>
Expand Down
4 changes: 3 additions & 1 deletion docs/reference/commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3535,7 +3535,9 @@ Use the dedicated gateway state directory created for that port, not a shared or
Onboarding rejects relative overrides, the shared NemoClaw state root or its parents, and existing nonempty directories without valid NemoClaw-managed gateway configuration.
Let onboarding create the directory when possible. Every existing ancestor, from its containing directory to the filesystem root, must be a real directory owned by the current user or root and must not be group- or world-writable. If the state directory already exists, it must be an owner-controlled, non-symbolic-link directory with mode `0700`.
If onboarding stops immediately after reserving that directory, uninstall removes the marker-only reservation only while the selected gateway port is free. Gateway configuration, a runtime marker, or a PID file moves cleanup to the managed-gateway checks instead. A port-bound marked gateway with valid generated configuration can be retired after the port is free and a complete process scan proves that no live process claims its state; a listener or unproven process preserves the directory. Inspect and stop the listener or matching gateway process, then rerun uninstall after the port is free.
Onboarding holds an exclusive lifecycle lock from reservation through gateway initialization. If uninstall reports that onboarding owns the state directory, wait for onboarding to finish and rerun uninstall; the reservation is preserved.
Onboarding holds an exclusive lifecycle lock from reservation through gateway initialization.
If uninstall reports that onboarding owns the state directory while onboarding is active, wait for onboarding to finish and rerun uninstall; the reservation is preserved.
If the reported `onboard.lock` remains after onboarding ended abruptly, confirm that no NemoClaw onboarding process is active in any environment that shares the state root, remove only the reported lock, and rerun uninstall.
Successful managed cleanup recursively removes that directory and all contents; portable cleanup and `--keep-openshell` preserve it.
Before cleanup, uninstall validates port-bound state-root ownership and exact live process identity. A marked, stopped gateway can instead use a free port plus a complete process-absence scan; pre-marker gateways can use their owner-private generated configuration as the legacy ownership proof only with live process identity.

Expand Down
14 changes: 7 additions & 7 deletions src/lib/onboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2674,9 +2674,13 @@ async function runOnboard(opts: OnboardOptions = {}): Promise<void> {
collector: null,
span: null,
};
let completed = false,
preserveDeferredExitSession = false,
preserveIncompleteSession = false;
let completed = false;
let preserveIncompleteSession = false;
registerIncompleteOnboardExitHandlerForSession(
{ ...onboardSession, releaseOnboardLock: portableRetirementEntry.release },
() => completed || preserveIncompleteSession,
);
let preserveDeferredExitSession = false;
try {
await portableRetirementEntry.run(async () => {
const entryOptions = resolveEntryOptions();
Expand Down Expand Up @@ -2798,10 +2802,6 @@ async function runOnboard(opts: OnboardOptions = {}): Promise<void> {
);
process.exit(1);
}
registerIncompleteOnboardExitHandlerForSession(
onboardSession,
() => completed || preserveIncompleteSession,
);
const agent = await selectOnboardAgent({
agentFlag: opts.agent,
session,
Expand Down
14 changes: 11 additions & 3 deletions src/lib/onboard/exit-step-failure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,31 +348,37 @@ describe("incomplete-onboard --resume backstop (#6003)", () => {
});

it.skipIf(process.platform === "win32")(
"prints the resume hint before re-raising SIGINT in a real subprocess",
"releases the owned lock before re-raising SIGINT in a real subprocess",
async () => {
const childDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-resume-signal-"));
const childScript = path.join(childDir, "signal-resume-hint.cjs");
const helperPath = path.resolve("src/lib/onboard/exit-step-failure.ts");
const onboardSessionPath = path.resolve("src/lib/state/onboard-session.ts");
fs.writeFileSync(
childScript,
`
const { registerIncompleteOnboardExitFailureHandler } = require(${JSON.stringify(helperPath)});
const onboardSession = require(${JSON.stringify(onboardSessionPath)});

if (!onboardSession.acquireOnboardLock("signal cleanup test").acquired) process.exit(2);

const resumableSession = { lastStepStarted: "inference" };
registerIncompleteOnboardExitFailureHandler(
{
loadSession: () => resumableSession,
finalizeIncompleteOnboardStep: () => resumableSession,
releaseOnboardLock: onboardSession.releaseOnboardLock,
},
() => false,
"Onboarding exited before the step completed.",
);
process.stdout.write("ready\\n");
process.stdout.write(JSON.stringify({ lockFile: onboardSession.LOCK_FILE }) + "\\n");
setInterval(() => {}, 1_000);
`,
);

const child = spawn(process.execPath, ["--require", "tsx/cjs", childScript], {
env: { ...process.env, HOME: childDir },
stdio: ["ignore", "pipe", "pipe"],
});
let stderr = "";
Expand All @@ -383,13 +389,15 @@ setInterval(() => {}, 1_000);

try {
const [ready] = await once(child.stdout, "data");
expect(String(ready)).toContain("ready");
const { lockFile } = JSON.parse(String(ready)) as { lockFile: string };
expect(fs.existsSync(lockFile)).toBe(true);
const exited = once(child, "exit");
child.kill("SIGINT");
const [code, signal] = await exited;
expect(code).toBeNull();
expect(signal).toBe("SIGINT");
expect(stderr).toContain("onboard --resume");
expect(fs.existsSync(lockFile)).toBe(false);
} finally {
child.kill("SIGKILL");
fs.rmSync(childDir, { recursive: true, force: true });
Expand Down
12 changes: 10 additions & 2 deletions src/lib/onboard/exit-step-failure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { printOnboardResumeHint } from "./resume-hint";

export interface ExitStepFailureSessionDeps {
loadSession(): Pick<Session, "lastStepStarted"> | null;
releaseOnboardLock?(): void;
finalizeIncompleteOnboardStep(
stepName: string,
message?: string | null,
Expand Down Expand Up @@ -81,8 +82,15 @@ export function registerIncompleteOnboardExitFailureHandler(
setImmediate(() => {
removeListener("SIGINT", onSigint);
removeListener("SIGTERM", onSigterm);
failIncompleteStep(true);
kill(pid, signal);
try {
failIncompleteStep(true);
} finally {
try {
deps.releaseOnboardLock?.();
} finally {
kill(pid, signal);
}
}
});
};
const onSigint = (): void => handleSignal("SIGINT");
Expand Down
6 changes: 4 additions & 2 deletions src/lib/state/legacy-port-migration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,14 +447,16 @@ describe("legacy non-default gateway state migration", () => {
const shared = path.join(home, ".nemoclaw");
const selected = path.join(shared, "gateways", "9123");
const recoveryFile = path.join(shared, "retained-sandbox-recovery.json");
const lockFile = path.join(root(shared, selected), "onboard.lock");
recordRecovery(recoveryFile, "port-box", 9123, "d");
const before = fs.readFileSync(recoveryFile, "utf8");
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
fs.mkdirSync(root(shared, selected), { recursive: true });
fs.writeFileSync(path.join(root(shared, selected), "onboard.lock"), "active writer");
fs.writeFileSync(lockFile, "active writer");

expect(() => migrateLegacyPortState({ home, gatewayPort: 9123 })).toThrow(
/onboarding lock .* is present/u,
`onboarding lock ${lockFile} is present; confirm that no NemoClaw onboarding process in any environment sharing this state root is active, then remove only ${lockFile} and retry; migration will not remove it automatically`,
);
expect(fs.readFileSync(lockFile, "utf8")).toBe("active writer");
expect(fs.readFileSync(recoveryFile, "utf8")).toBe(before);
expect(fs.existsSync(path.join(selected, "retained-sandbox-recovery.json"))).toBe(false);
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/state/legacy-port-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ function assertOnboardStateUnlocked(home: string, stateRoots: readonly string[])
const activeLock = path.join(stateRoot, "onboard.lock");
if (lstatNoFollow(home, activeLock)) {
throw migrationError(
`onboarding lock ${activeLock} is present; finish or stop that run before migrating state`,
`onboarding lock ${activeLock} is present; confirm that no NemoClaw onboarding process in any environment sharing this state root is active, then remove only ${activeLock} and retry; migration will not remove it automatically`,
);
}
}
Expand Down
14 changes: 11 additions & 3 deletions src/lib/state/onboard-session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1297,12 +1297,20 @@ describe("onboard session", () => {
}
});

it("ignores malformed lock files when releasing the onboard lock", () => {
it("preserves a foreign lock that uses the local PID when no descriptor is held", () => {
fs.mkdirSync(path.dirname(session.LOCK_FILE), { recursive: true });
fs.writeFileSync(session.LOCK_FILE, "{not-json", { mode: 0o600 });
const contents = JSON.stringify({
pid: process.pid,
startedAt: new Date().toISOString(),
command: "foreign owner",
processGeneration: "foreign-generation",
hostIdentity: "foreign-host",
pidNamespaceIdentity: "foreign-namespace",
});
fs.writeFileSync(session.LOCK_FILE, contents, { mode: 0o600 });

session.releaseOnboardLock();
expect(fs.existsSync(session.LOCK_FILE)).toBe(true);
expect(fs.readFileSync(session.LOCK_FILE, "utf8")).toBe(contents);
});

it("redacts sensitive values from persisted failure messages", () => {
Expand Down
20 changes: 2 additions & 18 deletions src/lib/state/onboard-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1696,24 +1696,8 @@ export function releaseOnboardLock(): void {
return;
}

// Fallback (no fd held — e.g., a test wrote the lock file directly,
// or a previous release already ran): preserve the legacy pid-based
// behavior so we never unlink a malformed lock and never unlink a
// lock owned by another pid.
try {
let snapshot: LockFileSnapshot;
try {
snapshot = readLockFileSnapshot();
} catch (error) {
if (isErrnoException(error) && error.code === "ENOENT") return;
throw error;
}
if (!snapshot.info) return;
if (snapshot.info.pid !== process.pid) return;
unlinkIfInodeMatches(LOCK_FILE, snapshot.inode);
} catch {
return;
}
// A PID match does not prove ownership across hosts or PID namespaces.
// Without the retained descriptor, this process has no cleanup authority.
}

// ── Step management ──────────────────────────────────────────────
Expand Down
Loading
Loading