Skip to content

Commit 87a1c62

Browse files
pass execution context through & other minor bug fixes
1 parent a2972b3 commit 87a1c62

File tree

5 files changed

+35
-31
lines changed

5 files changed

+35
-31
lines changed

apps/sim/lib/paginated-cache/paginate.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,10 @@ describe('autoPaginate', () => {
169169
).rejects.toThrow('Auto-pagination failed on page 1: rate limited')
170170
})
171171

172-
it('passes skipPostProcess=true for subsequent pages', async () => {
172+
it('passes executionContext and skipAutoPaginate for subsequent pages', async () => {
173173
const initialResult = makePageResponse([{ id: 1 }], true, 'cursor-1')
174174
mockExecuteTool.mockResolvedValueOnce(makePageResponse([{ id: 2 }], false, null))
175+
const mockContext = { workflowId: 'wf-1', executionId: 'exec-1' }
175176

176177
await autoPaginate({
177178
initialResult,
@@ -180,11 +181,14 @@ describe('autoPaginate', () => {
180181
executeTool: mockExecuteTool,
181182
toolId: 'zendesk_get_tickets',
182183
executionId: 'exec-1',
184+
executionContext: mockContext as never,
183185
})
184186

185187
expect(mockExecuteTool).toHaveBeenCalledWith(
186188
'zendesk_get_tickets',
187189
expect.objectContaining({ pageAfter: 'cursor-1' }),
190+
false,
191+
mockContext,
188192
true
189193
)
190194
})

apps/sim/lib/paginated-cache/paginate.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { PaginatedCacheStorageAdapter } from '@/lib/paginated-cache/adapter
55
import { RedisPaginatedCache } from '@/lib/paginated-cache/redis-cache'
66
import type { PaginatedCacheReference, ToolPaginationConfig } from '@/lib/paginated-cache/types'
77
import { isPaginatedCacheReference } from '@/lib/paginated-cache/types'
8+
import type { ExecutionContext } from '@/executor/types'
89
import type { ToolResponse } from '@/tools/types'
910

1011
const logger = createLogger('Paginator')
@@ -18,10 +19,13 @@ interface AutoPaginateOptions {
1819
executeTool: (
1920
toolId: string,
2021
params: Record<string, unknown>,
21-
skipPostProcess?: boolean
22+
skipPostProcess?: boolean,
23+
executionContext?: ExecutionContext,
24+
skipAutoPaginate?: boolean
2225
) => Promise<ToolResponse>
2326
toolId: string
2427
executionId: string
28+
executionContext?: ExecutionContext
2529
}
2630

2731
export async function autoPaginate(options: AutoPaginateOptions): Promise<ToolResponse> {
@@ -32,6 +36,7 @@ export async function autoPaginate(options: AutoPaginateOptions): Promise<ToolRe
3236
executeTool,
3337
toolId,
3438
executionId,
39+
executionContext,
3540
} = options
3641
const maxPages = config.maxPages ?? DEFAULT_MAX_PAGES
3742

@@ -55,7 +60,7 @@ export async function autoPaginate(options: AutoPaginateOptions): Promise<ToolRe
5560
let nextToken = config.getNextPageToken(initialResult.output)
5661
while (nextToken !== null && pageIndex < maxPages) {
5762
const nextParams = config.buildNextPageParams(params, nextToken)
58-
const pageResult = await executeTool(toolId, nextParams, true)
63+
const pageResult = await executeTool(toolId, nextParams, false, executionContext, true)
5964

6065
if (!pageResult.success) {
6166
throw new Error(

apps/sim/lib/workflows/executor/queued-workflow-execution.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -330,18 +330,9 @@ export async function executeQueuedWorkflowJob(
330330
await eventWriter.close()
331331
}
332332

333-
await cleanupExecutionBase64Cache(executionId).catch((error) => {
334-
logger.error('Failed to cleanup queued workflow base64 cache', {
335-
executionId,
336-
error: error instanceof Error ? error.message : String(error),
337-
})
338-
})
339-
340-
await cleanupPaginatedCache(executionId).catch((error) => {
341-
logger.error('Failed to cleanup queued workflow paginated cache', {
342-
executionId,
343-
error: error instanceof Error ? error.message : String(error),
344-
})
345-
})
333+
await Promise.allSettled([
334+
cleanupExecutionBase64Cache(executionId),
335+
cleanupPaginatedCache(executionId),
336+
])
346337
}
347338
}

apps/sim/lib/workflows/streaming/streaming.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
} from '@/lib/core/utils/response-format'
88
import { encodeSSE } from '@/lib/core/utils/sse'
99
import { buildTraceSpans } from '@/lib/logs/execution/trace-spans/trace-spans'
10-
import { processStreamingBlockLogs } from '@/lib/tokenization'
1110
import { cleanupPaginatedCache } from '@/lib/paginated-cache/paginate'
11+
import { processStreamingBlockLogs } from '@/lib/tokenization'
1212
import {
1313
cleanupExecutionBase64Cache,
1414
hydrateUserFilesWithBase64,
@@ -348,8 +348,10 @@ export async function createStreamingResponse(
348348
controller.enqueue(encodeSSE('[DONE]'))
349349

350350
if (executionId) {
351-
await cleanupExecutionBase64Cache(executionId)
352-
await cleanupPaginatedCache(executionId)
351+
await Promise.allSettled([
352+
cleanupExecutionBase64Cache(executionId),
353+
cleanupPaginatedCache(executionId),
354+
])
353355
}
354356

355357
controller.close()
@@ -360,8 +362,10 @@ export async function createStreamingResponse(
360362
)
361363

362364
if (executionId) {
363-
await cleanupExecutionBase64Cache(executionId)
364-
await cleanupPaginatedCache(executionId)
365+
await Promise.allSettled([
366+
cleanupExecutionBase64Cache(executionId),
367+
cleanupPaginatedCache(executionId),
368+
])
365369
}
366370

367371
controller.close()
@@ -374,12 +378,10 @@ export async function createStreamingResponse(
374378
timeoutController.abort()
375379
timeoutController.cleanup()
376380
if (executionId) {
377-
try {
378-
await cleanupExecutionBase64Cache(executionId)
379-
await cleanupPaginatedCache(executionId)
380-
} catch (error) {
381-
logger.error(`[${requestId}] Failed to cleanup cache`, { error })
382-
}
381+
await Promise.allSettled([
382+
cleanupExecutionBase64Cache(executionId),
383+
cleanupPaginatedCache(executionId),
384+
])
383385
}
384386
},
385387
})

apps/sim/tools/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,13 +609,13 @@ async function maybeAutoPaginate(
609609
finalResult: ToolResponse,
610610
contextParams: Record<string, unknown>,
611611
normalizedToolId: string,
612-
skipPostProcess: boolean,
612+
skipAutoPaginate: boolean,
613613
executionContext?: ExecutionContext
614614
): Promise<ToolResponse> {
615615
if (
616616
!tool.pagination ||
617617
!finalResult.success ||
618-
skipPostProcess ||
618+
skipAutoPaginate ||
619619
!executionContext?.executionId
620620
) {
621621
return finalResult
@@ -631,6 +631,7 @@ async function maybeAutoPaginate(
631631
executeTool,
632632
toolId: normalizedToolId,
633633
executionId: executionContext.executionId,
634+
executionContext,
634635
})
635636
}
636637

@@ -642,7 +643,8 @@ export async function executeTool(
642643
toolId: string,
643644
params: Record<string, any>,
644645
skipPostProcess = false,
645-
executionContext?: ExecutionContext
646+
executionContext?: ExecutionContext,
647+
skipAutoPaginate = false
646648
): Promise<ToolResponse> {
647649
// Capture start time for precise timing
648650
const startTime = new Date()
@@ -859,7 +861,7 @@ export async function executeTool(
859861
finalResult,
860862
contextParams,
861863
normalizedToolId,
862-
skipPostProcess,
864+
skipAutoPaginate,
863865
executionContext
864866
)
865867

0 commit comments

Comments
 (0)