fix(pipeline): make the #334 plausibility gate fire (capture committed_nodes before dump)
Summary
Builds on #433 (the status:degraded plausibility gate by @yangsec888) and fixes a capture-ordering bug that left the gate inert — it never tripped, so a catastrophically partial index would still report status: "indexed", the exact silent-success #334 set out to stop. @yangsec888 reviewed the finding and deferred to this fix (https://github.com/DeusData/codebase-memory-mcp/pull/433#issuecomment-4696991094).
Closes #334. Supersedes #433 (its gate commit is included here with authorship preserved).
The bug
dump_and_persist_hashes read the committed node count at pipeline.c after cbm_gbuf_dump_to_sqlite(), which runs release_and_remap_vectors() → release_gbuf_indexes() and frees node_by_qn (graph_buffer.c:348). cbm_gbuf_node_count() therefore returned 0. With committed_nodes = 0 ≤ CBM_DUMP_VERIFY_MIN_FLOOR, cbm_dump_verify_is_degraded() short-circuits to false.
Edges survive the free (edge_by_key is freed, but edges.count is not), which is why a healthy full index reported a plausible expected_edges while expected_nodes came back 0:
nodes: 13351 | expected_nodes: 0 | expected_edges: 50438
Separately, the incremental path (pipeline_incremental.c) never set the committed count at all, so the gate was also disabled on incremental/reparse reindexes — the scenario #334 actually reproduces (repeated index_repository on an already-present index).
The fix
pipeline.c— capturecommitted_nodes/committed_edgesbefore the dump.pipeline_incremental.c+pipeline_internal.h— record committed counts on the incremental path via a newcbm_pipeline_set_committed_counts()(the incremental unit cannot see the opaquecbm_pipelinestruct).tests/test_pipeline.c—pipeline_committed_counts_match_persisted: drives the real pipeline and assertscommitted_nodes > 0and== persisted. The existingdump_verifytests feed the predicate synthetic values, so they cover the pure function but not the pipeline wiring; this test fails on the pre-fix code and passes after.
Verification
- Built clean on macOS arm64 (
scripts/build.sh). - After the fix, a healthy full index reports
expected_nodes == nodeson both the full and incremental paths (was0before). - Full suite green:
scripts/test.sh→ 5,620 passing, including the new test. - The new test fails on the current code (
committed_nodes == 0) and passes after, so it genuinely guards the regression.
All commits are DCO signed-off.
Friendly ping on this — CI is green across all platforms (tests, lint, security, DCO) and @yangsec888 has signed off on the approach. Happy to rebase or adjust anything if it'd help it land. No rush, and thanks!
Glad you're back to these! Whenever you have a moment, #456 is green and ready — it fixes the inert-gate issue in the #334 plausibility check. Thanks!
Thanks @nguiaSoren — this is the version we want for #334: it fixes the inert-gate bug (capturing committed_nodes before the dump frees the index) and adds incremental-path coverage, and it reviewed clean. It currently conflicts with main, though — could you rebase on latest main? I'll merge as soon as it's conflict-free. 🙏
Rebased on latest main, conflict-free now (only overlap was an include line). CI re-running; should be green shortly. Thanks!