Skip to content

AST extraction emits source_location=L1 for zero-byte source files (unsatisfiable provenance anchor) #4041

Closed

Description

@geraldymakosso-cpu

Summary

AST extraction emits a provenance anchor for zero-byte source files:

source_file  = empty.py
file_type    = code
_origin      = ast
source_location = L1

empty.py is 0 bytes / 0 lines, so L1 designates a line that does not exist. The anchor is unsatisfiable by construction: it can neither be resolved nor rejected by reading the file.

Versions tested

version behavior
graphifyy 0.9.72 reproduces
graphifyy 0.9.74 reproduces (identical)

Behavior is identical on both versions — 0.9.74 does not change it.

Minimal fixture

Two files, one of them empty:

fixture/
  empty.py      0 bytes
  witness.py    VALUE = 1

Commands

graphify extract ./fixture --out ./out --code-only

Expected result

empty.py contains no code, so it should produce no code node. A file with 0 lines cannot carry a source_location.

Actual result

wrote graph.json: 2 nodes, 0 edges, 2 communities

Nodes emitted:

id=empty     file_type=code  _origin=ast  source_file=empty.py    source_location=L1
id=witness   file_type=code  _origin=ast  source_file=witness.py  source_location=L1

witness.py has 1 line, so L1 is correct there. Only the zero-byte file produces the impossible anchor.

Why L1 is invalid for a 0-byte file

source_location is a provenance anchor: it must designate a line that actually exists in the target file. For a 0-byte file:

  • the file has 0 lines;
  • L1 designates a non-existent line;
  • no line range is valid, so no anchor can be emitted at all.

Any provenance validator that compares source_location against the real file length will reject this. The node is therefore unusable for provenance purposes regardless of how the validator is configured.

Impact

Affects any project containing zero-byte Python files — in practice, any Python package, since __init__.py files are frequently empty. Because the anchor is provably unsatisfiable, such nodes block strict provenance validation of the whole graph.

Suggested fixes

Any one of these would resolve it:

  1. do not emit a node for a 0-byte file;
  2. emit the node without source_location;
  3. emit the node as file_type=file instead of code.

Environment

graphify 0.9.72 / 0.9.74
Python 3.13
Windows

Activity

  1. github-actions commented on Oct 3, 2026

    @github-actions

    Thanks for opening this issue, @geraldymakosso-cpu. 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.

  2. Mpasha17 commented on Oct 4, 2026

    @Mpasha17
    Contributor

    @geraldymakosso-cpu have you picked up this task already?

  3. added
    good first issue
    help wanted
    on Oct 4, 2026
  4. added a commit that references this issue on Oct 5, 2026
    1f078a3
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

    good first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions