Skip to content
Open
5 changes: 5 additions & 0 deletions .changeset/session-workdir-resume-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---

Restore older working-directory sessions in `/sessions` and `kimi --continue`.
4 changes: 3 additions & 1 deletion apps/kimi-code/src/cli/v2/run-v2-print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,9 @@ async function resolveNativeSession(

if (opts.continue) {
const page = await index.listRecent({});
const previous = page.items.find((summary) => summary.cwd === workDir);
const previous = page.items.find(
(summary) => summary.cwd !== undefined && resolve(summary.cwd) === resolve(workDir),

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 Compare Windows paths case-insensitively

When the same Windows working directory is entered with different component casing (for example, a stored C:/Users/Alice/Repo versus a current C:/users/alice/repo), resolve() makes the paths absolute and normalizes their syntax but preserves that casing, so this equality still fails and --continue silently starts a new session. Use the repository's Windows-aware workspace-root normalization, or otherwise case-fold Windows-shaped paths, before comparing them.

Useful? React with 👍 / 👎.

@creatiVision creatiVision Sep 26, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in commit 158ad7928. Added normalizePathForComparison in run-v2-print.ts, which case-folds paths on Windows (process.platform === 'win32' ? resolved.toLowerCase() : resolved) before equality comparison.

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 Resolve symlink aliases before comparing work directories

When a session was created through the SDK/API with a symlinked workDir (for example, /work/repo-link) and kimi --continue is later launched from the symlink target (/srv/repo), this still starts a fresh session. resolve() only performs lexical path normalization and leaves the symlink component intact, so the two paths remain unequal; use filesystem canonicalization such as realpath before comparing, with an appropriate fallback for unavailable paths.

Useful? React with 👍 / 👎.

@creatiVision creatiVision Sep 26, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in commit 158ad7928. In normalizePathForComparison, paths are canonicalized with realpathSync.native(p) (with fallback to resolve(p)), ensuring symlinks match their canonical target paths.

);
Comment on lines +469 to +474

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 Validate cached cwd before resolving it

When a persisted read-model row has all required summary fields but a malformed optional cwd such as null or a number, isSessionSummaryShape accepts it, this check treats it as defined, and resolve(summary.cwd) can throw instead of skipping the unusable session. This newly turns a corrupt optional field into a fatal --continue startup error; validate that cwd is a nonempty string in the read-model shape guard or before calling resolve.

Useful? React with 👍 / 👎.

@creatiVision creatiVision Sep 26, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in commit 158ad7928. Updated isSessionSummaryShape in sessionIndexService.ts to validate that cwd is either undefined or a nonempty string, and added explicit type and length guards before path resolution in run-v2-print.ts.

if (previous !== undefined) {
const session = await resumeById(previous.id);
const agentContext = await ensureMainAgent(session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,14 @@ export class FileSessionIndex extends Disposable implements ISessionIndex {

async listRecent(query: SessionListQuery): Promise<Page<SessionSummary>> {
return this.withReadModel(
(generation) => this.listRecentFromReadModel(generation, query),
async (generation) => {
const page = await this.listRecentFromReadModel(generation, query);
if (page.items.length === 0 && query.workspaceIds !== undefined) {
Comment thread
creatiVision marked this conversation as resolved.
const legacy = await this.listLegacy(query);
if (legacy.items.length > 0) return legacy;
}
return page;
},
() => this.listLegacy(query),
);
}
Expand Down
11 changes: 11 additions & 0 deletions packages/agent-core-v2/test/app/sessionIndex/sessionIndex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,17 @@ describe('FileSessionIndex (read model)', () => {
expect(fileStorage.listCalls).toBe(0);
});

it('coalesces a workspace-scoped miss onto the authoritative directory', async () => {
const store = build();
await store.prepare();
store.stopReconcileLoop();
await seedSession('legacy', { workDir: WORK_DIR, createdAt: 1, updatedAt: 2 });

const page = await store.listRecent({ workspaceIds: [workspaceId] });
expect(page.items.map((s) => s.id)).toEqual(['legacy']);
expect(page.items[0]).toMatchObject({ cwd: WORK_DIR });
});

it('paginates exactly through same-millisecond ties', async () => {
const specs: [string, number][] = [
['a', 100],
Expand Down