Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): normalize empty agent in sessions list (R1-L2)
Diego Zacariaseb3be6065cfc
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 8a33e7feb..74810f066 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.227",+ "version": "0.1.228","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.227",+ "version": "0.1.228","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 5dba6d20e..46b92f93b 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.227",+ "version": "0.1.228","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/server/__tests__/sessionRouteHandlers.test.ts b/mcp-host/src/server/__tests__/sessionRouteHandlers.test.tsnew file mode 100644index 000000000..6eb0d7006--- /dev/null+++ b/mcp-host/src/server/__tests__/sessionRouteHandlers.test.ts@@ -0,0 +1,36 @@+import { describe, expect, it } from 'vitest'+import { ConversationManager } from '../../core/conversation/conversation'+import { createSessionRouteHandlers } from '../sessionRouteHandlers'++function makeHandlersUnderTest() {+ const convManager = new ConversationManager()+ const { handleSessionsList, handleSessionMessages } = createSessionRouteHandlers({+ getConversationManager: () => convManager,+ redactToolError: (_toolName, rawError) => rawError,+ })+ return { convManager, handleSessionsList, handleSessionMessages }+}++async function seed(convManager: ConversationManager, key: string): Promise<void> {+ const conv = await convManager.getOrCreate(key)+ await convManager.startTurn(conv, 'q', 'task')+ await convManager.completeTurn(conv, 'a')+}++describe('createSessionRouteHandlers — handleSessionsList (R1-L2)', () => {+ it('treats an empty agent identically to an absent agent (unscoped catalog, not fail-closed)', async () => {+ const { convManager, handleSessionsList } = makeHandlersUnderTest()+ await seed(convManager, 'user-A:rpc:agent-x:chat-1')+ await seed(convManager, 'user-A:rpc:agent-y:chat-2')++ const absent = await handleSessionsList('user-A', {})+ const empty = await handleSessionsList('user-A', { agent: '' })++ // Absent agent → unscoped catalog spanning both agents.+ expect(absent.items.map(item => item.chatId).sort()).toEqual(['chat-1', 'chat-2'])+ // Empty agent must resolve to the SAME unscoped result. Before the fix the+ // prefix treated '' as falsy (unscoped) while the store query received ''+ // (agent scope), which fail-closed to an empty catalog — so the two diverged.+ expect(empty).toEqual(absent)+ })+})diff --git a/mcp-host/src/server/sessionRouteHandlers.ts b/mcp-host/src/server/sessionRouteHandlers.tsindex bc4112e6b..4f72473c4 100644--- a/mcp-host/src/server/sessionRouteHandlers.ts+++ b/mcp-host/src/server/sessionRouteHandlers.ts@@ -66,15 +66,23 @@ export function createSessionRouteHandlers(deps: SessionRouteHandlerDeps) {query: { agent?: string; limit?: number; cursor?: string }) => {const convManager = getConversationManager()- const keyPrefix = query.agent ? `${userSub}:rpc:${query.agent}:` : `${userSub}:rpc:`- const cursorScope = sessionsCursorScope(userSub, query.agent)+ // Normalize an empty `agent` to undefined ONCE, up front. An empty string is+ // "no agent scope", not the agent literally named "". Without this the three+ // downstream uses disagreed: the prefix treated '' as falsy (non-scoped) but+ // the store query and cursor scope received '' as a real agent — the store+ // then fail-closes ('' -> userIdFromRpcPrefix null -> []), so an empty agent+ // silently returned zero sessions instead of the unscoped catalog. The store+ // fail-close is correct and stays; the fix is to never send it '' from here.+ const agent = query.agent || undefined+ const keyPrefix = agent ? `${userSub}:rpc:${agent}:` : `${userSub}:rpc:`+ const cursorScope = sessionsCursorScope(userSub, agent)const cursor = decodeSessionsCursor(query.cursor, cursorScope)const entries = await convManager.listSessionSummariesForUserAsync(keyPrefix, {limit: query.limit === undefined ? undefined : query.limit + 1,cursor: cursor? { updatedAt: new Date(cursor.updatedAt), key: `${keyPrefix}${cursor.key}` }: undefined,- agent: query.agent,+ agent,})const { page, nextCursor } = paginateSessionSummaries(entries,