Repository navigation
perf(update): re-extract only the files whose content changed (#4800) - #4801
Deepjyoti-Sarmah wants to merge 5 commits into
Conversation
|
Thanks for the pull request, @Deepjyoti-Sarmah. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic. |
|
Thanks @Deepjyoti-Sarmah! One small thing: our changelog and release notes are built from PR titles, so we use the conventional-commits format, for example: Prefixes we use: |
There was a problem hiding this comment.
Graphify reviewed this change.
Worth a look — the grounded gate found no coupling regressions or blocking issues, but 2 advisory finding(s) below merit a look before merge.
Not checked: tests were not run; formal verification proved 0 of 3 changed function(s) (3 not verified).
Formal verification. PR-changed functions: 0/3 verified (0 proven, 0 may-equivalent, 0 distinguished) · 3 not verified (1 vacuous, 2 unsupported).
Not verified on this run: dispatch\_command (vacuous: never exercised), detect\_incremental (unsupported), \_rebuild\_code (unsupported).
Graphify review — findings
Makes graphify update re-extract only files whose content differs from the manifest, so a warm tree costs what changed instead of the whole corpus. _rebuild_code takes a new incremental flag that derives the change set from the manifest inside the lock. An explicit changed_paths list still wins, --force still forces a full rebuild, and a missing, unreadable or empty manifest falls back to the full path. A queued full rebuild overrides it, and an incremental request no longer writes a .pending_full marker. That makes the lock-held path the risky one, since the request has nothing queued to replay. Extracts classify_manifest_deletions from detect_incremental so the watcher shares the logic that separates genuinely deleted manifest rows (file gone from disk) from rows excluded by a changed ignore rule. Callers must pass every row they expect to see, including resolution_inputs, or those rows read as excluded on every run.
Worth a look
- Incremental request dropped when per-repo lock is held —
graphify/watch.py:1979· Escalate · high- NOT verified (no proof, no reproducing execution) — needs human review
- absolute_identity evaluated before the empty source_file guard —
graphify/watch.py:2403· Escalate · medium- NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 4013 functions depend on the 382 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
_rebuild_code()— 222 callers, 68 callees - worse:
load_manifest()— 17 callers, 5 callees - worse:
classify_manifest_files()— 4 callers, 5 callees
Verification — 4013 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 2517 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
120 of 466 test file(s) selected (26%) via static blast radius.
tests/test_affected_cli.py— impacttests/test_agents_platform.py— impacttests/test_astro_extraction.py— impacttests/test_atomic_writes.py— impacttests/test_backend_opt_in.py— impacttests/test_binary_media_words.py— impacttests/test_build.py— impacttests/test_cache_stale_import_target.py— impacttests/test_cargo_introspect.py— impacttests/test_charmap_encoding.py— impacttests/test_chunking.py— impacttests/test_cjs_module_extension.py— impacttests/test_claude_cli_backend.py— impacttests/test_cli_export.py— impacttests/test_cloud_cta.py— impacttests/test_codebuddy.py— impacttests/test_compact_graph_json.py— impacttests/test_dedup_shrink_refuses_force_write.py— impacttests/test_detect.py— impacttests/test_devin.py— impacttests/test_docx_to_markdown.py— impacttests/test_dotnet.py— impacttests/test_ejs_extractor.py— impacttests/test_elixir_import_resolution.py— impacttests/test_elixir_qualified_calls.py— impacttests/test_elixir_unqualified_call_scope.py— impacttests/test_evidence_binding.py— impacttests/test_explain_cli.py— impacttests/test_explain_same_file_tie.py— impacttests/test_export_direction.py— impacttests/test_ext_tagged_id_clash.py— impacttests/test_external_stub_endpoints.py— impacttests/test_extract.py— impacttests/test_extract_cli.py— impacttests/test_extract_cost_ledger.py— impacttests/test_file_slice.py— impacttests/test_file_truncation_warning.py— impacttests/test_global_add_tag_inference.py— impacttests/test_god_nodes_cli.py— impacttests/test_hollow_chunks_arm_shrink_guard.py— impacttests/test_hook_guard_token_match.py— impacttests/test_hook_nudge_wording.py— impacttests/test_hook_out_of_project_paths.py— impacttests/test_hook_strict.py— impacttests/test_ignore_file_encoding.py— impacttests/test_image_vision.py— impacttests/test_import_extension_resolution.py— impacttests/test_incomplete_build_guard.py— impacttests/test_incremental_mtime_collision.py— impacttests/test_incremental_unscanned_placeholders.py— impact- … and 70 more
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Docs that may be stale (advisory)
graphify/skill-agents.md§ Step 9 - Save manifest, update cost tracker, clean up, and report (lines 626-735): references changed symbols_corpusgraphify/skill-aider.md§ Step 9 - Save manifest, update cost tracker, clean up, and report (lines 706-788): references changed symbols_corpusgraphify/skill-amp.md§ Step 9 - Save manifest, update cost tracker, clean up, and report (lines 626-735): references changed symbols_corpusgraphify/skill-claw.md§ Step 9 - Save manifest, update cost tracker, clean up, and report (lines 629-738): references changed symbols_corpusgraphify/skill-codex.md§ Step 9 - Save manifest, update cost tracker, clean up, and report (lines 630-739): references changed symbols_corpusgraphify/skill-copilot.md§ Step 9 - Save manifest, update cost tracker, clean up, and report (lines 629-738): references changed symbols_corpusgraphify/skill-devin.md§ Step 9 - Save manifest, update cost tracker, clean up, and report (lines 824-907): references changed symbols_corpusgraphify/skill-droid.md§ Step 9 - Save manifest, update cost tracker, clean up, and report (lines 626-735): references changed symbols_corpusgraphify/skill-kilo.md§ Step 9 - Save manifest, update cost tracker, clean up, and report (lines 629-738): references changed symbols_corpusgraphify/skill-kiro.md§ Step 9 - Save manifest, update cost tracker, clean up, and report (lines 629-738): references changed symbols_corpus
…and 10 more.
Formal verification
Could not verify: Could not verify dispatch\_command.
The verifier did not have enough to check dispatch\_command, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 40 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly SystemExit — names the real obstacle, not a sampling gap)
Could not verify: Could not verify detect\_incremental.
The verifier did not have enough to check detect\_incremental, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: nondeterministic output (both versions disagreed with themselves on the witness) — not a behaviour change; a function whose output is not a function of its inputs (random / time / uuid / os.urandom, or state carried across calls) cannot be soundly distinguished by execution, so this tier abstains for the whole function
Could not verify: Could not verify \_rebuild\_code.
The verifier did not have enough to check \_rebuild\_code, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: nondeterministic output (both versions disagreed with themselves on the witness) — not a behaviour change; a function whose output is not a function of its inputs (random / time / uuid / os.urandom, or state carried across calls) cannot be soundly distinguished by execution, so this tier abstains for the whole function
· 3 more finding(s) on lines outside this diff (see the check run).
0ea45d7 to
83f6fb8
Compare
|
Landed in 0.9.102 (published to PyPI), cherry-picked with your authorship preserved. Verified the incremental graph is identical to a full re-extract. Fixes #4800. Thanks @Deepjyoti-Sarmah. |
#4801 made _rebuild_code's no-change gate read the process-wide stat index, so across the full suite a warm index left by an earlier test (thousands of roots hashed in one process) could serve a stale hash and make a rebuild skip re-extraction - failing watch/reconcile tests nondeterministically depending on ordering. Add an autouse conftest fixture that resets the stat index to its cold init state before each test (#3989: cross-root callers in one process must use a fresh process; a real update/extract always does). Product behavior unchanged. Co-Authored-By: Claude Opus 4.8 <[email protected]>
What does this PR do?
Fixes #4800.
graphify updatepays for the whole corpus however little changed.0.9.96 shipped the zero-change half (#4748): an untouched tree returns at the gate in
1.96 s. Change one file and the run costs 68.15 s again, because the gate can only
answer "all unchanged" or "not all unchanged", and nothing derives which files
differ.
Seven stages run, and only the first two read source text:
Everything downstream works on the graph, so a two-file edit paid for all seven
stages. This PR gives
updatea change set:On the issue's corpus (1,059 scanned files, one process per run): 68.15 s and
1,071 MB becomes 48.72 s and 537 MB. The stages after extraction still work over
every node, which is why this is 19 seconds and not 66. That is called out under
Limitations rather than buried.
The manifest already stores a content hash per file, and
_rebuild_codehas takenchanged_pathssince the hook work. The only caller that ever passed one was git:post-commitdiffs HEAD and forwards the touched paths.updatepassed nothing,which the function documents as "the full code corpus". So the missing piece was a
change set that does not depend on git. It is written with paths relative to the
scan root, so a copied checkout carries a usable baseline.
The rule the change set is built on
A false "changed" costs time. A false "unchanged" ships a graph that describes code
the reader no longer has. Every uncertain answer therefore resolves to "changed":
rsync --timesmoves mtime with identical bytes; a same-second rewrite leaves it putFive commits
The split is deliberate. The refactor is behaviour-neutral and provable as such.
The capability is default-off, so the watcher and the post-checkout hook are
untouched. The CLI flag is its own commit, so reverting it returns
updatetofull-corpus while the capability stays.
The commit subjects say
#4740, the umbrella issue this work started under. This PRfixes #4800, its scoped successor. #4748 already landed the gate this branch sits on.
Two of the commits are correctness fixes, and the new caller is what exposed them.
Deriving a change set means only the changed files are parsed, so a call from a
changed file into an unchanged one can lose its edge (#2406/#3763). v8 answers that
by passing the unchanged corpus's AST nodes as resolution context. Commit
2de3b0d0fixes the case where that context came back empty: the membership test anchored
stored paths via
identity(), which resolves against the tree recorded ingraphify-out/.graphify_root, while the set it was compared against was built withabsolute_identity(..., project_root). On a copied checkout the marker still namesthe original tree, so every stored node read as corpus-absent. Two lines, same
anchoring on both sides.
The stacked PR
_rebuild_codecan lose the per-repo lock. The other two request kinds record whatthey could not do, in
.pending_fulland.pending_changes. A manifest-derivedrequest names no paths, so before that PR it records nothing and returns the same
Falsethat a queued request returns. That PR adds.pending_incremental.It is latent today: every non-blocking caller passes explicit paths, and
updateblocks on the lock. So this PR is complete on its own for the CLI path, and the stack
closes the hole for a future non-blocking incremental caller. I would rather say that
than let a reviewer find it.
Type of change
Verification & Invariants
A partial rebuild is sound only if its key covers every input that reaches the graph,
and the cost of being wrong is asymmetric: over-reporting costs time, under-reporting
ships a stale graph.
Merge Danger
Door: two-way. No schema, cache-key or file-format change. Reverting the CLI
commit alone returns
updateto full-corpus rebuilds.Blast Radius: moderate, because this decides what gets re-extracted:
plus a matching manifest row. Everything else falls back to the full path.
shrink guard can attribute the loss.
incrementaldefaults to off, so the watcher, the post-checkout hook and everyexisting caller keep the full path.
detect_incrementalcalls the factoredhelpers with the same arguments; I checked the output matches the inline version on
a corpus with an edit, a delete and an add, for both
kind="ast"andkind="semantic".--forcestill means a full rebuild. An explicitchanged_pathsstill wins overthe derived set.
here). The change set is only computed when the gate declines.
Limitations
still work over every node, so 68 s becomes 49 s rather than seconds. On this
corpus the JS/TS resolution pass re-parses the TypeScript files too, because those
suffixes bypass the AST cache on purpose. That remaining half is the rest of [Bug]: one edited file still costs a full rebuild, so a warm graphify update goes from 2 s back to 68 s #4800.
On 1,059 files it keeps one sourceless
anynode and seven edges that a fullrebuild drops. This is not introduced here: v8 with an explicit
changed_pathsproduces the same node and edges. It is pre-existing
changed_pathsbehaviour thatthis PR makes reachable from the CLI.
corpus containing one can never reach the pure-skip case. This repository has one
(
worked/rsl-siege-manager/graph.json), which is whygraphify update .here stillre-extracts a handful of files.
graphify-out/.graphify_rootstill names the original tree, so stored source pathsresolve there and the fail-closed sweep reads the removed file as alive-out-of-scan
and preserves it. The full path behaves identically, so this predates the PR; it is
why this branch's deletion test uses a same-directory tree.
graphify update(AST) only.
graphify extractalready had its own incremental mode.read against a scan that already happened.
How was this tested?
tests/test_update_incremental.pyis new and has 17 tests. Fifteen drive the real_rebuild_codewith a spy onextract(): an unchanged copied checkout, two editedfiles reduced to the changed subset, an mtime bump with identical bytes, an added
file, a deleted file and the eviction that follows, the default path,
--force, anexplicit
changed_paths, a missing manifest, an unreadable manifest, a manifestanchored elsewhere, incremental output equal to a full rebuild on the same tree, the
lock path, the non-blocking queue behaviour, and a cross-file call edge surviving an
incremental update both in place and on a copied checkout. Two run the real CLI as a
subprocess:
updateend to end, andupdate --force.The assertion in
test_default_is_the_full_pathis the one that had to change tocoexist with the 0.9.96 gate, and a test that passes in both worlds can be vacuous,
so I checked it. The corpus now carries one change before the second run, which is
sound either way: a correct no-change gate cannot skip a tree that changed. Mutating
the derivation guard in a scratch copy to fire even when
incrementalis unset makesit fail, with and without the gate:
Gates, all with
PYTHONPATHset to the repo sosys.executable -m graphifychildrenload this tree rather than the installed package:
Wall time and peak RSS for
graphify update, one process per run, on 1,059 scannedfiles (583 code), the same tree and the same two-file edit in both rows:
dac06345)The unchanged case is unchanged by this PR, because the gate answers it first:
1.96 s and 46 MB.
Not tested: Windows. The change set uses paths from
detect()and the manifest'sexisting anchoring rules, and nothing here adds new path construction.
Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. (N/A: no skill fragments touched.)