Repository navigation
fix(onboard): persist credentialEnv clears when switching remote→local (#2625) - #3264
Conversation
#2625) Nullable session fields — credentialEnv, provider, model, endpointUrl, preferredInferenceApi, nimContainer — were silently dropped when passed as null through the session-update pipeline. The wizard correctly emits credentialEnv=null after a local-provider selection, but filterSafeUpdates only accepted typeof === 'string' values, and toSessionUpdates collapsed null→undefined via toOptionalString before the update ever reached the filter. The stale remote-provider credentialEnv survived on disk, and the next upgrade-sandboxes / rebuild preflight demanded a credential the current sandbox did not actually need. Fix both halves of the pipeline: * filterSafeUpdates: new assignNullableString helper treats null as an explicit clear, string as assign, undefined as leave-unchanged. Applied uniformly to all six nullable string fields on Session. * toSessionUpdates: new toNullableString helper preserves null instead of collapsing to undefined, matching the write-path contract. Tests: * Four new cases in onboard-session.test.ts covering: - provider switch OpenAI → Ollama clears credentialEnv - undefined leaves existing values untouched (clear vs no-op) - null-clear contract holds for every nullable field - completeSession honors the clear on terminal finalize * Existing 42 session tests and 16 rebuild-preflight tests still pass, including the narrower #2519 legacy-migration coverage. The rebuild-preflight legacy migration added for #2519 is retained unchanged; it remains the safety net for users whose session.json on disk predates this fix. Closes #2625 Related: #2306 (credential resolution canonicalization), #2519
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR fixes ChangesSession Null Clearing for Provider Switches
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
ericksoa
left a comment
There was a problem hiding this comment.
Reviewed current head b450b11 against current main. The null/undefined contract is preserved end-to-end: provider selection can persist credentialEnv=null for local providers, undefined remains a no-op for partial updates, and the nullable session string fields now share the same explicit-clear handling. The existing rebuild legacy migration remains intact for old local-inference sessions.\n\nValidated locally on a merge simulation with current origin/main: npm run build:cli; npx vitest run src/lib/state/onboard-session.test.ts test/rebuild-credential-preflight.test.ts test/rebuild-credential-hydration.test.ts; git diff --check.
Summary
Fixes the upgrade-sandboxes / per-sandbox rebuild preflight incorrectly demanding a stale provider credential (e.g.
OPENAI_API_KEY) after the user switches from a remote provider to a local one (Ollama / vLLM / local NIM). The wizard already emitscredentialEnv=nullon local-provider selection, but the session-update pipeline silently dropped the clear, so the stale value survived in~/.nemoclaw/onboard-session.jsonand the next rebuild preflight bailed out.Related Issue
Closes #2625
Related: #2306 (credential resolution canonicalization umbrella), #2519 (local Ollama caching OPENAI_API_KEY — pre-fix migration retained as safety net for on-disk sessions)
Changes
Two halves of the write path were broken for nullable session fields. Both fixed together:
src/lib/state/onboard-session.ts— newassignNullableStringhelper infilterSafeUpdatestreatsnullas an explicit clear,stringas assign (with optional normalizer), andundefinedas leave-unchanged. Applied uniformly to all six nullable string fields onSession:sandboxName,provider,model,endpointUrl,credentialEnv,preferredInferenceApi,nimContainer.SessionUpdateswidened tostring | nullfor those fields.src/lib/onboard.ts— newtoNullableStringhelper intoSessionUpdatespreservesnullinstead of collapsing toundefinedviatoOptionalString.toOptionalStringstays for genuinely optional (non-clearable) fields.src/lib/actions/sandbox/rebuild.ts— comment-only. Noted the [Linux][Brev]Ollama-local provider returns HTTP 401 Unauthorized via inference.local — wizard caches OPENAI_API_KEY env var into credentials.json and not refreshable via env unset #2519 legacy-migration block is still needed for users whose session.json predates this fix; fresh sessions no longer need it.src/lib/state/onboard-session.test.ts— 4 new cases:credentialEnv.undefinedregression guard: partial updates do not accidentally wipe fields.null-clear contract holds for every nullable field in one shot.completeSessionhonors the clear on terminal finalize.Type of Change
Verification
npm testpasses for the affected areas:src/lib/state/onboard-session.test.ts— 42/42 (4 new + 38 existing)test/rebuild-credential-preflight.test.ts+test/rebuild-credential-hydration.test.ts— 16/16 (including [Linux][Brev]Ollama-local provider returns HTTP 401 Unauthorized via inference.local — wizard caches OPENAI_API_KEY env var into credentials.json and not refreshable via env unset #2519 legacy-migration guards)src/lib/onboard-command.test.ts,src/lib/onboard-inference-probes.test.ts— unchanged, passnpm run build:cliclean (tsc -p tsconfig.src.json+ blueprint)biome lintclean on touched filesmake docs— not applicable (no user-facing doc changes; rebuild error path is the same on the failure case)Test plan for reviewers
The reporter's exact repro from the issue body is covered by the unit tests but is worth the manual check too:
nemoclaw onboardwith OpenAI, complete.unset OPENAI_API_KEY && nemoclaw credentials reset OPENAI_API_KEY.nemoclaw onboardselecting local Ollama (or any local provider).~/.nemoclaw/onboard-session.json—credentialEnvshould now benull(pre-fix it stayed as"OPENAI_API_KEY").nemoclaw upgrade-sandboxesshould no longer abort withMissing credential: OPENAI_API_KEY.Follow-up (not in this PR)
Phase 3 from the dev plan — downgrade the rebuild preflight to a warning when
credentialEnvis set but no env/saved value is found — would generalize the narrow #2519 migration into defense-in-depth for any stale remote-provider session on disk. Intentionally deferred to a separate PR to keep this one tightly scoped to the write-path root cause.Signed-off-by: Julie Yaunches jyaunches@nvidia.com
Summary by CodeRabbit
Bug Fixes
Tests