Skip to content

fix(plugins): preserve read errors before registry recovery - #131521

Merged
steipete merged 1 commit into
mainfrom
steipete/issue-131327-root-cause-a37529
Aug 28, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/issue-131327-root-cause-a37529

Conversation

@steipete

@steipete steipete commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #131327 — plugin-state read failures misreported as invalid or missing records.

What Problem This Solves

Fixes an issue where operators inspecting or repairing plugin state received invalid-record and row-deletion guidance when the database could not actually be read. The sibling full-index reader reported the same failures as an absent index, allowing a transient failed read to select a rebuild with empty install records.

The original isolated EACCES reproduction fails on current-main baseline ecb6acff90057a31b482f54146ea87e984e06cbc. A real-SQLite regression fixture additionally demonstrates a manual refresh overwriting its synthetic authoritative records after one injected read failure. This is synthetic-state proof, not a claim of observed production data loss.

Why This Change Was Made

Both projections now share a light read-only row boundary that propagates original errors and explicitly recognizes genuine missing database/table/row state. Removed the two broad catches and redundant SQLite forwarding function; kept install-record parsing independent of full-index parsing so intact records remain recoverable when derived metadata is malformed.

The persistence-recovery contract was explicitly accepted before implementation. No schema/version, representation, migration format, retention, transaction, writer, rollback, or successful-cache lifecycle changes. A failed authoritative read cannot authorize fallback, migration, or a persisted refresh. Malformed-envelope and missing-revision behavior remains unchanged. A code revert requires no data migration, but would restore the misleading classifications.

Best-fix judgment: repair the read owner, not runtime/Doctor diagnostics. An error-code allowlist would omit other real failures; a new unavailable-result layer adds no needed caller capability; routing records through full-index validation would break record salvage.

Production LOC: +48/-70 (net -22). Tests: +304/-0. Docs: +2/-0. The new row module replaces duplicated reader policy; no test-only production seam or dependency was added.

Provenance: original catch-to-null in #88794 — SQLite plugin-index persistence, authored and merged by @steipete; invalid-record classification in #121045 — install-record recovery, authored and merged by @vincentkoc. #125493 — newer-schema error preservation, authored and merged by @steipete, exempted schema errors but retained the remaining catch behavior. Blame and live merge metadata checked. Older stable tags contain catch-to-null behavior; the supplied current-main stat-injection reproduction was not run against a stable binary.

User Impact

Permission and lock failures remain permission and lock failures. Operators can restore database access and retry without being told to delete unread records. Genuine absence, invalid-record guidance after successful inspection, newer-schema refusal, and successful recovery remain supported. Updated the plugin state documentation.

AI-assisted repair and review; reporter and maintainer: @steipete.

Evidence

Rebased onto 629a47e3cc20a9f8b6d19c105f840b8a693ec4aa to resolve conflicts with #131417 — keep write machinery out of metadata reads. The writer module remains unchanged; the new regression suite imports refresh functions from its current owner. The approved read-error semantics are unchanged. All 163 tests across 9 files pass again, the original four-path EACCES reproduction and real SQLite owner lock probe pass again, and fresh isolated Codex autoreview is clean. Full build and built CLI proof below were completed before this module-split rebase; exact-head hosted CI run 33141896737 passed on 39b7447d49cd07d4986d0b85e6e6a1a3df284eca, including the required openclaw/ci-gate. The complete changed-file gate also passed again after rebase.

  • Original EACCES reproduction: before, four denied reads became invalid, a replacement runtime error, null, and Doctor row-deletion guidance. After, all four propagate the exact original error; no misleading classification or deletion guidance. The lead independently reran this probe.
  • Regression proof before production edits: Doctor 2 failing cases and plugin error/rebuild cases fail for the reported behavior. After moving the new store cases into their final focused suite, replay against baseline production: 5 failed, 8 passed; preservation cases intentionally already passed. Ordinary and leased manual refresh previously replaced synthetic records with {} and advanced revision; policy refresh also wrote after a failed required read.
  • Final focused and sibling proof: 163 tests passed across 9 files, covering sync/async readers, EACCES, BUSY/LOCKED, cache failure-then-success ordering, no managed-npm recovery after read failure, both Doctor preflight reads, exact stored JSON/revision/timestamp preservation, ordinary/leased/policy refresh, genuine absence, malformed data, newer-schema refusal, prototype-safe records, generation precedence, discovery, and metadata lifecycle.
  • Real SQLite owner proof: an isolated database held under BEGIN EXCLUSIVE returns actual ERR_SQLITE_ERROR / errcode: 5 / database is locked through full-index, runtime-record, and Doctor reads; the row remains unchanged; all succeed after unlocking.
  • Supplemental built CLI proof: isolated node openclaw.mjs plugins registry --json exits 1 with SQLite read-only worker database is locked, leaves exact row bytes/revision untouched, then exits 0 after unlock and preserves authoritative records. Limit: this CLI lock is caught by earlier shared-state bootstrap, not the changed plugin reader; changed-owner proof is the real SQLite probe and regression suite above. No operator Gateway or live state was touched.
  • pnpm build: passed, including CLI bootstrap/import checks and SDK exports; no ineffective-dynamic-import warning.
  • Final changed gate: passed formatting, ratchets, dead-export checks, production/test typechecking, changed-file lint, database-first/schema guards, zero runtime import cycles, and remaining scoped guards. Initial fixture type and test-file length failures were corrected without suppressions or production changes.
  • Fresh Codex autoreview of the final diff: clean, no accepted/actionable findings.

Focused test command:

node scripts/run-vitest.mjs src/plugins/installed-plugin-index-records.test.ts src/plugins/installed-plugin-index-store.test.ts src/plugins/installed-plugin-index-read-state.test.ts src/commands/doctor/shared/plugin-registry-migration.test.ts src/plugins/installed-plugin-index-store.install-record-map.test.ts src/plugins/installed-plugin-index-generation-precedence.test.ts src/plugins/plugin-registry-inspection.test.ts src/plugins/plugin-registry-snapshot.test.ts src/plugins/manifest-metadata-scan.test.ts

Changed gate:

node scripts/check-changed.mjs -- docs/cli/plugins.md src/plugins/installed-plugin-index-record-state.ts src/plugins/installed-plugin-index-row.ts src/plugins/installed-plugin-index-store.ts src/plugins/installed-plugin-index-records.test.ts src/plugins/installed-plugin-index-read-state.test.ts src/commands/doctor/shared/plugin-registry-migration.test.ts

Dependency contract checked directly: Node 26.7.0 SQLite get distinguishes SQLITE_DONE from errors; SQLite error construction retains result codes; SQLite BUSY/LOCKED describe concurrency failures rather than malformed data.

@clawsweeper

clawsweeper Bot commented Aug 28, 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: M maintainer Maintainer-authored PR labels Aug 28, 2026
@steipete
steipete force-pushed the steipete/issue-131327-root-cause-a37529 branch from 9f15d77 to 39b7447 Compare August 28, 2026 04:27
@steipete
steipete marked this pull request as ready for review August 28, 2026 04:28
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for 39b7447d49cd07d4986d0b85e6e6a1a3df284eca: the shared plugin-index row reader preserves original read errors, so unreadable state cannot select invalid-record guidance or a persisted rebuild. Genuine absence and independent install-record salvage remain supported. Writer, schema, retention, transaction, and cache lifecycle semantics are unchanged, within the accepted persistence design.

Rebased only to resolve the conflict with #131417's reader/writer module split; the new writer module remains untouched. Production +48/-70 (net -22); tests +304; docs +2. All 163 focused/sibling tests passed again, original EACCES reproduction preserved all four original exceptions, and the real SQLite exclusive-lock probe preserved the row and succeeded after unlocking. Fresh isolated Codex autoreview: no actionable findings.

Commands completed:

node scripts/run-vitest.mjs src/plugins/installed-plugin-index-records.test.ts src/plugins/installed-plugin-index-store.test.ts src/plugins/installed-plugin-index-read-state.test.ts src/commands/doctor/shared/plugin-registry-migration.test.ts src/plugins/installed-plugin-index-store.install-record-map.test.ts src/plugins/installed-plugin-index-generation-precedence.test.ts src/plugins/plugin-registry-inspection.test.ts src/plugins/plugin-registry-snapshot.test.ts src/plugins/manifest-metadata-scan.test.ts
node scripts/check-changed.mjs -- docs/cli/plugins.md src/plugins/installed-plugin-index-record-state.ts src/plugins/installed-plugin-index-row.ts src/plugins/installed-plugin-index-store.ts src/plugins/installed-plugin-index-records.test.ts src/plugins/installed-plugin-index-read-state.test.ts src/commands/doctor/shared/plugin-registry-migration.test.ts
node scripts/watch-pr-ci.mjs 131521 39b7447d49cd07d4986d0b85e6e6a1a3df284eca
scripts/pr review-init 131521
scripts/pr review-checkout-main 131521
scripts/pr review-checkout-pr 131521
scripts/pr review-artifacts-init 131521
scripts/pr review-validate-artifacts 131521
OPENCLAW_TESTBOX=1 scripts/pr prepare-run 131521

CI run 33141896737, attempt 1 passed on this exact head, including required openclaw/ci-gate. Native prepare passed and retained the same head. No CI failure or rerun. Live rules require linear history and this check; no independent approval rule is enforced. No review findings or requests are outstanding; ClawSweeper currently has only a review-start placeholder, with no published rank-up moves.

Proof limits: full local build and built CLI lock/unlock proof completed before the mechanical module-split rebase; fresh source proof and hosted CI cover the rebased head. The CLI lock was caught earlier in shared-state bootstrap, not the changed reader; the real SQLite owner probe covers that boundary. No operator Gateway or live state was touched, and no observed production data-loss claim is made. The original stat-injection probe was not run against a stable binary.

@steipete
steipete merged commit 2058fd7 into main Aug 28, 2026
305 checks passed
@steipete
steipete deleted the steipete/issue-131327-root-cause-a37529 branch August 28, 2026 04:48
@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 docs Improvements or additions to documentation maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Plugin state read failures are misreported as invalid or missing records

1 participant