Skip to content

fix(cli): resume older working-directory sessions in /sessions and --continue - #2952

Open
creatiVision wants to merge 1 commit into
MoonshotAI:mainfrom
creatiVision:fix/session-workdir-resume
Open

fix(cli): resume older working-directory sessions in /sessions and --continue#2952
creatiVision wants to merge 1 commit into
MoonshotAI:mainfrom
creatiVision:fix/session-workdir-resume

Conversation

@creatiVision

Copy link
Copy Markdown

Problem

Since the v2 engine became the CLI default (#2627), /sessions (working-directory scope) and kimi --continue stop surfacing the older sessions of the current working directory — most notably legacy/v1-era sessions recorded with only workDir (no cwd). /sessions shows an empty cwd list and --continue silently starts a fresh session.

Related: #2951 (report), #1650 (open, describes the same bucket-coordination gap).

What changed

Two spots covered:

  1. v2 session index read-model miss on a workspace-scoped listRecent (packages/agent-core-v2/src/app/sessionIndex/sessionIndexService.ts): when the minidb read model answers an empty page for a workspaceIds-scoped query, coalesce onto the authoritative directory read so sessions that exist on disk but were not projected (legacy workDir-only, alias buckets) are never hidden. This fixes the TUI /sessions working-directory scope.

  2. --continue matching (apps/kimi-code/src/cli/v2/run-v2-print.ts): normalize the cwd === workDir comparison with resolve(...) (matching the existing --session guard) so path variations (symlink, trailing slash, case) no longer drop the last session.

Changed

  • packages/agent-core-v2/src/app/sessionIndex/sessionIndexService.ts
  • apps/kimi-code/src/cli/v2/run-v2-print.ts
  • test in packages/agent-core-v2/test/app/sessionIndex/sessionIndex.test.ts
  • changeset @moonshot-ai/kimi-code patch

Out of scope

Checklist

  • Explain the problem
  • Describe what changed
  • Added a unit test covering the read-model fallback

@changeset-bot

changeset-bot Bot commented Aug 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5abe837

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

@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: 5abe8379c8

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

// alias buckets). Coalesce onto the authoritative source so `/sessions`
// (working-directory scope) and `--continue` never hide them. Unscooped
// reads stay on the projected recency column.
if (page.items.length === 0 && query.workspaceIds !== undefined) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Include authoritative misses in every affected listing

When a published generation omits a legacy/v1 session, this fallback runs only if the projected workspace page is completely empty. If that workspace has even one projected session, /sessions returns the nonempty stale page and still hides the omitted sessions; moreover, --continue calls listRecent({}), so its unscoped query can never enter this branch. Thus the exact stale-generation scenario this change targets remains broken for partial workspace misses and all unscoped resume reads; merge or otherwise reconcile authoritative results rather than treating only an empty scoped page as a miss.

AGENTS.md reference: packages/agent-core-v2/AGENTS.md:L81-L83

Useful? React with 👍 / 👎.

Comment on lines +331 to +335
// A workspace-scoped read that returns nothing can still hide sessions
// that exist on disk but were not projected into the read model (e.g.
// legacy/v1-era sessions recorded with only `workDir`, or sessions in
// alias buckets). Coalesce onto the authoritative source so `/sessions`
// (working-directory scope) and `--continue` never hide them. Unscooped

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Move method-body narration into the file header

This newly added explanatory block sits inside listRecent and narrates the implementation, while the scoped v2 guide requires comments to live solely in the top-of-file /** */ block and describe external responsibilities. Remove the inline narration or fold the relevant responsibility-level context into the existing module header.

AGENTS.md reference: packages/agent-core-v2/AGENTS.md:L36-L38

Useful? React with 👍 / 👎.

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