Skip to content

_check_shrink cannot fire on a full rebuild: rebuilt_sources is the entire corpus #3579

Open

Description

@turzail-png

Environment

  • graphifyy 0.9.42
  • Windows 11, Python 3.13, git 2.53.0.windows.1

Summary

On a full-corpus rebuild, _check_shrink can never refuse a write. The #479 shrink protection is structurally absent on exactly the code path the warning text recommends as the remedy ("Run a full rebuild (/graphify .) to be safe").

Mechanism

watch.py:1406-1414, inside _rebuild_code:

if changed_paths is None:
    rebuilt_sources = {
        _nsf(str(p.relative_to(project_root)), _rebuilt_root)
        for p in code_files if p.is_relative_to(project_root)
    }
else:
    rebuilt_sources = {(_nsf(str(p), _rebuilt_root) or str(p)) for p in extract_targets}

On a full rebuild rebuilt_sources is every code file in the corpus.

watch.py:889-901, inside _check_shrink:

if rebuilt_sources is not None:
    ...
    def _accounted(n: dict) -> bool:
        sf = n.get("source_file")
        if sf and failed_sources and _norm_source_file(sf) in failed_sources:
            return False
        return (not sf
                or sf in rebuilt_sources
                or _norm_source_file(sf) in rebuilt_sources)
    if all(_accounted(n) for n in lost):
        return True

A node is "accounted" when it has no source_file or its source_file is in rebuilt_sources. On a full rebuild both halves of that disjunction cover the entire node set, so all(_accounted(n) for n in lost) is always true and the guard returns True unconditionally. The only escape is failed_sources, i.e. a source whose AST extraction raised. A source that extracts "successfully" but yields nothing is not in failed_sources, and that is precisely the silent-shrink class the guard exists to catch.

Impact

A full rebuild that loses thousands of nodes to a silently-empty extraction pass writes them away with no warning and no refusal. The per-source accounting added for #1116 (so a legitimate delete does not need --force) is correct for the incremental path but degenerates to "always allow" for the full path.

Suggested direction

On a full rebuild, treat a source as accounting for its lost nodes only when it actually produced output this run (or is genuinely gone from disk), rather than merely having been scanned. rebuilt_sources as "the whole corpus" is not evidence that any particular loss was intentional.

Filed alongside a separate report of an incremental rebuild that zeroed 168 files and also got past this guard.

Activity

  1. turzail-png commented on Sep 15, 2026

    @turzail-png
    Author

    Related: #3580, an incremental rebuild that lost 1588 nodes and also got past _check_shrink.

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