kimi-code icon indicating copy to clipboard operation
kimi-code copied to clipboard

v2 engine (default): `/sessions` and `--continue` no longer show/up into old sessions of the current working directory

Open creatiVision opened this issue 3 months ago • 2 comments

Summary (main complaint)

With the v2 engine as the CLI default (#2627), the interactive /sessions picker (working-directory scope) and kimi --continue stop listing/resuming the older sessions of the current working directory. /sessions silently shows an empty/filtered list for the cwd, and --continue falls back to a fresh session (No sessions to continue under "<workDir>"; starting a fresh session.).

kimi --session <id> (resume directly by id) still works, and a fresh v2 session in the same dir is listed — this is why it is easy to miss.

Repro

  • Have older sessions under a workdir whose state.json records only workDir (legacy/v1-era) and no cwd, or that live in a legacy/alias bucket.
  • cd into that workdir.
  • Run /sessions (or kimi --continue).
  • Observed: old sessions are not listed / not resumed. Expected: they appear under the cwd scope.

Root cause

The v2 listing path filters by workspace-id set derived from the workdir, not by the physical session bucket like v1 did:

  • /sessions picker (cwd): fetchSessions('cwd') → listSessionsPage({ workDir }) (apps/kimi-code/src/tui/kimi-tui.ts) → SDK workspaceIdsFor(workDir) (packages/node-sdk/src/sdk-rpc-client-v2.ts:1080) → klient.global.sessions.list({ workspaceIds, … }) (v2 index).
    • workspaceIdsFor matches a workspace only when normalizeWorkDir(workspace.root) === workDir; legacy/alias buckets that don't resolve to the requested id-set are not returned.
  • kimi --continue (print mode): index.listRecent({}) then a client-side exact string summary.cwd === workDir (apps/kimi/src/cli/v2/run-v2-print.ts:362) — fails on path variations (symlink, trailing slash) and on sessions lacking an exact cwd.

Both converge on the same underlying gap: the v2 index/directory mapping does not fully reconcile v1-era buckets and sessions for "sessions of this working directory".

Suggested fix

Two levels, prefer the robust one:

  1. Recommended (server-side): make klient.global.sessions.list / the v2 session-index list accept a workDir (or resolve the full alias bucket set for a workDir, including legacy buckets) instead of requiring an exact workspace-id set. This restores /sessions and --continue together and scales (no client-side scan of every session).
  2. Minimal (client-side): in run-v2-print.ts (--continue), normalize the comparison to resolve(summary.cwd) === resolve(workDir) — but this only fixes print mode, not the TUI /sessions picker.

Related upstream work

  • #2627 — v2 engine became the CLI default (behavioral change introducing this).
  • #1659 ("preserve legacy buckets and coordinate queries", open) explicitly describes the sibling gap: "The v1 SessionStore.listWorkDir path still reads only the canonical bucket for legacy alias sessions; fixing that requires a separate indexed query change." The /sessions picker regression is the user-visible face of the same missing reconciliation.
  • #1390 (merged) — rebuilds the session index on boot; covers missing index lines, not this workdir-scoped listing.

Happy to open a PR with the client-side normalization first and help shape the server-side workdir-scoped query.

creatiVision avatar Aug 15 '26 13:08 creatiVision

I have submitted PR #2952 which implements the server-side fallback and fully resolves this issue! It correctly coalesces the authoritative on-disk sessions with the read model whenever a workspace-scoped query is used.

creatiVision avatar Aug 24 '26 05:08 creatiVision

A fix for this issue is available in PR #2952 (fix(cli): resume older working-directory sessions in /sessions and --continue).

Summary of Fix

  1. v2 session index read-model miss on workspace-scoped listRecent (sessionIndexService.ts): when the minidb read model yields an empty result for a workspaceIds-scoped query, coalesce onto the authoritative directory read so sessions on disk that weren't projected (legacy workDir-only or alias buckets) remain accessible in the TUI /sessions dialog.
  2. --continue matching (run-v2-print.ts): normalizes cwd === workDir comparisons via resolve(...) to handle trailing slashes, symlinks, and casing differences.
  3. Includes unit tests in sessionIndex.test.ts and changeset.

Per the updated CONTRIBUTING.md policy for bug fixes, could a maintainer please review and provide an /approve so PR #2952 can be officially considered? Thank you!

creatiVision avatar Sep 01 '26 16:09 creatiVision