Skip to content

No detection of a stale or partially-built graphify-out/ for git-tracked corpora #2841

Open

Description

@AutogenousEngine

Summary

The skill's only existing-graph check (top of SKILL.md) is "does graphify-out/graph.json exist," used to decide whether to take the query-only fast path. For a git-tracked corpus, this has two blind spots:

  1. Staleness: graph.json carries a built_at_commit field, but nothing compares it against the corpus's current HEAD before trusting an existing graph (fast path) or before starting a fresh build. A graph built at an old commit can be materially wrong — missing entire subsystems added since — while still passing every other health check.
  2. Interrupted runs: if a prior invocation reached Step 4 (graph built, report generated) but stopped before Step 5/6/9 (labeling, HTML export, cleanup), the graphify-out/ directory is left with orphaned .graphify_chunk_*.json / .graphify_extract.json / etc. temp files and a report full of generic Community N labels. Nothing in the skill detects or surfaces this state; a subsequent run (or a human) has to notice by inspection.

What happened

I found exactly this: an existing graphify-out/ with a fully-formed graph.json and GRAPH_REPORT.md, generic community labels, no HTML, and five leftover .graphify_*.json temp files. built_at_commit pointed to a commit from before a significant amount of subsequently-merged work — the existing graph was silently missing an entire subsystem. Diagnosing this took several manual steps (checking built_at_commit against git log, checking for an active writer process via lsof/ps, inspecting the detect.json file-type breakdown) that the skill gave no guidance for.

I chose to discard the existing state and rebuild fresh in an isolated worktree rather than trust or resume it, given the ambiguity.

Proposed fix

  • At the top of SKILL.md, before the fast-path check: if the corpus root is a git repository, compare graph.json's built_at_commit against git rev-parse HEAD (or the working tree's dirty state). If they differ, do not silently take the fast path — surface the staleness and suggest --update or a rebuild.
  • If graphify-out/ contains leftover .graphify_chunk_*.json / .graphify_extract.json / .graphify_ast.json / .graphify_semantic.json / .graphify_analysis.json at the start of a new invocation (i.e. before this run created them), that's diagnostic of an interrupted prior run. Surface this explicitly rather than letting Step 1-3 silently overwrite or ignore them.
  • This matters more than it might look: any workflow where multiple processes/sessions could plausibly invoke /graphify against a shared working directory (CI, multi-agent fleets, a team repo) will hit this.

