Skip to content

Commit efe8414

Browse files
waleedlatif1claude
andcommitted
fix(dagster): make list_runs hasMore exact via fetch N+1
Address PR review (list runs false hasMore): request one extra row (pageSize + 1), use its presence as the authoritative hasMore, and slice it off before mapping. Removes the false-positive hasMore (and misleading cursor) when the final page is exactly `limit` runs long. Mirrors the list_assets fix. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 3dec257 commit efe8414

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

apps/sim/tools/dagster/list_runs.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import {
77
} from '@/tools/dagster/utils'
88
import type { ToolConfig } from '@/tools/types'
99

10+
/** Default page size applied when the caller omits `limit`, so paging stays bounded and `hasMore` is meaningful. */
11+
const DEFAULT_LIST_RUNS_LIMIT = 20
12+
1013
/** Shape of each run in the `runsOrError` → `Runs.results` GraphQL selection set. */
1114
interface DagsterListRunsGraphqlRow {
1215
runId: string
@@ -124,7 +127,9 @@ export const listRunsTool: ToolConfig<DagsterListRunsParams, DagsterListRunsResp
124127
if (params.createdBefore != null) filter.createdBefore = params.createdBefore
125128

126129
const hasFilter = Object.keys(filter).length > 0
127-
const variables: Record<string, unknown> = { limit: params.limit || 20 }
130+
const pageSize = params.limit || DEFAULT_LIST_RUNS_LIMIT
131+
// Request one extra row so `hasMore` is exact even when the final page is exactly `pageSize` long.
132+
const variables: Record<string, unknown> = { limit: pageSize + 1 }
128133
if (params.cursor) variables.cursor = params.cursor
129134
if (hasFilter) variables.filter = filter
130135

@@ -147,7 +152,11 @@ export const listRunsTool: ToolConfig<DagsterListRunsParams, DagsterListRunsResp
147152
throw new Error(dagsterUnionErrorMessage(result, 'Dagster returned an error listing runs'))
148153
}
149154

150-
const runs = result.results.map((r: DagsterListRunsGraphqlRow) => ({
155+
const pageSize = params?.limit || DEFAULT_LIST_RUNS_LIMIT
156+
const hasMore = result.results.length > pageSize
157+
const pageRows = hasMore ? result.results.slice(0, pageSize) : result.results
158+
159+
const runs = pageRows.map((r: DagsterListRunsGraphqlRow) => ({
151160
runId: r.runId,
152161
jobName: r.jobName ?? null,
153162
status: r.status,
@@ -156,13 +165,12 @@ export const listRunsTool: ToolConfig<DagsterListRunsParams, DagsterListRunsResp
156165
endTime: r.endTime ?? null,
157166
}))
158167

159-
const limit = params?.limit || 20
160168
return {
161169
success: true,
162170
output: {
163171
runs,
164172
cursor: runs.length > 0 ? runs[runs.length - 1].runId : null,
165-
hasMore: runs.length >= limit,
173+
hasMore,
166174
},
167175
}
168176
},

0 commit comments

Comments
 (0)