-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(snapshot): preserve sealed OpenClaw config #9231
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
prekshivyas
merged 11 commits into
NVIDIA:main
from
HOYALIM:codex/fix-9215-sealed-config-backup
Aug 21, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
535b00b
fix(snapshot): preserve sealed OpenClaw config
HOYALIM 66c6545
fix(snapshot): diagnose privileged config capture
HOYALIM c4756fc
test(snapshot): execute privileged config capture
prekshivyas 22cd22a
test(snapshot): cover exact privileged capture limit
cv 01af8c5
test(snapshot): move rejection iteration to helper
cv 3f05000
test(snapshot): use table-driven rejection cases
cv 9a15e6e
test(snapshot): name capture boundaries precisely
cv 9483908
Merge branch 'main' into codex/fix-9215-sealed-config-backup
cv 88c3677
Merge branch 'main' into codex/fix-9215-sealed-config-backup
cv 356b9e1
merge(snapshot): refresh sealed config backup
apurvvkumaria e0cee7c
Merge branch 'main' into codex/fix-9215-sealed-config-backup
senthilr-nv 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
179 changes: 179 additions & 0 deletions
179
src/lib/actions/sandbox/snapshot/backup-authority-script.test.ts
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,179 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import fs from "node:fs"; | ||
| import os from "node:os"; | ||
| import path from "node:path"; | ||
| import { spawnSync } from "node:child_process"; | ||
|
|
||
| import { afterEach, describe, expect, it } from "vitest"; | ||
|
|
||
| import { OPENCLAW_CONFIG_CAPTURE_SCRIPT } from "./backup-authority"; | ||
|
|
||
| const CONFIG_NAME = "openclaw.json"; | ||
| const MAX_CONFIG_BYTES = 16 * 1024 * 1024; | ||
| const PROTOCOL_PREFIX = "nemoclaw-openclaw-config-capture:"; | ||
| const fixtureRoots: string[] = []; | ||
|
|
||
| interface CaptureResult { | ||
| readonly status: number | null; | ||
| readonly stdout: Buffer; | ||
| readonly stderr: string; | ||
| } | ||
|
|
||
| function fixtureDirectory(): string { | ||
| const root = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-openclaw-capture-")); | ||
| fixtureRoots.push(root); | ||
| const directory = path.join(root, ".openclaw"); | ||
| fs.mkdirSync(directory); | ||
| return directory; | ||
| } | ||
|
|
||
| function runCapture(directory: string, script = OPENCLAW_CONFIG_CAPTURE_SCRIPT): CaptureResult { | ||
| const result = spawnSync("/usr/bin/python3", ["-I", "-S", "-c", script, directory, CONFIG_NAME], { | ||
| encoding: null, | ||
| timeout: 30_000, | ||
| maxBuffer: MAX_CONFIG_BYTES + 1024 * 1024, | ||
| }); | ||
| return { | ||
| status: result.status, | ||
| stdout: Buffer.isBuffer(result.stdout) ? result.stdout : Buffer.alloc(0), | ||
| stderr: Buffer.isBuffer(result.stderr) ? result.stderr.toString("utf8") : "", | ||
| }; | ||
| } | ||
|
|
||
| function mutationHarness(mutation: string): string { | ||
| return `import os, sys | ||
| capture_script = ${JSON.stringify(OPENCLAW_CONFIG_CAPTURE_SCRIPT)} | ||
| directory = sys.argv[1] | ||
| name = sys.argv[2] | ||
| real_read = os.read | ||
| mutated = False | ||
| def mutate_after_first_read(fd, size): | ||
| global mutated | ||
| data = real_read(fd, size) | ||
| if not mutated: | ||
| mutated = True | ||
| ${mutation} | ||
| return data | ||
| os.read = mutate_after_first_read | ||
| exec(capture_script) | ||
| `; | ||
| } | ||
|
|
||
| afterEach(() => { | ||
| for (const root of fixtureRoots.splice(0)) { | ||
| fs.rmSync(root, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| describe("OpenClaw privileged config capture script", () => { | ||
| it("returns bytes only for a stable regular file", () => { | ||
| const directory = fixtureDirectory(); | ||
| const expected = Buffer.from('{"models":{"default":"nvidia/test"}}\n'); | ||
| fs.writeFileSync(path.join(directory, CONFIG_NAME), expected); | ||
|
|
||
| const result = runCapture(directory); | ||
|
|
||
| expect(result).toEqual({ status: 0, stdout: expected, stderr: "" }); | ||
| }); | ||
|
|
||
| it("returns all bytes for a stable file at the 16 MiB limit", () => { | ||
| const directory = fixtureDirectory(); | ||
| const expected = Buffer.alloc(MAX_CONFIG_BYTES, 0xa5); | ||
| fs.writeFileSync(path.join(directory, CONFIG_NAME), expected); | ||
|
|
||
| const result = runCapture(directory); | ||
|
|
||
| expect(result.status).toBe(0); | ||
| expect(result.stderr).toBe(""); | ||
| expect(result.stdout).toHaveLength(expected.length); | ||
| expect(result.stdout.equals(expected)).toBe(true); | ||
| }); | ||
|
|
||
| it.each([ | ||
| { | ||
| kind: "symbolic link", | ||
| setup(directory: string) { | ||
| const target = path.join(path.dirname(directory), "target.json"); | ||
| fs.writeFileSync(target, "target"); | ||
| fs.symlinkSync(target, path.join(directory, CONFIG_NAME)); | ||
| }, | ||
| }, | ||
| { | ||
| kind: "hard link", | ||
| setup(directory: string) { | ||
| const target = path.join(path.dirname(directory), "target.json"); | ||
| fs.writeFileSync(target, "target"); | ||
| fs.linkSync(target, path.join(directory, CONFIG_NAME)); | ||
| }, | ||
| }, | ||
| { | ||
| kind: "FIFO", | ||
| setup(directory: string) { | ||
| const result = spawnSync("mkfifo", [path.join(directory, CONFIG_NAME)]); | ||
| expect(result.status).toBe(0); | ||
| }, | ||
| }, | ||
| { | ||
| kind: "directory", | ||
| setup(directory: string) { | ||
| fs.mkdirSync(path.join(directory, CONFIG_NAME)); | ||
| }, | ||
| }, | ||
| { | ||
| kind: "oversized file", | ||
| setup(directory: string) { | ||
| const descriptor = fs.openSync(path.join(directory, CONFIG_NAME), "w"); | ||
| try { | ||
| fs.ftruncateSync(descriptor, MAX_CONFIG_BYTES + 1); | ||
| } finally { | ||
| fs.closeSync(descriptor); | ||
| } | ||
| }, | ||
| }, | ||
| ])("rejects a $kind without returning captured bytes", ({ setup }) => { | ||
| const directory = fixtureDirectory(); | ||
| setup(directory); | ||
|
|
||
| const result = runCapture(directory); | ||
|
|
||
| expect(result.status).not.toBe(0); | ||
| expect(result.stdout).toEqual(Buffer.alloc(0)); | ||
| expect(result.stderr).toContain(PROTOCOL_PREFIX); | ||
| }); | ||
|
|
||
| it("rejects a file replaced during the read without returning captured bytes", () => { | ||
| const directory = fixtureDirectory(); | ||
| fs.writeFileSync(path.join(directory, CONFIG_NAME), "original"); | ||
| const script = mutationHarness( | ||
| ` original = os.path.join(directory, name)\n` + | ||
| ` os.rename(original, original + ".old")\n` + | ||
| ` with open(original, "wb") as replacement:\n` + | ||
| ` replacement.write(b"replacement")`, | ||
| ); | ||
|
|
||
| const result = runCapture(directory, script); | ||
|
|
||
| expect(result.status).toBe(13); | ||
| expect(result.stdout).toEqual(Buffer.alloc(0)); | ||
| expect(result.stderr).toBe(`${PROTOCOL_PREFIX}file-changed-during-read\n`); | ||
| }); | ||
|
|
||
| it("rejects a directory replaced during the read without returning captured bytes", () => { | ||
| const directory = fixtureDirectory(); | ||
| fs.writeFileSync(path.join(directory, CONFIG_NAME), "original"); | ||
| const script = mutationHarness( | ||
| ` os.rename(directory, directory + ".old")\n` + | ||
| ` os.mkdir(directory)\n` + | ||
| ` with open(os.path.join(directory, name), "wb") as replacement:\n` + | ||
| ` replacement.write(b"replacement")`, | ||
| ); | ||
|
|
||
| const result = runCapture(directory, script); | ||
|
|
||
| expect(result.status).toBe(13); | ||
| expect(result.stdout).toEqual(Buffer.alloc(0)); | ||
| expect(result.stderr).toBe(`${PROTOCOL_PREFIX}directory-changed-during-read\n`); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
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.