Skip to content

fix: web session handling and legacy session recovery - #1554

Closed
wbxl2000 wants to merge 1 commit into
mainfrom
fix/web-session-handling
Closed

fix: web session handling and legacy session recovery#1554
wbxl2000 wants to merge 1 commit into
mainfrom
fix/web-session-handling

Conversation

@wbxl2000

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — these are four user-facing fixes verified together against the running daemon and web UI. Problems explained below.

Problem

  1. Mid-turn resync blob: when the web UI reconnects or resyncs while a turn is streaming, thinking blocks and tool calls from already-completed steps collapsed into one giant duplicated text blob trailing the structured history. in_flight_turn accumulated the whole turn's text even though the messages transcript already carried every completed step, so a reseeding client double-rendered prior steps as raw text.
  2. Server token re-entry: the server access token was mirrored to sessionStorage only, so every new tab or browser restart forced entering it again.
  3. Workspace picker: workspaces could only be added by browsing the folder tree — typing or pasting an absolute path was not supported.
  4. Legacy sessions invisible: sessions created by older (kimi-cli-era) versions vanished from the session list and failed to open in the web UI. Their state.json only records a bare top-level cwd, which the startup session-index rebuild did not recognize.

What changed

Mid-turn resync (server + protocol + web)

  • InFlightTurnTracker resets accumulated assistant/thinking text at every turn.step.started, so in_flight_turn describes only the step still streaming; completed steps come from the transcript.
  • Delta offsets are now step-relative, and the web projector (agentEventProjector) resets its local text/thinking counters at the same boundary so live deltas stay aligned with the seeded snapshot.
  • packages/protocol documents the step-relative semantics on the in_flight_turn schema.

Token persistence (web)

  • serverAuth mirrors the credential to localStorage instead of sessionStorage, so it survives tab close and browser restarts, with a one-time upgrade that adopts any legacy sessionStorage copy so the update itself does not force a re-entry. A 401 still clears it, and kimi server rotate-token invalidates stale copies.

Workspace path entry (web)

  • AddWorkspaceDialog switches from fuzzy search to path mode when the input starts with / or ~: live validation, prefix-matched completion candidates, and specific errors (path not found / parent does not exist). A valid path live-follows the browser so pressing Enter or "Open this folder" adds it; when file browsing is unavailable the picker degrades to a type-a-path box.
  • On success from the session onboarding composer, the picker flies into the workspace header anchor before closing (Dialog now exposes its panel/overlay so consumers can run exit animations).
  • useWorkspaceState unions the global session walk (the same source Cmd+K search uses) into the per-workspace load, so sessions with inconsistent workspace mappings — symlinked cwds, stale index entries, removed workspaces — stay visible.

Legacy session recovery (agent-core)

  • SessionStore reindex now falls back to the kimi-cli-era bare top-level cwd (after workDir and custom.cwd) when recovering a session's workDir, so those sessions get a correct index entry and appear in the web UI.
  • buildProtocolContent passes raw kosong content parts through for tool results that carry media (image/video/audio), matching the live tool.result event shape so REST consumers can still render the media.

Tests: new server-auth.test.ts (persistence + legacy-store migration), new inFlightTurnTracker.test.ts (step-boundary reset), extended agent-event-projector / turn-logic (resync keeps structured blocks, no blob), message-service (media tool results), and session-store (legacy cwd recovery).

Verification: affected package suites pass — kimi-web 45 tests, agent-core 33 tests, server 4 tests — plus vue-tsc / tsc --noEmit typechecks for the three touched packages. The four fixes were also verified end-to-end in the running web UI.

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. (Four patch changesets included, one per fix.)
  • Ran gen-docs skill, or this PR needs no doc update. (Web UI behavior fixes; CLI user docs unaffected.)

Four fixes verified against the running daemon and web UI:

- web: stop thinking blocks and tool calls from collapsing into one
  giant duplicated text blob when the page reconnects or resyncs
  mid-turn
- web: keep the server access token across tab close and browser
  restarts, so it only needs to be entered once per device
- web: add workspaces by typing an absolute path directly in the
  workspace picker's search box, with live validation and completion
  suggestions
- agent-core: recognize the legacy top-level cwd in session state
  files so sessions created by older versions appear in the session
  list and open in the web UI
@changeset-bot

changeset-bot Bot commented Jul 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 13c6568

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

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

commit: 13c6568

@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: 13c6568884

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

// switches from fuzzy search to path mode. A valid path live-follows (the
// browser jumps to it, so "Open this folder" submits it); an invalid one
// shows a specific error plus prefix-matched candidates in the list.
const PATH_LIKE = /^(?:\/|~(?:\/|$))/;

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 Recognize Windows absolute paths

When the web UI is used with a Windows daemon, absolute paths such as C:\Users\me or UNC paths do not start with / or ~, so this predicate never enters path mode. The server-side browser accepts platform-absolute paths via node:path.isAbsolute, so these paths are instead treated as fuzzy-search text, and in degraded mode pressing Enter does nothing because the paste fallback was removed.

Useful? React with 👍 / 👎.

Comment thread apps/kimi-web/src/App.vue
// Success: keep the dialog alive so it can fly into the workspace anchor; it
// emits close when the animation finishes (handleCloseAddWorkspace owns
// showAddWorkspace from there).
addWorkspaceSucceeded.value = true;

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 late workspace-add completions

If the user closes the picker while addWorkspaceByPath is still in flight and that request later succeeds, this late write leaves addWorkspaceSucceeded stuck at true after the dialog has unmounted. openAddWorkspace does not reset it, and AddWorkspaceDialog only reacts to a false→true change, so the next successful add will not trigger the success close/animation and the picker remains open.

Useful? React with 👍 / 👎.

@wbxl2000

Copy link
Copy Markdown
Collaborator Author

Closing: the four bundled fixes have been split up.

Branch fix/web-session-handling is kept for reference.

@wbxl2000 wbxl2000 closed this Jul 12, 2026
@wbxl2000

Copy link
Copy Markdown
Collaborator Author

Correction: #1567 now carries only the server token persistence fix. The legacy session-recovery parts (legacy top-level cwd fallback + global session-list union) were held back and are stashed locally, to be re-submitted separately later.

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