fix(web): make mid-turn delta offsets step-relative - #1607
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: 86be5e3 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 |
commit: |
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".
| s.turnTextLen = 0; | ||
| s.turnThinkLen = 0; |
There was a problem hiding this comment.
Preserve v1 turn-scoped offsets
When the web UI is connected to the v1 backend, these resets make every post-step delta look like a gap: packages/server/src/services/gateway/inFlightTurnTracker.ts still computes offset from the full turn text and never handles turn.step.started, so after step 1 the next v1 assistant.delta arrives with offset > 0 while turnTextLen has just been reset to 0 here. That routes normal streaming through historyCompacted/resync instead of appending, so multi-step turns on v1 can repeatedly resync or stop streaming. Either keep v1 counters turn-relative or update the v1 tracker in the same change.
Useful? React with 👍 / 👎.
|
Closing as superseded by #1609. #1609 contains this PR's exact commit 86be5e3 and adds the normalized resync-seed dedupe fix/tests in 51db588; it has merged. The legacy v1 compatibility concern also no longer applies after #1617 removed packages/server and made kap-server the only /api/v1 server path. |
Related Issue
No linked issue — focused bug fix for mid-turn resync on the v2 (
kap-server) path. Same class of bug as the earlier v1 mid-turn resync blob fix.Problem
During a multi-step turn,
in_flight_turntext and the wire deltaoffsetwere turn-scoped. After a mid-turn snapshot resync (reconnect / refresh /resync_required), the client seeded all prior steps' text again on top of the structured transcript, producing a duplicated wall of Markdown. Live deltas from step 2+ were also aligned against the wrong local length, so they were skipped or treated as gaps.What changed
Make in-flight accumulation and client delta alignment step-relative:
InFlightTurnTracker: clearassistantText/thinkingTextonturn.step.started(keeprunning_tools); stampedoffsetrestarts at 0 each step.agentEventProjector: resetturnTextLen/turnThinkLenon step boundaries so live deltas align against the current step.in_flight_turntext fields are current-step only.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update. (N/A — bug fix; no user-facing docs/config change.)Test plan
pnpm --filter @moonshot-ai/kimi-web test -- test/agent-event-projector.test.tspnpm --filter @moonshot-ai/kap-server exec vitest run test/inFlightTurnTracker.test.tspnpm dev:v2+ web), refresh or reconnect mid-turn, confirm prior steps stay structured and only the current step is seeded/streamed