Skip to content

fix(skill): a partly-read file is no longer a silent, permanent loss - #3987

Closed
nothariharan wants to merge 1 commit into
Graphify-Labs:v8from
nothariharan:fix/2225-partial-read-data-loss
Closed

nothariharan wants to merge 1 commit into
Graphify-Labs:v8from
nothariharan:fix/2225-partial-read-data-loss

Conversation

@nothariharan

Copy link
Copy Markdown
Contributor

Summary

graphify install + /graphify --update . never enters llm.py, so #1369's oversized-file guard does not apply. Step 3 Part B hands files to general-purpose subagents, 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:

  1. build_merge's replace-on-re-extract drops every existing node whose source_file is the re-extracted file, then re-adds only what the subagent returned — so the unread tail was deleted.
  2. The run reported success — valid JSON, chunk on disk, no warning.
  3. The manifest recorded 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 >2000 solo 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 by python -m tools.skillgen (no hand-editing of graphify/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-level coverage map of file -> 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.md Step 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.md Step 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 stamped partial: True, which load_cached treats as a miss
  • _stamped_manifest_files(..., partial_source_files=...) → left unstamped, so detect_incremental re-queues it

Both 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 --update re-dispatches the file and replace-on-re-extract swaps the partial node set for a complete one.

Why this is safe

  • Fail-safe in the direction that loses nothing. No coverage reported → no file flagged. A flagged file is re-read, never trusted. Nodes already extracted for those files are kept — they are still true.
  • No library behaviour change. The diff outside tools/skillgen/fragments is generated markdown. cache.py / cli.py already implement partial handling and are covered by tests/test_partial_cache.py.
  • All five skillgen guards pass: --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.
  • Windows render verified: the new inline python is inside the supported $(cat ...) -c form, so _core_to_powershell translates it to a here-string and the strict translator still rejects unknown bash. test_windows_python_step_bodies_match_posix_verbatim covers 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 real graphify-out, asserts the short file is named with read 10 of 50 lines and 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_cache must 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 on origin/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

codex collects 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

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
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

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.

@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.

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-safety
  • tests/test_affected_member_seed.py — full-run-safety
  • tests/test_agents_platform.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_benchmark.py — full-run-safety
  • tests/test_benchmark_raw_graph.py — full-run-safety
  • tests/test_blade_extractor.py — full-run-safety
  • tests/test_build.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_cache.py — 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 — full-run-safety
  • tests/test_chunking.py — 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_cluster.py — full-run-safety
  • tests/test_cluster_exclude_hubs.py — full-run-safety
  • tests/test_cobol_extractor.py — full-run-safety
  • tests/test_codebuddy.py — full-run-safety
  • tests/test_community_hub_labels.py — full-run-safety
  • tests/test_community_labels_skill.py — full-run-safety
  • tests/test_confidence.py — full-run-safety
  • tests/test_corrupt_graph_json.py — full-run-safety
  • tests/test_cpp_nested_and_cli.py — full-run-safety
  • tests/test_cpp_objc_cross_file_calls.py — full-run-safety
  • tests/test_cpp_preprocess.py — full-run-safety
  • tests/test_cross_extension_reexport_self_cycle.py — full-run-safety
  • tests/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).

@Kalessin-Roke

Copy link
Copy Markdown

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 --update on 0.9.69 (the extraction prompt and B1 are unchanged in 0.9.80): 15 docs (~660 KB) in 3 chunks by file count.

  • Chunk of 12 files (~200 KB): the subagent read 40-60 lines of 8 files and never opened the other 4. It still emitted nodes and edges for those 4 from their file names alone, marked INFERRED (19 nodes). The chunk was well-formed JSON.
  • Chunk of 2 files (~197 KB): it used only the headings of a 143 KB HTML file and the first 250 lines of a 54 KB doc. Those two files are 970 and 894 lines, 1,864 combined, so this chunk passes both the 2000-line solo rule and the ~6000-line cap. Only a byte bound would have split it.

Both were caught only because the subagents admitted it in their replies.

Two suggestions from that:

  1. In B3.5, treat a FILE_LIST entry with no coverage entry as unread, not complete. Re-queue it, and don't keep nodes whose source_file has no reported coverage. A subagent that invents nodes for a file won't report coverage for it, so "missing" is exactly the failure signature.
  2. Widen the prompt rule from partly-read to never-read files: "Never derive a node or an edge from a file name, a path, or content you have not read. INFERRED means inferred from text you read, not guessed from a title."

I've been running a local patch along these lines (an unread_files list, a byte cap per chunk, and re-dispatch of anything unread). I can share it if useful, but your coverage map is the better vehicle.

@nigamneelesh

Copy link
Copy Markdown

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.

safishamsi added a commit that referenced this pull request Oct 20, 2026
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]>
safishamsi added a commit that referenced this pull request Oct 20, 2026
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]>
@safishamsi

Copy link
Copy Markdown
Member

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 --update re-dispatches it. Thanks @nothariharan, and thanks @Ryanm218 for the report. Live on PyPI: https://pypi.org/project/graphifyy/0.9.93/

@safishamsi safishamsi closed this Oct 20, 2026
@Kalessin-Roke

Copy link
Copy Markdown

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:

  • Check every dispatched file (.graphify_uncached.txt), not only the coverage keys. A non-empty, non-image file with no coverage entry, or a count of 0, is unread.
  • For those files, drop what the chunks attribute to them by source_file, not by id. A read file can mint the same deterministic id, and dropping by id deletes its node too. Also drop edges and hyperedges whose own source_file is the unread file, and any that point at an id no remaining node carries. Edges to AST nodes outside the chunks stay.
  • Add those files to .graphify_partial.txt, so the existing partial/unstamped path retries them.
  • In the prompt: give every FILE_LIST path a coverage entry (0 = never opened). For a PDF, which the Read tool returns as pages, report pages read, otherwise a fully read PDF looks unread.

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.

@Ryanm218

Copy link
Copy Markdown

Thanks @Kalessin-Roke, +1 to opening that PR. We run the skill-path --update unattended nightly on 0.9.93, and the gap you describe is the one we have no local check for: our health probe only flags files of 400+ lines with 3 or fewer nodes, so a file the subagent never opened (nodes inferred from its name) passes it. Treating a dispatched file with no coverage entry as unread, dropping by source_file rather than id, and re-queueing via .graphify_partial.txt all sound right to us. The byte cap for long-line files would be a welcome addition too.

Thanks @safishamsi for landing the original fix.

nothariharan added a commit to nothariharan/graphify that referenced this pull request Oct 22, 2026
…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]>
safishamsi pushed a commit that referenced this pull request Nov 14, 2026
…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)
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.

Skill-path extraction silently truncates files >2000 lines; replace-on-re-extract then deletes the unread tail

5 participants