Skip to content

Claude/stream prefix dedup main - #549

Merged
Wang-Daoji merged 4 commits into
MemTensor:v1.1.9from
Wang-Daoji:claude/stream-prefix-dedup-main
Sep 28, 2026
Merged

Wang-Daoji merged 4 commits into
MemTensor:v1.1.9from
Wang-Daoji:claude/stream-prefix-dedup-main

Conversation

@Wang-Daoji

Copy link
Copy Markdown
Collaborator

No description provided.

Wang-Daoji and others added 4 commits September 23, 2026 18:06
Streaming text reaches a client over two independent paths: the live
in-memory push and the transcript-file replay. Both deliver the same chunk
to the same buffer, and stream content is appended rather than replaced, so
a re-delivery doubles the visible text. The frame carried no position
identity, leaving each client to guess — the CLI compared head/tail text
overlap, the GUI did neither.

Stamp a `transcript_offset` on every persisted record: the line's starting
byte position, which is the pre-write file size because appends land at the
end. Live delivery and file replay then share one identity for a chunk, and
dedup becomes a numeric comparison.

The stamp lands only after the write succeeds. Stamping first would let a
failed write broadcast an offset that was never persisted, advancing the
client watermark to a value the next real record also starts at — dropping
new content instead of a duplicate.

- transcript.ts: stamp the offset inside the single write path, so both
  delivery paths inherit it and no caller has to cooperate.
- websocket.ts: stop cloning before persisting so the broadcast payload and
  the stored record are one object; always copy in sendTurnPayload so the
  caller's payload is not mutated by the stamp.
- tui-gateway-client.ts: skip frames at or below the applied offset, falling
  through to the overlap heuristic for records written before this field.
- agent-chat-slice.ts: hold a per-chat watermark, dropped and advanced by
  delta / reasoning_delta / stream_end, and re-based on a full hydrate so a
  rebuilt transcript cannot be swallowed by a stale watermark.

Records written before this change carry no offset and keep their previous
behaviour, so no migration is needed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Wang-Daoji
Wang-Daoji merged commit 509c92b into MemTensor:v1.1.9 Sep 28, 2026
2 checks passed
@Wang-Daoji
Wang-Daoji deleted the claude/stream-prefix-dedup-main branch October 8, 2026 02:53
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