Skip to content

AST-only update drops EXTRACTED code→semantic edges (watch.py sem_edges filter) #3763

Open

Description

@rcruzp

Summary

On an AST-only rebuild (graphify update / the watch path), watch.py preserves semantic nodes (any node with file_type != "code") but only preserves edges whose confidence is INFERRED/AMBIGUOUS or whose both endpoints are non-code. As a result, EXTRACTED edges that connect a code node to a preserved semantic node (e.g. a script node → an external service/database node) are silently dropped on every update, even though both endpoints remain in the graph.

Impact

Cross-file semantic relationships (script → external system, code → doc concept) vanish on the next graphify update, so the graph loses information the semantic pass had already extracted. They only come back after another full semantic run. This is easy to miss because the update still prints a successful rebuild.

Reproduction

  1. Build a graph with a semantic pass that adds, for example:
    • node Salient_Cloud_SFTP with file_type: document (any non-code type)
    • edge script_py -> Salient_Cloud_SFTP with confidence: EXTRACTED
  2. Run graphify update ..
  3. The node survives; the edge is gone.

sem_nodes keeps anything non-code, so the node persists. sem_edges requires source not in code_ids and target not in code_ids, so a code→semantic edge fails the predicate and is discarded.

Relevant code

graphify/watch.py (AST-only merge, preserving semantic nodes/edges):

code_ids = {n["id"] for n in existing.get("nodes", []) if n.get("file_type") == "code"}
sem_nodes = [n for n in existing.get("nodes", []) if n.get("file_type") != "code"]
sem_edges = [e for e in existing.get("links", existing.get("edges", []))
             if e.get("confidence") in ("INFERRED", "AMBIGUOUS")
             or (e.get("source") not in code_ids and e.get("target") not in code_ids)]

Suggested fix

Keep any edge attached to a preserved semantic node:

code_ids = {n["id"] for n in existing.get("nodes", []) if n.get("file_type") == "code"}
sem_nodes = [n for n in existing.get("nodes", []) if n.get("file_type") != "code"]
sem_ids = {n["id"] for n in sem_nodes}
sem_edges = [e for e in existing.get("links", existing.get("edges", []))
             if e.get("confidence") in ("INFERRED", "AMBIGUOUS")
             or e.get("source") in sem_ids
             or e.get("target") in sem_ids
             or (e.get("source") not in code_ids and e.get("target") not in code_ids)]

I verified locally that this keeps code→semantic EXTRACTED edges across an AST-only rebuild.

Related observations

  • graphify/validate.py::validate_extraction only warns and never coerces or rejects invalid values, and graphify/build.py prints only real_errors[0]. So many invalid file_type values can accumulate and stay invisible. In one real corpus the single reported error hid 83 issues (71 invalid file_type, 6 missing file_type, 6 edges missing source_file).
  • The shipped skill prompt defines file_type as code|document|paper|image (e.g. skill-windows.md, skill-codex.md, skill-trae.md). That vocabulary omits rationale, which the validator accepts, and is not enforced, so models emit ad-hoc values (python, doc, concept, service, database). Aligning the prompt with VALID_FILE_TYPES (and mentioning rationale) would prevent most of these.

Activity

  1. SrijanSriv commented on Oct 5, 2026

    @SrijanSriv
    Contributor

    i checked on v8 at 35adf43. graphify update keeps Salient_Cloud_SFTP and the EXTRACTED edge from the script node. the confidence filter in the issue is not in watch.py anymore. we can safely close this issue

    cc: @safishamsi

  2. omsenjalia commented on Oct 18, 2026

    @omsenjalia
    Contributor

    This looks fixed on the v8 branch by 4ac5f07e (fix(watch): preserve semantic edges of re-extracted sources (#1865)). Could a maintainer confirm and close?

  3. ayushcodes10 commented on Oct 20, 2026

    @ayushcodes10
    Contributor

    Checked this against current v8 (b90b9df7) and the bug no longer reproduces — it looks fixed as a side effect of the tier-aware merge rewrite in 4ac5f07 (#1865) and 97656fa (#2333/#2334/#2336), neither of which cites this issue.

    watch.py's reconciliation no longer filters preserved edges by confidence/file_type the way the quoted snippet does. It now stamps every item with _origin ("ast" or "semantic", backfilled for legacy items via _is_ast_tier's shape fallback — a source_location of L<line> means AST, anything else means semantic) and only drops a semantic-tier edge when its owning source is actually deleted/excluded; AST-tier edges are additionally dropped when their source was re-extracted this run. Confidence and endpoint file_type play no part in that decision any more, so an EXTRACTED code→semantic edge (stamped _origin: semantic since it carries no AST line location) now survives an AST-only incremental update exactly like an INFERRED one does.

    Reproduced directly: built a real graph for a script.py + notes.md corpus, hand-added a script_run --uses(EXTRACTED)--> Salient_Cloud_SFTP edge (mirroring the shape in the issue) with the semantic node's backing file physically present on disk, then ran an incremental graphify extract . --code-only after adding an unrelated other.py. Both the semantic node and the EXTRACTED edge survived in graphify-out/graph.json, now carrying _origin: semantic.

    The two "related observations" in the issue (validate.py only warning on invalid file_type, and the shipped skill prompts' file_type vocabulary omitting rationale) are separate from the primary bug and still worth a look, but I didn't investigate those — just the edge-drop bug itself, which is already resolved. Not opening a PR; closing this out as already fixed, unless the related observations should stay open as their own issue.

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