Skip to content

fix(web): make mid-turn delta offsets step-relative - #1607

Closed
wbxl2000 wants to merge 1 commit into
mainfrom
fix/web-step-relative-delta-offset
Closed

fix(web): make mid-turn delta offsets step-relative#1607
wbxl2000 wants to merge 1 commit into
mainfrom
fix/web-step-relative-delta-offset

Conversation

@wbxl2000

Copy link
Copy Markdown
Collaborator

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_turn text and the wire delta offset were 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:

  • kap-server InFlightTurnTracker: clear assistantText / thinkingText on turn.step.started (keep running_tools); stamped offset restarts at 0 each step.
  • kimi-web agentEventProjector: reset turnTextLen / turnThinkLen on step boundaries so live deltas align against the current step.
  • protocol: document that in_flight_turn text fields are current-step only.
  • Tests cover step-boundary reset, step-relative offsets, and seed-then-continue alignment.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, 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.ts
  • pnpm --filter @moonshot-ai/kap-server exec vitest run test/inFlightTurnTracker.test.ts
  • Manual: start a multi-step turn on v2 (pnpm dev:v2 + web), refresh or reconnect mid-turn, confirm prior steps stay structured and only the current step is seeded/streamed

Reset in-flight text and client stream alignment at step boundaries so
resync seeds only the current step instead of duplicating prior steps.
@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 86be5e3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

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

@pkg-pr-new

pkg-pr-new Bot commented Jul 13, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@86be5e3
npx https://pkg.pr.new/@moonshot-ai/kimi-code@86be5e3

commit: 86be5e3

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +733 to +734
s.turnTextLen = 0;
s.turnThinkLen = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@wbxl2000

Copy link
Copy Markdown
Collaborator Author

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.

@wbxl2000 wbxl2000 closed this Jul 13, 2026
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