Skip to content

fix(llm) : bisect splittable documents below char cap on output truncation (#5072) - #5078

Closed
aadilrizwan wants to merge 1 commit into
Graphify-Labs:v8from
aadilrizwan:fix/5072-splittable-docs
Closed

aadilrizwan wants to merge 1 commit into
Graphify-Labs:v8from
aadilrizwan:fix/5072-splittable-docs

Conversation

@aadilrizwan

Copy link
Copy Markdown
Contributor

Resolves (#5072)

What does this PR do?

When a splittable document below _FILE_CHAR_CAP (20,000 characters) is extracted in semantic extraction, expand_oversized_files() leaves it as a raw Path unit. If the model's output truncates (finish_reason="length"), _extract_with_adaptive_retry() checks _split_lone_slice().

Previously, _split_lone_slice() only checked isinstance(chunk[0], FileSlice). Because the single-unit chunk was a Path, it returned None, immediately marked the file partial, and abandoned bisection even when recursion depth permitted further retries.

Adds make_full_slice(path: Path) -> FileSlice | None in graphify/file_slice.py to promote an eligible splittable text file (is_splittable_text) to a full-range FileSlice(path, 0, len(text), 0, 1), returning None for code and binary files.
Updates _split_lone_slice() in graphify/llm.py so that a lone Path eligible for text slicing is promoted to a FileSlice and bisected upon output truncation.
Restores ".yaml" and ".yml" to _SPLITTABLE_TEXT_SUFFIXES in graphify/file_slice.py(matching existing module docstrings).
Adds unit and regression tests proving bisection recovery across .yaml, .yml, .md, .txt, .rst while verifying that code and binary files remain unsliced.

Type of change

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

Verification & Invariants

  • Invariant 1 (Provenance & Source Attribution): Every slice produced by make_full_slice() retains the original Path as fs.path. In _read_files(), <untrusted_source path=...> points to the parent file so that extracted nodes and edges are attributed to the actual file and merge correctly.

  • Invariant 2 (Code & Binary Boundary): Code files (.py, .ts, .rs, etc.) and binary files (images/media) evaluate to is_splittable_text() == False. They are never sliced mid-symbol and continue to fail closed with a partial marker on persistent truncation.

  • Invariant 3 (Bounded Recursion & Partial Markers): If output truncation persists up to _depth >= max_depth, _split_lone_slice() returns None, _mark_partial() executes, and _partial_files propagates up _merged_partial_files()

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

How was this tested?

uv run pytest tests/test_file_slice.py -v
uv run pytest tests/test_oversized_document_slicing.py -v
uv run pytest tests/test_chunking.py -k "adaptive_retry"
uv run pytest tests/test_llm_backends.py -k "adaptive_retry"
uv run pytest tests/test_architecture_doc.py
uv run ruff check .

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.
  • (If applicable) I disclosed AI authorship in my commit messages.

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

Thanks for the pull request, @aadilrizwan. 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.

@github-actions github-actions Bot added the needs:title PR title should follow the conventional-commit format label Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

Thanks @aadilrizwan! One small thing: our changelog and release notes are built from PR titles, so we use the conventional-commits format, for example:

fix(python): resolve a bare stdlib import correctly

Prefixes we use: feat, fix, docs, chore, refactor, test, perf, build, ci. Editing the PR title clears this automatically. This is just a nudge and does not block review.

@aadilrizwan aadilrizwan changed the title fix : bisect splittable documents below char cap on output truncation (#5072) fix(llm) : bisect splittable documents below char cap on output truncation (#5072) Nov 7, 2026

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

Not verified on this run: \_extract\_with\_adaptive\_retry (vacuous: never exercised).


Graphify review — findings

Lets adaptive retry recover from output truncation on splittable text files that sit below the char cap, by promoting the raw path to a full-range FileSlice and bisecting it instead of marking the file partial (#5072). The new make_full_slice builds that slice and returns None for code, binary, or unreadable files. Code files therefore still stay whole and are reported partial on truncation, with no bisecting. .yaml and .yml are now treated as splittable text, so dense YAML can be sliced like markdown or plain text.

No blocking issues surfaced. 3 lower-confidence candidates did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 1227 functions depend on the 252 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: _extract_with_adaptive_retry() — 24 callers, 11 callees
  • new: make_full_slice() — 5 callers, 3 callees

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

Test selection

Test selection

63 of 527 test file(s) selected (12%) via static blast radius.

  • tests/test_5072_splittable_under_cap_retry.py — impact, changed-test
  • tests/test_backend_env_isolation.py — impact
  • tests/test_backend_extras.py — impact
  • tests/test_backend_opt_in.py — impact
  • tests/test_build.py — impact
  • tests/test_build_located_semantic_identity.py — impact
  • tests/test_build_merge_dedup_scope.py — impact
  • tests/test_build_merge_ghost_fold_4955.py — impact
  • tests/test_build_merge_hyperedges_and_prune.py — impact
  • tests/test_build_merge_shrink_guard.py — impact
  • tests/test_c_include_resolution.py — impact
  • tests/test_carried_hyperedge_remap.py — impact
  • tests/test_charmap_encoding.py — impact
  • tests/test_chunking.py — impact
  • tests/test_claude_cli_backend.py — impact
  • tests/test_corrupt_graph_json.py — impact
  • tests/test_cross_extension_reexport_self_cycle.py — impact
  • tests/test_dedup.py — impact
  • tests/test_dedup_remaps_hyperedges.py — impact
  • tests/test_dedup_shrink_refuses_force_write.py — impact
  • tests/test_dedup_survivor_richness.py — impact
  • tests/test_evidence_binding.py — impact
  • tests/test_ext_tagged_id_clash.py — impact
  • tests/test_file_id_collision_4854.py — impact
  • tests/test_file_slice.py — impact, changed-test
  • tests/test_file_truncation_warning.py — impact
  • tests/test_global_graph.py — impact
  • tests/test_go_qualified_resolution.py — impact
  • tests/test_hyperedge_member_shapes.py — impact
  • tests/test_image_vision.py — impact
  • tests/test_injection_sentinel_coverage.py — impact
  • tests/test_issue_3472_source_file_collision.py — impact
  • tests/test_js_member_collisions.py — impact
  • tests/test_label_retry.py — impact
  • tests/test_labeling.py — impact
  • tests/test_llm_backends.py — impact
  • tests/test_llm_null_token_counts.py — impact
  • tests/test_llm_parser.py — impact
  • tests/test_llm_parser_reasoning.py — impact
  • tests/test_merge_sweeps_reextract_orphans.py — impact
  • tests/test_no_dedup_flag.py — impact
  • tests/test_non_string_node_ids.py — impact
  • tests/test_ollama.py — impact
  • tests/test_ollama_ctx_sizing.py — impact
  • tests/test_ollama_live.py — impact
  • tests/test_ollama_native_chat.py — impact
  • tests/test_ollama_retry_cap.py — impact
  • tests/test_oversized_document_slicing.py — impact
  • tests/test_partial_cache.py — impact
  • tests/test_pdf_slicing.py — impact
  • … and 13 more

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 \_extract\_with\_adaptive\_retry.

The verifier did not have enough to check \_extract\_with\_adaptive\_retry, 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: not verifiable: all 264 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)

· 1 grounded finding(s) anchored inline below; 1 more finding(s) on lines outside this diff (see the check run).

Comment thread graphify/file_slice.py Resolved
safishamsi added a commit that referenced this pull request Nov 9, 2026
…ollow-up)

The doc-bisect fix added .yaml/.yml to _SPLITTABLE_TEXT_SUFFIXES, but those are
code, not documents (reclassified document->code in #2214), and never reach the
semantic pass, so slicing them at prose boundaries is meaningless. Drop the two
suffixes and their test parametrization; the core truncation-bisect fix stands.

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

Copy link
Copy Markdown
Member

Landed on v8 and shipped in 0.9.105 (now on PyPI), cherry-picked with -x. One follow-up: I dropped the .yaml/.yml additions to _SPLITTABLE_TEXT_SUFFIXES (and their test params) — those are code, not documents (reclassified document->code in #2214), so they never reach the semantic pass and slicing them at prose boundaries isn't meaningful. The core truncation-bisect fix (promote a splittable under-cap doc to a full slice and retry) is what shipped. Thanks @aadilrizwan (#5072).

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

Labels

needs:title PR title should follow the conventional-commit format

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants