fix(storage): skip corrupt pages in list_pages to prevent KB-wide crashes#360
fix(storage): skip corrupt pages in list_pages to prevent KB-wide crashes#360RealDiligent wants to merge 2 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughAdds a helper function ChangesResilient Page Listing
Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Is it really crashes? Attach the proof plz |
|
With v2.0.0, we'll be moving to a database-backed approach (e.g., SQLite) instead of Markdown files. That said, I'm still curious—under what circumstances could claims or pages become corrupted in the current or future setup? Are there specific failure modes we should be proactively guarding against (e.g., concurrent writes, partial saves, file system errors, or migration mishaps)? |
Gives maintainers a one-command proof of the pre-fix crash path and the fixed skip-and-continue behavior. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Thanks for the review — answers below. Re: "Is it really crashes? Attach the proof plz"Yes. On main, one corrupt Affected paths (all call
Why claims don't crash but pages do: # main — list_pages()
return [_deserialize_page(p.read_text(...)) for p in sorted(pdir.glob("*.md"))]Proof you can run: git checkout main
python scripts/repro_list_pages_crash.py # added in latest commit on this PR branchOr minimal inline repro: store.put_page(Page(id="good", title="ok", body="x"))
(store.kb_dir / "pages" / "bad.md").write_text("not valid frontmatter")
store.list_pages() # ValueError on mainOn this branch the same call logs Regression test: Re: corruption failure modes / v2.0 SQLiteAgree v2.0 may move durable storage to SQLite. Until then, files are the source of truth and these are the realistic ways a page/claim file becomes unreadable today:
Not primary targets for this PR: concurrent writes (create path uses This change is parity, not new architecture — the same skip-and-warn pattern already shipped for claims, entities, relations, evidence, sessions, sources, and proposals. One bad file shouldn't take the review gate offline while the operator fixes it. Happy to rebase onto |
e2468eb to
9657692
Compare
|
Rebased onto latest \ est\ (\�0674f1). Both commits replayed cleanly; \ est_list_pages_skips_unreadable_file\ and \scripts/repro_list_pages_crash.py\ verified locally. |
list_pages() lacked the _load_or_skip resilience applied to other list_* paths, so one bad pages/*.md file crashed status, search, lint, and MCP tools. Skip unreadable pages with a warning instead. Co-authored-by: Cursor <cursoragent@cursor.com>
Gives maintainers a one-command proof of the pre-fix crash path and the fixed skip-and-continue behavior. Co-authored-by: Cursor <cursoragent@cursor.com>
Summary
Root cause:
list_pages()was the only bulklist_*path that did not use the_load_or_skipresilience pattern. A single corrupt or hand-editedpages/*.mdfile (missing frontmatter, bad YAML, mojibake) raised an unhandled exception and crashedvouch status,vouch lint,kb.search(substring/hybrid fallback), MCPkb.list_pages, and other core paths — whilelist_claims(),list_proposals(), etc. already skipped bad files with a warning.Fix: Add
_load_page_or_skip()mirroring_load_or_skipand use it inlist_pages(). One regression test added alongside the existing claim test.Impact: One bad page no longer takes down the entire KB listing surface; operators get a logged warning and the rest of the vault keeps working.
Reproduction (proof of crash on main)
From repo root on main (without this fix), after placing one corrupt page file:
On this branch, the same script returns
good-pageand lint/status complete (bad file skipped with a warning).Minimal manual repro:
Realistic corruption / failure modes (today)
.vouch/pages/*.mdand breaks frontmatterReaderError) — same class of bug_load_or_skipalready guards for claims/sourcesinvalid_claimin lint; pages lacked the equivalent skip-on-listThis PR does not introduce a new architectural layer — it brings
list_pages()to parity withlist_claims()/list_entities()/list_sources(). Agree v2.0 SQLite may change the storage model; until then files are the source of truth and one bad artifact should not 500 the review gate.Risk / tradeoffs
get_page(id)still raises for a targeted read — intentional, matchesget_claimsemantics.Test plan
test_list_pages_skips_unreadable_file(new)test_list_claims_skips_unreadable_filepython scripts/repro_list_pages_crash.py