fix(plugin-sdk): guard legacy dedupe JSON parse against malformed files#98125
Conversation
|
Codex review: needs maintainer review before merge. Reviewed June 30, 2026, 7:37 AM ET / 11:37 UTC. Summary PR surface: Source +5, Tests +14. Total +19 across 2 files. Reproducibility: yes. Current main reads the malformed legacy file and calls JSON.parse without a catch, and the PR body includes terminal negative-control proof showing the SyntaxError path. Review metrics: none identified. Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Next step before merge
Security Review detailsBest possible solution: Merge the narrow parser guard and regression test after required maintainer checks, keeping active SQLite dedupe behavior unchanged while hardening retired JSON migration input. Do we have a high-confidence way to reproduce the issue? Yes. Current main reads the malformed legacy file and calls JSON.parse without a catch, and the PR body includes terminal negative-control proof showing the SyntaxError path. Is this the best way to solve the issue? Yes. The shared parser is the right fix point because it covers direct listing and migration callers without duplicating malformed-file handling in each plugin doctor path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 6cb82eaab865. Label changesLabel justifications:
Evidence reviewedPR surface: Source +5, Tests +14. Total +19 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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. How this review workflow works
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Merged via squash.
|
…es (openclaw#98125) (cherry picked from commit 169acd1)
…es (openclaw#98125) (cherry picked from commit 169acd1)
What Problem This Solves
listPersistentDedupeLegacyJsonFileEntries(used duringopenclaw doctorlegacy dedupe migration) callsJSON.parseon retired JSON cache files without catching parse errors. If a legacy dedupe file is partially written, truncated, or otherwise malformed, the entire doctor repair flow throws aSyntaxErrorinstead of treating the file as empty.Changes
src/plugin-sdk/persistent-dedupe.ts:parseLegacyDedupeDatanow wrapsJSON.parsein a try/catch. Malformed JSON is treated the same way as{}or[]— returning{ data: {}, invalidCount: 0 }— so the legacy migration continues instead of crashing.src/plugin-sdk/memory-host-events.test.ts: added a regression test that writes{not valid jsonto a legacy dedupe file and assertslistPersistentDedupeLegacyJsonFileEntriesresolves to an empty array.Real behavior proof
listPersistentDedupeLegacyJsonFileEntriesagainst a real temporary file on disk.node --import tsx /tmp/proof-persistent-dedupe.mtswrites a malformed legacy dedupe file, calls the production reader, and prints the result. The same script also verifies a well-formed file still returns the expected entry.RESULT: ok, entries=0; well-formed file →RESULT: ok, entries=1. Before the fix the malformed file threwSyntaxError: Expected property name or '}' in JSON at position 1.openclaw doctor --fixend-to-end flow was not run; the proof focuses on the exact entry-point function that doctor uses, and the in-repo Vitest regression locks the behavior.Evidence
Terminal proof (real production function, real malformed file on disk):
Negative control (temporary revert to
origin/main):Focused Vitest:
Type checks: