fix: large-file byte-path fold-in (read cap, retry trim, deterministic splice)#103
Merged
Conversation
…on metadata read_file applied the line range but never bounded the byte count, so a request for lines 1-220 on a minified/generated file returned the whole 443 KB — which main.go then mid-byte-cut to 131072 (the 128 KiB history cap), poisoning the session (celeste-cli/read_file-byte-cap). - Add a configurable returned-content budget (default 48 KiB, well under context.DefaultMaxToolResultBytes = 128 KiB) applied BEFORE the result is built, via WithMaxResultBytes. - budgetLines: keep as many whole lines as fit; cut on a line boundary. A single oversized/minified line falls back to a byte-bounded head (the only option), still marked truncated — never the 131072 poison blob. - lineAlignedCut: the in-memory read ceiling now cuts on a newline, not mid-byte. - Structured metadata: total_bytes, returned_bytes, truncated, end_line (actual returned), next_offset_line + a hint to page or use search. Tests: line-aligned budget truncation, small-file untouched, minified single line stays byte-bounded. Existing read_file tests unchanged. Root cause + the 128 KiB / 512 KB constants confirmed against source (main.go:952, limits.go:12). Bug 1 of 3 in the large-file-byte-path fold-in; retry-trim + deterministic inject_file follow.
Timeout retries were a no-op that replayed an identical oversized request (celeste-cli/retry-no-context-trim). Three root causes: A. Doomed retry: withRetry reused ONE ctx across all attempts, and callers baked a single deadline into it (main.go:715 60s, main.go:1889 GetTimeout). A timeout on attempt 1 left an already-expired ctx, so attempt 2 failed instantly. Now withRetry owns a FRESH per-attempt deadline derived from a cancel-only base ctx; callers pass context.WithCancel. Same per-request timeout value (60s default) — not raised — but the retry can actually run. B. Identical replay: fn re-sent the same messages slice. A beforeTry hook now trims the largest text tool-result before each attempt, with a progressively tighter budget on retries (48K, 24K, 12K), copy-on-write so session history is never mutated. Image tool-results and non-tool messages are left intact. C. No pre-flight guard: the attempt-0 trim pass caps any tool message already over 48 KiB before the first send. Parent-cancel (Ctrl+C) short-circuits the loop instead of replaying. Per the incident constraints: client-side only, nothing baked into provider/model config, and the timeout is not raised to mask the payload. Tests: fresh-deadline-per-attempt, stop-on-parent-cancel, beforeTry-per-attempt, trim line-boundary + copy-on-write + image/non-tool skipped. Existing retry tests migrated to the new signature. Full suite + lint green. Bug 2 of 3 in the large-file-byte-path fold-in; deterministic inject_file next.
Bulk byte-moving edits routed the whole payload through the model as tool arguments — slow, and a silent-corruption vector on a dropped/garbled stream delta (celeste-cli/edit-routes-bytes-through-model). splice_file moves a region between files deterministically: the model supplies WHERE the bytes are (source + line range or a start/end anchor pair) and WHERE they go (dest anchor to insert at, or an anchor pair to replace), and the bytes are copied on disk — never regenerated. Anchors must be unique (ambiguous or missing → error); anchor regions expand to whole lines so moves leave clean boundaries; copy leaves source intact, move removes the region. Post-write verification confirms the region is present in dest and absent from source (cross-file move). Result reports routed_through_llm=false. patch_file now rejects a new_string over 16 KiB and points to splice_file: a literal that large is almost always a byte-move that must be deterministic. Registered in Agent/Claw/Chat. Tests T1-T5 build the incident-shaped fixtures at runtime (115 KB inline-CSS extraction, line-range copy, replace-between- anchors, 478 KB byte-integrity, error taxonomy) plus intra-file move and the patch_file guard — no large binaries committed. Full suite + lint green. Bug 3 of 3 in the large-file-byte-path fold-in.
whykusanagi
force-pushed
the
fix/large-file-byte-path
branch
from
July 15, 2026 03:11
3517ede to
8bb00ff
Compare
This was referenced Jul 15, 2026
whykusanagi
added a commit
that referenced
this pull request
Jul 15, 2026
…lidated changelog (#105) Follow-up to #103, found by smoke-testing the binary. - fix(llm): raise maxToolMsgBytes to 64 KiB so the retry trim no longer re-truncates read_file's own capped result (48K content < 64K message trim < 128K history cap). - fix(ci): build release binaries with Go 1.26.5 (GO-2026-5856 crypto/tls fix). - test(smoke): assert index status on 'Symbols:' not stale 'index'. - docs: consolidated 1.14.0 changelog (skills browser + file-write fold-in) + splice_file in README (45 tools).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three compounding reliability bugs on the large-file byte path, folded into one release. Each is an independent commit with its own tests.
1.
read_filereturned oversized, silently-truncated blobs (fix)A line range applied the range but never bounded the byte count, so a request for lines 1–220 on a minified/generated file returned the whole payload — which
main.gothen mid-byte-cut at 131072 (the 128 KiB history cap), poisoning the session.DefaultMaxToolResultBytes) applied before the result is built.total_bytes,returned_bytes,truncated, actualend_line,next_offset_line+ a paging hint.2. Timeout retries replayed the identical oversized payload (fix)
withRetryreused onectxacross attempts; callers baked a single deadline into it, so a timeout on attempt 1 left an expired ctx and attempt 2 failed instantly. Now each attempt gets a fresh per-attempt deadline from a cancel-only base ctx (same 60s default — not raised).beforeTryhook trims the largest text tool-result before each attempt, with a progressively tighter budget on retries (48K/24K/12K), copy-on-write so history is never mutated. Images + non-tool messages untouched.3. Bulk byte-moving edits routed content through the model (feat)
New deterministic
splice_file: moves a region between files by anchors/line-ranges — the model says where, the bytes are copied on disk, never regenerated (slow + a silent-corruption vector otherwise). Unique-anchor enforcement, line-aligned regions, copy/move semantics, post-write verification.patch_filenow rejects anew_stringover 16 KiB and points tosplice_file.Constraints honored (from the incident spec)
Tests
Per-bug TDD: read_file byte-bounds + metadata; retry fresh-deadline / parent-cancel / trim line-boundary + copy-on-write; splice T1–T5 (115 KB inline-CSS extraction, line-range copy, replace-between-anchors, 478 KB byte-integrity, error taxonomy) + intra-file move + patch guard. Full suite +
golangci-lint(0 issues) + gofmt green. Large fixtures generated at runtime — no binaries committed.Release: contains a
feat(splice_file) → minor bump.