graphify icon indicating copy to clipboard operation
graphify copied to clipboard

save_manifest(kind="ast") blanks a valid semantic_hash stamped by kind="semantic" (content unchanged)

Open nathanschram opened this issue 2 months ago • 1 comments

Summary

save_manifest(kind="ast") blanks a still-valid semantic_hash when the previous write was kind="semantic" on content edited since the last AST stamp — with no content change in between.

kind="semantic" sets semantic_hash = h but carries the old ast_hash forward. The next AST-only write (graphify update, or any watch.py refresh) then compares the current hash against that stale ast_hash, sees a mismatch, and writes semantic_hash = "". detect_incremental(kind="semantic") then re-queues a doc that was just extracted.

Version: graphifyy 0.9.43 (graphify/detect.py, save_manifest, the else branch of if kind in ("semantic", "both"), ~L1950).

Repro

import json, os
from graphify.detect import save_manifest

open("a.md", "w").write("v1\n")
f = {"document": [os.path.abspath("a.md")]}
save_manifest(f, "m.json", kind="both")        # ast_hash = semantic_hash = H1
open("a.md", "w").write("v2\n")
save_manifest(f, "m.json", kind="semantic")    # semantic_hash = H2, ast_hash still H1
save_manifest(f, "m.json", kind="ast")         # content unchanged since the semantic stamp
print(json.load(open("m.json")))               # semantic_hash == ""  <-- stamp lost

Expected: semantic_hash == H2 (the content is exactly what was semantically extracted). Actual: semantic_hash == "".

Impact

In a split pipeline (a nightly AST graphify update plus a separate semantic pass that stamps kind="semantic"), every doc edited between the two passes loses its semantic stamp on the next AST refresh. We saw a clean pass report "38 docs semantically stamped" and a freshness check read 33 of them stale two hours later.

Proposed fix (2 lines)

Preserve the semantic stamp when the current content matches either the prior semantic hash or the prior AST hash:

# detect.py, save_manifest, AST-only branch
prev_sem = prev.get("semantic_hash", "")
entry["semantic_hash"] = prev_sem if h in (prev_sem, prev.get("ast_hash", "")) else ""

Happy to open a PR with a regression test if that's welcome.

Downstream tracking: littlebearapps/auditor-toolkit#3102

nathanschram avatar Sep 27 '26 01:09 nathanschram

Thanks for opening this issue, @nathanschram. A maintainer will take a look soon.

If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

github-actions[bot] avatar Sep 27 '26 01:09 github-actions[bot]