Skip to content

Commit 63a52b6

Browse files
waleedlatif1claude
andcommitted
fix(dagster): guard NaN numeric coercions and bound list_assets pagination
Address PR review: - Route all block numeric coercions (list_runs limit/createdAfter/createdBefore, get_run_logs logsLimit, list_assets assetsLimit) through a toFiniteNumber() guard so invalid/wand-generated text becomes undefined instead of NaN. - list_assets now applies a default page size (100) when no limit is given, so paging stays bounded and hasMore is meaningful even when limit is omitted. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent a36114f commit 63a52b6

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

apps/sim/blocks/blocks/dagster.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import type { BlockConfig } from '@/blocks/types'
33
import { IntegrationType } from '@/blocks/types'
44
import type { DagsterResponse } from '@/tools/dagster/types'
55

6+
/** Coerces a subBlock value to a finite number, returning undefined for empty or non-numeric input. */
7+
function toFiniteNumber(value: unknown): number | undefined {
8+
if (value == null || value === '') return undefined
9+
const parsed = Number(value)
10+
return Number.isFinite(parsed) ? parsed : undefined
11+
}
12+
613
export const DagsterBlock: BlockConfig<DagsterResponse> = {
714
type: 'dagster',
815
name: 'Dagster',
@@ -475,19 +482,16 @@ Return ONLY the comma-separated asset keys - no explanations, no extra text.`,
475482

476483
// list_runs: type-coerce limit + time filters, remap job name filter and cursor
477484
if (params.operation === 'list_runs') {
478-
if (params.limit != null && params.limit !== '') result.limit = Number(params.limit)
485+
result.limit = toFiniteNumber(params.limit)
479486
result.jobName = params.listRunsJobName || undefined
480-
if (params.createdAfter != null && params.createdAfter !== '')
481-
result.createdAfter = Number(params.createdAfter)
482-
if (params.createdBefore != null && params.createdBefore !== '')
483-
result.createdBefore = Number(params.createdBefore)
487+
result.createdAfter = toFiniteNumber(params.createdAfter)
488+
result.createdBefore = toFiniteNumber(params.createdBefore)
484489
result.cursor = params.runsCursor || undefined
485490
}
486491

487492
// get_run_logs: remap logsLimit → limit
488493
if (params.operation === 'get_run_logs') {
489-
if (params.logsLimit != null && params.logsLimit !== '')
490-
result.limit = Number(params.logsLimit)
494+
result.limit = toFiniteNumber(params.logsLimit)
491495
}
492496

493497
// reexecute_run: remap runId → parentRunId
@@ -506,8 +510,7 @@ Return ONLY the comma-separated asset keys - no explanations, no extra text.`,
506510
// list_assets: type-coerce limit and remap prefix/cursor
507511
if (params.operation === 'list_assets') {
508512
result.prefix = params.assetPrefix || undefined
509-
if (params.assetsLimit != null && params.assetsLimit !== '')
510-
result.limit = Number(params.assetsLimit)
513+
result.limit = toFiniteNumber(params.assetsLimit)
511514
result.cursor = params.assetsCursor || undefined
512515
}
513516

apps/sim/tools/dagster/list_assets.ts

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

11+
/** Default page size applied when the caller omits `limit`, so paging stays bounded and `hasMore` is meaningful. */
12+
const DEFAULT_LIST_ASSETS_LIMIT = 100
13+
1114
/** Shape of each asset node in the `assetsOrError` → `AssetConnection.nodes` selection set. */
1215
interface DagsterAssetGraphqlNode {
1316
key: { path: string[] }
@@ -69,7 +72,7 @@ export const listAssetsTool: ToolConfig<DagsterListAssetsParams, DagsterListAsse
6972
type: 'number',
7073
required: false,
7174
visibility: 'user-or-llm',
72-
description: 'Maximum number of assets to return (optional)',
75+
description: 'Maximum number of assets to return per page (default 100)',
7376
},
7477
},
7578

@@ -78,10 +81,11 @@ export const listAssetsTool: ToolConfig<DagsterListAssetsParams, DagsterListAsse
7881
method: 'POST',
7982
headers: (params) => dagsterRequestHeaders(params),
8083
body: (params) => {
81-
const variables: Record<string, unknown> = {}
84+
const variables: Record<string, unknown> = {
85+
limit: params.limit ?? DEFAULT_LIST_ASSETS_LIMIT,
86+
}
8287
if (params.prefix) variables.prefix = parseAssetKeyPath(params.prefix)
8388
if (params.cursor) variables.cursor = params.cursor
84-
if (params.limit != null) variables.limit = params.limit
8589
return { query: LIST_ASSETS_QUERY, variables }
8690
},
8791
},
@@ -103,12 +107,13 @@ export const listAssetsTool: ToolConfig<DagsterListAssetsParams, DagsterListAsse
103107
path: node.key.path,
104108
}))
105109

110+
const limit = params?.limit ?? DEFAULT_LIST_ASSETS_LIMIT
106111
return {
107112
success: true,
108113
output: {
109114
assets,
110115
cursor: result.cursor ?? null,
111-
hasMore: params?.limit != null && assets.length >= params.limit,
116+
hasMore: assets.length >= limit,
112117
},
113118
}
114119
},

0 commit comments

Comments
 (0)