Skip to content

[Feature]: Incremental reuse rejects truncated reads, capped and regex searches, so long Markdown documents never qualify #368

Done

Description

@xeonvs

Toolkit version

0.16.1 (OCR v1.14.6)

Platform

macOS arm64, ocr-ci review --local --incremental

Problem

A branch that changes only three Markdown files (about 250, 680 and 455 lines, 85–191 KB each) saved its baseline as

Incremental baseline: 3 groups, 0 qualified.
Unqualified groups by reason: read_verification 1, search_tool 2

Tool calls: file_read 33, code_search 9, ocr_toolkit_evidence 4, file_find 3, file_read_diff 1. Each repeat review of such a branch costs about 1.4 million tokens, so documentation reviews get no benefit from the Markdown reuse added in #353.

Each of the four rejection paths below is deterministic and is reached by ordinary native tool use on long Markdown documents:

Native behavior (OCR 1.14.6) Toolkit 0.16.1 Reason counted
file_read cuts a line longer than 2048 bytes, stops at 500 lines or at 256 KiB, and reports IS_TRUNCATED: true _read_observation requires IS_TRUNCATED: false read_verification
code_search returns the first 100 matches plus a truncation note _render_search raises when there are more than 100 raw matches search_tool
code_search with use_perl_regexp: true validated_replay_arguments rejects it search_tool
code_search with pathspec magic in file_patterns, e.g. :(exclude)dir/ (the tool description suggests this form) rejected by _SEARCH_PATTERN search_tool

All three changed files contain lines longer than 2048 bytes. In Cyrillic text that is about 1,000 characters, for example one long table row. One file also exceeds 500 lines. In one documentation-heavy repository, 129 of 667 Markdown files contain such lines and 30 files exceed 500 lines.

Synthetic reproducer

import json
from ocr_toolkit.local_incremental_dependencies import _read_observation
from ocr_toolkit.local_incremental_replay import _render_search
from ocr_toolkit.local_incremental_state import validated_replay_arguments, ReviewRange

rr = ReviewRange("a" * 40, "b" * 40)
def attempt(label, fn):
    try:
        fn(); print(label, "-> accepted")
    except Exception as e:
        print(label, "->", type(e).__name__, e)

long = "x" * 3000
resp = (f"File: doc.md (Total lines: 3)\nIS_TRUNCATED: true\nLINE_RANGE: 1-2\n1|short\n"
        f"2|{long[:2048]} …[line truncated, 952 more bytes omitted]\n\n"
        "Note: Lines longer than 2048 bytes were cut mid-line and the omitted bytes are not part of this result. "
        "Reason about the visible part only.\n")
attempt("truncated read", lambda: _read_observation(
    {"file_path": "doc.md", "start_line": 1, "end_line": 2}, resp, rr, ok=True))
rows = b"".join(b"%s:f.md\x00%d\x00hit\n" % (b"b" * 40, i) for i in range(1, 102))
attempt("search, 101 raw matches", lambda: _render_search(rows, "b" * 40))
attempt("use_perl_regexp", lambda: validated_replay_arguments("code_search",
    json.dumps({"search_text": "A-(1|2)", "use_perl_regexp": True}).encode()))
attempt("pathspec exclude", lambda: validated_replay_arguments("code_search",
    json.dumps({"search_text": "A-1", "file_patterns": [":(exclude)specs/"]}).encode()))

Output: all four attempts raise IncrementalError. A plain code_search with file_patterns: ["docs/"] is accepted.

Proposal

The native outputs are pure functions of the immutable revision, the arguments and fixed native limits, so they can be verified instead of rejected:

  1. Truncated reads. Record the limits that applied: 500 lines, 2048 bytes per line with the rune-safe cut and the omitted-byte count, 256 KiB. Verify the rendered window by recomputing it from the blob with the same limits.
  2. Capped searches. Replay the search and compare the first 100 matches and the reported matched-file count, which the native note includes.
  3. Regex searches. Replay with the same git grep -P invocation that OCR builds.
  4. Pathspec magic. Accept the pathspec forms that OCR passes to git grep and replay them unchanged.
  5. Diagnostics. Split the reason counts so the user can see which of these applied, for example read_truncated, search_capped, search_regex, search_pathspec.

Acceptance

A second incremental run of a Markdown-only branch whose groups read long-line files and used capped or regex searches reuses the groups whose files and replayed results are unchanged.

Related

#342, #352, #353.

Activity

  1. added
    enhancement
    on Dec 2, 2026
  2. added this to the v0.16.2 milestone on Dec 2, 2026
  3. xeonvs commented on Dec 2, 2026

    @xeonvs
    OwnerAuthor

    Measured #369 on synthetic Markdown with the installed, qualified OCR 1.14.6. Control and candidate used identical revisions, model and settings. The local measurement adapter preserves the installed executable path and checks its qualified digest. Default release executable staging is unchanged.

    Run (filter disabled on both sides) Input Output Cached input, included in input Model requests Tool calls
    0.16.1 first 105,756 1,051 61,440 12 14
    0.16.1 follow-up 82,712 894 31,744 10 9
    Candidate first 103,481 1,195 54,272 12 12
    Candidate follow-up 40,855 535 22,528 6 6

    The follow-up used 50.5% fewer input + output tokens on this fixture. On 0.16.1 zero of two groups qualified. On the candidate both initial groups qualified; the subsequent change required one fresh group. The known unit-conversion finding was carried byte for byte with its original provenance. On the candidate with the default filter, a separate first/follow-up pair used 91,172/53,049 tokens and 12/8 requests. That pair compares different review stages within one version. A read or search with unproved output still requires fresh review. The original issue's 1.4M figure was not independently reproduced.

    Offline preparation measurements on a fixed range used fresh processes and warm OS caches. Standalone local preflight took 1.04–1.43 s. Preparation through the first request to a local deterministic peer took 4.53–5.03 s before and 2.80–2.88 s after the change; native preview also varied. Within preparation, evidence collection fell from 1.43–1.54 s to 0.98–1.01 s. Full collector tree walks fell from five to two, with byte-identical evidence and bootstrap. Peak RSS increased from approximately 103–104 to 109–110 MB. The first fixed MCP list request took 419–453 ms including cold server startup; the same query on the running server took approximately 1.5 ms, returned identical data, and issued no Git subprocesses.

  4. github-actions commented on Dec 2, 2026

    @github-actions

    Stable v0.16.2 delivery is verified by immutable release asset release-receipt.json in v0.16.2 (SHA-256 6a08c5772052b1b6219d6cdf4086bd702b0dcd69a2414c65f9902b201ea92049).

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

    enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions