Skip to content

fix(watch): quick-scan Markdown that detect() classifies as a paper (#4750) - #4751

Closed
jaimemartinez wants to merge 2 commits into
Graphify-Labs:v8from
jaimemartinez:fix/update-ast-scan-paper-markdown
Closed

jaimemartinez wants to merge 2 commits into
Graphify-Labs:v8from
jaimemartinez:fix/update-ast-scan-paper-markdown

Conversation

@jaimemartinez

@jaimemartinez jaimemartinez commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #4750 with the reporter's preferred option (1): documents that detect() classifies as paper and that have an AST extractor (.md, .mdx, .qmd today) now get the same quick-scan as other documents in the AST-only rebuild.

classify_file reclassifies a text document as paper when its first 3,000 characters match _PAPER_SIGNAL_THRESHOLD of the _PAPER_SIGNALS (an arXiv id, "arxiv" and an "Abstract" heading are enough). _rebuild_code, the path behind graphify update and the git hooks, reads only the code and document buckets. So those notes got zero nodes, with no warning, while a near-identical file kept its heading structure.

The change feeds detected['files']['paper'] through the same _get_extractor filter that document files already go through:

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

Invariant: an AST-only rebuild represents every text document it can parse, independent of whether detect() labels it document or paper. A doc that already has semantic nodes is never quick-scanned on top of them.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

test_rebuild_code_quick_scans_markdown_classified_as_paper (tests/test_watch.py) builds a corpus with the issue's two files plus a PDF stub. It first asserts the precondition that paper_notes.md lands in detect()'s paper bucket, then checks three things after a full _rebuild_code:

  • paper_notes.md has nodes;
  • plain_notes.md is unchanged;
  • scan.pdf has none.

The test fails on unmodified v8 with paper-classified Markdown got zero nodes (#4750).

test_rebuild_code_does_not_quick_scan_semantic_backed_paper_markdown (full and incremental rebuild, added after review) seeds a semantic layer for a paper-classified .md and asserts that no AST heading nodes are added on top and the node count is unchanged. I checked that the full-rebuild case fails if the #1915 gate is disabled. The incremental case passes even then, because the incremental path has its own semantic-doc exclusion.

Limitations: the classification itself is unchanged. A paper-like .md is still labelled paper in detect() output and still goes through paper handling in the full /graphify pipeline. This PR only stops the AST-only rebuild from dropping it. Options 2 (an opt-out setting) and 3 (a warning) from the issue are not needed once the file is represented.

How was this tested?

Windows 11, Python 3.10, uv sync, on v8 at 92741d1.

uv run pytest tests/test_watch.py -k "paper or quick_scan"  # 4 passed
uv run pytest tests/test_watch.py -q                       # 193 passed, 9 skipped
uv run pytest tests/test_watch.py tests/test_build.py tests/*paper*.py tests/*update*.py tests/*incremental*.py tests/*semantic*.py -q
    # 416 passed, 10 skipped, 2 failed
uv run ruff check graphify/watch.py tests/test_watch.py    # All checks passed
uv run pyright graphify/watch.py tests/test_watch.py       # 33 errors, the same 33 as on unmodified v8; none in the changed lines

The 2 failures are test_code_only_update_follows_its_paragraph_and_merges_the_new_function (2 params). They also fail on unmodified v8 on this machine, and the test doesn't touch this code path.

Manual repro from the issue, using PYTHONHASHSEED=0 python -m graphify update .:

  • before: plain_notes.md 3 nodes, paper_notes.md 0;
  • after: both have 3 nodes.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (not applicable: no skill fragments touched)
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

…raphify-Labs#4750)

A .md/.txt whose opening text matches enough _PAPER_SIGNALS (an arXiv id,
"arxiv", an Abstract heading) is classified as `paper`, and the AST-only
rebuild behind `graphify update` and the hooks read only the `code` and
`document` buckets. Such notes got zero nodes, silently, while an
otherwise identical file kept its heading structure.

Feed the `paper` bucket through the same AST-extractor filter as
documents. Binary papers (PDF) have no AST extractor and stay out; a
paper that already has a semantic layer is still excluded from the
quick-scan by the Graphify-Labs#1915 gate, so nothing is double-represented.
@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Oct 25, 2026
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @jaimemartinez. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.

Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 not verified).

Formal verification. PR-changed functions: 0/1 verified (0 proven, 0 may-equivalent, 0 distinguished) · 1 not verified (1 unsupported).

Not verified on this run: \_rebuild\_code (unsupported).


Graphify review — findings

Fixes AST-only rebuilds giving zero nodes to Markdown/text files that detect() reclassifies as papers (e.g. notes quoting an arXiv abstract). _rebuild_code now runs the same doc quick-scan over the paper bucket as over document, and the _get_extractor filter still keeps PDFs and other binary papers out. Adds a regression test (#4750) covering a paper-classified .md, a plain .md, and a PDF.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 799 functions depend on the 505 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: _rebuild_code() — 188 callers, 60 callees

Verification — 799 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 570 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

26 of 453 test file(s) selected (6%) via static blast radius.

  • tests/test_cache_stale_import_target.py — impact
  • tests/test_compact_graph_json.py — impact
  • tests/test_elixir_import_resolution.py — impact
  • tests/test_elixir_qualified_calls.py — impact
  • tests/test_elixir_unqualified_call_scope.py — impact
  • tests/test_export_direction.py — impact
  • tests/test_external_stub_endpoints.py — impact
  • tests/test_incremental_unscanned_placeholders.py — impact
  • tests/test_java_member_calls.py — impact
  • tests/test_kotlin_grammar.py — impact
  • tests/test_labeling.py — impact
  • tests/test_language_override_lifecycle.py — impact
  • tests/test_lost_saved_semantic_nodes.py — impact
  • tests/test_markdown_code_spans.py — impact
  • tests/test_no_cluster_undeclared_endpoints.py — impact
  • tests/test_pr10_watch_overrides.py — impact
  • tests/test_python_inherited_method_calls.py — impact
  • tests/test_python_property_reads.py — impact
  • tests/test_python_pytest_fixture_receivers.py — impact
  • tests/test_rust_use_trees.py — impact
  • tests/test_skill_persisted_scan_options.py — impact
  • tests/test_solidity_inherited_calls.py — impact
  • tests/test_terraform_modules.py — impact
  • tests/test_watch.py — impact, changed-test
  • tests/test_watch_identity_cache.py — impact
  • tests/test_watch_manifest_location.py — impact

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Formal verification

Could not verify: Could not verify \_rebuild\_code.

The verifier did not have enough to check \_rebuild\_code, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: nondeterministic output (both versions disagreed with themselves on the witness) — not a behaviour change; a function whose output is not a function of its inputs (random / time / uuid / os.urandom, or state carried across calls) cannot be soundly distinguished by execution, so this tier abstains for the whole function

· 1 more finding(s) on lines outside this diff (see the check run).

@nothariharan nothariharan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified this solves #4750. I ran the issue's repro and the semantic-layer interaction against this branch (0c5e62e) and v8 (92741d1).

Issue repro

paper_notes.md  v8: 0 nodes  ->  this PR: 3 nodes
plain_notes.md  v8: 3 nodes  ->  this PR: 3 nodes

Exit 0, no warning, same as the issue.

What I also checked

  • A scan.pdf in the same corpus stays out, because _get_extractor returns None for PDFs.
  • The #1915 gate holds: I turned a paper-classified .md into a semantic-backed doc (removed _origin, set file_type="paper", source_location=None), ran update again, and no AST heading layer was added on top. The semantic nodes were preserved unchanged.
  • tests/test_watch.py -k "paper or quick_scan": 2 passed.
  • CI is green on 3.10, 3.12, 3.13, and 3.14.

One non-blocking note

The PR body says .md/.txt files are quick-scanned, but only .md, .mdx, and .qmd have an AST extractor in this tree. _get_extractor returns None for .txt, .rst, and .html, so a paper-classified .txt still gets zero nodes on update. That matches the stated invariant ("every text document it can parse") and is not a regression from v8, but the .txt wording is inaccurate.

Optional: add a regression test for the semantic-backed paper case, so the #1915 interaction is locked in and not just the plain-paper case. Not a blocker.

Approving.

…er Markdown (Graphify-Labs#4750)

Review follow-up on Graphify-Labs#4751. A paper-classified .md that already has a
semantic layer must not gain an AST heading layer now that papers enter
the quick-scan; cover the full and incremental rebuild. Also correct the
comment: only formats with an AST extractor (.md/.mdx/.qmd today)
qualify, so a paper-classified .txt still gets no nodes, as on v8.
@jaimemartinez

Copy link
Copy Markdown
Contributor Author

Thanks for verifying this, @nothariharan. Both points are addressed in daf0be4:

  • .txt wording: you're right; only .md/.mdx/.qmd have an AST extractor here. I corrected the PR description and the code comment. A paper-classified .txt still gets no nodes, as on v8, and the description now says so.
  • Semantic-backed paper test: added test_rebuild_code_does_not_quick_scan_semantic_backed_paper_markdown, for both the full and the incremental rebuild. With the watch._rebuild_code produces a ~4× bloated graph vs graphify . --update — AST-scans Markdown docs, then merges preserved semantic nodes on top #1915 gate disabled, the full-rebuild case fails with AST layer added on a semantic-backed paper: {'paper_notes', 'paper_notes_abstract', 'paper_notes_notes_on_a_paper'}. The incremental case still passes, because that path has its own semantic-doc exclusion.

tests/test_watch.py: 193 passed, 9 skipped.

@bercedev bercedev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New test fails on v8 and passes here. test_rebuild_code_prunes_deleted_file_nodes fails in my run too, but it fails the same way on v8, so it's not from this change. Running paper through the existing _get_extractor filter keeps PDFs and .txt out, as the comment says. LGTM.

safishamsi pushed a commit that referenced this pull request Oct 26, 2026
…4750)

Review follow-up on #4751. A paper-classified .md that already has a
semantic layer must not gain an AST heading layer now that papers enter
the quick-scan; cover the full and incremental rebuild. Also correct the
comment: only formats with an AST extractor (.md/.mdx/.qmd today)
qualify, so a paper-classified .txt still gets no nodes, as on v8.

(cherry picked from commit daf0be4)
@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.96, now on PyPI (pip install graphifyy==0.9.96). Markdown that detect() classifies as a paper is quick-scanned. Thanks for the fix, @jaimemartinez.

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

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

graphify update silently skips .md files classified as paper (no option to disable)

4 participants