[Bug]: changed-files rebuild (hook/watch) evicts placeholder nodes for files that were never scanned

Đã đóng Phù hợp với người mới
#4,160 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

  • #4161 của @rohit-jsfreaky — đã đóng, không merge

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
85/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Lỗi nằm ở logic quét tập ngữ liệu của hàm _reconcile_existing_graph; bắt đầu từ đó để sửa đổi kiểm tra loại bỏ cho các đường dẫn nguồn bị thiếu. Sử dụng manifest.json của lần quét trước (chỉ được ghi lại sau khi quá trình đối chiếu kết thúc) làm bằng chứng xóa: chỉ loại bỏ đường dẫn bị thiếu nếu nó có mặt trong manifest cuối cùng, nếu không giữ lại các nút giữ chỗ cho các tệp chưa từng được quét. Chạy script repro.py được cung cấp để xác nhận các nút giữ chỗ và các cạnh của chúng được giữ lại trong các lần tái tạo tệp đã thay đổi, khớp với đầu ra của tái tạo toàn bộ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug
Pre-flight checks
  • I have checked the Troubleshooting section in the README
What happened?

An extractor can mint a node for a file that is not in the checkout: the target of an unresolved dynamic import (import('./queue.js')), or a project a .sln / .slnx / <ProjectReference> names. The node carries the missing path as its source_file, but it is the referring file's output (label ./queue.js, edges only from the referrer).

On a changed-files rebuild (_rebuild_code(changed_paths=...), used by the post-commit hook and graphify watch), the corpus sweep in _reconcile_existing_graph reads that missing path as a deleted source and evicts the node. The unchanged referrer's preserved edges to it then dangle and are dropped. A full rebuild of the same tree keeps both, so after every hook or watch rebuild the graph silently differs from a full rebuild, and it flips back on the next graphify update.

This goes against CONTRIBUTING ("Cross-file edges: must be preserved during incremental updates") and against the intent of #1795 ("require deletion evidence before evicting a missing source"): a path that was never scanned has no deletion evidence.

On graphify's own repo (975 files, v8 5c7b847), editing one unrelated file and running the changed-files rebuild loses 8 nodes and 15 edges compared with a full rebuild of the same tree: the placeholders for tests/fixtures/dynamic_import.ts's missing ./queue.js, ./mayaEngine.js, ./staticHelper, and the .csproj projects sample.sln, sample.slnx and sample.csproj reference.

Related to #3570 (same symptom class); the commenters there found that cause fixed by 32b209a, and this is a different mechanism that still reproduces on 0.9.77.

Steps to reproduce
cat > repro.py <<'EOF'
import json, tempfile
from pathlib import Path
from graphify.watch import _rebuild_code

def placeholder(c):
    g = json.loads((c / "graphify-out/graph.json").read_text(encoding="utf-8"))
    nodes = [n["id"] for n in g["nodes"] if n.get("source_file", "").endswith("queue.js")]
    edges = [(e["source"], e["relation"]) for e in g["links"] if e["target"] in nodes]
    return nodes, edges

if __name__ == "__main__":
    c = Path(tempfile.mkdtemp()) / "corpus"; c.mkdir()
    (c / "app.ts").write_text("export async function load() {\n  return import('./queue.js');\n}\n")
    (c / "other.ts").write_text("export function other() {\n  return 1;\n}\n")
    _rebuild_code(c, no_cluster=True, acquire_lock=False, force=True)
    print("full rebuild:              ", placeholder(c))
    (c / "other.ts").write_text("export function other() {\n  return 2;\n}\n")
    _rebuild_code(c, changed_paths=[Path("other.ts")], no_cluster=True, acquire_lock=False, force=True)
    print("changed-files (other.ts):  ", placeholder(c))
    _rebuild_code(c, no_cluster=True, acquire_lock=False, force=True)
    print("full rebuild, same tree:   ", placeholder(c))
EOF
PYTHONHASHSEED=0 python repro.py
Error output or graph output
full rebuild:               (['queue'], [('app_load', 'imports_from'), ('app', 'dynamic_import')])
changed-files (other.ts):   ([], [])
full rebuild, same tree:    (['queue'], [('app_load', 'imports_from'), ('app', 'dynamic_import')])

On graphify's own repo, after a one-file edit: changed-files rebuild 18,617 nodes / 37,920 edges vs full rebuild of the same tree 18,625 / 37,935.
Graphify version

0.9.77 (5c7b847)

Operating System

Windows

Python Version

3.12

Installation Method

built from source (git clone)

Additional Environment Details

AST-only, no provider environment variables, PYTHONHASHSEED=0. A clean checkout of v8 at 5c7b847 reproduces it. Found while comparing changed-files and full rebuilds of graphify's own repo.

Additional context

Fix ready: use the previous scan (manifest.json, rewritten only after reconcile) as the deletion evidence. A missing path that was in the last scan is evicted as before; one that was never scanned is kept while a referrer that is not re-extracted this run still points at it. No manifest: old behaviour. PR right after this.

Ngôn ngữ chính
Python
Star
124k
Fork
11.9k
Merge trung bình
1 giờ 26 phút
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Graphify-Labs/graphify

Tất cả issue của Graphify-Labs/graphify

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.