Skip to content

fix(onboard): validate reset options before deleting state#111348

Merged
steipete merged 1 commit into
mainfrom
claude/fix-onboard-reset-safety
Jul 19, 2026
Merged

fix(onboard): validate reset options before deleting state#111348
steipete merged 1 commit into
mainfrom
claude/fix-onboard-reset-safety

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users running onboarding with --reset could have their config, credentials, sessions, or workspace moved to Trash before invalid options were rejected. It also fixes full reset targeting the default workspace when a schema-invalid but parseable config pointed at a custom workspace.

AI-assisted change; the implementation and proof were reviewed locally before submission.

Why This Change Was Made

Reset is now the final step before setup dispatch, after deterministic mode, option, gateway, provider-auth, credential-storage, setup-token, and workspace checks complete. Provider-owned non-interactive auth methods expose a side-effect-free validation hook; migration import fails closed when combined with reset because migration providers do not yet expose a reusable read-only import plan.

For full reset, the parsed source config remains authoritative even when schema validation fails. OpenClaw deletes only the configured workspace, and refuses the reset when the workspace cannot be determined safely.

User Impact

Invalid onboarding invocations no longer destroy existing state before reporting their error. Users with a schema-invalid config and a custom workspace can safely request a full reset without risking deletion of the unrelated default workspace.

Evidence

Reproduction before this change:

  1. Run openclaw onboard --reset --non-interactive --accept-risk --mode typo with existing state.
  2. Observe the state moved to Trash before onboarding reports the invalid mode.

After this change, the same invocation reports the invalid mode and does not call reset. A second regression test supplies a schema-invalid parsed config whose agents.defaults.workspace is custom; full reset targets that custom path and never the default workspace.

Focused proof:

  • node scripts/run-vitest.mjs src/commands/onboard.test.ts src/commands/onboard-non-interactive.gateway.test.ts src/commands/onboard-remote.test.ts src/plugins/provider-api-key-auth.test.ts — 64 tests passed across four files.
  • node scripts/run-vitest.mjs extensions/anthropic/index.test.ts — 47 tests passed.
  • pnpm tsgo
  • pnpm check:test-types
  • node scripts/run-oxlint.mjs <touched files>
  • pnpm plugin-sdk:surface:check
  • pnpm deadcode:exports
  • git diff --check
  • Fresh branch autoreview against origin/main: clean, no accepted/actionable findings.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations extensions: anthropic size: XL maintainer Maintainer-authored PR labels Jul 19, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 626ab893f1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/commands/onboard.ts
Comment on lines +503 to +505
snapshot.exists &&
!snapshot.valid &&
!snapshot.sourceConfig

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Detect unreadable snapshots without testing object truthiness

When --reset-scope full encounters malformed JSON5 or an unreadable config, this guard never runs: ConfigFileSnapshot.sourceConfig is required, and the snapshot reader supplies {} on parse failure (src/config/io.snapshot.ts:90-99) and read failure. Because {} is truthy, onboarding falls through to DEFAULT_WORKSPACE and moves that unrelated workspace to Trash even though the actual configured workspace is unknown. Check parse/read failure state such as raw, readError, or snapshot issues instead.

Useful? React with 👍 / 👎.

@steipete
steipete merged commit d4ed089 into main Jul 19, 2026
147 of 150 checks passed
@steipete
steipete deleted the claude/fix-onboard-reset-safety branch July 19, 2026 09:42
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations extensions: anthropic maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant