fix(web): make mid-turn delta offsets step-relative - #1609
Conversation
Reset in-flight text and client stream alignment at step boundaries so resync seeds only the current step instead of duplicating prior steps.
🦋 Changeset detectedLatest commit: 51db588 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 86be5e384e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
commit: |
The exact-JSON content signature missed duplicates when the two copies differed by thinking signature, tool progress, part boundaries, or the tool set (finished parallel tools leave running_tools). Reduce content to concatenated stream text plus sorted tool-call ids and treat a covered subset as the duplicate, merging the seed's tool progress into the existing cards before dropping it.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 51db588b98
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Related Issue
No linked issue — the problem is explained below.
Problem
In kimi-web, when a snapshot resync happens while a multi-step turn is still running (page refresh, WebSocket reconnect on tab focus, or a server-requested resync), the turn re-renders incorrectly: earlier steps' body text is re-appended as a trailing blob of duplicated Markdown after the structured history, and thinking blocks / tool cards stop separating properly. Long turns (30+ steps, thinking enabled) make it most visible.
Root cause on the v2 (kap-server) sync path: the server's in-flight turn tracker accumulated
assistant_text/thinking_textfor the WHOLE turn instead of the currently-streaming step. Completed steps are already present in the snapshot transcript as structured messages, so when a reconnecting client seeded a partially-streamed assistant message fromin_flight_turn, it carried a second copy of every earlier step's text.What changed
turn.step.started(running tool calls are intentionally kept — a call without a result yet is not in the transcript and must still be seeded). The pre-appendoffsetstamped on volatile delta frames becomes step-relative as a consequence.turn.step.startedto match the step-relative offsets. Without this, every delta from step 2 onward misaligns (silently skipped as a duplicate, or misread as a gap). A lost head-of-step delta now surfaces as a recoverable gap → resync instead of a permanent silent stall.signature, tool progressoutputLines, part boundaries, or the tool set (a finished parallel tool leavesrunning_tools, so the seed's id set is a strict subset). Before dropping the seed, its tool progress is merged into the existing card so a mid-tool refresh keeps the latest output (and never overwrites a settled tool result).in_flight_turn.assistant_text/thinking_textas current-step accumulation (reset atturn.step.started; earlier steps are inmessages).Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.