Skip to content

Commit d644eb9

Browse files
authored
fix(search): recheck Hex workspace after notebook reads (#9759)
1 parent d149272 commit d644eb9

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎apps/sim/lib/sim-search/live/hex-mcp.test.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,21 @@ describe('Hex source retrieval', () => {
192192
await expect(readHexMcp(client({ workspace: OTHER }), reference)).rejects.toThrow(/workspace/i)
193193
})
194194

195+
it('withholds notebook source when the provider workspace changes during paging', async () => {
196+
const api = client()
197+
let connectedWorkspace = WORKSPACE
198+
const changingWorkspace: ManagedSearchMcpClient = {
199+
async call(name, args) {
200+
if (name === 'get_me') return { org: { id: connectedWorkspace } }
201+
const result = await api.call(name, args)
202+
if (name === 'list_cells') connectedWorkspace = OTHER
203+
return result
204+
},
205+
}
206+
207+
await expect(readHexMcp(changingWorkspace, reference)).rejects.toThrow(/workspace/i)
208+
})
209+
195210
it.each([
196211
{ ...metadata, id: OTHER },
197212
{ ...metadata, trashedAt: '2026-01-01T13:00:00Z' },
@@ -253,4 +268,24 @@ describe('Hex source retrieval', () => {
253268
)
254269
).rejects.toThrow(/page limit/i)
255270
})
271+
272+
it('reads a complete eight-page notebook within the managed request budget', async () => {
273+
const api = client({
274+
pages: Array.from({ length: 8 }, (_, index) => ({
275+
values: [cell(`cell-${index}`, 'MARKDOWN', `Source page ${index}`)],
276+
pagination: { after: index === 7 ? null : `page-${index}` },
277+
})),
278+
})
279+
let requests = 0
280+
const budgetedClient: ManagedSearchMcpClient = {
281+
call(name, args) {
282+
if (++requests > 12) throw new Error('Managed request budget exceeded')
283+
return api.call(name, args)
284+
},
285+
}
286+
287+
const result = await readHexMcp(budgetedClient, reference)
288+
expect(result.content).toContain('Source page 0')
289+
expect(result.content).toContain('Source page 7')
290+
})
256291
})

‎apps/sim/lib/sim-search/live/hex-mcp.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ export async function readHexMcp(
213213
const current = await project(client, reference.id, workspaceId)
214214
if (!current || current.revision !== before.revision)
215215
invalid('The Hex project changed while it was being read. Search again.')
216+
if ((await workspace(client)) !== workspaceId)
217+
invalid('The Hex workspace changed while it was being read. Search again.')
216218
return { ...current, content: parts.join('\n\n') }
217219
}
218220
if (

0 commit comments

Comments
 (0)