Skip to content

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

TypeScript

fix(mcp-host): drop the chain entry of a settled keyed sync write

Alfredo Lopez515f72ff7479
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index 2c029dab8..ac0c8c719 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.576",
+ "version": "0.1.577",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.576",
+ "version": "0.1.577",
"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 3e0f48a8e..a3cd4abbc 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.576",
+ "version": "0.1.577",
"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__/persistQueue.test.ts b/mcp-host/src/core/conversation/persistence/__tests__/persistQueue.test.ts
index 7211bd0c7..68aa11084 100644
--- a/mcp-host/src/core/conversation/persistence/__tests__/persistQueue.test.ts
+++ b/mcp-host/src/core/conversation/persistence/__tests__/persistQueue.test.ts
@@ -35,6 +35,32 @@ describe('PersistQueue', () => {
await expect(promise).resolves.toBe('pong')
})
+ it.each([
+ ['ok', { ok: true, result: 'pong' }],
+ ['error', { ok: false, error: { code: 'BOOM', message: 'kaboom' } }],
+ ] as const)(
+ 'drops the chain entry of a keyed enqueueSync once its %s reply settles',
+ async (_label, reply) => {
+ const worker = new FakeWorker()
+ const q = new PersistQueue(worker, {
+ syncTimeoutMs: 200,
+ asyncTimeoutMs: 500,
+ stallTimeoutMs: 30_000,
+ })
+ const chains = (q as unknown as { writeChain: Map<string, unknown> }).writeChain
+ const promise = q.enqueueSync({ kind: 'ping' }, 'session-1').catch((err: Error) => err)
+ // Liveness witness: the write is chained under its key while in flight.
+ expect(chains.has('session-1')).toBe(true)
+ await vi.waitFor(() => expect(worker.sent).toHaveLength(1))
+ worker.emit('message', { id: worker.sent[0].id, ...reply } as WorkerReply)
+ const outcome = await promise
+ expect(outcome instanceof Error ? outcome.message : outcome).toBe(
+ reply.ok ? 'pong' : 'kaboom'
+ )
+ await vi.waitFor(() => expect(chains.has('session-1')).toBe(false))
+ }
+ )
+
it('rejects enqueueSync when worker replies with error', async () => {
const worker = new FakeWorker()
const q = new PersistQueue(worker, {
diff --git a/mcp-host/src/core/conversation/persistence/persistQueue.ts b/mcp-host/src/core/conversation/persistence/persistQueue.ts
index 23a1913c1..aabe7d6f1 100644
--- a/mcp-host/src/core/conversation/persistence/persistQueue.ts
+++ b/mcp-host/src/core/conversation/persistence/persistQueue.ts
@@ -183,24 +183,24 @@ export class PersistQueue {
}
if (sessionKey) {
const prev = this.writeChain.get(sessionKey) ?? Promise.resolve()
- const next = prev
- .then(() => this.sendUnlessFailed<T>(op, this.opts.syncTimeoutMs))
- .finally(() => {
- if (this.writeChain.get(sessionKey) === (next as Promise<unknown>)) {
- this.writeChain.delete(sessionKey)
- }
- })
+ const next = prev.then(() => this.sendUnlessFailed<T>(op, this.opts.syncTimeoutMs))
// The chain derivative must never surface the rejection itself — the
// caller gets it via the returned `next` (loud there). Without the
// rejection handler a failed sync write would ALSO raise a process-level
- // unhandledRejection from this internal bookkeeping copy (D3).
- this.writeChain.set(
- sessionKey,
- next.then(
+ // unhandledRejection from this internal bookkeeping copy (D3). The
+ // cleanup compares against the derivative, because that is what the map
+ // holds.
+ const chained: Promise<void> = next
+ .then(
() => undefined,
() => undefined
)
- )
+ .finally(() => {
+ if (this.writeChain.get(sessionKey) === chained) {
+ this.writeChain.delete(sessionKey)
+ }
+ })
+ this.writeChain.set(sessionKey, chained)
return next
}
return this.send<T>(op, this.opts.syncTimeoutMs)