Skip to content

fix(web): reconcile session from snapshot on reopen - #1409

Merged
wbxl2000 merged 11 commits into
mainfrom
fix/web-reopen-reconcile
Jul 6, 2026
Merged

fix(web): reconcile session from snapshot on reopen#1409
wbxl2000 merged 11 commits into
mainfrom
fix/web-reopen-reconcile

Conversation

@wbxl2000

@wbxl2000 wbxl2000 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the problem was reproduced live and is described below.

Problem

The web client builds the live transcript from WebSocket events. Assistant text deltas are volatile frames: they are never journaled and never replayed after a reconnect (packages/protocol/src/events.ts). When a transport hiccup covers the tail of a turn — easy to hit during a swarm, where many subagents stream over the same socket — the projector's offset-based gap detection never fires (it needs a later delta to notice the hole), so the model's final report text is silently lost. The data is intact on disk and the server snapshot is authoritative, but the local transcript stayed broken forever: reopening the session only re-subscribed from the cursor, which has nothing to replay.

User-facing symptom: the end of a long reply is missing and stays missing even after switching away and back.

What changed

Deliberately simple: re-opening an already-loaded session refreshes it from a fresh server snapshot (reopenSessionsyncSessionFromSnapshot). The snapshot is cheap server-side (LRU keyed on the wire file's size/mtime), so going to the authoritative record is the most reliable way to recover from any lost-tail scenario.

One adjustment keeps this simple without a regression: the snapshot only carries the most recent message page, so applying it now merges into already-loaded messages — any older pages the user already fetched are preserved, and the snapshot is authoritative for its own window. This keeps scrollback intact while still repairing the latest turn tail.

Trade-off (accepted): a snapshot GET that returns during a live stream can briefly overwrite in-flight assistant delta text; the user notices immediately and a refresh or the next re-open reconciles.

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. — Added coverage for preserving already-loaded older messages when merging the snapshot tail.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update. — Reliability fix with no new user-facing behavior to document.

@changeset-bot

changeset-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 26d60df

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 6, 2026

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

commit: 26d60df

@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: c9064a5193

ℹ️ 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 thread apps/kimi-web/src/composables/useKimiWebClient.ts Outdated
@wbxl2000

wbxl2000 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

@codex

@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: 003d0de531

ℹ️ 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 thread apps/kimi-web/src/composables/useKimiWebClient.ts Outdated
Comment thread apps/kimi-web/src/composables/useKimiWebClient.ts Outdated
@wbxl2000

wbxl2000 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

@codex

@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: d051f9b144

ℹ️ 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 thread apps/kimi-web/src/composables/useKimiWebClient.ts Outdated
@wbxl2000

wbxl2000 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

@codex

@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: d6c18a63c3

ℹ️ 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 thread apps/kimi-web/src/composables/useKimiWebClient.ts Outdated
@wbxl2000

wbxl2000 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

@codex

@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: 829da36dbf

ℹ️ 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 thread apps/kimi-web/src/composables/useKimiWebClient.ts Outdated
@wbxl2000

wbxl2000 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

@codex

@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: c12c42378c

ℹ️ 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 thread apps/kimi-web/src/composables/useKimiWebClient.ts Outdated
@wbxl2000

wbxl2000 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

@codex

@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: 57b06efe87

ℹ️ 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 thread apps/kimi-web/src/composables/useKimiWebClient.ts Outdated
@wbxl2000

wbxl2000 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

@codex

@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: 49609017a8

ℹ️ 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 thread apps/kimi-web/src/composables/useKimiWebClient.ts Outdated
@wbxl2000

wbxl2000 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

@codex

@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: a5e312c793

ℹ️ 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 thread apps/kimi-web/src/composables/useKimiWebClient.ts
Comment on lines +1151 to +1154
if (!opts?.force && wasLoaded && !sessionsWithStaleCursor.has(sessionId)) {
if ((rawState.lastSeqBySession[sessionId] ?? 0) > snap.asOfSeq) return 'ok';
if (rawState.promptIdBySession[sessionId] !== promptBefore) return 'ok';
if (inFlightPromptSessions.has(sessionId) !== inFlightBefore) return 'ok';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Guard snapshots against pending card resolutions

When a loaded session waiting on an approval/question is reopened, the UI remains usable while the snapshot GET is in flight, but this staleness guard only tracks seq, prompt id, and prompt sends. If the user approves or answers during that window and the REST call removes the card before the WS resolved event advances lastSeqBySession, a snapshot response that still contains the pending card will overwrite approvalsBySession/questionsBySession and resurrect the resolved prompt. Include pending approval/question actions in the guard or filter stale snapshot cards before applying them.

Useful? React with 👍 / 👎.

@wbxl2000

wbxl2000 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review. I have rewritten the fix as a much simpler approach: reopenSession now always rebuilds from a fresh server snapshot with no staleness guard, accepting the optimistic-message-overwrite trade-off described in the PR body.

@wbxl2000

wbxl2000 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review. I have rewritten the fix as a much simpler approach: reopenSession now always rebuilds from a fresh server snapshot with no staleness guard, accepting the optimistic-message-overwrite trade-off described in the PR body.
@codex review。我已将修复方案重写为更简洁的方式:reopenSession 现在始终基于最新的服务器快照重建,不再设置陈旧性保护,接受 PR 正文中描述的乐观消息覆盖权衡。

@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: dc8b992fab

ℹ️ 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 thread apps/kimi-web/src/composables/useKimiWebClient.ts
@wbxl2000

wbxl2000 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@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: 26d60df9b7

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

);
rawState.messagesHasMoreBySession = {
...rawState.messagesHasMoreBySession,
[sessionId]: snap.hasMoreMessages,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3 Badge Preserve exhausted pagination after snapshot merge

When a user has already loaded all older messages (messagesHasMoreBySession[sessionId] is false), reopening a long session now merges that full prefix with the latest snapshot but then resets the pagination flag to snap.hasMoreMessages. That flag is only relative to the snapshot's bounded tail, so sessions with more than the snapshot page size will incorrectly show “load older” again and issue an unnecessary empty request before returning to false.

Useful? React with 👍 / 👎.

@wbxl2000
wbxl2000 merged commit 578f7d3 into main Jul 6, 2026
11 checks passed
@wbxl2000
wbxl2000 deleted the fix/web-reopen-reconcile branch July 6, 2026 13:30
This was referenced Jul 6, 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