Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(mcp-host): log the conversation store path only after the worker opens it

Alfredo Lopezf428991687c3
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index b456fa4d5..7afc4621c 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.566",
+ "version": "0.1.567",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.566",
+ "version": "0.1.567",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --git a/mcp-host/package.json b/mcp-host/package.json
index 7b55eb592..8856784a3 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.566",
+ "version": "0.1.567",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/core/conversation/persistence/__tests__/conversationStoreFactory.test.ts b/mcp-host/src/core/conversation/persistence/__tests__/conversationStoreFactory.test.ts
index f35b45dca..6d0e263be 100644
--- a/mcp-host/src/core/conversation/persistence/__tests__/conversationStoreFactory.test.ts
+++ b/mcp-host/src/core/conversation/persistence/__tests__/conversationStoreFactory.test.ts
@@ -141,6 +141,108 @@ describe('createConversationStore store identity', () => {
}
})
+ it('logs the database path only after the worker answers its first operation', async () => {
+ const script = workerScript(`
+ const fs = require('node:fs')
+ const path = require('node:path')
+ const { parentPort, workerData } = require('node:worker_threads')
+ const held = []
+ parentPort.on('message', msg => {
+ if (msg.op.kind === 'ping') {
+ fs.writeFileSync(path.join(path.dirname(workerData.dbPath), 'ping-received'), '')
+ held.push(msg.id)
+ }
+ if (msg.op.kind === 'release') {
+ for (const id of held.splice(0)) parentPort.postMessage({ id, ok: true, result: 'pong' })
+ parentPort.postMessage({ id: msg.id, ok: true, result: 'released' })
+ }
+ if (msg.op.kind === 'shutdown') {
+ parentPort.postMessage({ id: msg.id, ok: true, result: { ok: true } })
+ process.exit(0)
+ }
+ })
+ `)
+ const dbPath = path.join(path.dirname(script), 'state.db')
+ const marker = path.join(path.dirname(script), 'ping-received')
+ const info = vi.spyOn(logger, 'info')
+ const opened = () => info.mock.calls.filter(([, msg]) => msg === '[ConversationStore] opened')
+ try {
+ const handle = createConversationStore({
+ mode: 'sqlite',
+ dbPath,
+ cacheSize: 10,
+ syncTimeoutMs: 5000,
+ asyncTimeoutMs: 5000,
+ checkpointEveryWrites: 100,
+ heartbeatMs: 60_000,
+ workerScriptPath: script,
+ })
+ // Liveness witness: the factory's first operation reached the worker.
+ await waitFor<void>(resolve => {
+ const poll = setInterval(() => {
+ if (fs.existsSync(marker)) {
+ clearInterval(poll)
+ resolve()
+ }
+ }, 5)
+ }, 3000)
+ expect(opened()).toEqual([])
+
+ await expect(handle.persistQueue?.enqueueSync({ kind: 'release' } as never)).resolves.toBe(
+ 'released'
+ )
+ await waitFor<void>(resolve => {
+ const poll = setInterval(() => {
+ if (opened().length > 0) {
+ clearInterval(poll)
+ resolve()
+ }
+ }, 5)
+ }, 3000)
+ expect(opened()).toEqual([[{ dbPath, mode: 'sqlite' }, '[ConversationStore] opened']])
+ await handle.shutdown()
+ } finally {
+ info.mockRestore()
+ }
+ })
+
+ it('logs no database path when the worker exits before opening the database', async () => {
+ const script = workerScript(`process.exit(1)`)
+ const info = vi.spyOn(logger, 'info')
+ const errors = vi.spyOn(logger, 'error')
+ try {
+ const failure = waitFor<Error>(resolve => {
+ createConversationStore({
+ mode: 'sqlite',
+ dbPath: path.join(path.dirname(script), 'state.db'),
+ cacheSize: 10,
+ syncTimeoutMs: 2000,
+ asyncTimeoutMs: 2000,
+ checkpointEveryWrites: 100,
+ heartbeatMs: 60_000,
+ workerScriptPath: script,
+ onPersistFailure: resolve,
+ })
+ }, 5000)
+ // Liveness witness: the factory saw the worker exit.
+ await expect(failure).resolves.toMatchObject({ message: 'db worker exited (code=1)' })
+ await waitFor<void>(resolve => {
+ const poll = setInterval(() => {
+ if (
+ errors.mock.calls.some(([, msg]) => msg === '[ConversationStore] database did not open')
+ ) {
+ clearInterval(poll)
+ resolve()
+ }
+ }, 5)
+ }, 3000)
+ expect(info.mock.calls.filter(([, msg]) => msg === '[ConversationStore] opened')).toEqual([])
+ } finally {
+ info.mockRestore()
+ errors.mockRestore()
+ }
+ })
+
it('logs no database path for a memory store', () => {
const info = vi.spyOn(logger, 'info')
try {
diff --git a/mcp-host/src/core/conversation/persistence/conversationStoreFactory.ts b/mcp-host/src/core/conversation/persistence/conversationStoreFactory.ts
index f686a8026..e7b17ffa8 100644
--- a/mcp-host/src/core/conversation/persistence/conversationStoreFactory.ts
+++ b/mcp-host/src/core/conversation/persistence/conversationStoreFactory.ts
@@ -92,9 +92,6 @@ export function createConversationStore(
}
const worker = spawnWorker(opts) as unknown as WorkerLike & Worker
- // One line per process names the database this Host reads and writes, so a
- // Pod replacement that changes the store is visible in the Pod logs.
- logger.info({ dbPath: opts.dbPath, mode: opts.mode }, '[ConversationStore] opened')
const persistQueue = new PersistQueue(worker, {
syncTimeoutMs: opts.syncTimeoutMs,
asyncTimeoutMs: opts.asyncTimeoutMs,
@@ -106,6 +103,15 @@ export function createConversationStore(
},
onFailure: opts.onPersistFailure,
})
+ // The worker answers only after it has opened and migrated the database, so
+ // the path is logged once that is true. One line per process names the
+ // database this Host reads and writes, so a Pod replacement that changes the
+ // store is visible in the Pod logs. A worker exit also ends the process
+ // through `onFailure`; this line only names the cause in the log.
+ persistQueue.enqueueSync({ kind: 'ping' }).then(
+ () => logger.info({ dbPath: opts.dbPath, mode: opts.mode }, '[ConversationStore] opened'),
+ (err: unknown) => logger.error({ err }, '[ConversationStore] database did not open')
+ )
const sqliteStore = new SqliteConversationStore(persistQueue, {
cacheSize: opts.cacheSize,