Skip to content

Splittable documents below character cap cannot bisect after output truncation #5072

Closed

Description

@CBEPX

Splittable documents below _FILE_CHAR_CAP remain raw Path units when their output truncates. Adaptive retry cannot bisect those units.

Reproduced with graphifyy 0.9.82 and 0.9.101, CPython 3.13, macOS arm64. The same text completes through native bisection when supplied as a full-range FileSlice.

The following offline example mocks only the model response. It returns finish_reason="length" above 700 input characters. No API key or network request is needed.

"""Synthetic public-safe native retry reproduction; no API calls."""
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import patch
from contextlib import redirect_stderr
from importlib.metadata import version
import io
import json
import graphify.llm as llm
from graphify.file_slice import FileSlice, unit_source_text, read_slice_text


def model_leaf(chunk, **kwargs):
    text = ''.join(read_slice_text(u) if isinstance(u, FileSlice) else unit_source_text(u) for u in chunk)
    return {'nodes': [], 'edges': [], 'hyperedges': [],
            'finish_reason': 'length' if len(text) > 700 else 'stop'}


with TemporaryDirectory() as directory:
    path = Path(directory) / 'dense.yaml'
    path.write_text('records:\n' + ''.join(f'  item{i}: value{i}\n' for i in range(80)))
    text = unit_source_text(path)
    raw = llm.expand_oversized_files([path], llm._FILE_CHAR_CAP)
    control = [FileSlice(path, 0, len(text), 0, 1)]
    results = {}
    with patch.object(llm, 'extract_files_direct', side_effect=model_leaf), redirect_stderr(io.StringIO()):
        for name, units in [('raw_path', raw), ('full_slice_control', control)]:
            result = llm._extract_with_adaptive_retry(units, 'kimi', 'offline', 'offline', path.parent, 3)
            results[name] = {'unit_type': type(units[0]).__name__,
                             'partial': bool(result.get('partial') or result.get('_partial_files'))}
    assert results['raw_path']['partial'] and not results['full_slice_control']['partial']
    print(json.dumps({'version': version('graphifyy'), 'chars': len(text),
                      'native_char_cap': llm._FILE_CHAR_CAP, 'results': results}, indent=2))

Both versions report a 1,429-character document below the 20,000-character cap. raw_path reports partial: true. full_slice_control reports partial: false.

A real corpus also stopped on this boundary: a YAML document contained 18,742 characters in 20,020 bytes. Its response exhausted a 32,768-token output limit. The run used a 12,000-token input budget and retry depth 3. The file remained a raw Path, so the single-file retry returned a partial result. Our strict controller stopped that run.

expand_oversized_files() only creates slices above the character cap. _extract_with_adaptive_retry() can bisect a single unit only when it is already a FileSlice. Lowering the chunk input budget does not change that initial eligibility check.

A possible fix is to promote an eligible raw text Path to a full-range FileSlice after output truncation. Native bisection can then retry within the existing depth limit. The fix should preserve partial markers, source attribution, and the limits for code or binary files.

A local workaround supplies native slices for the byte-pinned failing document. It preserves every input character. Native packing can recombine the initial slices, but later adaptive splitting becomes possible. Real extraction and semantic acceptance are still pending.

Related: #730 covers output-token configuration. #1369 introduced intra-file slicing. This report isolates the below-cap eligibility gap.

Activity

  1. github-actions commented on Nov 6, 2026

    @github-actions

    Thanks for opening this issue, @CBEPX. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

  2. Jvxoq commented on Nov 7, 2026

    @Jvxoq
    Contributor

    I'd like to work on this. My plan is to promote an eligible raw text Path to a full-range FileSlice when its output truncates, so _extract_with_adaptive_retry can bisect it within the existing depth limit. I'll keep partial markers, source attribution, and the code/binary limits, and add a regression test based on the offline repro above. I'll open a PR soon.

  3. safishamsi commented on Nov 9, 2026

    @safishamsi
    Member

    Fixed in 0.9.105 (now on PyPI) via #5078: a splittable document whose output truncates is now promoted to a full slice and bisected/retried instead of being kept partial.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions