Skip to content

fix(plugins): preserve install records during recovery - #121045

Merged
vincentkoc merged 7 commits into
mainfrom
fix/plugin-install-record-owner-rebuild-20260809
Aug 9, 2026
Merged

vincentkoc merged 7 commits into
mainfrom
fix/plugin-install-record-owner-rebuild-20260809

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 9, 2026 •

Copy link
Copy Markdown
Member

Related: #120687
Related landed slice: #120906

What Problem This Solves

Fixes an issue where malformed or legacy plugin install-record state could be treated like missing state and enter destructive migration or recovery paths. The same owner path could lose legal plugin IDs such as __proto__, constructor, and toString, reorder numeric-looking or Unicode IDs inconsistently, and drop passthrough data or record identity during update and Doctor handoffs.

Invalid persisted input must now stop before revisions, SQLite rewrites, archive/recovery work, package cleanup, generation retirement, host-link repair, or state-directory movement.

Why This Change Was Made

The install-record owner now has one canonical flow:

  • a shared parser validates current and full-shaped legacy records before migration;
  • null-prototype maps, own-key lookup, and safe insertion preserve every legal plugin ID;
  • UTF-8 byte ordering defines deterministic persistence independently of JavaScript property enumeration;
  • passthrough fields and untouched record identity survive loading, mutation, post-core handoff, persistence, and Doctor;
  • candidate and persisted records are validated before any persistence transaction or lifecycle mutation;
  • persisted-state inspection stays private to the plugin index owner, avoiding accidental Plugin SDK declaration closure.

Doctor remains non-mutating for invalid state and reports a precise backup/manual recovery step.

Why a replacement PR is required

The source PR, #120687, is currently conflicting/dirty and has maintainer edits disabled, so the source branch cannot be repaired directly. Its agent-database portion was independently rebuilt and landed through #120906 with a materially different diff. This PR is the clean current-main replacement for the remaining plugin install-record owner work; it deliberately excludes fingerprint semantic changes, agent-database relocation, and SQLite schema changes.

Do not close #120687 until this replacement actually lands.

User Impact

Operators upgrading or repairing plugin state get deterministic, lossless install-record persistence. Invalid state fails closed without changing package files, revisions, archives, links, or databases, and Doctor tells the operator exactly how to recover. Updates and startup checks continue to recognize legal special-key plugin IDs.

Credit

Galin Iliev (@galiniliev) originated the investigation and historical intent in #120687. All six semantic task commits plus the signed current-main merge preserve Galin's Co-authored-by credit.

Evidence

  • Exact head: 585212ebfe6a8875543892676b4a2b2239365d27.
  • Six semantic task commits plus one signed current-main merge; every task-created commit has a good ED25519 signature plus recognized Punchcard-Session: amber-workshop-workshop-36 and Galin co-author trailers.
  • Independent reviewer verdict on the production head: APPROVE FOR PUBLICATION. The follow-up only updates a current-main test assertion for the canonical null-prototype map and merges current main without changing the production diff. Landing remains gated on hosted exact-head CI and ClawSweeper.
  • Focused owner proof: 175/175 tests passed across config, persistence, migration, Doctor, post-core handoff, and plugin index owners.
  • Sibling convergence proof: 33/33 tests passed, including __proto__, constructor, and toString identity/enumerability plus active __proto__ smoke/path classification.
  • Redacted copied-state upgrade proof on this exact head: 5/5 selected real-filesystem/SQLite cases passed.
    • Valid persisted records round-tripped __proto__, constructor, and toString as inert own properties in a null-prototype map.
    • Invalid retired config records stopped before persistence, created no plugin index, left the managed package directory intact, and instructed the operator to back up openclaw.json, repair the record, and rerun openclaw doctor --fix.
    • Invalid SQLite records preserved the exact install_records_json, migration version, and update timestamp. Doctor instructed the operator to stop the Gateway, back up the database, delete only the installed_plugin_index row with index_key='installed-plugin-index', and rerun openclaw doctor --fix.
    • Commands: node scripts/run-vitest.mjs --config test/vitest/vitest.unit-fast.config.ts src/plugins/installed-plugin-index-store.install-record-map.test.ts -t "persists legal prototype-named plugin ids as inert own properties" --reporter=verbose; node scripts/run-vitest.mjs --config test/vitest/vitest.commands.config.ts src/commands/doctor/shared/plugin-registry-migration.test.ts -t "rejects invalid SQLite install records without rewriting the row|rejects invalid config install records before recovery or persistence" --reporter=verbose; node scripts/run-vitest.mjs --config test/vitest/vitest.commands.config.ts src/commands/doctor-plugin-registry.test.ts -t "does not mutate stale packages when config install records are invalid|reports the supported manual recovery for invalid persisted records" --reporter=verbose.
  • Hosted run 31310878068, job 93238607739, found one stale current-main assertion that strictly expected a plain empty object. The focused load-path file now passes 2/2 while explicitly asserting no keys and a null prototype.
  • Hosted run 31311350221, job 93239605272, found one stale state-migration fixture that treated malformed legacy record metadata as a benign conflict. The selected test now passes while asserting the exact warning, absent notices, unchanged source bytes, and no archive.
  • Exact formatting and git diff --check pass for the follow-up. The path-scoped oxlint wrapper did not reach the changed file because its Plugin SDK DTS prerequisite hit an unrelated local dependency/type mismatch in packages/terminal-core/src/ansi.ts; hosted exact-head CI is the authority for that gate.
  • Production-head formatting, focused oxlint, Plugin SDK API baseline, autoreview, and git diff --check passed before publication.
  • Current-main proof: exact main 4cb33d48cddb527101123e3ff69f73a00fd7e049 is a parent of the signed head; the only merge conflict was the repaired test assertion.
  • Local changed-gate routing never reached a check subcommand: Blacksmith was unauthenticated and the router's Daytona readiness probe timed out before a direct healthy probe completed. Hosted exact-head openclaw/ci-gate is therefore the remaining validation gate.
  • Production LOC: +573/-351 (net +222). The growth establishes the canonical map/parser/serializer owner, private tri-state persisted-state inspection, atomic mutation barriers, and actionable Doctor recovery.
  • Test LOC: +844/-90 (net +754).

No live provider or channel proof is claimed. No release, tag, package publication, fingerprint semantic change, agent-database relocation, or SQLite schema change is included.

AI-assisted: yes. The implementation and proof were independently reviewed before publication.

vincentkoc and others added 4 commits August 9, 2026 12:11
Preserve canonical fields, passthrough metadata, untouched record identity, and deterministic serialized ordering across SQLite and post-core handoff.

Punchcard-Session: amber-workshop-workshop-36
Co-authored-by: Galin Iliev <[email protected]>
Preflight persisted and legacy install-record state before registry repair, package cleanup, generation retirement, archival, or state-directory moves.

Punchcard-Session: amber-workshop-workshop-36
Co-authored-by: Galin Iliev <[email protected]>
Punchcard-Session: amber-workshop-workshop-36
Co-authored-by: Galin Iliev <[email protected]>
Punchcard-Session: amber-workshop-workshop-36
Co-authored-by: Galin Iliev <[email protected]>
@vincentkoc vincentkoc self-assigned this Aug 9, 2026
@clawsweeper

clawsweeper Bot commented Aug 9, 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 cli CLI command changes commands Command implementations size: XL maintainer Maintainer-authored PR labels Aug 9, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review August 9, 2026 11:28
vincentkoc and others added 2 commits August 9, 2026 13:35
Punchcard-Session: amber-workshop-workshop-36
Co-authored-by: Galin Iliev <[email protected]>
Punchcard-Session: amber-workshop-workshop-36
Co-authored-by: Galin Iliev <[email protected]>
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 9, 2026
@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 9, 2026, 7:47 AM ET / 11:47 UTC.

ClawSweeper review

What this changes

This PR centralizes parsing and prototype-safe persistence of plugin install records so updates, Doctor, and the SQLite index preserve valid records and stop before mutating invalid ones.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open for maintainer merge review: the branch is a coherent replacement for the remaining install-record work and fixes a current unsafe recovery boundary, but its fail-closed upgrade behavior needs exact-head upgrade proof before landing.

Priority: P1
Reviewed head: 0fc35190c400bad3396acf821eaadf6ab469f713
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a coherent, well-covered owner-boundary repair, with exact-head CI and upgrade-safety evidence still needed before merge.
Proof confidence 🌊 off-meta tidepool Not applicable: The author is a repository MEMBER, so the external-contributor proof gate does not apply; the supplied focused test and CI evidence remains supplemental to requested upgrade proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The author is a repository MEMBER, so the external-contributor proof gate does not apply; the supplied focused test and CI evidence remains supplemental to requested upgrade proof.
Evidence reviewed 6 items Current-main unsafe boundary: The base implementation converted an invalid legacy install-record map into an empty map, allowing recovery to continue as though state were absent.
Canonical owner path: The PR adds one parser, null-prototype map construction, own-key lookup, and deterministic serialization for all install-record forms.
Mutation barrier: The SQLite writer validates the prior persisted record JSON before allocating a revision or writing the replacement index.
Findings None None.
Security None None.

How this fits together

