Skip to content

fix(skill): a dispatched file with no coverage entry is unread, not complete - #4680

Closed
Kalessin-Roke wants to merge 1 commit into
Graphify-Labs:v8from
Kalessin-Roke:fix/skill-unreported-file-is-unread
Closed

Kalessin-Roke wants to merge 1 commit into
Graphify-Labs:v8from
Kalessin-Roke:fix/skill-unreported-file-is-unread

Conversation

@Kalessin-Roke

Copy link
Copy Markdown

What does this PR do?

Follow-up to #3987 (landed in 0.9.93 for #2225), as discussed in #3987 (comment).

Step B3.5 compares each file's reported coverage with its real length, so a file a subagent never reported is not checked ("A file a subagent did not report at all is not counted as partial"). That is the failure I hit in practice: a subagent never opened 4 of 12 files and still emitted 19 INFERRED nodes for them, guessed from their file names. Those nodes were merged, cached as a complete entry and stamped, so no later --update retried the files.

Changes:

  • graphify.cache.drop_unreported_chunk_sources(out_dir, root) (new). Every dispatched file in .graphify_uncached.txt that is not an image (graphify.detect.IMAGE_EXTENSIONS), is non-empty on disk and has no positive coverage count is unread. What the chunk files attribute to it is dropped by source_file, not by id (a file that was read can mint the same deterministic id). Edges/hyperedges from read files are dropped only when they point at an id that no kept chunk node, AST node (.graphify_ast.json) or cached node (.graphify_cached.json) still carries. It returns the unread files.
  • Step B3.5 calls it (4 added lines, so the lean core stays under its 800-line budget at 797) and writes partly-read and unread files to .graphify_partial.txt in the same write. The existing fix(skill): a partly-read file is no longer a silent, permanent loss #3987 partial/unstamped path then retries them. Because it is one script, there is no new step to run in the right order.
  • Both extraction-spec variants now ask for a coverage entry for EVERY FILE_LIST path (0 = never opened, with nothing emitted for it), forbid nodes derived from a file name, and say to report pages for a PDF so a fully read PDF is not mistaken for an unread one.

A chunk that has no coverage map at all (a producer predating the contract, or a subagent that ignored it entirely) is not judged: its files keep their items, as before. Only a missing entry in a run that does report coverage is treated as unread.

Type of change

  • Bug fix

Verification & Invariants

Invariant: a file whose text no subagent read must not end up cached or stamped as complete, and nothing guessed from its name may enter the graph. Items from files that were read, including ones sharing an id with an unread file, are untouched.

  • Old failure, shown on unmodified origin/v8 steps (B3.5 + merge + cache) with the test fixture: the guessed node is in the merged output, and on the next run check_semantic_cache re-dispatches only the 0-count file, so the never-reported file stays cached as complete. With this PR both are re-dispatched and the guessed items are gone.
  • New tests in tests/test_skillgen.py (the step tests execute the rendered python, like the existing Skill-path extraction silently truncates files >2000 lines; replace-on-re-extract then deletes the unread tail #2225 tests):
    • test_drop_unreported_chunk_sources_drops_by_source_file_and_returns_unread: never-reported and 0-count files returned; image, empty and deleted files not; shared-id node from the read file kept; AST-target edges kept, including one whose id the unread file also guessed; idempotent.
    • ..._without_a_dispatch_list_is_a_no_op, ..._ignores_chunks_without_a_coverage_contract, ..._leaves_a_chunk_without_coverage_unjudged.
    • test_coverage_step_flags_unreported_files_alongside_partly_read_ones: one write holds both kinds of flag, each once.
    • test_an_unreported_file_is_retried_instead_of_cached_as_complete: end to end through the real B3.5, merge and save_semantic_cache / check_semantic_cache.
    • test_extraction_specs_require_a_coverage_entry_for_every_file: both spec variants.
  • All of them fail without the fix (the end-to-end one on the old behaviour itself).

Limitations / not in this PR

  • PDFs in B3.5 (pre-existing): B3.5 counts the raw lines of the file, which for a binary PDF is meaningless (373,597 for one real 12-page PDF here), so any count a subagent reports for a PDF flags it partial and it is re-dispatched every run. Left for a separate issue; this PR only makes sure a read PDF is not treated as unread.
  • A malformed chunk file or a non-numeric coverage value raises in B3.5 (already true before this PR, since B3.5 parses every chunk and calls int() on every count).
  • .graphify_partial.txt can name a file twice if the FILE_LIST spelling and the .graphify_uncached.txt spelling of its path differ; harmless, since both resolve to one file downstream.
  • Happy to move the helper or its unit tests (e.g. into tests/test_partial_cache.py) if you prefer a different home.
  • A byte cap per chunk (the ~197 KB / 1,864-line chunk from the comment above) is a separate concern and not included.

How was this tested?

Windows 11, Python 3.12 (uv, --all-extras), branch off upstream/v8 at c588b72.

uv run python -m tools.skillgen --bless
uv run python -m tools.skillgen --check / --audit-coverage / --schema-singleton / --monolith-roundtrip / --always-on-roundtrip   all OK
uv run --frozen pytest tests -q          7 failed, 8452 passed, 132 skipped (clean v8 here: the same 7 failed, 8445 passed)
uv run --frozen ruff check .             All checks passed!
uv run --frozen pyright                  657 errors, identical count on clean v8; none in the new function

These 7 failures fail identically on a clean v8 checkout on this Windows machine (watch/memoization/hooks/C-include tests); none touch the changed code. Not run on Python 3.10 / 3.13 or on Linux/macOS locally.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments.
  • 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.
  • I disclosed AI authorship in my commit messages.

🤖 Generated with Claude Code

…omplete

Step B3.5 (Graphify-Labs#2225) compares each file's reported coverage with its real
length, so a file the subagent never reported was not checked at all. A
subagent that never opened a file could still emit nodes for it, guessed
from its name; those were merged, cached as a complete entry and stamped,
so no later --update retried the file.

Add graphify.cache.drop_unreported_chunk_sources(): a dispatched,
non-empty, non-image file with no positive coverage count is unread. What
the chunks attribute to it is dropped by source_file (never by id, since a
file that was read can mint the same deterministic id); edges and
hyperedges from read files are dropped only when they point at an id no
kept chunk node, AST node or cached node still carries. A chunk with no
coverage map at all is not judged. Step B3.5 calls it and writes partly
read and unread files to .graphify_partial.txt in one write, so the
existing partial/unstamped path retries them.

Both extraction-spec variants now ask for a coverage entry for every
FILE_LIST path (0 = never opened, with nothing emitted), forbid nodes
derived from a file name, and ask for pages read for a PDF.

Follow-up to Graphify-Labs#3987.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @Kalessin-Roke. 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; no formal proof of the changed code.


Graphify review — findings

Adds drop_unreported_chunk_sources, which treats a dispatched, non-empty, non-image file with no positive coverage entry as never opened. It drops the nodes, edges and hyperedges guessed for that file from the chunk JSON, and returns the file so it is re-dispatched on the next --update. Items are matched by source_file rather than id, files in chunks that carry no coverage map are left unjudged, and with no coverage map anywhere the check does nothing, so older producers are unaffected. Wires the check into the coverage step of every platform skill template (agents, amp, claw, kilo, kiro and the rest) and the matching generated fragments and expected outputs. The snippet merges unread files into .graphify_partial.txt, prints a separate warning with the dropped-item count, and suppresses the "Coverage OK" message when anything was unread. Replaces the old note that unreported files are "not counted as partial" with the #2225 behaviour, and updates the skillgen tests to match the regenerated skill text.

Review partial — this diff was larger than one review pass covers, so later files were not reviewed; some findings may be missing.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 3609 functions depend on the 1060 functions this change touches.

Health — this change adds coupling hotspots:

  • new: _unreported_fixture() — 6 callers, 4 callees
  • new: drop_unreported_chunk_sources() — 5 callers, 4 callees
  • new: test_an_unreported_file_is_retried_instead_of_cached_as_complete() — 0 callers, 6 callees

Verification — 3609 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: 2300 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

443 of 443 test file(s) selected (100%) via static blast radius.

Escalated to a full run for safety — the selection is not trustworthy on its own (see below). CI should run the whole suite.

  • tests/pi.test.ts — full-run-safety
  • tests/test_affected_cli.py — full-run-safety
  • tests/test_affected_defines.py — full-run-safety
  • tests/test_affected_member_seed.py — full-run-safety
  • tests/test_affected_overrides.py — full-run-safety
  • tests/test_agents_platform.py — full-run-safety
  • tests/test_alias_folding.py — full-run-safety
  • tests/test_analyze.py — full-run-safety
  • tests/test_anthropic_custom_endpoint.py — full-run-safety
  • tests/test_antigravity_install.py — full-run-safety
  • tests/test_apm_fallback_version.py — full-run-safety
  • tests/test_architecture_doc.py — full-run-safety
  • tests/test_astro_extraction.py — full-run-safety
  • tests/test_astro_import_ids.py — full-run-safety
  • tests/test_atomic_canvas_export.py — full-run-safety
  • tests/test_atomic_version_stamp.py — full-run-safety
  • tests/test_atomic_writes.py — full-run-safety
  • tests/test_backend_env_isolation.py — full-run-safety
  • tests/test_backend_extras.py — full-run-safety
  • tests/test_backend_opt_in.py — full-run-safety
  • tests/test_benchmark.py — full-run-safety
  • tests/test_benchmark_raw_graph.py — full-run-safety
  • tests/test_benchmark_real_query.py — full-run-safety
  • tests/test_blade_extractor.py — full-run-safety
  • tests/test_build.py — full-run-safety
  • tests/test_build_located_semantic_identity.py — full-run-safety
  • tests/test_build_merge_dedup_scope.py — full-run-safety
  • tests/test_build_merge_hyperedges_and_prune.py — full-run-safety
  • tests/test_build_merge_shrink_guard.py — full-run-safety
  • tests/test_builtin_global_type_refs.py — full-run-safety
  • tests/test_c_include_resolution.py — full-run-safety
  • tests/test_cache.py — impact, full-run-safety
  • tests/test_cache_stale_import_target.py — impact, full-run-safety
  • tests/test_callflow_html.py — full-run-safety
  • tests/test_cargo_introspect.py — full-run-safety
  • tests/test_cargo_missing_manifest.py — full-run-safety
  • tests/test_carried_hyperedge_remap.py — full-run-safety
  • tests/test_case_sensitive_resolution.py — full-run-safety
  • tests/test_charmap_encoding.py — impact, full-run-safety
  • tests/test_chunking.py — impact, full-run-safety
  • tests/test_cjs_module_extension.py — full-run-safety
  • tests/test_claude_cli_backend.py — full-run-safety
  • tests/test_claude_md.py — full-run-safety
  • tests/test_cli_broken_pipe.py — full-run-safety
  • tests/test_cli_export.py — full-run-safety
  • tests/test_cli_help.py — full-run-safety
  • tests/test_cloud_cta.py — full-run-safety
  • tests/test_cluster.py — full-run-safety
  • tests/test_cluster_ambiguous_scale.py — full-run-safety
  • tests/test_cluster_exclude_hubs.py — full-run-safety
  • … and 393 more

non-code file(s) changed (graphify/skill-agents.md, graphify/skill-amp.md, graphify/skill-claw.md, graphify/skill-codex.md, graphify/skill-copilot.md …) → running the full suite for safety (a code graph can't see config/fixture/data deps)

changed code file(s) with no mapped test (graphify/skill-agents.md, graphify/skill-amp.md, graphify/skill-claw.md, graphify/skill-codex.md, graphify/skill-copilot.md …) — a coverage gap or a missing link — running the full suite rather than only the selected tests

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.

Docs that may be stale (advisory)

…and 10 more.

· 3 grounded finding(s) anchored inline below.

Comment thread graphify/cache.py
return saved


def drop_unreported_chunk_sources(out_dir: Path, root: Path) -> tuple[list[str], int]:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — drop_unreported_chunk_sources()

high coupling complexity (Ca·Ce = 20).

Grounded coupling-delta finding (deterministic), not an LLM guess.

Comment thread tests/test_skillgen.py
# chunks attribute to that file by source_file and flags it partial so it is retried
# (graphify.cache.drop_unreported_chunk_sources).

def _unreported_fixture(tmp_path: Path) -> dict:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — _unreported_fixture()

6 callers depend on it (afferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

Comment thread tests/test_skillgen.py
assert len(flagged) == len(set(flagged)), f"a file was flagged twice: {flagged}"


def test_an_unreported_file_is_retried_instead_of_cached_as_complete(tmp_path, capsys, monkeypatch):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — test_an_unreported_file_is_retried_instead_of_cached_as_complete()

fans out to 6 callees (efferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

safishamsi added a commit that referenced this pull request Nov 14, 2026
…ge step

#4680 was authored before the #4762 injection hardening, so its B3.5
Python block passed a quoted `Path('INPUT_PATH')` literal to
drop_unreported_chunk_sources. That is the exact substitution pattern
#4762 removed: a scan root whose name holds a quote or `$()` could break
out and run as code. Use the `INPUT_PATH` variable the block already
reads from the trusted graphify-out/.graphify_root sidecar, and
regenerate the skill artifacts. Caught by
test_skillgen_input_path_injection.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Landed on v8 as dcf438f via authorship-preserving cherry-pick, released in graphify 0.9.109. Thanks @Kalessin-Roke. (Maintainer follow-up: the B3.5 step was updated to read the scan root from .graphify_root rather than a quoted INPUT_PATH literal, to keep the #4762 injection hardening.)

@safishamsi safishamsi closed this Nov 14, 2026
@Kalessin-Roke

Copy link
Copy Markdown
Author

Follow-up now that this shipped in 0.9.109 (thanks for landing it).

One case this PR left open on purpose, and I now think that was the wrong call: a chunk file with no coverage key at all is exempted (unjudged in drop_unreported_chunk_sources, pinned by test_drop_unreported_chunk_sources_leaves_a_chunk_without_coverage_unjudged). B3.5's line check sees nothing for it either. So in a mixed run, where the other chunks do report coverage, every node that chunk guessed is cached as a complete extraction.

Minimal fixture against 0.9.123: three 3-line files; a.md sits in a chunk with coverage, while b.md and c.md sit in a chunk without one.

drop_unreported_chunk_sources(out, root)   -> ([], 0)               # b.md and c.md pass
after deleting the coverage-less chunk     -> (['b.md', 'c.md'], 0)

Why I'd now treat those files as unread:

  • Since 0.9.93 the spec asks for a coverage entry for every FILE_LIST path. A missing map in a run where other chunks have one is a broken chunk, not an older producer. The existing early return (no chunk has coverage at all) still covers the older-producer case.
  • The two errors cost different amounts. Dropping a chunk that was in fact read costs one retry on the next --update, but a guessed node that is kept is never caught.
  • It matches how fix(skill): coverage, chunk-parse, stale-extract and directed-explain bugs in skill templates (#5340) #5351 (item 2) handles an invalid chunk: warn, remove it, leave its files unstamped so they are retried.

Suggested change: drop the unjudged exemption whenever at least one chunk reports coverage, and flip that test. I'm happy to send the PR if you agree.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants