Skip to content

Commit 81ea2f9

Browse files
committed
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.
1 parent 2fbc5f3 commit 81ea2f9

10 files changed

Lines changed: 89 additions & 66 deletions

File tree

‎apps/sim/executor/execution/block-executor.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ export class BlockExecutor {
469469
stateOutput,
470470
duration,
471471
stateProvenance,
472-
site !== undefined && sideEffects?.answeredWithPlaceholder(site) === true
472+
site !== undefined && sideEffects?.answeredWithPlaceholder(site, stateOutput) === true
473473
)
474474

475475
if (!isSentinel && blockLog) {

‎apps/sim/executor/execution/types.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,9 @@ export interface SideEffectPolicy {
468468
answersBlock(block: SideEffectBlockSite): boolean
469469
/**
470470
* Whether the run has answered this block, or a call it made, with a placeholder (its mock is
471-
* not one), so its output may hold made-up values.
471+
* not one), or its `output` carries one it was handed, so the output may hold made-up values.
472472
*/
473-
answeredWithPlaceholder(block: SideEffectBlockSite): boolean
473+
answeredWithPlaceholder(block: SideEffectBlockSite, output: unknown): boolean
474474
/** The output answering a block that does not run: its mock, or a recorded placeholder. */
475475
answerBlock(call: AnsweredBlockCall): Promise<NormalizedBlockOutput>
476476
}

‎apps/sim/lib/logs/execution/trace-spans/factory.ts‎

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,18 @@ function childDeploymentVersionOf(
202202
}
203203

204204
/**
205-
* The deployment version a workflow run as an Agent tool reported. Read only for
206-
* `workflow_executor`, so another tool returning the same key records nothing.
205+
* Moves the deployment version a workflow run as an Agent tool reported from its output onto the
206+
* span, as a workflow block span has it. Trusted only when the raw tool name is
207+
* `workflow_executor`: a streamed custom tool titled that way still carries its `custom_` prefix
208+
* here, and the Agent drops the key from a non-streamed custom tool's result.
207209
*/
208-
function workflowToolVersion(
209-
toolName: string,
210+
function liftWorkflowToolVersion(
211+
rawToolName: string | undefined,
210212
output: Record<string, unknown> | undefined
211-
): Pick<TraceSpan, 'childDeploymentVersionId'> {
212-
return toolName === WORKFLOW_TOOL_ID ? childDeploymentVersionOf(output) : {}
213+
): { output: Record<string, unknown> | undefined } & Pick<TraceSpan, 'childDeploymentVersionId'> {
214+
const version = rawToolName === WORKFLOW_TOOL_ID ? childDeploymentVersionOf(output) : {}
215+
if (!output || !version.childDeploymentVersionId) return { output }
216+
return { output: omit(output, ['childDeploymentVersionId']), ...version }
213217
}
214218

215219
/** Enriches a span with provider timing, cost, tokens, and model from block output. */
@@ -301,9 +305,8 @@ function buildChildrenFromTimeSegments(
301305
const currentIndex = toolCallIndices.get(normalizedName) ?? 0
302306
const match = callsForName[currentIndex]
303307
toolCallIndices.set(normalizedName, currentIndex + 1)
304-
const { output, handle } = liftChildTraceHandle(
305-
normalizeTraceOutput(match?.result ?? match?.output)
306-
)
308+
const lifted = liftChildTraceHandle(normalizeTraceOutput(match?.result ?? match?.output))
309+
const { output, ...version } = liftWorkflowToolVersion(segment.name, lifted.output)
307310

308311
const toolChild: TraceSpan = {
309312
id: `${span.id}-segment-${index}`,
@@ -315,8 +318,8 @@ function buildChildrenFromTimeSegments(
315318
status: match?.error || segment.errorMessage ? 'error' : 'success',
316319
input: match?.arguments ?? match?.input,
317320
output: match?.error ? { error: match.error, ...output } : output,
318-
...handle,
319-
...workflowToolVersion(normalizedName, output),
321+
...lifted.handle,
322+
...version,
320323
}
321324
if (segment.toolCallId) toolChild.toolCallId = segment.toolCallId
322325
if (segment.errorType) toolChild.errorType = segment.errorType
@@ -383,20 +386,20 @@ function buildChildrenFromToolCalls(span: TraceSpan, log: ValidBlockLog): TraceS
383386
return toolCalls.map((tc, index) => {
384387
const startTime = tc.startTime ?? log.startedAt
385388
const endTime = tc.endTime ?? log.endedAt
386-
const { output, handle } = liftChildTraceHandle(normalizeTraceOutput(tc.result ?? tc.output))
387-
const name = stripCustomToolPrefix(tc.name ?? 'unnamed-tool')
389+
const lifted = liftChildTraceHandle(normalizeTraceOutput(tc.result ?? tc.output))
390+
const { output, ...version } = liftWorkflowToolVersion(tc.name, lifted.output)
388391
return {
389392
id: `${span.id}-tool-${index}`,
390-
name,
393+
name: stripCustomToolPrefix(tc.name ?? 'unnamed-tool'),
391394
type: 'tool',
392395
duration: tc.duration ?? 0,
393396
startTime,
394397
endTime,
395398
status: tc.error ? 'error' : 'success',
396399
input: tc.arguments ?? tc.input,
397400
output: tc.error ? { error: tc.error, ...output } : output,
398-
...handle,
399-
...workflowToolVersion(name, output),
401+
...lifted.handle,
402+
...version,
400403
}
401404
})
402405
}

‎apps/sim/lib/logs/execution/trace-spans/trace-spans.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,21 @@ describe('child deployment version on spans', () => {
17471747
)
17481748

17491749
expect(toolSpan?.childDeploymentVersionId).toBe('dv-9')
1750+
expect(toolSpan?.output).not.toHaveProperty('childDeploymentVersionId')
1751+
}
1752+
)
1753+
1754+
it.each([true, false])(
1755+
'ignores the key on a streamed custom tool titled like the workflow tool (time segments: %s)',
1756+
(withSegments) => {
1757+
const toolSpan = agentToolSpan(
1758+
'custom_workflow_executor',
1759+
{ childDeploymentVersionId: 'forged' },
1760+
withSegments
1761+
)
1762+
1763+
expect(toolSpan).toBeDefined()
1764+
expect(toolSpan?.childDeploymentVersionId).toBeUndefined()
17501765
}
17511766
)
17521767

‎apps/sim/lib/mcp/output-schema.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function readMcpToolOutputSchema(value: unknown): McpToolSchema | undefin
5656
}
5757

5858
/** Reduce a declared JSON Schema to the structure a block output can declare. */
59-
function toMcpToolOutputShape(schema: McpToolSchema): McpToolOutputShape {
59+
export function toMcpToolOutputShape(schema: McpToolSchema): McpToolOutputShape {
6060
const budget = { nodes: MAX_SHAPE_NODES }
6161
return reduceNode(schema, 0, budget)
6262
}

‎apps/sim/lib/workflows/application/dry-run.integration.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2888,6 +2888,33 @@ describe('a dry run’s mocks from an earlier run, read as that run shows them',
28882888
expect(replayed.sideEffects?.stubbed[0]?.request).toMatchObject({ data: { note: 'count 7' } })
28892889
})
28902890

2891+
it('refuse a block whose output carries a placeholder it was handed', async () => {
2892+
const tableId = await createTable()
2893+
const fixture = lookupThenSave(tableId, 'a@b.co')
2894+
const workflowId = await saveWorkflow(
2895+
graph(
2896+
[
2897+
...Object.values(fixture.state.blocks),
2898+
block('format', 'function', { language: 'javascript', code: 'return { saved: <save> }' }),
2899+
],
2900+
[
2901+
['start', 'lookup'],
2902+
['lookup', 'save'],
2903+
['save', 'format'],
2904+
]
2905+
).state
2906+
)
2907+
const source = await run(workflowId, { dry: true })
2908+
expect(source.status, JSON.stringify(source.error)).toBe('completed')
2909+
2910+
await expect(
2911+
run(workflowId, { dry: true, mocksFrom: { runId: source.executionId, blocks: ['format'] } })
2912+
).rejects.toMatchObject({
2913+
...validationError,
2914+
message: expect.stringContaining('with a placeholder'),
2915+
})
2916+
})
2917+
28912918
it('refuse a block a test run logged before placeholders were recorded did not mock', async () => {
28922919
const tableId = await createTable()
28932920
const workflowId = await saveWorkflow(lookupThenSave(tableId, 'a@b.co').state)

‎apps/sim/lib/workflows/dry-run/placeholders.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ const TOKEN_PREFIX = 'dry_run_'
1818
const TOKEN_RUN = /^[a-z0-9_]+/
1919
/** Where a token can end inside a run: after a whole `_<digits>`. */
2020
const TOKEN_END = /_\d+/g
21-
const DIGIT_RUN = /\d+/g
2221
/** Digits a placeholder number has: every one is above {@link DRY_RUN_NUMBER_BASE}. */
2322
const PLACEHOLDER_NUMBER_DIGITS = String(DRY_RUN_NUMBER_BASE).length
23+
/** A whole run of exactly that many digits, so a long string is scanned without listing every run. */
24+
const PLACEHOLDER_NUMBER_RUN = new RegExp(`(?<!\\d)\\d{${PLACEHOLDER_NUMBER_DIGITS}}(?!\\d)`, 'g')
2425
/** Longest token a scan reads at one `dry_run_`. */
2526
const MAX_TOKEN_LENGTH = 256
2627

@@ -115,10 +116,8 @@ export class PlaceholderTokens {
115116
if (this.tokens.has(token)) return true
116117
}
117118
if (this.numbers.size === 0) return false
118-
for (const digits of value.match(DIGIT_RUN) ?? []) {
119-
if (digits.length >= PLACEHOLDER_NUMBER_DIGITS && this.numbers.has(Number(digits))) {
120-
return true
121-
}
119+
for (const [digits] of value.matchAll(PLACEHOLDER_NUMBER_RUN)) {
120+
if (this.numbers.has(Number(digits))) return true
122121
}
123122
return false
124123
})

‎apps/sim/lib/workflows/dry-run/samples.ts‎

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import { isPlainRecord } from '@sim/utils/object'
2+
import {
3+
type McpToolOutputShape,
4+
readMcpToolOutputSchema,
5+
toMcpToolOutputShape,
6+
} from '@/lib/mcp/output-schema'
27
import { getEffectiveBlockOutputs } from '@/lib/workflows/blocks/outputs'
38
import { generateMockPayloadFromOutputsDefinition } from '@/lib/workflows/triggers/mock-payload'
49
import { isRunControlledOutputField } from '@/executor/utils/mock-output'
@@ -129,55 +134,29 @@ function overlayFields(
129134
)
130135
}
131136

132-
/** Nesting of a discovered JSON Schema an output declaration follows. */
133-
const MAX_SCHEMA_DEPTH = 10
134-
135137
/**
136-
* A discovered JSON Schema (an MCP tool's `outputSchema`) as an output declaration the sample
137-
* reads: `integer` is a `number`, a union reads as its first non-null member, and a field whose
138-
* type cannot be told is left out rather than sampled as a guess.
138+
* A discovered output schema (an MCP tool's `outputSchema`), reduced within the same node and
139+
* depth budget a block's saved MCP output snapshot uses, as an output declaration the sample
140+
* reads. A field whose type cannot be told is left out rather than sampled as a guess.
139141
*/
140-
function outputFromJsonSchema(schema: unknown, depth = 0): Record<string, unknown> | undefined {
141-
if (!isPlainRecord(schema) || depth > MAX_SCHEMA_DEPTH) return undefined
142-
const variants = Array.isArray(schema.anyOf) ? schema.anyOf : schema.oneOf
143-
if (Array.isArray(variants)) {
144-
const member = variants.find((variant) => !(isPlainRecord(variant) && variant.type === 'null'))
145-
return outputFromJsonSchema(member, depth + 1)
146-
}
147-
const declared = Array.isArray(schema.type)
148-
? schema.type.find((type) => type !== 'null')
149-
: schema.type
150-
const type =
151-
typeof declared === 'string'
152-
? declared
153-
: isPlainRecord(schema.properties)
154-
? 'object'
155-
: schema.items !== undefined
156-
? 'array'
157-
: undefined
158-
switch (type) {
142+
function outputFromShape(shape: McpToolOutputShape): Record<string, unknown> | undefined {
143+
switch (shape.type) {
159144
case 'object': {
160145
const properties: Record<string, unknown> = {}
161-
for (const [field, child] of Object.entries(
162-
isPlainRecord(schema.properties) ? schema.properties : {}
163-
)) {
164-
const output = outputFromJsonSchema(child, depth + 1)
146+
for (const [field, child] of Object.entries(shape.properties ?? {})) {
147+
const output = outputFromShape(child)
165148
if (output) properties[field] = output
166149
}
167150
return { type: 'object', properties }
168151
}
169152
case 'array': {
170-
const items = outputFromJsonSchema(schema.items, depth + 1)
153+
const items = shape.items && outputFromShape(shape.items)
171154
return items ? { type: 'array', items } : undefined
172155
}
173-
case 'integer':
174-
case 'number':
175-
return { type: 'number' }
176-
case 'string':
177-
case 'boolean':
178-
return { type }
179-
default:
156+
case 'any':
180157
return undefined
158+
default:
159+
return { type: shape.type }
181160
}
182161
}
183162

@@ -196,7 +175,8 @@ export function sampleToolOutput(
196175
if (!declared && !discovered) return {}
197176
const outputs: Record<string, unknown> = { ...declared }
198177
for (const [field, schema] of Object.entries(discovered ?? {})) {
199-
const output = outputFromJsonSchema(schema)
178+
const objectSchema = readMcpToolOutputSchema(schema)
179+
const output = objectSchema && outputFromShape(toMcpToolOutputShape(objectSchema))
200180
if (output) outputs[field] = output
201181
}
202182
const sample = withEmptyFileLists(

‎apps/sim/lib/workflows/dry-run/side-effects.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ export class WriteStubPolicy implements SideEffectPolicy {
341341
return false
342342
}
343343

344-
answeredWithPlaceholder(block: SideEffectBlockSite): boolean {
345-
return this.answeredSites.has(overrideKey(block))
344+
answeredWithPlaceholder(block: SideEffectBlockSite, output: unknown): boolean {
345+
return this.answeredSites.has(overrideKey(block)) || this.placeholders.occursIn(output)
346346
}
347347

348348
async answerBlock(call: AnsweredBlockCall): Promise<NormalizedBlockOutput> {

‎apps/sim/lib/workspaces/__integration__/members.integration.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import { GET as listMembers } from '@/app/api/v2/workspaces/[workspaceId]/member
3333
import { addGroupMember, insertScimGroup } from '@/ee/scim/lib/repository/groups'
3434

3535
/** Directory provisioning on a self-hosted deployment, so a locked SCIM member is refused. */
36-
3736
vi.mock('@/lib/core/config/env-flags', () => ({ ...envFlagsMock, isScimEnabled: true }))
3837

3938
const USER_NAMES = [

0 commit comments

Comments
 (0)