Plugin install records connect configured plugin sources to the durable plugin index used by startup, updates, and Doctor. The changed paths validate persisted records before recovery, then either preserve them through the next lifecycle step or produce recovery guidance.

flowchart LR
  A[Config and SQLite install records] --> B[Shared record parser]
  B --> C{Valid record map?}
  C -->|Yes| D[Doctor and update recovery]
  C -->|No| E[Recovery guidance]
  D --> F[Plugin index persistence]
  D --> G[Plugin startup and updates]
Loading

Decision needed

Question Recommendation
Should this PR make malformed existing plugin install records a fail-closed recovery condition after exact-head upgrade proof demonstrates the operator recovery path? Require copied-state upgrade proof: Verify valid special-key records remain usable and invalid SQLite/config records produce the stated non-mutating Doctor recovery outcome before merge.

Why: This intentionally changes behavior for persisted upgrade state and may stop recovery or startup until the operator repairs invalid data; a maintainer must accept that compatibility tradeoff.

Before merge

  • Resolve merge risk (P1) - Existing malformed plugin-record state will now fail closed rather than continue through recovery; operators need proven, actionable upgrade guidance before this compatibility change lands.
  • Resolve merge risk (P1) - Exact-head CI is still incomplete, and the PR has no observed copied-state recovery trace covering both valid special IDs and invalid persisted input.
  • Complete next step (P1) - The protected maintainer label and compatibility-sensitive fail-closed upgrade behavior require explicit maintainer acceptance after exact-head validation.
Agent review details

Security

None.

PR surface

Source +222, Tests +743. Total +965 across 30 files.

View PR surface stats
Area Files Added Removed Net
Source 18 573 351 +222
Tests 12 833 90 +743
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 30 1406 441 +965

Review metrics

Metric Value Why it matters
Production versus test delta production +573/-351; tests +833/-90 The net production growth is justified by consolidating a persisted-state ownership boundary; the broad lifecycle coverage should receive upgrade-focused validation.
Persisted record contract 1 shared parser adopted across SQLite, Doctor, state migration, and update handoff This changes compatibility behavior for existing plugin install records even without adding a user configuration option.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/cli/update-cli/update-command-post-core.ts, migration/backfill/repair: src/commands/doctor-plugin-registry.test.ts, migration/backfill/repair: src/commands/doctor-plugin-registry.ts, migration/backfill/repair: src/commands/doctor/shared/missing-configured-plugin-install.load-path.test.ts, migration/backfill/repair: src/commands/doctor/shared/plugin-registry-migration.test.ts, migration/backfill/repair: src/commands/doctor/shared/plugin-registry-migration.ts, and 16 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Prove valid and invalid upgrade paths (recommended)
    Before merge, run the exact head against copied state with valid special-ID records and malformed records, confirming preservation in the first case and no lifecycle mutation plus clear recovery output in the second.
  2. Accept manual recovery
    Merge the fail-closed change with the current SQLite/config repair guidance if maintainers explicitly accept the operator intervention for malformed historical state.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Require copied-state upgrade proof for valid special IDs and invalid persisted records, then wait for exact-head CI.

Technical review

Best possible solution:

Land one shared install-record owner only after a copied-state upgrade run proves valid legacy records survive unchanged and invalid records leave the index, package files, and state-directory layout untouched while Doctor gives usable recovery guidance.

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

Yes—source-reproducible: the base code treats invalid config install records as empty state, while the branch validates them before recovery or persistence; no runtime test was run in this read-only review.

Is this the best way to solve the issue?

Yes: centralizing parsing, own-key semantics, and serialization at the install-record owner is safer than retaining separate permissive readers in update, Doctor, and SQLite paths.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5d98d2e6ecd7.

Labels

Label changes:

  • add P1: The PR repairs persisted plugin-state recovery that can affect startup, updates, and Doctor for existing operators.
  • add merge-risk: 🚨 compatibility: Malformed and legacy install-record state changes from permissive recovery to a fail-closed path with operator remediation.
  • add merge-risk: 🚨 availability: A persisted record rejected during recovery can prevent the affected plugin lifecycle path from proceeding until repaired.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The author is a repository MEMBER, so the external-contributor proof gate does not apply; the supplied focused test and CI evidence remains supplemental to requested upgrade proof.

Label justifications:

  • P1: The PR repairs persisted plugin-state recovery that can affect startup, updates, and Doctor for existing operators.
  • merge-risk: 🚨 compatibility: Malformed and legacy install-record state changes from permissive recovery to a fail-closed path with operator remediation.
  • merge-risk: 🚨 availability: A persisted record rejected during recovery can prevent the affected plugin lifecycle path from proceeding until repaired.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The author is a repository MEMBER, so the external-contributor proof gate does not apply; the supplied focused test and CI evidence remains supplemental to requested upgrade proof.

Evidence

What I checked:

Likely related people:

  • steipete: Current plugin-index placement and related state-migration work are attributed to Peter Steinberger in central-file history. (role: recent plugin architecture contributor; confidence: high; commits: cc4cc83e3622, 4c2d8d8adb39; files: src/plugins/installed-plugin-index-store.ts, src/commands/doctor/shared/plugin-registry-migration.ts)
  • shakkernerd: History shows prior shipped-config migration and install-record preservation work in this owner area. (role: historical install-record contributor; confidence: medium; commits: 194c26b, babbad81, 569d489; files: src/config/plugin-install-config-migration.ts, src/plugins/installed-plugin-index-record-reader.ts)
  • vincentkoc: Beyond this PR, prior current-main work covers plugin-registry preflight and SQLite read-only handling. (role: prior area contributor; confidence: medium; commits: d7cf803, 4ea758d; files: src/commands/doctor/shared/plugin-registry-migration.ts, src/plugins/installed-plugin-index-record-state.ts)

Rank-up moves

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

  • Provide a redacted copied-state recovery transcript for valid special IDs and malformed persisted records.
  • Wait for all exact-head CI checks to finish successfully.

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.

Punchcard-Session: amber-workshop-workshop-36
Co-authored-by: Galin Iliev <[email protected]>
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review exact head 585212ebfe6a8875543892676b4a2b2239365d27.

Exact-head CI run 31311941223 completed successfully. The PR body now includes the requested redacted copied-state upgrade proof for valid __proto__, constructor, and toString records plus malformed config and SQLite fail-closed paths, unchanged persisted/package state, and actionable Doctor recovery guidance.

@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper status

Report the exact-head review state for 585212ebfe6a8875543892676b4a2b2239365d27. The re-review command is acknowledged, but no matching review worker has appeared while the queue reports throttle-retry backoff.

Status only. Do not repair, rebase, or merge.

@clawsweeper

clawsweeper Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper could not start a freeform assist pass for this item.

Reason: freeform assist requires an open issue or PR.

Request: Report the exact-head review state for 585212ebfe6a8875543892676b4a2b2239365d27. The re-review command is acknowledged, but no matching review worker has appeared while the queue reports throttle-retry backoff. Status only. Do not repair, rebase, or merge.

@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer acceptance: the fail-closed recovery behavior for malformed persisted plugin install records is intentional. Invalid config or SQLite state must remain non-mutating and require the documented manual recovery path.

The two optional ClawSweeper Rank-up moves are satisfied on exact head 585212ebfe6a8875543892676b4a2b2239365d27: the PR body contains the redacted 5/5 copied-state proof, and hosted CI run 31311941223 is green, including openclaw/ci-gate. The delta after reviewed head 0fc35190c400bad3396acf821eaadf6ab469f713 is test-only (src/commands/doctor-state-migrations.test.ts).

I accept the compatibility and availability tradeoff: malformed historical records stop recovery until the operator follows the actionable Doctor guidance; valid records, including prototype-named IDs, continue through the canonical owner path.

@vincentkoc
vincentkoc merged commit 1471881 into main Aug 9, 2026
132 checks passed
@vincentkoc
vincentkoc deleted the fix/plugin-install-record-owner-rebuild-20260809 branch August 9, 2026 12:24
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 10, 2026
* fix(plugins): canonicalize install record persistence

Preserve canonical fields, passthrough metadata, untouched record identity, and deterministic serialized ordering across SQLite and post-core handoff.

Punchcard-Session: amber-workshop-workshop-36
Co-authored-by: Galin Iliev <[email protected]>

* fix(doctor): block invalid plugin record mutations

Preflight persisted and legacy install-record state before registry repair, package cleanup, generation retirement, archival, or state-directory moves.

Punchcard-Session: amber-workshop-workshop-36
Co-authored-by: Galin Iliev <[email protected]>

* fix(plugins): harden install record map ownership

Punchcard-Session: amber-workshop-workshop-36
Co-authored-by: Galin Iliev <[email protected]>

* fix(update): preserve special plugin ids in payload checks

Punchcard-Session: amber-workshop-workshop-36
Co-authored-by: Galin Iliev <[email protected]>

* test(doctor): assert canonical install record maps

Punchcard-Session: amber-workshop-workshop-36
Co-authored-by: Galin Iliev <[email protected]>

* test(doctor): preserve invalid plugin index fixtures

Punchcard-Session: amber-workshop-workshop-36
Co-authored-by: Galin Iliev <[email protected]>

---------

Co-authored-by: Galin Iliev <[email protected]>
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 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. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant