fix(detect): clear stale semantic_hash for dispatched-but-omitted files (#1948)
Fixes #1948.
save_manifest's seed loop copied every on-disk manifest row verbatim for files still alive on disk, with no way to distinguish "never touched this run" from "dispatched this run but omitted from the result". So a doc whose chunk the LLM dropped on a --force re-run kept its stale semantic_hash from the earlier successful run, detect_incremental(kind="semantic") reported it unchanged, and the #1890 re-run promise silently never happened — exactly the failure this issue describes, and what the manual "blank the hash by hand" workaround was compensating for.
Change
save_manifest()(graphify/detect.py) gains a keyword-onlyclear_semanticset: for any file in it, the seed loop forcessemantic_hashto""instead of inheriting the prior run's value. Defaults toNone(no-op) — every existing caller and the #917/#1908 seed/prune behaviors are unchanged (guard tests pass unmodified).cli.pyderives the set assemantic_filesminus_stamped_manifest_files()'s result — i.e. dispatched this run but not stamped, regardless of why.semantic_filesis what was actually sent to the backend (narrowed by the incremental gate and--code-only, widened by deep mode), so untouched live files are never in the set and a partial incremental run cannot blank the rest of the corpus's stamps.- The set is threaded through all three
_save_manifestcall sites.
Review note (why the derivation matters)
An earlier draft of this branch derived the set from files_by_type (the full live corpus). Adversarial review before pushing caught that this wipes semantic_hash for every unchanged file on any partial incremental run — forcing a full-corpus re-extraction on the next run, which would have been worse than the bug. The committed version derives from the dispatched subset and adds an end-to-end regression test for exactly that scenario.
Tests
- Unit:
test_save_manifest_clear_semantic_erases_stale_hash_for_omitted_file(red before the detect.py change, green after), plus the seven pre-existing seed/prune guards, unmodified. - End-to-end (new):
test_incremental_partial_run_preserves_untouched_semantic_hash— full-scan run stamps two docs, a second incremental run dispatches only the changed one (asserted via the captured dispatch list), and the untouched doc'ssemantic_hashmust survive inmanifest.json. Red on thefiles_by_typederivation, green on the committed one. - Suites:
test_extract_cli.py+test_extract_code_only_cli.py+test_detect.py+test_build.py→ 226 passed. Full suite: 3269 passed; the 15 failures intest_ollama_retry_cap.py/test_skillgen.pyare pre-existing on a clean v8 checkout (verified byte-identical before/after).
🤖 Generated with Claude Code