Activity

  1. hopstreax commented on Aug 18, 2026

    @hopstreax
    Contributor

    I investigated this and implemented the proposed fix in phases.

    The implementation now:

    • detects stale graphs by comparing built_at_commit against the current git HEAD and relevant dirty-worktree changes
    • detects interrupted builds through leftover intermediate artifacts
    • distinguishes FRESH, STALE, INCOMPLETE, BUILDING, UNVERIFIABLE, and ABSENT states
    • integrates the state check into the skill's existing-graph fast path
    • adds a unified build-lock protocol with PID/token ownership, stale-lock recovery, and safe release
    • updates the generated platform skills and regression coverage

    The focused graph-state and skillgen suites are fully passing, and I also verified the existing lock tests against the new metadata-bearing lock format.

    I've opened a PR with the implementation: #<PR_NUMBER>.

    Happy to adjust the design or split anything further based on review.

  2. Sparrow-56 commented on Aug 29, 2026

    @Sparrow-56

    Hit this independently on 0.8.39 (AST-only build, git corpus). Two refinements on top of the state machine in the comment above, both from the shape of the failure I actually got.

    1. STALE is two states, and the remedies differ

    A comparison of built_at_commit against HEAD catches staleness but flattens two situations that need different handling:

    • built_at_commit is an ancestor of HEAD, N commits back. A valid older view of this line of development. Incremental --update is the right remedy.
    • built_at_commit is not an ancestor of HEAD. The graph was built on a branch that diverged — in my case, one that was abandoned and never merged. This is not an older view of the current tree, it is a view of a different tree.

    Mine was the second. The graph sat in the repo for five weeks pointing at a commit from a dead feature branch. Every existence check passed, and the content it described was work that never landed.

    Worth splitting out as its own state (DIVERGENT?) rather than folding into STALE, because I don't think --update recovers it: given #2908 (--update leaves stale nodes when files leave scan scope) and #2418 (post-merge phantom nodes are never healed), an incremental pass over a divergent graph seems likely to leave symbols from the abandoned branch behind. That case probably needs a full rebuild. Would be good to know whether the maintainers agree — if --update can reconcile it, this collapses back into one state and the point is moot.

    The test is one command:

    git merge-base --is-ancestor "$built_at_commit" HEAD
    built_at_commit vs HEAD State Remedy
    equal FRESH —
    ancestor, ≤ N commits FRESH (report the lag) optional --update
    ancestor, > N commits STALE --update
    not an ancestor DIVERGENT full rebuild
    not a commit in this repo UNVERIFIABLE full rebuild

    2. GRAPH_REPORT.md is a second consumer, and it currently prints the check instead of running it

    The comment above integrates the state check into "the skill's existing-graph fast path." Worth confirming the report generator moves with it, because every generated GRAPH_REPORT.md currently contains:

    ## Graph Freshness
    - Built from commit: `9c28a91c`
    - Run `git rev-parse HEAD` and compare to check if the graph is stale.
    - Run `graphify update .` after code changes (no API cost).

    The generator has built_at_commit, is running in the corpus, and emits a two-command comparison for the reader to perform by hand — then doesn't perform it.

    In practice nobody performs it. This file is read by an agent, and an agent reading line 2 has no reason to treat "run this and compare" as a precondition rather than as prose. That is exactly how mine went unnoticed: the report told every reader how to detect the problem, in the same section that contained the answer.

    Since the generator already holds both values, it could emit the verdict instead of the instructions:

    ## Graph Freshness
    - Built from commit: `9c28a91c`
    - **DIVERGENT** — not an ancestor of HEAD; this graph describes a different branch.
    - Rebuild before trusting it.

    Note this is not #2696 or #2534 — built_at_commit is stamped correctly in my case. The field is right; nothing consumes it.


    For what it's worth, I worked around this outside the tool, with a PreToolUse hook that runs the merge-base check and declines to endorse the graph when it fails. That works, but it means every user has to reimplement the check in their own hook config against a field the tool already writes — which is the argument for #2841 landing.

  3. munishjindal931 commented on Sep 10, 2026

    @munishjindal931

    A third case for the state table in the comment above: commit identity is the wrong predicate when graphify-out/ is tracked inside the corpus it indexes.

    Every row of that table compares built_at_commit to HEAD by ancestry. That holds when the graph lives outside the tree. When graphify-out/ is committed — the only way the graph shows up in review diffs — the index can never name its own commit: committing the rebuilt graph moves HEAD one past the stamp it just wrote. The stamp is therefore permanently an ancestor, and that lag is structural rather than evidence of anything.

    Concretely, on 0.9.54 with a tracked graphify-out/ and the convention of a separate reindex commit:

    stamp = 64f7c15   HEAD = 081e4a5
    
    git rev-parse HEAD                                    → differs  → "stale"
    git diff 64f7c15 HEAD -- . ':(exclude)graphify-out'   → empty    → nothing indexed changed
    

    Against the table that classifies as ancestor, ≤ N commits → FRESH (report the lag) — the right verdict for the wrong reason, and it decays. Both commits between those two SHAs touched nothing but graphify-out/ (a reindex and a label refresh), and a repo whose post-commit hook reindexes routinely accumulates them without bound, pushing the count past any fixed N into STALE with no source having changed. There is no correct N, because the quantity being thresholded is not a measure of staleness.

    The fix is to stop asking about commits and ask about content:

    git diff --quiet "$built_at_commit" -- . ":(exclude)${GRAPHIFY_OUT:-graphify-out}"

    Exit 0 is fresh. Three properties the ancestry check doesn't have:

    • No threshold. It answers exactly "has any indexed path changed since the build," which is the actual question.
    • It catches uncommitted edits. Diffing against the working tree rather than a second rev means a dirty tree registers. A HEAD-to-HEAD comparison misses that entirely — the first comment lists "relevant dirty-worktree changes" as a separate concern, and this collapses it into the same command. Verified both ways: appending a line to a tracked source file flips it to stale, reverting flips it back.
    • It subsumes DIVERGENT. On a divergent branch the diff is non-empty, so it reports stale with no merge-base call. Keeping git merge-base --is-ancestor is still worthwhile to name that state, since divergence wants a full rebuild rather than --update — but as a classifier applied after the freshness verdict, not as the verdict itself.

    On GRAPH_REPORT.md printing the check rather than running it: agreed, and worth noting the printed check carries this same defect, so emitting a verdict fixes both halves at once. I've patched report.py locally to emit the source-scoped command instead of the rev-parse instruction, which is the shape I'd suggest, but it belongs inside whatever state-machine work lands here rather than as a change of its own.

    One caveat against my own suggestion: the exclusion is graphify-out by convention and GRAPHIFY_OUT by configuration, but a graph written elsewhere via --out is covered by neither at report time. Deriving the excluded path from the actual output directory would be more robust than reading the env var.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions