From 78456fde3e4f218ddda396c3c11e70ecd3ced4d8 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Tue, 17 Nov 2026 20:26:44 -0800 Subject: [PATCH 1/4] fix(lint): check table json inputs that hold bare block references Table input checks JSON-parsed raw field values, so a reference written outside a JSON string (e.g. {"count": } or a whole-field ), which resolves to valid JSON at runtime, made the whole check end with an 'Invalid JSON' could-not-complete note. Quote those references in the lint-local copy before the Table block's own parser runs, so literal keys are still checked and the references reach the existing runtime-resolution notes. --- .../read-workflow-lint-tables.test.ts | 58 +++++++++++++++++++ .../application/read-workflow-lint.ts | 39 ++++++++++++- 2 files changed, 96 insertions(+), 1 deletion(-) diff --git a/apps/sim/lib/workflows/application/read-workflow-lint-tables.test.ts b/apps/sim/lib/workflows/application/read-workflow-lint-tables.test.ts index 6608a6ae858..aae69ff828a 100644 --- a/apps/sim/lib/workflows/application/read-workflow-lint-tables.test.ts +++ b/apps/sim/lib/workflows/application/read-workflow-lint-tables.test.ts @@ -236,6 +236,64 @@ describe('standalone table diagnostics against the actual Table block', () => { expect(result.tableFieldIssues).toEqual([]) }) + it('checks literal row keys around bare references that resolve to JSON at runtime', async () => { + setGraph( + block('write', { + operation: 'insert_row', + data: '{"name": , "missing": , "note": "<3 {{SUFFIX}}", "env": {{N}}}', + }) + ) + const result = await lint() + expect(result.notes.filter((note) => note.includes('could not complete'))).toEqual([]) + expect( + result.unresolvedReferences.filter((reference) => reference.kind === 'resource') + ).toEqual([ + expect.objectContaining({ + blockId: 'write', + field: 'data', + value: ['missing', 'note', 'env'], + }), + ]) + }) + + it('checks literal filter fields around a bare reference value', async () => { + setGraph(block('query', { filter: '{"name": , "other": {"$gt": }}' })) + const result = await lint() + expect(result.notes.filter((note) => note.includes('could not complete'))).toEqual([]) + expect(result.tableFieldIssues.map(({ field }) => field)).toEqual(['other']) + }) + + it.each([ + ['data', 'insert_row', '', 'Table row "write".data is not a static object'], + [ + 'rows', + 'batch_insert_rows', + '', + 'Table rows in block "write" are not a static array', + ], + ['rows', 'batch_insert_rows', '[, {"name":"Ada"}]', 'Table row "write".rows[0]'], + ])( + 'notes a %s value that is a bare reference instead of a failed check (%s, %s)', + async (field, operation, value, note) => { + setGraph(block('write', { operation, [field]: value })) + const result = await lint() + expect(result.notes.filter((entry) => entry.includes('could not complete'))).toEqual([]) + expect(result.notes).toEqual(expect.arrayContaining([expect.stringContaining(note)])) + } + ) + + it('still reports malformed literal JSON that contains a reference', async () => { + setGraph(block('write', { operation: 'insert_row', data: '{"name": ,}' })) + const result = await lint() + expect(result.notes).toEqual( + expect.arrayContaining([ + expect.stringContaining( + 'Table input checks in block "write" could not complete before runtime: Invalid JSON in Row Data' + ), + ]) + ) + }) + it('reports a query object whose entire value requires runtime resolution', async () => { setGraph(block('query', { filter: '""' })) const result = await lint() diff --git a/apps/sim/lib/workflows/application/read-workflow-lint.ts b/apps/sim/lib/workflows/application/read-workflow-lint.ts index ec17565104b..3788bd5d19f 100644 --- a/apps/sim/lib/workflows/application/read-workflow-lint.ts +++ b/apps/sim/lib/workflows/application/read-workflow-lint.ts @@ -1,6 +1,7 @@ import { requirePrincipalSubjectUserId } from '@sim/auth/principal' import { getErrorMessage } from '@sim/utils/errors' import { isPlainRecord } from '@sim/utils/object' +import { findWorkflowReferenceTokens } from '@sim/utils/workflow-references' import type { CursorKey } from '@/lib/api/list-query' import { bindCopilotWorkspaceOperation } from '@/lib/core/application/copilot-workspace-invocation' import type { PrincipalForOperation } from '@/lib/core/application/workspace-operation' @@ -254,6 +255,42 @@ function hasRuntimeReference(value: string): boolean { return createReferencePattern().test(value) || createEnvVarPattern().test(value) } +/** + * Outside Function code a reference resolves to JSON text (objects, numbers, booleans), so + * `{"name": }` or a whole-field `` is valid JSON at runtime but not before. + * Quoting each reference written outside a JSON string lets the Table block's own parser read the + * literal parts, and the quoted references then reach the existing runtime-resolution notes. + * Only this lint-local copy is rewritten; references to string outputs left unquoted are reported + * separately by `collectUnquotedJsonStringReferences`. + */ +function quoteBareReferenceParams(params: Record): Record { + return Object.fromEntries( + Object.entries(params).map(([key, value]) => [ + key, + typeof value === 'string' ? quoteBareReferences(value) : value, + ]) + ) +} + +function quoteBareReferences(json: string): string { + const tokens = findWorkflowReferenceTokens(json) + if (tokens.length === 0) return json + let result = '' + let cursor = 0 + let inString = false + for (const token of tokens) { + for (let index = cursor; index < token.start; index++) { + const char = json[index] + if (inString && char === '\\') index++ + else if (char === '"') inString = !inString + } + result += json.slice(cursor, token.start) + result += inString ? token.value : JSON.stringify(token.value) + cursor = token.end + } + return result + json.slice(cursor) +} + /** Read each active table once; column checks consume the Table block's own pure input transform. */ async function readTableDiagnostics( graph: ReadWorkflowGraphResult, @@ -320,7 +357,7 @@ async function readTableDiagnostics( if (!transform) throw new Error('Table input normalization is unavailable') let normalized: Record try { - normalized = transform(params) + normalized = transform(quoteBareReferenceParams(params)) } catch (error) { result.notes.push( `Table input checks in block "${block.name || blockId}" could not complete before runtime: ${getErrorMessage(error)}` From a560d00121987d3f99ea8779ee550192fad13fdb Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Tue, 17 Nov 2026 20:38:26 -0800 Subject: [PATCH 2/4] fix(lint): defer table inputs whose quoted references fail predicate shape checks A quoted reference can still fail the Table block's shape validation, for example a filter in-list or a whole-field filter. Retry the transform without those runtime-only fields and note them as runtime-resolved, so the remaining literal inputs are still checked. Filter cases now run against the registered TableV2Block. --- .../read-workflow-lint-tables.test.ts | 49 +++++++++++++++-- .../application/read-workflow-lint.ts | 53 ++++++++++++++----- 2 files changed, 84 insertions(+), 18 deletions(-) diff --git a/apps/sim/lib/workflows/application/read-workflow-lint-tables.test.ts b/apps/sim/lib/workflows/application/read-workflow-lint-tables.test.ts index aae69ff828a..9d2d77f63d5 100644 --- a/apps/sim/lib/workflows/application/read-workflow-lint-tables.test.ts +++ b/apps/sim/lib/workflows/application/read-workflow-lint-tables.test.ts @@ -41,6 +41,7 @@ vi.mock('@/lib/workflows/editing/validation', () => ({ import { OrchestrationError } from '@/lib/core/orchestration/types' import { readWorkflowLint } from '@/lib/workflows/application/read-workflow-lint' import { TableBlock } from '@/blocks/blocks/table' +import { TableV2Block } from '@/blocks/blocks/table_v2' const mocks = { snapshot: workflowsQueriesMockFns.mockLoadWorkflowReadSnapshot, @@ -256,11 +257,49 @@ describe('standalone table diagnostics against the actual Table block', () => { ]) }) - it('checks literal filter fields around a bare reference value', async () => { - setGraph(block('query', { filter: '{"name": , "other": {"$gt": }}' })) - const result = await lint() - expect(result.notes.filter((note) => note.includes('could not complete'))).toEqual([]) - expect(result.tableFieldIssues.map(({ field }) => field)).toEqual(['other']) + describe('with the registered TableV2Block predicate grammar', () => { + beforeEach(() => { + mockGetBlock.mockImplementation((type: string) => + type === 'table_v2' ? TableV2Block : undefined + ) + }) + + it('checks literal predicate fields around a bare reference value', async () => { + setGraph( + block('query', { + filter: + '{"all":[{"field":"name","op":"eq","value":},{"field":"other","op":"gt","value":}]}', + }) + ) + const result = await lint() + expect(result.notes.filter((note) => note.includes('could not complete'))).toEqual([]) + expect(result.tableFieldIssues.map(({ field }) => field)).toEqual(['other']) + }) + + it.each([ + ['an in-list', '{"field":"name","op":"in","value":}'], + ['a whole-field', ''], + ])( + 'notes %s filter reference as runtime-resolved and still checks literal row data', + async (_shape, filter) => { + setGraph( + block('write', { + operation: 'update_rows_by_filter', + bulkFilterMode: 'json', + filter, + data: '{"name":"Ada","missing":1}', + }) + ) + const result = await lint() + expect(result.notes.filter((note) => note.includes('could not complete'))).toEqual([]) + expect(result.notes).toContain( + 'Table inputs in block "write" depend on references resolved at runtime and were not checked: filterInput.' + ) + expect( + result.unresolvedReferences.filter((reference) => reference.kind === 'resource') + ).toEqual([expect.objectContaining({ field: 'data', value: ['missing'] })]) + } + ) }) it.each([ diff --git a/apps/sim/lib/workflows/application/read-workflow-lint.ts b/apps/sim/lib/workflows/application/read-workflow-lint.ts index 3788bd5d19f..40dbb4641bc 100644 --- a/apps/sim/lib/workflows/application/read-workflow-lint.ts +++ b/apps/sim/lib/workflows/application/read-workflow-lint.ts @@ -256,20 +256,41 @@ function hasRuntimeReference(value: string): boolean { } /** - * Outside Function code a reference resolves to JSON text (objects, numbers, booleans), so + * Outside Function code a reference resolves to JSON text (objects, arrays, numbers, booleans), so * `{"name": }` or a whole-field `` is valid JSON at runtime but not before. - * Quoting each reference written outside a JSON string lets the Table block's own parser read the - * literal parts, and the quoted references then reach the existing runtime-resolution notes. - * Only this lint-local copy is rewritten; references to string outputs left unquoted are reported - * separately by `collectUnquotedJsonStringReferences`. + * Quoting each reference written outside a JSON string lets the Table block's own transform read + * the literal parts, and the quoted references then reach the existing runtime-resolution notes. + * When the transform's shape validation rejects a quoted reference (a filter `in` list, a + * whole-field filter), the fields that only parse once quoted are left out and returned as + * `runtimeFields`; malformed literal JSON still throws. Only this lint-local copy is rewritten; + * references to string outputs left unquoted are reported by `collectUnquotedJsonStringReferences`. */ -function quoteBareReferenceParams(params: Record): Record { - return Object.fromEntries( - Object.entries(params).map(([key, value]) => [ - key, - typeof value === 'string' ? quoteBareReferences(value) : value, - ]) - ) +function normalizeTableInputs( + transform: (params: Record) => Record, + params: Record +): { normalized: Record; runtimeFields: string[] } { + const quoted: Record = {} + const runtimeFields: string[] = [] + for (const [key, value] of Object.entries(params)) { + quoted[key] = typeof value === 'string' ? quoteBareReferences(value) : value + if (quoted[key] !== value && parsesAsJson(quoted[key])) runtimeFields.push(key) + } + try { + return { normalized: transform(quoted), runtimeFields: [] } + } catch (error) { + if (runtimeFields.length === 0) throw error + for (const key of runtimeFields) delete quoted[key] + return { normalized: transform(quoted), runtimeFields } + } +} + +function parsesAsJson(value: unknown): boolean { + try { + JSON.parse(String(value)) + return true + } catch { + return false + } } function quoteBareReferences(json: string): string { @@ -357,7 +378,13 @@ async function readTableDiagnostics( if (!transform) throw new Error('Table input normalization is unavailable') let normalized: Record try { - normalized = transform(quoteBareReferenceParams(params)) + const inputs = normalizeTableInputs(transform, params) + normalized = inputs.normalized + if (inputs.runtimeFields.length > 0) { + result.notes.push( + `Table inputs in block "${block.name || blockId}" depend on references resolved at runtime and were not checked: ${inputs.runtimeFields.join(', ')}.` + ) + } } catch (error) { result.notes.push( `Table input checks in block "${block.name || blockId}" could not complete before runtime: ${getErrorMessage(error)}` From 69cde75c372da607fa2b723edac763e89451fd2d Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Tue, 17 Nov 2026 20:50:30 -0800 Subject: [PATCH 3/4] fix(lint): keep literal table input errors visible beside references Try string and one-item-list placeholders per reference instead of dropping any field that holds one, so in-list references are still checked and an invalid literal condition still reports. Only a field that is a single whole reference is deferred to runtime. --- .../read-workflow-lint-tables.test.ts | 71 ++++++++++------ .../application/read-workflow-lint.ts | 82 +++++++++++++------ 2 files changed, 103 insertions(+), 50 deletions(-) diff --git a/apps/sim/lib/workflows/application/read-workflow-lint-tables.test.ts b/apps/sim/lib/workflows/application/read-workflow-lint-tables.test.ts index 9d2d77f63d5..5bb384e47cb 100644 --- a/apps/sim/lib/workflows/application/read-workflow-lint-tables.test.ts +++ b/apps/sim/lib/workflows/application/read-workflow-lint-tables.test.ts @@ -276,30 +276,53 @@ describe('standalone table diagnostics against the actual Table block', () => { expect(result.tableFieldIssues.map(({ field }) => field)).toEqual(['other']) }) - it.each([ - ['an in-list', '{"field":"name","op":"in","value":}'], - ['a whole-field', ''], - ])( - 'notes %s filter reference as runtime-resolved and still checks literal row data', - async (_shape, filter) => { - setGraph( - block('write', { - operation: 'update_rows_by_filter', - bulkFilterMode: 'json', - filter, - data: '{"name":"Ada","missing":1}', - }) - ) - const result = await lint() - expect(result.notes.filter((note) => note.includes('could not complete'))).toEqual([]) - expect(result.notes).toContain( - 'Table inputs in block "write" depend on references resolved at runtime and were not checked: filterInput.' - ) - expect( - result.unresolvedReferences.filter((reference) => reference.kind === 'resource') - ).toEqual([expect.objectContaining({ field: 'data', value: ['missing'] })]) - } - ) + it('checks predicate fields around an in-list reference', async () => { + setGraph( + block('query', { + filter: + '{"all":[{"field":"other","op":"in","value":},{"field":"name","op":"eq","value":}]}', + }) + ) + const result = await lint() + expect(result.notes.filter((note) => note.includes('could not complete'))).toEqual([]) + expect(result.tableFieldIssues.map(({ field }) => field)).toEqual(['other']) + }) + + it('notes a whole-field filter reference as runtime-resolved and still checks row data', async () => { + setGraph( + block('write', { + operation: 'update_rows_by_filter', + bulkFilterMode: 'json', + filter: '', + data: '{"name":"Ada","missing":1}', + }) + ) + const result = await lint() + expect(result.notes.filter((note) => note.includes('could not complete'))).toEqual([]) + expect(result.notes).toContain( + 'Table inputs in block "write" depend on references resolved at runtime and were not checked: filterInput.' + ) + expect( + result.unresolvedReferences.filter((reference) => reference.kind === 'resource') + ).toEqual([expect.objectContaining({ field: 'data', value: ['missing'] })]) + }) + + it('still reports an invalid literal condition beside a reference', async () => { + setGraph( + block('query', { + filter: + '{"all":[{"field":"name","op":"eq","value":},{"field":"name","op":"in","value":"not a list"}]}', + }) + ) + const result = await lint() + expect(result.notes).toEqual( + expect.arrayContaining([ + expect.stringContaining( + 'Table input checks in block "query" could not complete before runtime:' + ), + ]) + ) + }) }) it.each([ diff --git a/apps/sim/lib/workflows/application/read-workflow-lint.ts b/apps/sim/lib/workflows/application/read-workflow-lint.ts index 40dbb4641bc..a4437ee48f6 100644 --- a/apps/sim/lib/workflows/application/read-workflow-lint.ts +++ b/apps/sim/lib/workflows/application/read-workflow-lint.ts @@ -258,42 +258,72 @@ function hasRuntimeReference(value: string): boolean { /** * Outside Function code a reference resolves to JSON text (objects, arrays, numbers, booleans), so * `{"name": }` or a whole-field `` is valid JSON at runtime but not before. - * Quoting each reference written outside a JSON string lets the Table block's own transform read - * the literal parts, and the quoted references then reach the existing runtime-resolution notes. - * When the transform's shape validation rejects a quoted reference (a filter `in` list, a - * whole-field filter), the fields that only parse once quoted are left out and returned as - * `runtimeFields`; malformed literal JSON still throws. Only this lint-local copy is rewritten; - * references to string outputs left unquoted are reported by `collectUnquotedJsonStringReferences`. + * Each reference written outside a JSON string is replaced by a placeholder so the Table block's + * own transform reads the literal parts: a quoted string, or a one-item list for slots such as a + * filter `in`. Every combination is tried while there are few references (otherwise all-string + * and all-list). A field that is a single whole reference has no literal part, so if no + * combination fits it is left out and returned in `runtimeFields`. Any other failure, such as + * malformed JSON or an invalid literal condition, is rethrown. Only this lint-local copy is + * rewritten; references to string outputs left unquoted are reported by + * `collectUnquotedJsonStringReferences`. */ function normalizeTableInputs( transform: (params: Record) => Record, params: Record ): { normalized: Record; runtimeFields: string[] } { - const quoted: Record = {} - const runtimeFields: string[] = [] + let hasReference = false + const wholeReferenceFields: string[] = [] for (const [key, value] of Object.entries(params)) { - quoted[key] = typeof value === 'string' ? quoteBareReferences(value) : value - if (quoted[key] !== value && parsesAsJson(quoted[key])) runtimeFields.push(key) + if (typeof value !== 'string') continue + const trimmed = value.trim() + const tokens = findWorkflowReferenceTokens(trimmed) + if (tokens.length === 0) continue + hasReference = true + if (tokens.length === 1 && tokens[0].start === 0 && tokens[0].end === trimmed.length) { + wholeReferenceFields.push(key) + } } - try { - return { normalized: transform(quoted), runtimeFields: [] } - } catch (error) { - if (runtimeFields.length === 0) throw error - for (const key of runtimeFields) delete quoted[key] - return { normalized: transform(quoted), runtimeFields } + if (!hasReference) return { normalized: transform(params), runtimeFields: [] } + const tiers = wholeReferenceFields.length > 0 ? [[], wholeReferenceFields] : [[]] + let firstError: unknown + for (const runtimeFields of tiers) { + const withPlaceholders = (asList: (ordinal: number) => boolean) => { + let ordinal = 0 + const candidate: Record = {} + for (const [key, value] of Object.entries(params)) { + if (runtimeFields.includes(key)) continue + candidate[key] = + typeof value === 'string' + ? replaceBareReferences(value, (reference) => + asList(ordinal++) ? `[${JSON.stringify(reference)}]` : JSON.stringify(reference) + ) + : value + } + return { candidate, count: ordinal } + } + const { count } = withPlaceholders(() => false) + const assignments: Array<(ordinal: number) => boolean> = + count <= MAX_PLACEHOLDER_SEARCH_REFERENCES + ? Array.from( + { length: 2 ** count }, + (_, mask) => (ordinal) => ((mask >> ordinal) & 1) === 1 + ) + : [() => false, () => true] + for (const asList of assignments) { + try { + return { normalized: transform(withPlaceholders(asList).candidate), runtimeFields } + } catch (error) { + firstError ??= error + } + } } + throw firstError } -function parsesAsJson(value: unknown): boolean { - try { - JSON.parse(String(value)) - return true - } catch { - return false - } -} +/** Bounds the placeholder search to 2^6 pure transform calls per Table block. */ +const MAX_PLACEHOLDER_SEARCH_REFERENCES = 6 -function quoteBareReferences(json: string): string { +function replaceBareReferences(json: string, placeholder: (reference: string) => string): string { const tokens = findWorkflowReferenceTokens(json) if (tokens.length === 0) return json let result = '' @@ -306,7 +336,7 @@ function quoteBareReferences(json: string): string { else if (char === '"') inString = !inString } result += json.slice(cursor, token.start) - result += inString ? token.value : JSON.stringify(token.value) + result += inString ? token.value : placeholder(token.value) cursor = token.end } return result + json.slice(cursor) From 83b209d4deb4b1d1bddd92f2d7a13973f0e4fb11 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Tue, 17 Nov 2026 21:02:41 -0800 Subject: [PATCH 4/4] fix(lint): defer reference fields past the placeholder search bound Above the search bound an all-string or all-list fallback cannot tell a literal error from a reference type mismatch, so leave the reference-bearing fields out and keep checking the other inputs instead of ending the table check. --- .../read-workflow-lint-tables.test.ts | 23 +++++++++++ .../application/read-workflow-lint.ts | 40 ++++++++++--------- 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/apps/sim/lib/workflows/application/read-workflow-lint-tables.test.ts b/apps/sim/lib/workflows/application/read-workflow-lint-tables.test.ts index 5bb384e47cb..960ebe70a0e 100644 --- a/apps/sim/lib/workflows/application/read-workflow-lint-tables.test.ts +++ b/apps/sim/lib/workflows/application/read-workflow-lint-tables.test.ts @@ -307,6 +307,29 @@ describe('standalone table diagnostics against the actual Table block', () => { ).toEqual([expect.objectContaining({ field: 'data', value: ['missing'] })]) }) + it('defers a filter with more mixed references than the placeholder search covers', async () => { + const conditions = [ + ...['a', 'b', 'c', 'd'].map((name) => `{"field":"name","op":"eq","value":}`), + ...['e', 'f', 'g'].map((name) => `{"field":"name","op":"in","value":}`), + ] + setGraph( + block('write', { + operation: 'update_rows_by_filter', + bulkFilterMode: 'json', + filter: `{"all":[${conditions.join(',')}]}`, + data: '{"name":"Ada","missing":1}', + }) + ) + const result = await lint() + expect(result.notes.filter((note) => note.includes('could not complete'))).toEqual([]) + expect(result.notes).toContain( + 'Table inputs in block "write" depend on references resolved at runtime and were not checked: filterInput.' + ) + expect( + result.unresolvedReferences.filter((reference) => reference.kind === 'resource') + ).toEqual([expect.objectContaining({ field: 'data', value: ['missing'] })]) + }) + it('still reports an invalid literal condition beside a reference', async () => { setGraph( block('query', { diff --git a/apps/sim/lib/workflows/application/read-workflow-lint.ts b/apps/sim/lib/workflows/application/read-workflow-lint.ts index a4437ee48f6..7bda45a2750 100644 --- a/apps/sim/lib/workflows/application/read-workflow-lint.ts +++ b/apps/sim/lib/workflows/application/read-workflow-lint.ts @@ -260,31 +260,33 @@ function hasRuntimeReference(value: string): boolean { * `{"name": }` or a whole-field `` is valid JSON at runtime but not before. * Each reference written outside a JSON string is replaced by a placeholder so the Table block's * own transform reads the literal parts: a quoted string, or a one-item list for slots such as a - * filter `in`. Every combination is tried while there are few references (otherwise all-string - * and all-list). A field that is a single whole reference has no literal part, so if no - * combination fits it is left out and returned in `runtimeFields`. Any other failure, such as - * malformed JSON or an invalid literal condition, is rethrown. Only this lint-local copy is - * rewritten; references to string outputs left unquoted are reported by + * filter `in`, trying every combination. A field that is a single whole reference has no literal + * part, so if no combination fits it is left out and returned in `runtimeFields`. When the search + * is exhaustive and still fails, the error comes from the literal parts (malformed JSON, an + * invalid literal condition) and is rethrown. Past the search bound that cannot be told apart, so + * every reference-bearing field is left out instead and the other inputs are still checked. Only + * this lint-local copy is rewritten; references to string outputs left unquoted are reported by * `collectUnquotedJsonStringReferences`. */ function normalizeTableInputs( transform: (params: Record) => Record, params: Record ): { normalized: Record; runtimeFields: string[] } { - let hasReference = false + const referenceFields: string[] = [] const wholeReferenceFields: string[] = [] for (const [key, value] of Object.entries(params)) { if (typeof value !== 'string') continue const trimmed = value.trim() const tokens = findWorkflowReferenceTokens(trimmed) if (tokens.length === 0) continue - hasReference = true + referenceFields.push(key) if (tokens.length === 1 && tokens[0].start === 0 && tokens[0].end === trimmed.length) { wholeReferenceFields.push(key) } } - if (!hasReference) return { normalized: transform(params), runtimeFields: [] } + if (referenceFields.length === 0) return { normalized: transform(params), runtimeFields: [] } const tiers = wholeReferenceFields.length > 0 ? [[], wholeReferenceFields] : [[]] + let searchBounded = false let firstError: unknown for (const runtimeFields of tiers) { const withPlaceholders = (asList: (ordinal: number) => boolean) => { @@ -302,22 +304,24 @@ function normalizeTableInputs( return { candidate, count: ordinal } } const { count } = withPlaceholders(() => false) - const assignments: Array<(ordinal: number) => boolean> = - count <= MAX_PLACEHOLDER_SEARCH_REFERENCES - ? Array.from( - { length: 2 ** count }, - (_, mask) => (ordinal) => ((mask >> ordinal) & 1) === 1 - ) - : [() => false, () => true] - for (const asList of assignments) { + if (count > MAX_PLACEHOLDER_SEARCH_REFERENCES) { + searchBounded = true + continue + } + for (let mask = 0; mask < 2 ** count; mask++) { try { - return { normalized: transform(withPlaceholders(asList).candidate), runtimeFields } + const { candidate } = withPlaceholders((ordinal) => ((mask >> ordinal) & 1) === 1) + return { normalized: transform(candidate), runtimeFields } } catch (error) { firstError ??= error } } } - throw firstError + if (!searchBounded) throw firstError + const literal = Object.fromEntries( + Object.entries(params).filter(([key]) => !referenceFields.includes(key)) + ) + return { normalized: transform(literal), runtimeFields: referenceFields } } /** Bounds the placeholder search to 2^6 pure transform calls per Table block. */