Skip to content

fix: stamp graph provenance from the analysed repo, not the shell cwd - #2699

Closed
C0KERNEL wants to merge 1 commit into
Graphify-Labs:v8from
C0KERNEL:fix-extract-commit-stamp
Closed

C0KERNEL wants to merge 1 commit into
Graphify-Labs:v8from
C0KERNEL:fix-extract-commit-stamp

Conversation

@C0KERNEL

Copy link
Copy Markdown
Contributor

Fixes #2696.

graphify extract <target> run from another repo's working directory stamps the invoker's HEAD into the target's graph.json: the extract write path never passes built_at_commit, so to_json's fallback runs git rev-parse HEAD in the process cwd. cluster then preserves the extract-time stamp by design (#2534), so GRAPH_REPORT.md's "Built from commit" line can name a commit that does not exist in the repo it describes, and the staleness comparison the report suggests can never match. Batch-building several targets from one shell stamps the same foreign SHA into all of them.

This is the same cwd-anchoring mistake #2316 fixed for watch/update, surviving in the extract path. The fix closes both layers:

Test

tests/test_export.py::test_to_json_commit_fallback_uses_output_repo_not_cwd — builds two throwaway repos, chdirs into one, writes a graph into the other, and asserts the stamp is the target repo's HEAD. Fails before the patch (stamps the invoker), passes after.

uv run pytest tests/ -q: 4253 passed, 42 skipped; the 5 failures (test_ollama_retry_cap.py ×4, test_labeling.py::test_label_communities_batches_when_over_batch_size) are pre-existing on the untouched v8 tip and unrelated.

Running extract against a target from another repo's working directory
stamped the invoker's HEAD into the target's graph.json: the extract
write path never passed built_at_commit, so to_json's fallback ran
git rev-parse HEAD in the process cwd. cluster then preserves the
extract-time stamp by design (#2534), so GRAPH_REPORT.md's 'Built from
commit' line can name a commit that does not exist in the repo it
describes, and the staleness comparison the report suggests can never
match. Batch-building several targets from one shell stamps the same
foreign SHA into all of them.

Same cwd-anchoring mistake #2316 fixed for watch/update, surviving in
the extract path. Fix both layers: extract now passes the target's
HEAD explicitly, and to_json's fallback asks the repo containing
output_path instead of the cwd.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Formal verification. 1 change(s) tested, no difference found (not proven).


Graphify review — findings

This PR changes how git commit provenance is determined when writing a graph's graph.json. It adds an optional cwd parameter to export._git_head() so callers can specify which repository to query, and updates to_json()'s fallback to derive the commit from the output path's repo rather than the shell's current working directory. The CLI's extract dispatch path is also updated to explicitly stamp the target repo's HEAD, and a new test verifies the fallback uses the output repo's commit rather than the invoking repo's. The surface area touches graphify/cli.py (extract dispatch), graphify/export.py (_git_head signature and to_json fallback), and adds one test in tests/test_export.py. The diff also references a large set of renamed/reorganized symbols across these files.

No blocking issues surfaced. 2 lower-confidence candidates did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 566 functions depend on the 194 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: to_json() — 44 callers, 6 callees

Verification — 566 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: 523 function(s) in the blast radius were not formally verified this run

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: not verifiable: all 23 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 \_git\_head.

The verifier did not have enough to check \_git\_head, 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: parameter `cwd` is annotated `'str | Path | None'` — outside the synthesizable primitive/collection set

No difference found (not proven): No behavior difference found in to\_json (not a proof).

The verifier ran both versions of to\_json on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

· 1 more finding(s) on lines outside this diff (see the check run).

safishamsi added a commit that referenced this pull request Aug 13, 2026
Correctness (#2685 loop-binding shadow, #2699 provenance, #2707 affected
seed, #2688 py subpackage imports, #2602 sql grammar, #2683 cache
integrity, #2682 report basename) + Windows portability/docs batch.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.42 (graphifyy==0.9.42 on PyPI). Provenance stamped from the analysed repo, not the shell cwd (#2534 family). Credited in the release notes. Thanks @C0KERNEL!

@safishamsi safishamsi closed this Aug 13, 2026
@C0KERNEL
C0KERNEL deleted the fix-extract-commit-stamp branch August 14, 2026 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extract stamps the invoking repo's HEAD into built_at_commit when run against another repo

2 participants