fix(swarm): treat missing worker chat state.db as no-session, not error (#232)

Swarm worker chat readers currently surface a raw "state.db missing" error
when a worker profile hasn't been provisioned yet. Treat that condition
as "no session" — return an empty message list rather than propagating
the file-not-found exception to the UI.

Adds a regression test in swarm-chat-reader.test.ts covering the missing
state.db path.

Worked with Interstellar Code
This commit is contained in:
Interstellar-code
2026-05-02 19:34:30 +02:00
committed by GitHub
parent e230a501ff
commit 00bbace2e1
2 changed files with 25 additions and 1 deletions

View File

@@ -0,0 +1,25 @@
import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { describe, expect, it } from 'vitest'
import { readWorkerMessages } from './swarm-chat-reader'
describe('readWorkerMessages', () => {
it('treats a missing state.db as an unavailable session, not a UI error', () => {
const profilePath = mkdtempSync(join(tmpdir(), 'swarm-chat-reader-'))
try {
const result = readWorkerMessages(profilePath, 30)
expect(result).toEqual({
sessionId: null,
sessionTitle: null,
messages: [],
ok: false,
})
expect(result.error).toBeUndefined()
} finally {
rmSync(profilePath, { recursive: true, force: true })
}
})
})

View File

@@ -147,7 +147,6 @@ export function readWorkerMessages(profilePath: string, limit: number): SwarmCha
sessionTitle: null,
messages: [],
ok: false,
error: `state.db missing at ${dbPath}`,
}
}
try {