Skip to content

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

TypeScript

fix: validate transcript pagination before host resolution

Josué484946db4580
diff --git a/mcp-host/src/core/conversation/__tests__/inMemoryConversationStore.test.ts b/mcp-host/src/core/conversation/__tests__/inMemoryConversationStore.test.ts
index e1ffe1c5a..e341c2dab 100644
--- a/mcp-host/src/core/conversation/__tests__/inMemoryConversationStore.test.ts
+++ b/mcp-host/src/core/conversation/__tests__/inMemoryConversationStore.test.ts
@@ -182,6 +182,30 @@ describe('InMemoryConversationStore', () => {
])
})
+ it('rejects malformed unscoped keys before applying the page limit', async () => {
+ const malformedEmptyAgent = {
+ ...makeConversation('u-1'),
+ updated_at: new Date('2026-01-03T00:00:00.000Z'),
+ }
+ const malformedEmptyChat = {
+ ...makeConversation('u-1'),
+ updated_at: new Date('2026-01-02T00:00:00.000Z'),
+ }
+ const valid = {
+ ...makeConversation('u-1'),
+ updated_at: new Date('2026-01-01T00:00:00.000Z'),
+ }
+ store.set('u-1:rpc::missing-agent', malformedEmptyAgent)
+ store.set('u-1:rpc:agent-x:', malformedEmptyChat)
+ store.set('u-1:rpc:agent-x:chat-1', valid)
+
+ const summaries = await store.listSessionSummariesByPrefix('u-1:rpc:', { limit: 1 })
+
+ expect(summaries.map(session => [session.agent, session.chatId])).toEqual([
+ ['agent-x', 'chat-1'],
+ ])
+ })
+
it('counts user and assistant bubbles without counting tool storage rows', async () => {
const conversation = makeConversation('u-1')
conversation.turns = [
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 01a2cbd31..3f37744f2 100644
--- a/mcp-host/src/core/conversation/persistence/__tests__/sqliteConversationStore.test.ts
+++ b/mcp-host/src/core/conversation/persistence/__tests__/sqliteConversationStore.test.ts
@@ -286,6 +286,12 @@ describe('SqliteConversationStore — session summary listing', () => {
VALUES (?, ?, 'rpc', ?, ?, ?)`
)
.run('degenerate-newest', 'u-1:rpc::bad', 'u-1', 399, 400)
+ handle.worker.db
+ .prepare(
+ `INSERT INTO sessions (id, session_key, source, user_id, started_at, last_activity_at)
+ VALUES (?, ?, 'rpc', ?, ?, ?)`
+ )
+ .run('degenerate-empty-chat', 'u-1:rpc:agent-x:', 'u-1', 398, 399)
handle.worker.db
.prepare(
`INSERT INTO sessions (id, session_key, source, user_id, started_at, last_activity_at)
diff --git a/rpc-proxy/src/__tests__/sessions-passthrough.test.ts b/rpc-proxy/src/__tests__/sessions-passthrough.test.ts
index 2d7ae7c31..8c435eaa2 100644
--- a/rpc-proxy/src/__tests__/sessions-passthrough.test.ts
+++ b/rpc-proxy/src/__tests__/sessions-passthrough.test.ts
@@ -251,6 +251,7 @@ describe('GET /rpc/hosts/:hostRef/sessions/:agent/:chatId/messages — passthrou
.set('authorization', 'Bearer user-token')
.expect(400)
+ expect(serviceMock.resolveHostConnectionForUser).not.toHaveBeenCalled()
expect(fetchMock).not.toHaveBeenCalled()
})
diff --git a/rpc-proxy/src/routes/rpc.ts b/rpc-proxy/src/routes/rpc.ts
index a8d728e38..e1a3b1bd6 100644
--- a/rpc-proxy/src/routes/rpc.ts
+++ b/rpc-proxy/src/routes/rpc.ts
@@ -752,17 +752,6 @@ export function createRpcRouter(): Router {
res.status(400).json({ error: 'Invalid hostRef, agent, or chatId' })
return
}
- const host = await resolveHostConnectionForUser(auth.sub, hostRef, rpcAccessToken, {
- teamId: auth.teamId,
- })
- if (!host) {
- res.status(403).json({ error: 'Forbidden: user cannot access this host' })
- return
- }
- const baseUrl = host.url.replace(/\/+$/, '')
- const upstreamUrl = new URL(
- `${baseUrl}/v1/runtime/sessions/${encodeURIComponent(agent)}/${encodeURIComponent(chatId)}/messages`
- )
const rawLimit = parseUnsignedIntegerQuery(req.query.limit)
const beforeTurn = parseUnsignedIntegerQuery(req.query.beforeTurn)
const afterTurn = parseUnsignedIntegerQuery(req.query.afterTurn)
@@ -782,6 +771,17 @@ export function createRpcRouter(): Router {
res.status(400).json({ error: 'Invalid session messages pagination query' })
return
}
+ const host = await resolveHostConnectionForUser(auth.sub, hostRef, rpcAccessToken, {
+ teamId: auth.teamId,
+ })
+ if (!host) {
+ res.status(403).json({ error: 'Forbidden: user cannot access this host' })
+ return
+ }
+ const baseUrl = host.url.replace(/\/+$/, '')
+ const upstreamUrl = new URL(
+ `${baseUrl}/v1/runtime/sessions/${encodeURIComponent(agent)}/${encodeURIComponent(chatId)}/messages`
+ )
if (rawLimit !== undefined) {
upstreamUrl.searchParams.set('limit', String(Math.min(rawLimit, 200)))
}