Skip to content

fix(web): dedupe optimistic user message against snapshot resync - #1620

Merged
wbxl2000 merged 3 commits into
mainfrom
fix/web-duplicate-user-message
Jul 13, 2026
Merged

fix(web): dedupe optimistic user message against snapshot resync#1620
wbxl2000 merged 3 commits into
mainfrom
fix/web-duplicate-user-message

Conversation

@wbxl2000

@wbxl2000 wbxl2000 commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the problem is explained below.

Problem

In kimi-web, a snapshot resync can occasionally leave an optimistic user message next to the snapshot's authoritative copy. The optimistic bubble deliberately keeps its client-side msg_opt_* id to avoid remounting, while the v2 submit result stamps the authoritative user-message id into promptId. mergeSnapshotMessages previously only used createdAt to decide which loaded messages fell before the snapshot window, so it did not use the stable identity already available.

What changed

  • Build a set of snapshot user-message ids and drop an older loaded user message when its promptId matches one of those ids. This follows the v2 identity contract where prompt_id and user_message_id are the same value.
  • Keep messages with repeated text or the same media count when their ids differ; snapshot merging no longer guesses identity from content.
  • Cover the real v2 snapshot shape in tests: the optimistic message carries the authoritative id in promptId, while the snapshot message carries it in id and omits promptId.

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.

@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d0388de

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

@wbxl2000
wbxl2000 force-pushed the fix/web-duplicate-user-message branch from 85ae548 to 5eb3a15 Compare July 13, 2026 13:15
@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

s.turnTextLen = 0;
s.turnThinkLen = 0;

P1 Badge Preserve v1 whole-turn delta offsets

This reset assumes every backend stamps assistant.delta / thinking.delta offsets relative to the current step, but the v1 backend still uses whole-turn offsets: packages/server/src/services/gateway/inFlightTurnTracker.ts:54-80 only resets on turn.started / turn.ended and accumulates text across all steps. Since kimi-web still supports and defaults to the v1 server, any v1 turn with a second turn.step.started will reset the local length to 0 here, then receive a step-2 delta whose offset includes step-1 text, causing alignDelta to emit historyCompacted instead of rendering the stream. Please either update the v1 tracker to the same step-relative contract or keep the client compatible with whole-turn offsets for v1.

ℹ️ 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".

@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@d0388de
npx https://pkg.pr.new/@moonshot-ai/kimi-code@d0388de

commit: d0388de

@wbxl2000

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: d0388dec60

ℹ️ 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".

@wbxl2000
wbxl2000 merged commit e91a616 into main Jul 13, 2026
14 checks passed
@wbxl2000
wbxl2000 deleted the fix/web-duplicate-user-message branch July 13, 2026 13:54
@github-actions github-actions Bot mentioned this pull request Jul 14, 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