From 81ea2f9991fd677d6e5d8cf6c04e32bec66cc47a Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Thu, 26 Nov 2026 11:18:59 -0800 Subject: [PATCH 1/2] fix(release): v0.9.66 audit follow-ups for child versions on spans and dry-run placeholders - A streamed custom tool titled workflow_executor no longer records a child deployment version: the span factory trusts the raw tool name, which still carries the custom_ prefix on that path. A workflow tool span also stops repeating the version in its output, like a workflow block span. - A dry run now marks a block whose output carries a placeholder it was handed (a Function formatting a stubbed write, an Agent whose workflow tool stubbed one), so mocking from that run refuses the block instead of replaying made-up values. - Dry-run samples reduce an MCP outputSchema with the shared, node-budgeted reducer, and the placeholder scan looks only for whole nine-digit runs in a string. - Reattach a SCIM integration test's doc comment to the mock it describes. --- apps/sim/executor/execution/block-executor.ts | 2 +- apps/sim/executor/execution/types.ts | 4 +- .../lib/logs/execution/trace-spans/factory.ts | 35 ++++++------ .../execution/trace-spans/trace-spans.test.ts | 15 +++++ apps/sim/lib/mcp/output-schema.ts | 2 +- .../application/dry-run.integration.ts | 27 +++++++++ .../sim/lib/workflows/dry-run/placeholders.ts | 9 ++- apps/sim/lib/workflows/dry-run/samples.ts | 56 ++++++------------- .../sim/lib/workflows/dry-run/side-effects.ts | 4 +- .../__integration__/members.integration.ts | 1 - 10 files changed, 89 insertions(+), 66 deletions(-) diff --git a/apps/sim/executor/execution/block-executor.ts b/apps/sim/executor/execution/block-executor.ts index e0ee204ca0f..1da91d6239a 100644 --- a/apps/sim/executor/execution/block-executor.ts +++ b/apps/sim/executor/execution/block-executor.ts @@ -469,7 +469,7 @@ export class BlockExecutor { stateOutput, duration, stateProvenance, - site !== undefined && sideEffects?.answeredWithPlaceholder(site) === true + site !== undefined && sideEffects?.answeredWithPlaceholder(site, stateOutput) === true ) if (!isSentinel && blockLog) { diff --git a/apps/sim/executor/execution/types.ts b/apps/sim/executor/execution/types.ts index 794bef84280..550b308a809 100644 --- a/apps/sim/executor/execution/types.ts +++ b/apps/sim/executor/execution/types.ts @@ -468,9 +468,9 @@ export interface SideEffectPolicy { answersBlock(block: SideEffectBlockSite): boolean /** * Whether the run has answered this block, or a call it made, with a placeholder (its mock is - * not one), so its output may hold made-up values. + * not one), or its `output` carries one it was handed, so the output may hold made-up values. */ - answeredWithPlaceholder(block: SideEffectBlockSite): boolean + answeredWithPlaceholder(block: SideEffectBlockSite, output: unknown): boolean /** The output answering a block that does not run: its mock, or a recorded placeholder. */ answerBlock(call: AnsweredBlockCall): Promise } diff --git a/apps/sim/lib/logs/execution/trace-spans/factory.ts b/apps/sim/lib/logs/execution/trace-spans/factory.ts index 66da7ac5f9f..3f2728afd7a 100644 --- a/apps/sim/lib/logs/execution/trace-spans/factory.ts +++ b/apps/sim/lib/logs/execution/trace-spans/factory.ts @@ -202,14 +202,18 @@ function childDeploymentVersionOf( } /** - * The deployment version a workflow run as an Agent tool reported. Read only for - * `workflow_executor`, so another tool returning the same key records nothing. + * Moves the deployment version a workflow run as an Agent tool reported from its output onto the + * span, as a workflow block span has it. Trusted only when the raw tool name is + * `workflow_executor`: a streamed custom tool titled that way still carries its `custom_` prefix + * here, and the Agent drops the key from a non-streamed custom tool's result. */ -function workflowToolVersion( - toolName: string, +function liftWorkflowToolVersion( + rawToolName: string | undefined, output: Record | undefined -): Pick { - return toolName === WORKFLOW_TOOL_ID ? childDeploymentVersionOf(output) : {} +): { output: Record | undefined } & Pick { + const version = rawToolName === WORKFLOW_TOOL_ID ? childDeploymentVersionOf(output) : {} + if (!output || !version.childDeploymentVersionId) return { output } + return { output: omit(output, ['childDeploymentVersionId']), ...version } } /** Enriches a span with provider timing, cost, tokens, and model from block output. */ @@ -301,9 +305,8 @@ function buildChildrenFromTimeSegments( const currentIndex = toolCallIndices.get(normalizedName) ?? 0 const match = callsForName[currentIndex] toolCallIndices.set(normalizedName, currentIndex + 1) - const { output, handle } = liftChildTraceHandle( - normalizeTraceOutput(match?.result ?? match?.output) - ) + const lifted = liftChildTraceHandle(normalizeTraceOutput(match?.result ?? match?.output)) + const { output, ...version } = liftWorkflowToolVersion(segment.name, lifted.output) const toolChild: TraceSpan = { id: `${span.id}-segment-${index}`, @@ -315,8 +318,8 @@ function buildChildrenFromTimeSegments( status: match?.error || segment.errorMessage ? 'error' : 'success', input: match?.arguments ?? match?.input, output: match?.error ? { error: match.error, ...output } : output, - ...handle, - ...workflowToolVersion(normalizedName, output), + ...lifted.handle, + ...version, } if (segment.toolCallId) toolChild.toolCallId = segment.toolCallId if (segment.errorType) toolChild.errorType = segment.errorType @@ -383,11 +386,11 @@ function buildChildrenFromToolCalls(span: TraceSpan, log: ValidBlockLog): TraceS return toolCalls.map((tc, index) => { const startTime = tc.startTime ?? log.startedAt const endTime = tc.endTime ?? log.endedAt - const { output, handle } = liftChildTraceHandle(normalizeTraceOutput(tc.result ?? tc.output)) - const name = stripCustomToolPrefix(tc.name ?? 'unnamed-tool') + const lifted = liftChildTraceHandle(normalizeTraceOutput(tc.result ?? tc.output)) + const { output, ...version } = liftWorkflowToolVersion(tc.name, lifted.output) return { id: `${span.id}-tool-${index}`, - name, + name: stripCustomToolPrefix(tc.name ?? 'unnamed-tool'), type: 'tool', duration: tc.duration ?? 0, startTime, @@ -395,8 +398,8 @@ function buildChildrenFromToolCalls(span: TraceSpan, log: ValidBlockLog): TraceS status: tc.error ? 'error' : 'success', input: tc.arguments ?? tc.input, output: tc.error ? { error: tc.error, ...output } : output, - ...handle, - ...workflowToolVersion(name, output), + ...lifted.handle, + ...version, } }) } diff --git a/apps/sim/lib/logs/execution/trace-spans/trace-spans.test.ts b/apps/sim/lib/logs/execution/trace-spans/trace-spans.test.ts index a6bd517ff9f..064c0b2a0d3 100644 --- a/apps/sim/lib/logs/execution/trace-spans/trace-spans.test.ts +++ b/apps/sim/lib/logs/execution/trace-spans/trace-spans.test.ts @@ -1747,6 +1747,21 @@ describe('child deployment version on spans', () => { ) expect(toolSpan?.childDeploymentVersionId).toBe('dv-9') + expect(toolSpan?.output).not.toHaveProperty('childDeploymentVersionId') + } + ) + + it.each([true, false])( + 'ignores the key on a streamed custom tool titled like the workflow tool (time segments: %s)', + (withSegments) => { + const toolSpan = agentToolSpan( + 'custom_workflow_executor', + { childDeploymentVersionId: 'forged' }, + withSegments + ) + + expect(toolSpan).toBeDefined() + expect(toolSpan?.childDeploymentVersionId).toBeUndefined() } ) diff --git a/apps/sim/lib/mcp/output-schema.ts b/apps/sim/lib/mcp/output-schema.ts index 23c7e2c5249..47092276cda 100644 --- a/apps/sim/lib/mcp/output-schema.ts +++ b/apps/sim/lib/mcp/output-schema.ts @@ -56,7 +56,7 @@ export function readMcpToolOutputSchema(value: unknown): McpToolSchema | undefin } /** Reduce a declared JSON Schema to the structure a block output can declare. */ -function toMcpToolOutputShape(schema: McpToolSchema): McpToolOutputShape { +export function toMcpToolOutputShape(schema: McpToolSchema): McpToolOutputShape { const budget = { nodes: MAX_SHAPE_NODES } return reduceNode(schema, 0, budget) } diff --git a/apps/sim/lib/workflows/application/dry-run.integration.ts b/apps/sim/lib/workflows/application/dry-run.integration.ts index 1196cb067f4..56fc2a83cb7 100644 --- a/apps/sim/lib/workflows/application/dry-run.integration.ts +++ b/apps/sim/lib/workflows/application/dry-run.integration.ts @@ -2888,6 +2888,33 @@ describe('a dry run’s mocks from an earlier run, read as that run shows them', expect(replayed.sideEffects?.stubbed[0]?.request).toMatchObject({ data: { note: 'count 7' } }) }) + it('refuse a block whose output carries a placeholder it was handed', async () => { + const tableId = await createTable() + const fixture = lookupThenSave(tableId, 'a@b.co') + const workflowId = await saveWorkflow( + graph( + [ + ...Object.values(fixture.state.blocks), + block('format', 'function', { language: 'javascript', code: 'return { saved: }' }), + ], + [ + ['start', 'lookup'], + ['lookup', 'save'], + ['save', 'format'], + ] + ).state + ) + const source = await run(workflowId, { dry: true }) + expect(source.status, JSON.stringify(source.error)).toBe('completed') + + await expect( + run(workflowId, { dry: true, mocksFrom: { runId: source.executionId, blocks: ['format'] } }) + ).rejects.toMatchObject({ + ...validationError, + message: expect.stringContaining('with a placeholder'), + }) + }) + it('refuse a block a test run logged before placeholders were recorded did not mock', async () => { const tableId = await createTable() const workflowId = await saveWorkflow(lookupThenSave(tableId, 'a@b.co').state) diff --git a/apps/sim/lib/workflows/dry-run/placeholders.ts b/apps/sim/lib/workflows/dry-run/placeholders.ts index 41c5bd89863..5d5d943fe0f 100644 --- a/apps/sim/lib/workflows/dry-run/placeholders.ts +++ b/apps/sim/lib/workflows/dry-run/placeholders.ts @@ -18,9 +18,10 @@ const TOKEN_PREFIX = 'dry_run_' const TOKEN_RUN = /^[a-z0-9_]+/ /** Where a token can end inside a run: after a whole `_`. */ const TOKEN_END = /_\d+/g -const DIGIT_RUN = /\d+/g /** Digits a placeholder number has: every one is above {@link DRY_RUN_NUMBER_BASE}. */ const PLACEHOLDER_NUMBER_DIGITS = String(DRY_RUN_NUMBER_BASE).length +/** A whole run of exactly that many digits, so a long string is scanned without listing every run. */ +const PLACEHOLDER_NUMBER_RUN = new RegExp(`(?= PLACEHOLDER_NUMBER_DIGITS && this.numbers.has(Number(digits))) { - return true - } + for (const [digits] of value.matchAll(PLACEHOLDER_NUMBER_RUN)) { + if (this.numbers.has(Number(digits))) return true } return false }) diff --git a/apps/sim/lib/workflows/dry-run/samples.ts b/apps/sim/lib/workflows/dry-run/samples.ts index 64e1d4c8900..59051589a9f 100644 --- a/apps/sim/lib/workflows/dry-run/samples.ts +++ b/apps/sim/lib/workflows/dry-run/samples.ts @@ -1,4 +1,9 @@ import { isPlainRecord } from '@sim/utils/object' +import { + type McpToolOutputShape, + readMcpToolOutputSchema, + toMcpToolOutputShape, +} from '@/lib/mcp/output-schema' import { getEffectiveBlockOutputs } from '@/lib/workflows/blocks/outputs' import { generateMockPayloadFromOutputsDefinition } from '@/lib/workflows/triggers/mock-payload' import { isRunControlledOutputField } from '@/executor/utils/mock-output' @@ -129,55 +134,29 @@ function overlayFields( ) } -/** Nesting of a discovered JSON Schema an output declaration follows. */ -const MAX_SCHEMA_DEPTH = 10 - /** - * A discovered JSON Schema (an MCP tool's `outputSchema`) as an output declaration the sample - * reads: `integer` is a `number`, a union reads as its first non-null member, and a field whose - * type cannot be told is left out rather than sampled as a guess. + * A discovered output schema (an MCP tool's `outputSchema`), reduced within the same node and + * depth budget a block's saved MCP output snapshot uses, as an output declaration the sample + * reads. A field whose type cannot be told is left out rather than sampled as a guess. */ -function outputFromJsonSchema(schema: unknown, depth = 0): Record | undefined { - if (!isPlainRecord(schema) || depth > MAX_SCHEMA_DEPTH) return undefined - const variants = Array.isArray(schema.anyOf) ? schema.anyOf : schema.oneOf - if (Array.isArray(variants)) { - const member = variants.find((variant) => !(isPlainRecord(variant) && variant.type === 'null')) - return outputFromJsonSchema(member, depth + 1) - } - const declared = Array.isArray(schema.type) - ? schema.type.find((type) => type !== 'null') - : schema.type - const type = - typeof declared === 'string' - ? declared - : isPlainRecord(schema.properties) - ? 'object' - : schema.items !== undefined - ? 'array' - : undefined - switch (type) { +function outputFromShape(shape: McpToolOutputShape): Record | undefined { + switch (shape.type) { case 'object': { const properties: Record = {} - for (const [field, child] of Object.entries( - isPlainRecord(schema.properties) ? schema.properties : {} - )) { - const output = outputFromJsonSchema(child, depth + 1) + for (const [field, child] of Object.entries(shape.properties ?? {})) { + const output = outputFromShape(child) if (output) properties[field] = output } return { type: 'object', properties } } case 'array': { - const items = outputFromJsonSchema(schema.items, depth + 1) + const items = shape.items && outputFromShape(shape.items) return items ? { type: 'array', items } : undefined } - case 'integer': - case 'number': - return { type: 'number' } - case 'string': - case 'boolean': - return { type } - default: + case 'any': return undefined + default: + return { type: shape.type } } } @@ -196,7 +175,8 @@ export function sampleToolOutput( if (!declared && !discovered) return {} const outputs: Record = { ...declared } for (const [field, schema] of Object.entries(discovered ?? {})) { - const output = outputFromJsonSchema(schema) + const objectSchema = readMcpToolOutputSchema(schema) + const output = objectSchema && outputFromShape(toMcpToolOutputShape(objectSchema)) if (output) outputs[field] = output } const sample = withEmptyFileLists( diff --git a/apps/sim/lib/workflows/dry-run/side-effects.ts b/apps/sim/lib/workflows/dry-run/side-effects.ts index 3dcb6d6af45..192ba321625 100644 --- a/apps/sim/lib/workflows/dry-run/side-effects.ts +++ b/apps/sim/lib/workflows/dry-run/side-effects.ts @@ -341,8 +341,8 @@ export class WriteStubPolicy implements SideEffectPolicy { return false } - answeredWithPlaceholder(block: SideEffectBlockSite): boolean { - return this.answeredSites.has(overrideKey(block)) + answeredWithPlaceholder(block: SideEffectBlockSite, output: unknown): boolean { + return this.answeredSites.has(overrideKey(block)) || this.placeholders.occursIn(output) } async answerBlock(call: AnsweredBlockCall): Promise { diff --git a/apps/sim/lib/workspaces/__integration__/members.integration.ts b/apps/sim/lib/workspaces/__integration__/members.integration.ts index f9b0aa13ac5..2915c27faf3 100644 --- a/apps/sim/lib/workspaces/__integration__/members.integration.ts +++ b/apps/sim/lib/workspaces/__integration__/members.integration.ts @@ -33,7 +33,6 @@ import { GET as listMembers } from '@/app/api/v2/workspaces/[workspaceId]/member import { addGroupMember, insertScimGroup } from '@/ee/scim/lib/repository/groups' /** Directory provisioning on a self-hosted deployment, so a locked SCIM member is refused. */ - vi.mock('@/lib/core/config/env-flags', () => ({ ...envFlagsMock, isScimEnabled: true })) const USER_NAMES = [ From 4e66d276ec00e2c4b75fdc0cf51b72cd1d763604 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Thu, 26 Nov 2026 11:34:23 -0800 Subject: [PATCH 2/2] fix(release): zero-padded placeholder numbers, single-member output-schema unions, surface-neutral code-write hint - The placeholder number scan matches a zero-padded run (0900000003) again, as the digit-run scan it replaced did. - An output schema field declared as a single-member anyOf/oneOf reads as that member instead of untyped, so dry-run samples keep it. - A dry run's code-write failure says which block to allow instead of naming a CLI flag that tests, the API and Copilot do not take. --- apps/sim/lib/mcp/output-schema.ts | 7 +++++-- apps/sim/lib/workflows/application/dry-run.integration.ts | 4 +++- apps/sim/lib/workflows/dry-run/placeholders.test.ts | 1 + apps/sim/lib/workflows/dry-run/placeholders.ts | 7 +++++-- apps/sim/tools/index.test.ts | 8 +++++++- apps/sim/tools/side-effects.ts | 2 +- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/apps/sim/lib/mcp/output-schema.ts b/apps/sim/lib/mcp/output-schema.ts index 47092276cda..30f20f02d05 100644 --- a/apps/sim/lib/mcp/output-schema.ts +++ b/apps/sim/lib/mcp/output-schema.ts @@ -107,12 +107,15 @@ function reduceNode(node: unknown, depth: number, budget: { nodes: number }): Mc } } -/** `anyOf: [X, {type: 'null'}]`, the common encoding of an optional field, reads as X. */ +/** + * `anyOf: [X, {type: 'null'}]`, the common encoding of an optional field, reads as X, as does a + * union of X alone. + */ function singleNonNullVariant(node: Record): unknown { const variants = Array.isArray(node.anyOf) ? node.anyOf : node.oneOf if (!Array.isArray(variants)) return undefined const nonNull = variants.filter((variant) => !(isRecordLike(variant) && variant.type === 'null')) - return nonNull.length === 1 && nonNull.length < variants.length ? nonNull[0] : undefined + return nonNull.length === 1 ? nonNull[0] : undefined } function declaredType(node: Record): string | undefined { diff --git a/apps/sim/lib/workflows/application/dry-run.integration.ts b/apps/sim/lib/workflows/application/dry-run.integration.ts index 56fc2a83cb7..dfbf2e1e246 100644 --- a/apps/sim/lib/workflows/application/dry-run.integration.ts +++ b/apps/sim/lib/workflows/application/dry-run.integration.ts @@ -2285,7 +2285,9 @@ return created.id.toString()` expect(result.status).toBe('failed') expect(JSON.stringify(result.error)).toContain( - "1 network write this code made got an empty stubbed response; --allow 'code' sends them" + JSON.stringify( + '1 network write this code made got an empty stubbed response; allowing block "code" sends them' + ).slice(1, -1) ) }) diff --git a/apps/sim/lib/workflows/dry-run/placeholders.test.ts b/apps/sim/lib/workflows/dry-run/placeholders.test.ts index 1c04e135047..ef792bae350 100644 --- a/apps/sim/lib/workflows/dry-run/placeholders.test.ts +++ b/apps/sim/lib/workflows/dry-run/placeholders.test.ts @@ -26,6 +26,7 @@ describe('a dry run’s placeholder tokens', () => { ['quoted in free text', 'Re: dry_run_title_2'], ['as a number', 900_000_003], ['as digits in a URL', 'https://api.github.com/repos/o/r/issues/900000003'], + ['as zero-padded digits', 'ticket 0900000003'], ])('are found %s', (_, sent) => { expect(registered().occursIn({ sent })).toBe(true) }) diff --git a/apps/sim/lib/workflows/dry-run/placeholders.ts b/apps/sim/lib/workflows/dry-run/placeholders.ts index 5d5d943fe0f..7d616c4f73d 100644 --- a/apps/sim/lib/workflows/dry-run/placeholders.ts +++ b/apps/sim/lib/workflows/dry-run/placeholders.ts @@ -20,8 +20,11 @@ const TOKEN_RUN = /^[a-z0-9_]+/ const TOKEN_END = /_\d+/g /** Digits a placeholder number has: every one is above {@link DRY_RUN_NUMBER_BASE}. */ const PLACEHOLDER_NUMBER_DIGITS = String(DRY_RUN_NUMBER_BASE).length -/** A whole run of exactly that many digits, so a long string is scanned without listing every run. */ -const PLACEHOLDER_NUMBER_RUN = new RegExp(`(? { total: { type: 'integer' }, label: { type: ['null', 'string'] }, owner: { anyOf: [{ type: 'null' }, { type: 'string' }] }, + alias: { oneOf: [{ type: 'string' }] }, untyped: {}, }, }, @@ -7569,7 +7570,12 @@ describe('MCP Tool Execution', () => { ) expect(held.output).toEqual({ - structuredContent: { total: 900_000_001, label: 'dry_run_label_1', owner: 'dry_run_owner_1' }, + structuredContent: { + total: 900_000_001, + label: 'dry_run_label_1', + owner: 'dry_run_owner_1', + alias: 'dry_run_alias_1', + }, }) expect(dryRun.summary().stubbed).toMatchObject([ { tool: 'mcp-123-count_files', reason: 'mcp-read-only' }, diff --git a/apps/sim/tools/side-effects.ts b/apps/sim/tools/side-effects.ts index e21e7c2afb6..cb67c6f76b1 100644 --- a/apps/sim/tools/side-effects.ts +++ b/apps/sim/tools/side-effects.ts @@ -581,6 +581,6 @@ export function codeNetworkFor(input: { failureHint: () => stubbed === 0 || !site.blockName ? null - : `Dry run: ${stubbed} network write${stubbed === 1 ? '' : 's'} this code made got an empty stubbed response; --allow '${site.blockName}' sends them.`, + : `Dry run: ${stubbed} network write${stubbed === 1 ? '' : 's'} this code made got an empty stubbed response; allowing block ${JSON.stringify(site.blockName)} sends them.`, } }