v2 engine (default): `/sessions` and `--continue` no longer show/up into old sessions of the current working directory
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.jsonrecords onlyworkDir(legacy/v1-era) and nocwd, or that live in a legacy/alias bucket. cdinto that workdir.- Run
/sessions(orkimi --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:
/sessionspicker (cwd):fetchSessions('cwd')→listSessionsPage({ workDir })(apps/kimi-code/src/tui/kimi-tui.ts) → SDKworkspaceIdsFor(workDir)(packages/node-sdk/src/sdk-rpc-client-v2.ts:1080) →klient.global.sessions.list({ workspaceIds, … })(v2 index).workspaceIdsFormatches a workspace only whennormalizeWorkDir(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 stringsummary.cwd === workDir(apps/kimi/src/cli/v2/run-v2-print.ts:362) — fails on path variations (symlink, trailing slash) and on sessions lacking an exactcwd.
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:
- Recommended (server-side): make
klient.global.sessions.list/ the v2 session-index list accept aworkDir(or resolve the full alias bucket set for a workDir, including legacy buckets) instead of requiring an exact workspace-id set. This restores/sessionsand--continuetogether and scales (no client-side scan of every session). - Minimal (client-side): in
run-v2-print.ts(--continue), normalize the comparison toresolve(summary.cwd) === resolve(workDir)— but this only fixes print mode, not the TUI/sessionspicker.
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.listWorkDirpath still reads only the canonical bucket for legacy alias sessions; fixing that requires a separate indexed query change." The/sessionspicker 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.
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.
A fix for this issue is available in PR #2952 (fix(cli): resume older working-directory sessions in /sessions and --continue).
Summary of Fix
- v2 session index read-model miss on workspace-scoped
listRecent(sessionIndexService.ts): when the minidb read model yields an empty result for aworkspaceIds-scoped query, coalesce onto the authoritative directory read so sessions on disk that weren't projected (legacyworkDir-only or alias buckets) remain accessible in the TUI/sessionsdialog. --continuematching (run-v2-print.ts): normalizescwd === workDircomparisons viaresolve(...)to handle trailing slashes, symlinks, and casing differences.- Includes unit tests in
sessionIndex.test.tsand 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!