Skip to content
Merged
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/archive-missing-workspace.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---

Fix sessions failing to archive when their workspace folder no longer exists.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export async function setSessionArchived(
): Promise<ColdSessionArchiveOutcome> {
const manager = accessor.get(ISessionManager);
return manager.withLifecycleSerialization(sessionId, async (unguarded) => {
await manager.whenResumeSettled(sessionId);
await manager.whenResumeSettled(sessionId).catch(() => undefined);
const live = getLiveSessionById(accessor, sessionId);
if (live !== undefined) {
if (archived) await unguarded.archive();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,16 @@ describe('setSessionArchivedBatch', () => {
expect(persisted['isCustomTitle']).toBe(true);
});

it('fails the item when a concurrent resume failed instead of cold-classifying', async () => {
it('cold-classifies the item when a concurrent resume failed', async () => {
const outcomes = await setSessionArchivedBatch(
coldPathAccessor({
storeGet: async () => {
throw new Error('unreachable — the settle throws first');
},
storeGet: async () => ({ id: 's1', createdAt: 1, updatedAt: 2, archived: false }),
resumeError: new Error('resume boom'),
}),
['s1'],
true,
);
expect(outcomes).toEqual([
{ id: 's1', ok: false, reason: 'error', message: 'resume boom' },
]);
expect(outcomes).toEqual([{ id: 's1', ok: true }]);
});

it('reads and migrates the legacy session-meta location before answering not_found', async () => {
Expand Down
26 changes: 26 additions & 0 deletions packages/kap-server/test/sessions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import {
IEventService,
ISessionCronService,
ISessionManager,
IWorkspaceService,
MAIN_AGENT_ID,
closeSessionById,
getLiveSessionById,
resumeSessionById,
sessionDirOf,
type ServiceIdentifier,
type ScopeSeed,
Expand Down Expand Up @@ -782,6 +784,30 @@ describe('server-v2 /api/v1/sessions', () => {
expect(got.body.data.archived).toBe(true);
});

it('archives a cold session after a failed resume when the workspace root is gone', async () => {
const cwd = join(home as string, 'gone-ws');
await mkdir(cwd);
const created = await postJson<SessionWire>('/api/v1/sessions', { metadata: { cwd } });
const id = created.body.data.id;
await closeSessionById((server as RunningServer).core.accessor, id);
await (server as RunningServer).core.accessor
.get(IWorkspaceService)
.delete(encodeWorkDirKey(cwd));
await rm(cwd, { recursive: true, force: true });

await expect(
resumeSessionById((server as RunningServer).core.accessor, id),
).rejects.toThrow(/does not exist/);

const archived = await postJson<{ archived: boolean }>(`/api/v1/sessions/${id}:archive`);
expect(archived.body.code).toBe(0);
expect(archived.body.data).toEqual({ archived: true });

const got = await getJson<SessionWire>(`/api/v1/sessions/${id}`);
expect(got.body.code).toBe(0);
expect(got.body.data.archived).toBe(true);
});

it('restores an archived session via :restore and returns it to the default list', async () => {
const cwd = home as string;
const created = await postJson<SessionWire>('/api/v1/sessions', { metadata: { cwd } });
Expand Down
Loading