-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(credentials): clean up empty legacy credentials.json on upgrade #3119
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
ericksoa
merged 4 commits into
main
from
fix/issue-3105-cleanup-empty-legacy-credentials
May 7, 2026
+424
−1
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d0ec779
fix(credentials): clean up empty legacy credentials.json on upgrade
laitingsheng 0a089df
fix(credentials): widen empty-file detection and verify unlink success
laitingsheng 8e22ede
Merge branch 'main' into fix/issue-3105-cleanup-empty-legacy-credentials
laitingsheng a6561ad
Merge remote-tracking branch 'origin/main' into fix/issue-3105-cleanu…
ericksoa 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| // Post-upgrade stale-file cleanup. | ||
| // | ||
| // As NemoClaw evolves, host-side state migrates: older versions wrote files | ||
| // under the user's home that newer versions no longer use. Each entry in | ||
| // STALE_FILES owns the safety logic for one specific stale file and reports | ||
| // back when it actually removed something. The runner invokes them all once | ||
| // during the onboard completion path so a fresh post-upgrade onboard sweeps | ||
| // every leftover in a single uniform pass. Adding a future cleanup is one | ||
| // entry on STALE_FILES; the loop does not change. If a future leftover is a | ||
| // folder or symlink instead of a file, widen the shape at that point. | ||
|
|
||
| import { removeLegacyCredentialsFileIfEmpty } from "./credentials"; | ||
|
|
||
| interface StaleHostFile { | ||
| /** Human-readable description for the success log line. */ | ||
| readonly description: string; | ||
| /** | ||
| * Atomically inspect-and-remove the file iff its safety guards | ||
| * permit it. Returns true iff the file was actually removed. | ||
| * Splitting "is-removable?" from "remove" would be TOCTOU-unsafe, | ||
| * so each entry exposes a single combined operation. | ||
| */ | ||
| readonly tryRemove: () => boolean; | ||
| } | ||
|
|
||
| const STALE_FILES: readonly StaleHostFile[] = [ | ||
| { | ||
| description: "~/.nemoclaw/credentials.json (no migratable credentials)", | ||
| tryRemove: removeLegacyCredentialsFileIfEmpty, | ||
| }, | ||
| ]; | ||
|
|
||
| /** | ||
| * Sweep every registered stale host file left behind by older NemoClaw | ||
| * versions. Best-effort: a failure inside one entry is logged to stderr | ||
| * but never aborts the others or the surrounding onboard. Logs a single | ||
| * line to stdout per file actually removed so the user can audit what | ||
| * changed. Safe to call after a successful onboard regardless of which | ||
| * migration paths fired earlier — every entry is a no-op when its | ||
| * target doesn't exist or doesn't satisfy the entry's safety rules. | ||
| */ | ||
| export function cleanupStaleHostFiles(): void { | ||
| for (const file of STALE_FILES) { | ||
| try { | ||
| if (file.tryRemove()) { | ||
| console.log(` Removed stale ${file.description}.`); | ||
| } | ||
| } catch (error) { | ||
| console.error( | ||
| ` Skipped stale-file cleanup ${file.description}: ${ | ||
| error instanceof Error ? error.message : String(error) | ||
| }`, | ||
| ); | ||
| } | ||
| } | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't inspect one inode and delete another.
The emptiness check is done on the fd-backed inode you read here, but Line 459 deletes by pathname after that fd has been closed. If another process replaces
credentials.jsonin that window, this can classify inode A as empty and then wipe inode B instead — including a newly written real credential file. Please keep the validated inode pinned through cleanup, or abort when the current path no longer matches the inode you inspected.🤖 Prompt for AI Agents