Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 👍 / 👎.

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 👍 / 👎.

);
Comment on lines +451 to +453

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 👍 / 👎.

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