Skip to content

fix(web): finish local prompt state from session snapshot after a reconnect - #1572

Merged
wbxl2000 merged 1 commit into
mainfrom
fix/web-prompt-finish-on-snapshot
Jul 12, 2026
Merged

fix(web): finish local prompt state from session snapshot after a reconnect#1572
wbxl2000 merged 1 commit into
mainfrom
fix/web-prompt-finish-on-snapshot

Conversation

@wbxl2000

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the problem is explained below.

Problem

In the web UI, a turn that finishes while the client is disconnected (laptop
closed, backgrounded tab, network drop) can leave the session stuck: the
working spinner never stops and the next message is queued behind a turn that
already ended.

The missed turn end is normally recovered by durable-event replay on
reconnect, but not when the client rebuilds from a session snapshot instead —
server-initiated resync (buffer overflow / epoch change / delta gap) or an
LRU-evicted subscription rebuild. Local prompt state (in-flight flag, sending
flag, cached prompt id, the message queue) was only ever cleared by the WS
sessionStatusChanged idle/aborted event, and snapshots never delivered one.

What changed

Web-only fix; no server, protocol, or UI style changes.

  • A shared local-turn-start lifecycle (generation + submit-pending, in
    useWorkspaceState) is now entered by every local turn start: prompt
    submit, steer, and skill activation. A snapshot requested before or during
    a turn start can tell it cannot reflect that turn.
  • syncSessionFromSnapshot rejects a snapshot that predates a local turn
    (or raced one) and re-syncs once the turn start settles, instead of
    permanently ignoring it. Snapshots that fall behind the live cursor during
    the fetch are dropped (one retry) rather than applied — resync/LRU rebuilds
    still always apply because their projector was deliberately reset.
  • When an authoritative snapshot shows the turn ended (inFlightTurn === null, status idle/aborted), it finishes the local prompt state through the
    same cleanup the WS idle path uses (finishPromptLocal), without firing
    completion notifications/sounds — opening a historical session must not cry
    wolf.
  • Turn-end side effects on the WS path are gated on the durable cursor
    actually advancing, so a late duplicate idle can never drain a second
    queued message.
  • window focus / online also trigger the existing stale-socket recovery
    (previously only visibilitychange); recovery still only reconnects when
    the socket actually looks stale.

Tests cover the snapshot finish path, the running/awaiting cases, the
new-prompt-during-fetch and submit-pending rejections, and the settle
callback retry.

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

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c8ed644

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

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

commit: c8ed644

@wbxl2000
wbxl2000 force-pushed the fix/web-prompt-finish-on-snapshot branch from 9ef18ec to c8ed644 Compare July 12, 2026 10:50
@wbxl2000
wbxl2000 merged commit 3a7aad6 into main Jul 12, 2026
10 checks passed
@wbxl2000
wbxl2000 deleted the fix/web-prompt-finish-on-snapshot branch July 12, 2026 11:01
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