-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(onboard): keep pending route reservation through not-ready recreate #6626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4e5c7b7
fix(onboard): keep pending route reservation through not-ready recreate
laitingsheng f8798f2
refactor(onboard): extract reservation recreate guard for net-neutral…
laitingsheng 0642e00
fix(onboard): stamp session id on the initial inference route reserva…
laitingsheng a5a33d6
test(onboard): cover reservation ownership boundaries
cjagwani fd0249d
merge(main): sync reservation ownership fix
cjagwani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import assert from "node:assert/strict"; | ||
| import { spawnSync } from "node:child_process"; | ||
| import fs from "node:fs"; | ||
| import os from "node:os"; | ||
| import path from "node:path"; | ||
| import { describe, it } from "vitest"; | ||
| import { writeOkOpenshell } from "./helpers/onboard-openshell-fixture"; | ||
|
|
||
| const repoRoot = path.join(import.meta.dirname, ".."); | ||
| const onboardScriptMocksPath = JSON.stringify( | ||
| path.join(repoRoot, "test", "helpers", "onboard-script-mocks.cjs"), | ||
| ); | ||
|
|
||
| describe("onboard sandbox recreate reservation safety", () => { | ||
| it("preserves a current-session pending route reservation across a not-ready recreate (#6562)", { | ||
| timeout: 60_000, | ||
| }, async () => { | ||
| const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-onboard-reservation-survives-")); | ||
| const fakeBin = path.join(tmpDir, "bin"); | ||
| const scriptPath = path.join(tmpDir, "reservation-survives.js"); | ||
| const onboardPath = JSON.stringify(path.join(repoRoot, "src", "lib", "onboard.ts")); | ||
| const runnerPath = JSON.stringify(path.join(repoRoot, "src", "lib", "runner.ts")); | ||
| const registryPath = JSON.stringify(path.join(repoRoot, "src", "lib", "state", "registry.ts")); | ||
| const onboardSessionPath = JSON.stringify( | ||
| path.join(repoRoot, "src", "lib", "state", "onboard-session.ts"), | ||
| ); | ||
|
|
||
| fs.mkdirSync(fakeBin, { recursive: true }); | ||
| writeOkOpenshell(fakeBin); | ||
|
|
||
| const script = String.raw` | ||
| const runner = require(${runnerPath}); | ||
| const _n = (c) => (Array.isArray(c) ? c.join(" ") : String(c)).replace(/'/g, ""); | ||
| const registry = require(${registryPath}); | ||
| const onboardSession = require(${onboardSessionPath}); | ||
| const childProcess = require("node:child_process"); | ||
| const { EventEmitter } = require("node:events"); | ||
|
|
||
| const events = []; | ||
| let sandboxDeleted = false; | ||
| runner.run = (command) => { | ||
| const cmd = _n(command); | ||
| events.push({ kind: "run", cmd }); | ||
| if (cmd.includes("sandbox delete")) sandboxDeleted = true; | ||
| return { status: 0 }; | ||
| }; | ||
| runner.runCapture = (command) => { | ||
| const cmd = _n(command); | ||
| if (cmd.includes("sandbox get my-assistant")) return "my-assistant"; | ||
| if (cmd.includes("sandbox list")) { | ||
| return sandboxDeleted ? "my-assistant Ready" : "my-assistant NotReady"; | ||
| } | ||
| if (cmd.includes("forward list")) return "my-assistant 127.0.0.1 18789 12345 running"; | ||
| { | ||
| const mockedCapture = require(${onboardScriptMocksPath}).mockOnboardRunCapture(command, { | ||
| defaultCurlOutput: "ok", | ||
| }); | ||
| if (mockedCapture !== null) return mockedCapture; | ||
| } | ||
| return ""; | ||
| }; | ||
|
|
||
| onboardSession.loadSession = () => ({ sessionId: "session-owner" }); | ||
|
|
||
| registry.getSandbox = () => ({ | ||
| name: "my-assistant", | ||
| gpuEnabled: false, | ||
| pendingRouteReservation: true, | ||
| reservationSessionId: "session-owner", | ||
| }); | ||
| registry.registerSandbox = () => true; | ||
| registry.updateSandbox = () => true; | ||
| registry.setDefault = () => true; | ||
| registry.removeSandbox = (name) => { | ||
| events.push({ kind: "removeSandbox", name }); | ||
| return true; | ||
| }; | ||
|
|
||
| const preflight = require(${JSON.stringify(path.join(repoRoot, "src", "lib", "onboard", "preflight.ts"))}); | ||
| preflight.checkPortAvailable = async () => ({ ok: true }); | ||
|
|
||
| childProcess.spawn = (...args) => { | ||
| const child = new EventEmitter(); | ||
| child.stdout = new EventEmitter(); | ||
| child.stderr = new EventEmitter(); | ||
| child.unref = () => {}; | ||
| child.pid = 4246; | ||
| events.push({ kind: "spawn", cmd: _n([args[0], ...(Array.isArray(args[1]) ? args[1] : [])]) }); | ||
| process.nextTick(() => { | ||
| child.stdout.emit("data", Buffer.from("Created sandbox: my-assistant\n")); | ||
| child.emit("close", 0); | ||
| }); | ||
| return child; | ||
| }; | ||
|
|
||
| const { createSandbox } = require(${onboardPath}); | ||
|
|
||
| (async () => { | ||
| process.env.OPENSHELL_GATEWAY = "nemoclaw"; | ||
| process.env.NEMOCLAW_RECREATE_SANDBOX = "1"; | ||
| process.env.NEMOCLAW_RECREATE_WITHOUT_BACKUP = "1"; | ||
| const sandboxName = await createSandbox(null, "gpt-5.4", "nvidia-prod", null, "my-assistant"); | ||
| console.log(JSON.stringify({ sandboxName, events })); | ||
| })().catch((error) => { | ||
| console.error(error); | ||
| process.exit(1); | ||
| }); | ||
| `; | ||
| fs.writeFileSync(scriptPath, script); | ||
|
|
||
| const result = spawnSync(process.execPath, [scriptPath], { | ||
| cwd: repoRoot, | ||
| encoding: "utf-8", | ||
| env: { | ||
| ...process.env, | ||
| HOME: tmpDir, | ||
| PATH: `${fakeBin}:${process.env.PATH || ""}`, | ||
| NEMOCLAW_NON_INTERACTIVE: "1", | ||
| }, | ||
| }); | ||
|
|
||
| assert.equal(result.status, 0, result.stderr); | ||
| const payloadLine = result.stdout | ||
| .trim() | ||
| .split("\n") | ||
| .slice() | ||
| .reverse() | ||
| .find((line) => line.startsWith("{") && line.endsWith("}")); | ||
| assert.ok(payloadLine, `expected JSON payload in stdout:\n${result.stdout}`); | ||
| const payload = JSON.parse(payloadLine); | ||
| assert.equal(payload.sandboxName, "my-assistant"); | ||
|
|
||
| const events = payload.events as Array<{ kind: string; cmd?: string; name?: string }>; | ||
| const removedReservation = events.some( | ||
| (e) => e.kind === "removeSandbox" && e.name === "my-assistant", | ||
| ); | ||
| assert.equal( | ||
| removedReservation, | ||
| false, | ||
| "must not delete the current session's pending route reservation during recreate", | ||
| ); | ||
| assert.ok( | ||
| events.some((e) => e.kind === "run" && (e.cmd || "").includes("sandbox delete")), | ||
| "should still delete the not-ready gateway sandbox before rebuilding", | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.