Skip to content

fix(doctor): surface unreadable legacy plugin state instead of silently skipping migration - #130956

Merged
steipete merged 1 commit into
mainfrom
steipete/doctor-migration-error-surfacing
Aug 27, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/doctor-migration-error-surfacing

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

The shared plugin migration helper defineLegacyJsonStateMigration (src/plugin-sdk/runtime-doctor-migrations.ts:324-355) converted every read, JSON-parse, and plugin-parser exception into null — including EACCES and transient I/O errors. Detection then reported "no migration", and direct migration returned empty changes/warnings. The caller boundaries that already convert thrown detector failures into visible Doctor warnings (src/infra/state-migrations.doctor.ts:253-268, :951-973) never saw the error.

Consequence (probed with injected EACCES pre-fix: {"detected":null,"migrated":{"changes":[],"warnings":[]}}): an unreadable legacy Active Memory session-toggles.json silently vanishes from doctor --fix — no warning, no migration — and runtime treats the absent opt-outs as enabled (extensions/active-memory/session-policy.ts:31-43). Device Pair notification subscriptions share the helper. This is the silent-failure class: an action ends with neither a visible outcome nor a recorded non-outcome.

The core sibling already does this right: src/infra/state-migrations.runtime-state.ts:69-75 reports both read and JSON-syntax failures.

Why This Change Was Made

Minimal owner-level distinction instead of a new warning channel: ENOENT (source legitimately absent) still yields null/clean skip, and intentional parser null still skips migration — every other exception now propagates unchanged to the existing Doctor warning boundaries, which do their established job. Public signature, row selection, imports, archive, and persistence behavior are unchanged. The SDK migration doc gains the absence-vs-error distinction.

User Impact

openclaw doctor now tells the operator when legacy plugin state exists but cannot be read or parsed, instead of silently pretending there is nothing to migrate — protecting Active Memory session opt-outs and Device Pair notification subscriptions from disappearing without a trace.

Evidence

  • Failing-first Doctor-boundary regressions (src/infra/state-migrations.legacy-json.test.ts, +134 lines): pre-fix 6 failed / 4 passed (EACCES, EIO, malformed JSON each silent in detection and direct migration; ENOENT and parser-null controls passed); post-fix 10 passed. Assertions exercise the real Doctor warning boundaries and verify source preservation with no archive.
  • Real-filesystem probe (no mocks): chmod-000 produced EACCES for both helper methods, original source bytes survived, no archive appeared; actual removal yielded clean skips. Disposable temp dir only.
  • Requested suites: 580 passed / 3 skipped across infra migrations, SDK helper, Active Memory and Device Pair migration contracts. Focused re-run green on rebased head ee35c1e6a90.
  • check-changed: all guards, formatting, SDK surface checks, dead-export scans, four typecheck stages green; one lint finding in the new test itself (no-base-to-string) fixed by using direct path equality; targeted lint re-run exit 0; remaining repo guards (import cycles, database-first, pairing, webhook order) all green.
  • Codex autoreview (--mode uncommitted), both passes: no findings; reviewer confirmed absence/parser-null skips, both warning boundaries, and unchanged persistence/archive/signature behavior.
  • Production LOC +5/−1 (errno distinction + existing-helper import); tests +134; docs +5.
  • Named follow-up (out of scope, preserved behavior): src/plugins/doctor-state-migration-fs.ts:5-12 suppresses stat errors in legacyStateFileExists — separate audit scope.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 27, 2026 13:52
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S maintainer Maintainer-authored PR labels Aug 27, 2026
…ly skipping migration

Preserve missing-source and intentional parser-null skips while forwarding other read and JSON parse errors to the existing Doctor warning boundaries. Keep plugin import, archive, and persistence behavior unchanged.
@steipete
steipete force-pushed the steipete/doctor-migration-error-surfacing branch from ee35c1e to 26b6e6f Compare August 27, 2026 14:49
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. 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 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 27, 2026, 10:56 AM ET / 14:56 UTC.

ClawSweeper review

What this changes

The PR changes the shared legacy JSON plugin-state migration helper so missing files skip cleanly while other read and JSON errors become Doctor warnings, with regression coverage and SDK migration documentation.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open: the intended owner-level fix is close, but its catch block still silently treats a plugin parser exception with code: "ENOENT" as a missing source.

Priority: P2
Reviewed head: 26b6e6f410848f5004796e12ee8ad5f648c02373

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, well-scoped repair with one concrete error-boundary defect to correct before merge.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless describes a real filesystem probe.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless describes a real filesystem probe.
Evidence reviewed 5 items Current main still suppresses the error: Current main returns null for every exception from the combined read, JSON parse, and plugin parser expression, so the reported silent skip remains unfixed there.
Existing Doctor warning owner: The collector catches detector exceptions and records a visible Failed detecting warning, which is the correct downstream boundary once the helper propagates a non-absence error.
Parser error remains incorrectly classified: The proposed try includes params.parse; therefore a parser-thrown errno-shaped ENOENT reaches hasErrnoCode and returns null instead of the documented Doctor warning.
Findings 1 actionable finding [P2] Limit the ENOENT catch to the filesystem read
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/infra/state-migrations.legacy-json.test.ts

Result: FAIL (failed) — step 1 expect_output legacy JSON plugin migration diagnostics: expected terminal output was not visible within 30 seconds: "legacy JSON plugin migration diagnostics"

[test] starting test/vitest/vitest.infra.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130956-2UQ0T6/target

 ✓  infra  src/infra/state-migrations.legacy-json.test.ts (10 tests) 110ms

 Test Files  1 passed (1)
      Tests  10 passed (10)
   Start at  14:57:15
   Duration  11.57s (transform 9.06s, setup 1.28s, import 10.05s, tests 110ms, environment 0ms)

[test] passed 1 Vitest shard in 18.68s

Assertions:

  • FAIL expect_output: legacy JSON plugin migration diagnostics

How this fits together

OpenClaw Doctor detects and imports legacy plugin-owned JSON state into the current plugin-state store. The shared helper reads a legacy file, then Doctor either presents migration work or records an operator-visible warning.

flowchart LR
  A[Legacy plugin JSON] --> B[Shared migration helper]
  B --> C{Missing source?}
  C -->|Yes| D[Clean skip]
  C -->|No or parser error| E[Doctor warning boundary]
  E --> F[Operator fixes and retries]
  B --> G[Plugin state import]
Loading

Before merge

  • Limit the ENOENT catch to the filesystem read (P2) - params.parse(...) executes inside this try, so a parser that throws an errno-shaped ENOENT is still converted to null. That contradicts this PR’s absence-vs-parser-error contract and suppresses the existing Doctor warning. Read the file in its own ENOENT-only guard, then parse outside it; add the corresponding regression case.
  • Resolve merge risk (P1) - The public helper’s broadened error contract remains incomplete until only the filesystem read, rather than parser execution, is eligible for the ENOENT clean-skip path.
  • Complete next step (P2) - This maintainer-labeled PR should remain open for the author to make the two-line boundary correction and add its focused regression.

Findings

  • [P2] Limit the ENOENT catch to the filesystem read — src/plugin-sdk/runtime-doctor-migrations.ts:327-331
Agent review details

Security

None.

PR surface

Source +4, Tests +134, Docs +5. Total +143 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 5 1 +4
Tests 1 134 0 +134
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 144 1 +143

Review metrics

Metric Value Why it matters
Production versus test delta production +5/-1 (net +4); tests +134; docs +5 The production growth is for error classification at a public SDK helper and needs the narrower read-only boundary before merge.

Stored data model

Persistent data-model change detected: migration/backfill/repair: docs/plugins/sdk-migration.md. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Narrow ENOENT handling to file reads (recommended)
    Catch ENOENT around fs.readFile alone, then add a parser-thrown errno-shaped case proving it becomes a Doctor warning.

Technical review

Best possible solution:

Make source absence a filesystem-read-only decision, leaving JSON and plugin-parser exceptions to the established Doctor warning boundaries.

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

Yes, by source: a parser callback can throw an errno-shaped ENOENT within the proposed combined try block, which is then returned as a clean skip instead of reaching Doctor’s warning collector.

Is this the best way to solve the issue?

No. The proposed propagation is the right owner boundary, but the ENOENT branch must be scoped to fs.readFile so plugin parser failures cannot be misclassified as source absence.

Full review comments:

  • [P2] Limit the ENOENT catch to the filesystem read — src/plugin-sdk/runtime-doctor-migrations.ts:327-331
    params.parse(...) executes inside this try, so a parser that throws an errno-shaped ENOENT is still converted to null. That contradicts this PR’s absence-vs-parser-error contract and suppresses the existing Doctor warning. Read the file in its own ENOENT-only guard, then parse outside it; add the corresponding regression case.
    Confidence: 0.95

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: The PR repairs a bounded operator-visible Doctor migration diagnostic path but needs one focused correctness fix.
  • add merge-risk: 🚨 compatibility: The shared Plugin SDK migration helper changes externally reachable error semantics for plugin-provided parsers.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless describes a real filesystem probe.

Label justifications:

  • P2: The PR repairs a bounded operator-visible Doctor migration diagnostic path but needs one focused correctness fix.
  • merge-risk: 🚨 compatibility: The shared Plugin SDK migration helper changes externally reachable error semantics for plugin-provided parsers.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless describes a real filesystem probe.

Evidence

What I checked:

Likely related people:

  • Josh Lehman: Git blame assigns the existing catch that suppresses all errors to this commit; its history also includes the current helper file. (role: current helper-boundary author; confidence: high; commits: bbce34077e76; files: src/plugin-sdk/runtime-doctor-migrations.ts)
  • steipete: Recent merged history shows sustained work on Doctor and state-migration architecture, in addition to this PR. (role: recent state-migration contributor; confidence: medium; commits: 75dbe52e3e40, 1ea2640f5428; files: src/infra/state-migrations.doctor.ts, src/plugin-sdk/runtime-doctor-migrations.ts)

Rank-up moves

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

  • Scope the ENOENT clean skip to fs.readFile only.
  • Add a parser-thrown errno-shaped error case and rerun the focused Doctor migration suite.

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.

@steipete
steipete merged commit 23ae7bc into main Aug 27, 2026
210 checks passed
@steipete
steipete deleted the steipete/doctor-migration-error-surfacing branch August 27, 2026 15:13
@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 28, 2026
…ly skipping migration (openclaw#130956)

Preserve missing-source and intentional parser-null skips while forwarding other read and JSON parse errors to the existing Doctor warning boundaries. Keep plugin import, archive, and persistence behavior unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S 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