Add post-dump plausibility gate returning status:degraded (#334)
Summary
- Adds a self-referential plausibility gate after
index_repositorycompletes: when persisted SQLite node rows fall far below the in-memory graph buffer count at dump time, returnstatus:"degraded"withexpected_nodes/expected_edgesinstead of silentstatus:"indexed". - Closes the observability gap left after #387 (WAL checkpoint on open/close) for cases where the store is partial or integrity-check auto-clean removes the DB.
Fixes #334 (design b as discussed in the issue thread).
Motivation
Rapid kill/restart cycles could leave status:"indexed" with a small fraction of the true node count. Maintainer agreed on design (b): compare persisted rows to extracted/committed rows (self-referential, no cross-repo assumptions).
Changes
src/foundation/dump_verify.c— purecbm_dump_verify_is_degraded()+CBM_DUMP_VERIFY_MIN_RATIOenv (default 0.5,0disables).src/pipeline/pipeline.c— capturecommitted_nodes/committed_edgesat dump; accessorcbm_pipeline_get_committed_counts.src/mcp/mcp.c— gate after successful pipeline; checkpoint+recount once; new response fields.tests/test_dump_verify.c— pure-function case matrix.tests/test_dump_verify_io.c— store I/O tests (realcbm_store_count_nodes, shortfall simulation, fork/crash WAL recovery).
Response shape
{
"project": "...",
"status": "degraded",
"nodes": 469,
"edges": 1200,
"expected_nodes": 5915,
"expected_edges": 9531,
"hint": "Persisted far fewer nodes than indexed — likely durability loss..."
}
isError remains false so partial graphs stay queryable. Downstream parsers that only require nodes/edges continue to work; new status is opt-in.
Design notes
- Nodes-only gate — edges legitimately shrink at dump when endpoints fail to resolve; comparing edge counts would false-trigger.
resolve_storeNULL (integrity auto-clean) →degradedwithnodes:0, not silentindexed.CBM_DUMP_VERIFY_MIN_RATIO=0disables the gate (escape hatch).committed_nodes = -1sentinel when dump did not run (explicit init;calloczero would be ambiguous).
Test plan
- [x]
make -f Makefile.cbm testgreen (5581 passed) - [x]
suite_dump_verifypure-function matrix - [x]
suite_dump_verify_iostore I/O + fork/crash WAL recovery (POSIX) - [ ] Manual: index repo, kill sibling mid-WAL, re-index →
status:"degraded"
Related
- Complements #387 / v0.7.0 WAL durability
Heads-up: this project now validates every PR automatically — tests, lint, security/license gates, and DCO sign-off (CONTRIBUTING.md). Your branch predates this, so CI will flag the missing Signed-off-by trailers. Fixing it is one command: git rebase --signoff origin/main && git push --force-with-lease. No other action needed — and thanks again for the contribution!
Built this on macOS arm64 and tested it against the 72k-LOC Rust repo from #333 (I'm the #333 reporter / #334 author). The design and the predicate are right, and the unit/IO tests are thorough — but I think the gate is currently inert in practice: it never trips, because committed_nodes is captured after the node index is already freed.
Root cause. dump_and_persist_hashes reads the committed count at pipeline.c:832, after cbm_gbuf_dump_to_sqlite() → release_and_remap_vectors() → release_gbuf_indexes() frees node_by_qn (graph_buffer.c:348). cbm_gbuf_node_count() then returns 0. Edges survive (edge_by_key is freed but edges.count isn't) — which is exactly why expected_edges looks right while expected_nodes comes back 0.
Observed on a healthy full index:
nodes: 13351 | expected_nodes: 0 | expected_edges: 50438
With committed_nodes = 0 ≤ CBM_DUMP_VERIFY_MIN_FLOOR, cbm_dump_verify_is_degraded() always returns false — so even a catastrophically partial index would still report status: "indexed", which is the silent-success this is meant to stop.
Two parts to it:
- Capture
committed_nodes/edgesbefore the dump. - The incremental path (
pipeline_incremental.c) never sets the committed count at all, so the gate is also disabled on incremental/reparse reindexes — which is the scenario #334 actually reproduces (repeatedindex_repositoryon an already-present index).
The existing tests pass because they feed the predicate synthetic committed values; an integration test that runs the real pipeline and asserts committed_nodes > 0 (and == persisted) catches it.
I have a patch for all three (capture-before-dump + incremental setter + that integration test) — built clean, full suite green (5,620 passing), DCO-signed. It fails on the current code (committed_nodes == 0) and passes after. Happy to open it as a PR (it builds on this branch) or drop the diff here — whatever you and @DeusData prefer.
@nguiaSoren This is a great catch, thank you for digging in this far.
I traced it through and you're spot on: dump_and_persist_hashes reads cbm_gbuf_node_count() at pipeline.c:832, which is after cbm_gbuf_dump_to_sqlite() has already run release_gbuf_indexes() and freed node_by_qn, so committed_nodes is always 0. With 0 <= CBM_DUMP_VERIFY_MIN_FLOOR the predicate short-circuits to false, and the gate never trips. Edges surviving the free is exactly why expected_edges looked plausible while expected_nodes came back 0, which I should have caught from my own response shape. The incremental path never setting the count is the more important miss, since that's the actual #334 repro.
You're also right about why my tests stayed green — they feed the predicate synthetic committed values, so the pure function is covered but the real pipeline wiring isn't. An integration test that runs the real pipeline and asserts committed_nodes > 0 && == persisted is the right guard.
Please go ahead and open the PR on top of this branch — capture-before-dump + incremental setter + the integration test all sound right, and it'd be good to have the test that fails on the current code. I'll happily defer to your fix here. Thanks again for the thorough writeup (and for testing it against the real 72k-LOC repo).
I have the following issue too
Thanks so much for this, @yangsec888 — the status:degraded post-dump plausibility gate you designed here is the foundation, and it's fully preserved (with your authorship) in #456, which additionally fixes a capture-ordering bug that would otherwise have left the gate permanently inert, and adds incremental-reindex coverage.
So I'm consolidating the #334 work on #456 and closing this one. Genuinely appreciate you building the gate — it's exactly the silent-success guard #334 needed. 🙏