diff --git a/.changeset/session-workdir-resume-fix.md b/.changeset/session-workdir-resume-fix.md new file mode 100644 index 00000000000..95dfe8237ec --- /dev/null +++ b/.changeset/session-workdir-resume-fix.md @@ -0,0 +1,5 @@ +--- +"@moonshot-ai/kimi-code": patch +--- + +Restore older working-directory sessions in `/sessions` and `kimi --continue`. diff --git a/apps/kimi-code/src/cli/v2/run-v2-print.ts b/apps/kimi-code/src/cli/v2/run-v2-print.ts index 97f35d13046..5cb957f1c72 100644 --- a/apps/kimi-code/src/cli/v2/run-v2-print.ts +++ b/apps/kimi-code/src/cli/v2/run-v2-print.ts @@ -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), + ); if (previous !== undefined) { const session = await resumeById(previous.id); const agentContext = await ensureMainAgent(session); diff --git a/packages/agent-core-v2/src/app/sessionIndex/sessionIndexService.ts b/packages/agent-core-v2/src/app/sessionIndex/sessionIndexService.ts index eb55317feec..4d9c4f32809 100644 --- a/packages/agent-core-v2/src/app/sessionIndex/sessionIndexService.ts +++ b/packages/agent-core-v2/src/app/sessionIndex/sessionIndexService.ts @@ -297,7 +297,14 @@ export class FileSessionIndex extends Disposable implements ISessionIndex { async listRecent(query: SessionListQuery): Promise> { 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) { + const legacy = await this.listLegacy(query); + if (legacy.items.length > 0) return legacy; + } + return page; + }, () => this.listLegacy(query), ); } diff --git a/packages/agent-core-v2/test/app/sessionIndex/sessionIndex.test.ts b/packages/agent-core-v2/test/app/sessionIndex/sessionIndex.test.ts index 439b6cabe16..f7548926b51 100644 --- a/packages/agent-core-v2/test/app/sessionIndex/sessionIndex.test.ts +++ b/packages/agent-core-v2/test/app/sessionIndex/sessionIndex.test.ts @@ -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],