Skip to content

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

TypeScript

fix(mcp-host): retain legacy catalog sessions

Josué8423c4b6c168
diff --git a/mcp-host/src/core/conversation/persistence/__tests__/sqliteConversationStore.test.ts b/mcp-host/src/core/conversation/persistence/__tests__/sqliteConversationStore.test.ts
index 347f876c3..9217984f5 100644
--- a/mcp-host/src/core/conversation/persistence/__tests__/sqliteConversationStore.test.ts
+++ b/mcp-host/src/core/conversation/persistence/__tests__/sqliteConversationStore.test.ts
@@ -384,7 +384,9 @@ describe('SqliteConversationStore — session summary listing', () => {
const manager = new ConversationManager(handle.store)
const userId = 'subject:rpc:embedded'
const key = `${userId}:rpc:agent-x:chat-1`
- const conversation = await manager.getOrCreate(key, { userId })
+ // Catalog visibility remains keyed by the authenticated prefix even when
+ // an older persistence path derived user_id differently.
+ const conversation = await manager.getOrCreate(key)
await manager.startTurn(conversation, 'hello', 'task-1')
await manager.completeTurn(conversation, 'done')
await handle.persistQueue.drainSessionKey(key)
@@ -395,6 +397,14 @@ describe('SqliteConversationStore — session summary listing', () => {
expect(summaries.map(session => [session.agent, session.chatId])).toEqual([
['agent-x', 'chat-1'],
])
+
+ handle.worker.db.prepare('UPDATE sessions SET user_id = NULL WHERE id = ?').run(
+ conversation.id
+ )
+ const legacySummaries = await handle.store.listSessionSummariesByPrefix(`${userId}:rpc:`)
+ expect(legacySummaries.map(session => [session.agent, session.chatId])).toEqual([
+ ['agent-x', 'chat-1'],
+ ])
} finally {
await handle.shutdown()
}
diff --git a/mcp-host/src/db/migrations/__tests__/011-session-summary-user-activity-index.test.ts b/mcp-host/src/db/migrations/__tests__/011-session-summary-user-activity-index.test.ts
index 608715fbe..07e2c449d 100644
--- a/mcp-host/src/db/migrations/__tests__/011-session-summary-user-activity-index.test.ts
+++ b/mcp-host/src/db/migrations/__tests__/011-session-summary-user-activity-index.test.ts
@@ -5,7 +5,7 @@ import * as m011 from '../011-session-summary-user-activity-index'
import { migrations } from '../index'
describe('migration 011 — session summary user/activity index', () => {
- it('serves the production catalog query without a temporary sort', () => {
+ it('serves current rows by activity and legacy rows by session-key range', () => {
const db = new Database(':memory:')
for (const migration of migrations) migration.up(db)
@@ -33,7 +33,7 @@ describe('migration 011 — session summary user/activity index', () => {
}) as Array<{ detail: string }>
expect(plan.some(step => step.detail.includes('idx_sessions_summary_activity'))).toBe(true)
- expect(plan.some(step => step.detail.includes('idx_sessions_session_key'))).toBe(false)
+ expect(plan.some(step => step.detail.includes('idx_sessions_session_key'))).toBe(true)
m011.down(db)
const downgraded = db
diff --git a/mcp-host/src/db/statements.ts b/mcp-host/src/db/statements.ts
index 8e460fd6e..334c36c9b 100644
--- a/mcp-host/src/db/statements.ts
+++ b/mcp-host/src/db/statements.ts
@@ -236,13 +236,27 @@ export function prepareStatements(db: Database): PreparedStatements {
SELECT * FROM sessions WHERE session_key LIKE ? ORDER BY started_at DESC
`),
selectSessionSummariesByPrefix: db.prepare(`
- WITH scoped_sessions AS (
+ WITH candidate_sessions AS (
+ -- Current rows take the user/activity index fast path. The second arm
+ -- preserves catalog visibility for legacy rows whose nullable user_id
+ -- was absent or derived differently; the authenticated key range still
+ -- provides the tenant boundary for both arms.
SELECT *
- FROM sessions
+ FROM sessions
WHERE user_id = @user_id
AND session_key >= @prefix_start
AND session_key < @prefix_end
- AND (
+ UNION ALL
+ SELECT *
+ FROM sessions
+ WHERE (user_id IS NULL OR user_id <> @user_id)
+ AND session_key >= @prefix_start
+ AND session_key < @prefix_end
+ ),
+ scoped_sessions AS (
+ SELECT *
+ FROM candidate_sessions
+ WHERE (
(@agent_scoped = 1 AND length(session_key) > length(@prefix_start))
OR
(