graphify icon indicating copy to clipboard operation
graphify copied to clipboard

fix(detect): clear stale semantic_hash for dispatched-but-omitted files (#1948)

Open alphanury opened this issue 4 months ago • 0 comments

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-only clear_semantic set: for any file in it, the seed loop forces semantic_hash to "" instead of inheriting the prior run's value. Defaults to None (no-op) — every existing caller and the #917/#1908 seed/prune behaviors are unchanged (guard tests pass unmodified).
  • cli.py derives the set as semantic_files minus _stamped_manifest_files()'s result — i.e. dispatched this run but not stamped, regardless of why. semantic_files is 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_manifest call 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's semantic_hash must survive in manifest.json. Red on the files_by_type derivation, 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 in test_ollama_retry_cap.py/test_skillgen.py are pre-existing on a clean v8 checkout (verified byte-identical before/after).

🤖 Generated with Claude Code

alphanury avatar Jul 16 '26 23:07 alphanury