Skip to content

parser: full re-parse when an appended region restates a cached message id#772

Merged
iamtoruk merged 1 commit into
mainfrom
fix/append-straddle-guard
Jul 20, 2026
Merged

parser: full re-parse when an appended region restates a cached message id#772
iamtoruk merged 1 commit into
mainfrom
fix/append-straddle-guard

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

Found during the adversarial review of #744: the incremental-append parser on main over-counts when a streamed assistant message id straddles the append boundary (real shape: image tool-results streaming one id across several records; 5 of 1672 local files; reproduced at 111 calls vs the full-parse 110 with turn-splice corruption at some alignments). The appended region is grouped before the file's own cached keys join the dedup set, and the boundary merge can splice the restated id into the wrong turn.

Fix is the conservative one: on any id overlap between appended entries and cached turns, abandon the shortcut and re-parse that file from byte 0. Costs a full parse on ~0.3% of files; exact everywhere. Regression test compares against a cold-reparse oracle and is mutation-verified. This also defines the bar #744's checkpoint design must meet when it is reworked (its turn-boundary resume can eventually handle this shape without the fallback).

…ge id

The incremental-append path groups the appended region before the file's
own cached keys join the dedup set, so a streamed assistant id restated
across the append boundary counted twice, and the boundary merge could
splice it into the wrong turn (reproduced on real image-heavy sessions:
one id streamed across several records over seconds, 111 calls vs the
110 a full re-parse yields). Suppressing the restatement instead would
freeze the stale first emission, so neither shortcut matches a full
re-parse. On any id overlap between the appended entries and the cached
turns the shortcut is abandoned and the file re-parses from byte 0.
Rare (about 0.3 percent of real files) and bounded to one file per
refresh. Regression test uses the cold-reparse oracle; mutation-verified
against the unguarded code.
@iamtoruk
iamtoruk merged commit be748c8 into main Jul 20, 2026
3 checks passed
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.

1 participant