Skip to content

fix(cli): refuse live state reset and uninstall - #125253

Merged
steipete merged 7 commits into
mainfrom
steipete/relaxed-tu-d098ba
Aug 17, 2026
Merged

steipete merged 7 commits into
mainfrom
steipete/relaxed-tu-d098ba

Conversation

@steipete

@steipete steipete commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where openclaw reset --scope full and openclaw uninstall --state could remove the selected state directory while an unmanaged, Nix-managed, or otherwise service-manager-undetected Gateway still owned the live SQLite database and its WAL/SHM files.

This change does not attribute that command path to the 2026-08-17 Molty incident; command-history proof would be required for that conclusion.

Why This Change Was Made

Destructive maintenance now owns the lifecycle boundary rather than trusting service-manager status. A stable Gateway-presence coordinator fences live Gateway instances, while a separate state-operation coordinator covers short SQLite mutations. Cleanup holds both through state removal, in-tree lock detachment, linked-path cleanup, and finalization; linked config/OAuth files are removed only after guarded state cleanup succeeds.

The CLI startup catalog skips the normal migration/observation bootstrap for reset and uninstall, because that bootstrap itself writes shared SQLite state. The command then performs a validity-aware, non-observing config snapshot read: malformed, unreadable, include-broken, or unresolved workspace configuration fails closed before deletion. Non-sandboxed macOS clients that can share CLI state use the common lifecycle namespace; sandboxed Apple app/extension state remains container-owned and uses a sandbox-writable coordinator.

Cleanup canonicalizes state aliases, preserves unselected workspaces, rejects workspace paths overlapping active locks, and retains external Gateway ownership until every destructive phase is complete. Beta-only predecessor coordinator paths are intentionally hard-cut under the repository compatibility policy.

AI-assisted: yes. The implementation was independently reviewed through the repository autoreview gate, including P1 findings and repairs.

User Impact

Operators now get an actionable nonzero refusal instead of live-state deletion or even incidental WAL mutation when a Gateway still owns the selected state. Legitimate offline full reset and state-only uninstall continue to work; state-only uninstall preserves configured workspaces. Invalid workspace configuration also fails closed rather than guessing which nested paths are safe to delete.

Evidence

  • Production LOC: +614/-140 (net +474) | Tests/support: +721/-148 (net +573) | Docs: +4/-0. The production growth establishes the missing cross-process/cross-language lifecycle owner, two-phase finalization, non-observing command startup, and validity-aware workspace preservation.
  • Pre-fix regression proof: unmanaged reset, Nix reset, and state-only uninstall all proceeded instead of refusing. Separate injected regressions proved external linked paths were deleted before later cleanup failure, a competing Gateway could acquire during finalization, runtime config planning mutated live WAL/SHM, and best-effort parsing deleted state when workspace configuration was malformed.
  • Final focused proof: 91 TypeScript tests and 42 Swift tests pass across command startup policy, cleanup commands, Gateway ownership, shared-state coordination, device identity, canonical aliases, workspace preservation, malformed-config refusal, and sandbox/non-sandbox coordinator selection.
  • Formatting and git diff --check pass. The full changed gate also passed during the repair sequence; final exact-head GitHub CI is attached to the SHA below.
  • P1 branch autoreview: clean, no accepted/actionable findings.
  • Exact-head source-blind CLI validation passes on 13a073f2b7196802155980080d39e082a6a4e595: unmanaged full reset, Nix full reset, and state-only uninstall all exit nonzero with owner-lock guidance while marker, main DB, WAL, SHM, and config remain byte-for-byte identical. The owner remains healthy; SQLite reports journal_mode=wal and quick_check=ok. Malformed workspace-bearing config also refuses without changing recursive state/workspace manifests. Stopped-owner full reset removes state, and offline state-only uninstall removes state/config while preserving the configured external workspace. Only high ephemeral ports were used; port 18789 was never requested; all processes and fixtures were cleaned up.
  • Exact-head CI: https://github.com/openclaw/openclaw/actions/runs/32033275831 is green, including native Windows and macOS jobs.

@clawsweeper

clawsweeper Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation commands Command implementations size: XL maintainer Maintainer-authored PR labels Aug 17, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 17, 2026
@clawsweeper

clawsweeper Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 17, 2026, 12:11 PM ET / 16:11 UTC.

ClawSweeper review

What this changes

The PR adds cross-process lifecycle coordination so full reset and state-only uninstall refuse to delete selected SQLite state while a Gateway or another state operation owns it.

Merge readiness

⚠️ Needs maintainer review before merge - 4 items remain

Keep this PR open: it materially protects full reset and state-only uninstall, but the default partial reset still deletes config, credentials, and session directories after only a managed-service check. The protected maintainer label also requires maintainer handling before merge.

Priority: P0
Reviewed head: 13a073f2b7196802155980080d39e082a6a4e595

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The evidence for the covered commands is strong, but a P1 unguarded reset scope prevents merge readiness.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body supplies exact-head terminal evidence for the full-reset and state-only-uninstall paths; that proof does not cover the remaining partial-reset finding.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body supplies exact-head terminal evidence for the full-reset and state-only-uninstall paths; that proof does not cover the remaining partial-reset finding.
Evidence reviewed 5 items Partial reset remains unfenced: The documented config+creds+sessions scope removes configuration, credentials, and per-agent session directories, but its branch deletes those paths directly after only the managed-service stop attempt.
Lifecycle fence is full/state-only: Exclusive ownership is acquired inside removeStateAndLinkedPaths, which the reset command calls only from the full branch; the live-owner regression table likewise covers full reset and state-only uninstall only.
Default onboarding reset shares the partial scope: openclaw onboard --reset defaults to config+creds+sessions and calls the separate reset helper, so the shared lifecycle invariant needs an explicit sibling-surface decision.
Findings 1 actionable finding [P1] Fence partial reset before deleting live state
Security None None.

How this fits together

CLI reset and uninstall remove local configuration, credentials, session directories, and/or SQLite state. A running Gateway may own those paths, so destructive commands must coordinate with Gateway lifecycle ownership before deletion.

flowchart LR
  A[Reset or uninstall command] --> B[Scope selection]
  B --> C[Full or state cleanup]
  B --> D[Partial reset]
  E[Running Gateway] --> F[Lifecycle coordinator]
  C --> F
  F --> G{Exclusive ownership?}
  G -->|No| H[Refuse deletion]
  G -->|Yes| I[Remove selected paths]
  D --> I
Loading

Before merge

  • Fence partial reset before deleting live state (P1) - Late finding: the new lifecycle fence is acquired only by removeStateAndLinkedPaths, which this command reaches for full only. The default config+creds+sessions scope still deletes config, credentials, and per-agent session directories after an unmanaged/Nix Gateway passes the service check. Reuse the exclusive ownership boundary here and add a live-owner refusal regression.
  • Resolve merge risk (P1) - The default config+creds+sessions reset can still delete live Gateway-owned credentials and session directories when an unmanaged or Nix-supervised Gateway is running.
  • Resolve merge risk (P1) - Merging changes existing reset/uninstall recovery behavior to fail closed on lifecycle ownership; that compatibility and availability change needs the same invariant across all destructive reset paths.
  • Complete next step (P2) - The repair is concrete, but the protected maintainer label requires maintainer handling before automated follow-up.

Findings

  • [P1] Fence partial reset before deleting live state — src/commands/reset.ts:142-144
Agent review details

Security

None.

PR surface

Source +438, Tests +550, Docs +4, Other +59. Total +1051 across 28 files.

View PR surface stats
Area Files Added Removed Net
Source 11 571 133 +438
Tests 12 689 139 +550
Docs 2 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 3 75 16 +59
Total 28 1339 288 +1051

Review metrics

Metric Value Why it matters
Production versus test delta production +614/-140 (net +474); tests/support +721/-148 (net +573); docs +4/-0 The substantial production growth establishes a cross-process lifecycle boundary, so every destructive scope must reuse it rather than retain an unguarded sibling path.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/infra/device-identity.test.ts, serialized state: src/commands/cleanup-utils.test.ts, serialized state: src/infra/gateway-lock.state-dir.test.ts, serialized state: src/infra/state-database-coordinator.test.ts, serialized state: src/infra/state-database-coordinator.ts, serialized state: src/state/openclaw-state-db.test.ts, and 5 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Fence partial reset before merge (recommended)
    Apply the existing lifecycle-owner guard to config+creds+sessions and prove unmanaged/Nix live-owner refusal plus offline cleanup.
  2. Accept live partial-reset deletion
    Merge with the documented full-reset-only guarantee, leaving unmanaged partial reset outside the ownership fence.

Technical review

Best possible solution:

Use one shared exclusive lifecycle-ownership boundary for every reset path that deletes state-owned files, then add live-owner refusal and offline-success coverage for partial reset and its onboarding caller.

Do we have a high-confidence way to reproduce the issue?

Yes—source provides a high-confidence path: hold an unmanaged Gateway owner, then run reset --scope config+creds+sessions; the branch deletes the documented paths without acquiring the new lifecycle fence. This read-only review did not execute it.

Is this the best way to solve the issue?

No. The coordinator is the right owner boundary, but the proposed wiring is incomplete because the default partial reset bypasses it.

Full review comments:

  • [P1] Fence partial reset before deleting live state — src/commands/reset.ts:142-144
    Late finding: the new lifecycle fence is acquired only by removeStateAndLinkedPaths, which this command reaches for full only. The default config+creds+sessions scope still deletes config, credentials, and per-agent session directories after an unmanaged/Nix Gateway passes the service check. Reuse the exclusive ownership boundary here and add a live-owner refusal regression.
    Confidence: 0.98
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 793669c8f6dd.

Labels

Label justifications:

  • P0: The PR addresses destructive deletion of state owned by a live Gateway, a data-loss-class failure.
  • merge-risk: 🚨 compatibility: Existing reset and uninstall flows now intentionally refuse when exclusive ownership cannot be established.
  • merge-risk: 🚨 availability: The new coordinator participates in Gateway lifecycle admission and can block startup or cleanup when ownership is held.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The PR body supplies exact-head terminal evidence for the full-reset and state-only-uninstall paths; that proof does not cover the remaining partial-reset finding.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies exact-head terminal evidence for the full-reset and state-only-uninstall paths; that proof does not cover the remaining partial-reset finding.

Evidence

What I checked:

  • Partial reset remains unfenced: The documented config+creds+sessions scope removes configuration, credentials, and per-agent session directories, but its branch deletes those paths directly after only the managed-service stop attempt. (src/commands/reset.ts:142, 13a073f2b719)
  • Lifecycle fence is full/state-only: Exclusive ownership is acquired inside removeStateAndLinkedPaths, which the reset command calls only from the full branch; the live-owner regression table likewise covers full reset and state-only uninstall only. (src/commands/cleanup-utils.ts:362, 13a073f2b719)
  • Default onboarding reset shares the partial scope: openclaw onboard --reset defaults to config+creds+sessions and calls the separate reset helper, so the shared lifecycle invariant needs an explicit sibling-surface decision. (src/commands/onboard.ts:573, 13a073f2b719)
  • Current main does not supersede the PR: Current main still directly removes the partial reset paths and has no state-database coordinator module, so the central full-reset/state-uninstall repair remains necessary. (src/commands/reset.ts:127, 793669c8f6dd)
  • Area provenance: The existing reset path appears to date to Peter Steinberger's onboarding-recovery work, and the same contributor authored this PR head. (src/commands/reset.ts:151, 890a5e895b4c)

Likely related people:

  • steipete: Peter Steinberger authored the prior reset-path work and the current lifecycle-coordination branch. (role: recent CLI lifecycle contributor; confidence: high; commits: 890a5e895b4c, 13a073f2b719; files: src/commands/reset.ts, src/commands/cleanup-utils.ts, src/infra/state-database-coordinator.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Apply the lifecycle fence to partial reset.
  • Add live-owner refusal and offline-success coverage for that scope.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-08-17T11:38:48.935Z sha 20f445f1eafaeb2fb79a7881bd230a693dfc839c :: found issues before merge. :: [P1] Preserve external paths until state cleanup succeeds
  • reviewed 2026-08-17T11:46:58.724Z sha 20f445f1eafaeb2fb79a7881bd230a693dfc839c :: needs changes before merge. :: [P1] Preserve linked paths until state cleanup succeeds
  • reviewed 2026-08-17T13:13:16.351Z sha 13a073f :: needs maintainer review before merge. :: none
  • reviewed 2026-08-17T14:01:58.188Z sha 13a073f :: needs maintainer review before merge. :: none

@steipete
steipete marked this pull request as ready for review August 17, 2026 11:40
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 17, 2026
@steipete steipete self-assigned this Aug 17, 2026
@steipete
steipete force-pushed the steipete/relaxed-tu-d098ba branch from 20f445f to dd2da11 Compare August 17, 2026 12:19
@openclaw-barnacle openclaw-barnacle Bot added the cli CLI command changes label Aug 17, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 17, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for exact head 13a073f2b7196802155980080d39e082a6a4e595:

  • Exact-head CI is green, including native Windows and macOS: https://github.com/openclaw/openclaw/actions/runs/32033275831
  • Source-blind CLI validation passed: unmanaged full reset, Nix full reset, and state-only uninstall each refused with byte-identical marker, main DB, WAL, SHM, and config. The live Gateway remained healthy and SQLite reported journal_mode=wal plus quick_check=ok.
  • Malformed workspace-bearing config refused state-only uninstall without changing recursive state/workspace manifests.
  • Offline full reset removed the canonical state directory; offline state-only uninstall removed state/config while preserving the configured external workspace.
  • Focused proof passed: 91 TypeScript tests and 42 Swift tests, plus formatting and git diff --check.
  • P1 branch autoreview and exact-head ClawSweeper review found no actionable issues.
  • The final local changed gate encountered only the stale-base src/config/sessions/types.ts max-lines violation already fixed on current main; the exact-head merge-ref CI core lint is green.

Known proof gaps: none.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 17, 2026
@steipete
steipete merged commit b834477 into main Aug 17, 2026
245 checks passed
@steipete
steipete deleted the steipete/relaxed-tu-d098ba branch August 17, 2026 16:44
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 18, 2026
* fix(cli): guard live state cleanup

* fix(cli): preserve linked paths on cleanup failure

* fix(cli): retain gateway ownership through cleanup

* fix(cli): keep cleanup planning read-only

* fix(cli): skip mutating bootstrap for cleanup

* fix(apple): keep identity locks sandbox-writable

* docs(apple): clarify identity lock domains
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant