Repository navigation
fix(skill): a partly-read file is no longer a silent, permanent loss - #3987
nothariharan wants to merge 1 commit into
Conversation
The Read tool returns at most 2000 lines per call and reports no error when it truncates, so a subagent that read only the head of a long file still writes a well-formed chunk. Step B3 treated "chunk exists and parses" as success, and because build_merge replaces a re-extracted file's nodes, the unread tail was not merely missed: it was deleted, the run reported success, and the manifest recorded the file as done so no later --update retried it. On a 4165-line file that left 103 nodes covering 31% of the document, with 90 of 131 entries gone and the manifest treating it as finished. Three changes, in the fragments, so all thirteen disk-dispatching hosts pick them up from one edit: The extraction spec (verbose and compact) now states the cap and forbids emitting nodes for a partly-read file, and asks the subagent to report a top-level "coverage" map of file -> lines read. A short count is recoverable; a missing entry is indistinguishable from a complete read, which is why the machine check needs the prompt to ask. Step B1 bounds a chunk by total lines as well as file count (20-25 files AND ~6000 lines), and gives any file past 2000 lines a chunk to itself. File count alone was only half the mechanism: a subagent holding 25 files also dilutes attention, which is how a 590-line plan came back with zero nodes. Step B3.5 compares each reported coverage against the file's real length, names what was short, and hands the list to the two places that decide whether a file is ever looked at again: save_semantic_cache(partial_source_files=...) stamps those entries partial, which load_cached treats as a miss, and _stamped_manifest_files(partial_source_files=...) leaves them unstamped so detect_incremental re-queues them. Both are the existing contract the library path already uses for a truncated LLM response (Graphify-Labs#933, Graphify-Labs#1950), so the skill and library paths now recover the same way. Nodes already found for those files are kept; the next run's replace-on-re-extract swaps them for a complete set. The check is fail-safe in the direction that loses nothing: no coverage reported means no file is flagged, and a flagged file is re-read rather than trusted. Codex collects subagent results in memory with no per-chunk files on disk, so it gets the prompt-layer fix but not the Step B3.5 gate; its inline extraction has no chunk file to compare against. Tests execute the emitted python instead of matching its source (the Graphify-Labs#2126/Graphify-Labs#2641 convention), including a round trip through the real semantic cache: the partly-read file must come back as uncached, while the fully-read file still hits. Reverting the fix makes that round trip return an empty uncached list - the file served from cache forever, which is the bug. Fixes Graphify-Labs#2225
|
Thanks for the pull request, @nothariharan. 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. |
There was a problem hiding this comment.
Graphify reviewed this change.
Worth a look — the grounded gate found no coupling regressions or blocking issues, but 3 advisory finding(s) below merit a look before merge.
Graphify review — findings
Tightens the generated skill's semantic-extraction chunking so each chunk is capped at ~6000 total lines as well as 20-25 files, and a file over 2000 lines (the Read tool's single-call cap) gets a chunk to itself. Adds a Step B3.5 that compares each subagent's self-reported coverage against the file's real line count and warns about files that were only partly read. Those files keep their extracted nodes but go to save_semantic_cache as partial_source_files and stay unstamped in _stamped_manifest_files, so the next --update re-dispatches them instead of serving a truncated extraction forever (#2225).
Worth a look
- Coverage verifier treats files with missing coverage entries as complete —
graphify/skill-claw.md:316· Escalate · medium- agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
- Partial-file paths are never normalized before the cache and manifest filters —
graphify/skill-agents.md:315· Escalate · medium- agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
- Coverage verifier line-counts binary/image chunks as UTF-8 text —
graphify/skill-codex.md:314· Escalate · medium- agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
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 — 941 functions depend on the 941 functions this change touches.
Health — this change adds coupling hotspots:
- new:
test_audit_catches_a_dropped_non_allowlisted_heading()— 0 callers, 6 callees
Verification — 941 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: 941 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
312 of 312 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/test_affected_cli.py— full-run-safetytests/test_affected_member_seed.py— full-run-safetytests/test_agents_platform.py— full-run-safetytests/test_analyze.py— full-run-safetytests/test_anthropic_custom_endpoint.py— full-run-safetytests/test_antigravity_install.py— full-run-safetytests/test_apm_fallback_version.py— full-run-safetytests/test_architecture_doc.py— full-run-safetytests/test_astro_extraction.py— full-run-safetytests/test_astro_import_ids.py— full-run-safetytests/test_atomic_canvas_export.py— full-run-safetytests/test_atomic_version_stamp.py— full-run-safetytests/test_atomic_writes.py— full-run-safetytests/test_backend_env_isolation.py— full-run-safetytests/test_backend_extras.py— full-run-safetytests/test_benchmark.py— full-run-safetytests/test_benchmark_raw_graph.py— full-run-safetytests/test_blade_extractor.py— full-run-safetytests/test_build.py— full-run-safetytests/test_build_merge_dedup_scope.py— full-run-safetytests/test_build_merge_hyperedges_and_prune.py— full-run-safetytests/test_build_merge_shrink_guard.py— full-run-safetytests/test_builtin_global_type_refs.py— full-run-safetytests/test_cache.py— full-run-safetytests/test_callflow_html.py— full-run-safetytests/test_cargo_introspect.py— full-run-safetytests/test_cargo_missing_manifest.py— full-run-safetytests/test_carried_hyperedge_remap.py— full-run-safetytests/test_case_sensitive_resolution.py— full-run-safetytests/test_charmap_encoding.py— full-run-safetytests/test_chunking.py— full-run-safetytests/test_cjs_module_extension.py— full-run-safetytests/test_claude_cli_backend.py— full-run-safetytests/test_claude_md.py— full-run-safetytests/test_cli_broken_pipe.py— full-run-safetytests/test_cli_export.py— full-run-safetytests/test_cli_help.py— full-run-safetytests/test_cluster.py— full-run-safetytests/test_cluster_exclude_hubs.py— full-run-safetytests/test_cobol_extractor.py— full-run-safetytests/test_codebuddy.py— full-run-safetytests/test_community_hub_labels.py— full-run-safetytests/test_community_labels_skill.py— full-run-safetytests/test_confidence.py— full-run-safetytests/test_corrupt_graph_json.py— full-run-safetytests/test_cpp_nested_and_cli.py— full-run-safetytests/test_cpp_objc_cross_file_calls.py— full-run-safetytests/test_cpp_preprocess.py— full-run-safetytests/test_cross_extension_reexport_self_cycle.py— full-run-safetytests/test_cross_language_call_resolution.py— full-run-safety- … and 262 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.
· 1 more finding(s) on lines outside this diff (see the check run).
|
Real-run evidence for the bot's first advisory finding ("Coverage verifier treats files with missing coverage entries as complete"). In my case it wasn't hypothetical, and the file was never opened at all, not just partly read. Skill-path
Both were caught only because the subagents admitted it in their replies. Two suggestions from that:
I've been running a local patch along these lines (an |
|
Another data point for this, from a mixed docs/code corpus (Claude Code, 20 files per chunk). Several chunks held 1–10 MB PDFs, long converted .docx text and large .html prototypes. 4 of 5 document subagents read only headings, and several never opened some files: two large HTML files, two PDFs and five long scripts each ended up as a single bare node. Every chunk still wrote valid JSON, so the B3 success check passed. Both halves of this PR would have caught it: the line bound would have split those chunks, and the coverage map would have flagged the unopened files. One suggestion: let the coverage map distinguish "not opened" from "partly read", because an unopened file is the cheaper case to re-queue and report. |
Land #3987 (@nothariharan, reported by @Ryanm218): on the skill extraction path a long file a subagent only skimmed was cached as complete and its unread tail silently dropped on the next replace-on- re-extract. The chunk coverage self-report is now checked against each file's real line count; a short file is cached partial and left unstamped so --update retries it, reusing the library's existing partial_source_files contract (#933, #1950). Co-Authored-By: Claude Opus 4.8 <[email protected]>
The partial-read coverage check (#3987) adds a python block between the Step B3 merge and Part C. Two skill-path tests that landed separately in the 0.9.9x skill work hard-code the block count in that range (3) and then execute every block in it. Bump the expected count to 4; the behavioral assertions (token sums, merged node sets, stale-chunk clearing) still hold because B3.5 only writes an empty .graphify_partial.txt on the all-cached and codex-merge paths. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Landed in 0.9.93, cherry-picked as 8a982c4 so your authorship is preserved. The skill extraction path now has each chunk self-report the lines it covered and compares that against the real file length; a short read is written to .graphify_partial.txt, cached as partial, and left unstamped so the next |
|
Thanks for landing this in 0.9.93. I've re-based my local patch on it, and the coverage check is a clear improvement. One gap is left, and it's the case from my earlier comment. The B3.5 note says "A file a subagent did not report at all is not counted as partial." In my run that was the main failure: 4 of 12 files were never opened, and 19 INFERRED nodes came from their file names alone. @nigamneelesh saw the same with PDFs and large HTML files. Those subagents reported no coverage for the files they skipped, so B3.5 passes them. What I run locally as an extra step after B3.5:
Smaller point: the line bound still misses long-line files. My 2-file chunk of ~197 KB was only 1,864 lines, so it passes both line rules, yet it was read only from its headings. A byte cap (~50 KB per chunk, larger files on their own) closes that. Happy to open a PR for the unreported-file step if that's useful. |
|
Thanks @Kalessin-Roke, +1 to opening that PR. We run the skill-path Thanks @safishamsi for landing the original fix. |
…step (Graphify-Labs#197) Upstream 0.9.93 added Step B3.5 to the skill: an inline `python -c` block that compares each subagent-reported coverage count against the file's real length and records the files that came up short in .graphify_partial.txt, so the cache and the manifest leave them unstamped and the next --update re-dispatches them (Graphify-Labs#3987, Graphify-Labs#2225). That block is inline Python again, which is exactly what Graphify-Labs#197 removed, so it becomes `graphify pipeline check-coverage`: - graphify/pipeline.py: step_check_coverage writes .graphify_partial.txt; step_save_cache forwards it to save_semantic_cache(partial_source_files=) and step_save_manifest forwards it to _stamped_manifest_files(), which is how a partly-read file is cached as a miss and left unstamped; step_cleanup removes the sidecar. - graphify/cli.py: the new subcommand, and save-cache now reports how many files were left partial for retry. - tools/skillgen/fragments/core/core.md: the inline block becomes the subcommand. The malformed-chunk case is skipped with a warning rather than aborting: a chunk is untrusted subagent output, and it must not fail the run the way it must not fail the merge (Graphify-Labs#825). Co-Authored-By: opencode <[email protected]>
…omplete Step B3.5 (#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 #3987. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit de59b49)
Summary
graphify install+/graphify --update .never entersllm.py, so #1369's oversized-file guard does not apply. Step 3 Part B hands files togeneral-purposesubagents, and the Read tool returns at most 2000 lines per call while reporting no error when it truncates. A subagent that read only the head of a long file still writes a well-formed chunk, so Step B3's success signal ("chunk exists and parses") was never evidence of coverage.Three behaviours turned that into permanent loss rather than a miss:
build_merge's replace-on-re-extract drops every existing node whosesource_fileis the re-extracted file, then re-adds only what the subagent returned — so the unread tail was deleted.semantic_hash, so the file was never retried.On the reported 4165-line archive: 103 nodes covering ~31%, 90 of 131
###entries with no surviving node, and every later run skipped it.@Ryanm218's follow-up measured a second mechanism that made the obvious fix insufficient, and this PR implements both bounds rather than only the
>2000solo rule: a 590-line plan extracted to zero nodes, which no Read-cap guard explains. File-count-only chunking (20–25 files) dilutes attention across the chunk.What changed
All edits are in
tools/skillgen/fragments/, so the 13 disk-dispatching hosts pick them up from one edit and the generated artifacts are regenerated bypython -m tools.skillgen(no hand-editing ofgraphify/skill*.md).1.
references/shared/extraction-spec.md+-compact.md— the prompt states the cap, forbids emitting nodes for a partly-read file and says why (replace-on-re-extract deletes first), and asks the subagent for a top-levelcoveragemap offile -> lines read. The field is in the emitted schema, not just the prose. Both variants are covered: fixing only the verbose one would leave codex/claw/kiro/pi silently half-reading.2.
core/core.mdStep B1 — a chunk is bounded by both limits (20–25 files and ~6000 total lines), and a file past 2000 lines gets a chunk to itself.3.
core/core.mdStep B3.5 (new) — compares each reported coverage against the file's real length, names what was short, and writes the list to.graphify_partial.txt. That list is then handed to the two places that decide whether a file is ever looked at again:save_semantic_cache(..., partial_source_files=...)→ the entry is stampedpartial: True, whichload_cachedtreats as a miss_stamped_manifest_files(..., partial_source_files=...)→ left unstamped, sodetect_incrementalre-queues itBoth parameters already exist and are already used by the library path for a truncated LLM response (#933, #1950, #3203). This PR wires the skill path to the same contract rather than inventing a second one, so the next
--updatere-dispatches the file and replace-on-re-extract swaps the partial node set for a complete one.Why this is safe
coveragereported → no file flagged. A flagged file is re-read, never trusted. Nodes already extracted for those files are kept — they are still true.tools/skillgen/fragmentsis generated markdown.cache.py/cli.pyalready implement partial handling and are covered bytests/test_partial_cache.py.--check,--audit-coverage,--schema-singleton,--monolith-roundtrip,--always-on-roundtrip. The monolith round-trip is untouched because the two monoliths (aider, devin) extract sequentially one file at a time and never chunk — see below.$(cat ...) -cform, so_core_to_powershelltranslates it to a here-string and the strict translator still rejects unknown bash.test_windows_python_step_bodies_match_posix_verbatimcovers parity.Tests
The two load-bearing tests execute the emitted python rather than matching its source, per the #2126/#2641 convention that static assertions gave this class of bug no coverage:
test_coverage_check_flags_a_partly_read_file_and_clears_a_complete_one— runs Step B3.5 against a realgraphify-out, asserts the short file is named withread 10 of 50 linesand written to.graphify_partial.txt, then that a full count clears the warning.test_a_partly_read_file_is_cached_as_a_miss_so_the_next_update_retries_it— round-trips the real semantic cache: after the cache write,check_semantic_cachemust return the partly-read file as uncached while the fully-read file still hits.That second test is the one that matters, because the loss was permanent precisely because the file was served from cache forever. Verified non-vacuous: reverting just the
partial_source_files=argument makes the same round trip return an empty uncached list.Plus prompt-contract tests asserting both spec variants carry the rule, and that Step B1 keeps both bounds.
Full suite:
6020 passed. The 52 failures in this environment are pre-existing onorigin/v8(symlink/mtime/timing on Windows) — I diffed the failing set against a stashed baseline and my change adds none; the one apparent delta,test_same_size_rewrite_in_one_tick_is_requeued, passes 3/3 in isolation.Known gap
codexcollects subagent results in memory with no per-chunk files, so Step B3.5 has nothing to compare against — it gets the prompt-layer fix but not the machine gate. The two monoliths (aider,devin) extract sequentially per file and never chunk, so the attention-dilution half does not apply to them; they would still want the read-completely rule, which I left out to keep this diff to the reported path. Happy to follow up on either.Fixes #2225