Skip to content

Commit 414b743

Browse files
committed
improvement(workflows): dry-run placeholders echo the writes they stand in for
A stubbed write was answered with a generic sample of the tool's outputs, so a Function reading a dry-run table upsert's row.data.<field> got null and an agent testing its workflow concluded its logic was wrong. A tool may now declare a pure dryRunOutput(params) on its config: the outputs the request alone determines. It receives the params with every secret masked (as sideEffects.stubbed[].request is built), its result is redacted like that request, and the sample of the declared outputs fills whatever it leaves out (ids, nested fields, each array item from the sample's first). Tools without it keep the sample. Declared for table insert/upsert/update row (row.data echoes the written data; update keeps the named row id) and batch insert (rows and insertedCount), file write (requested name, text byte size), and knowledge create document (the document name as stored). Filter updates and deletes are left out: their outputs depend on stored state.
1 parent 14316ca commit 414b743

17 files changed

Lines changed: 180 additions & 32 deletions

File tree

‎.agents/skills/add-tools/SKILL.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ search that returns no email or phone, and an email verifier.
234234
when the run cannot vouch that no secret remains in it, or cannot build it once secrets are
235235
masked (a URL that is wholly a secret); then check the tool label alone and compare the request
236236
fields only on entries that carry one.
237+
- A dry run answers a `write` with a sample of its `outputs`. When downstream blocks read output the
238+
request alone determines (a table write's `row.data`, a created file's `name`), declare a pure
239+
`dryRunOutput(params)` returning just those fields; it gets params with secrets masked, and the
240+
sample fills ids and everything else. Never guess at what the provider would add.
237241

238242
## Critical Rules for Parameters
239243

‎apps/docs/content/docs/api-reference/build-and-run-workflows.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Apply without `dryRun`. Set `atomic: true` in the body to write nothing when any
166166

167167
## 7. Test the draft [#test-run]
168168

169-
Run the saved draft with `run.source: "manual"` and `run.dry: true`. A dry run sends no writes: every tool call not declared `read` (table writes, sends, HTTP calls, custom and MCP tools) returns a placeholder shaped like the tool's output, and the result lists it under `sideEffects.stubbed` with the request it would have sent, credentials, secrets and password fields redacted. Check those payloads instead of cleaning up test data. Reads and model calls run for real, child workflows run dry too, and custom blocks are answered whole. Code runs for real (a Function block's, a Condition's expressions, a While or Do While loop's condition, or code an Agent's model writes) and is listed under `sideEffects.unchecked`. A dry run keeps nothing beyond its own log, which is under the `test` trigger: Agents read their memory but write none, and it raises no workspace event and does not count as a run of the workflow. Human in the loop and Wait blocks are answered whole, so a dry run never pauses, and a test run is never resumed. A failed dry run still returns its `sideEffects`, and only another dry run can use it, or a workflow test's run, as `run.entry.sourceRunId`. Allowing an Agent with `run.allowBlocks` sends only its own tool calls, not a workflow or custom block it calls. A mock is data: it cannot replace a locked block or set a field the run's execution, trace or billing reads (such as `cost`, `tokens`, `model` or a field starting with `_`), and the run records only which blocks were mocked, so a rerun passes `run.mocks` again, while the run's log shows a mocked block's output like any other block's. `run.mocks` names at most 50 blocks. Manual runs are synchronous or streamed, never `async`; a dry run is synchronous only.
169+
Run the saved draft with `run.source: "manual"` and `run.dry: true`. A dry run sends no writes: every tool call not declared `read` (table writes, sends, HTTP calls, custom and MCP tools) returns a correctly shaped placeholder (a table write echoes the row it would have written, secrets masked, so a block reading `row.data` gets the values it wrote), and the result lists it under `sideEffects.stubbed` with the request it would have sent, credentials, secrets and password fields redacted. Check those payloads instead of cleaning up test data. Reads and model calls run for real, child workflows run dry too, and custom blocks are answered whole. Code runs for real (a Function block's, a Condition's expressions, a While or Do While loop's condition, or code an Agent's model writes) and is listed under `sideEffects.unchecked`. A dry run keeps nothing beyond its own log, which is under the `test` trigger: Agents read their memory but write none, and it raises no workspace event and does not count as a run of the workflow. Human in the loop and Wait blocks are answered whole, so a dry run never pauses, and a test run is never resumed. A failed dry run still returns its `sideEffects`, and only another dry run can use it, or a workflow test's run, as `run.entry.sourceRunId`. Allowing an Agent with `run.allowBlocks` sends only its own tool calls, not a workflow or custom block it calls. A mock is data: it cannot replace a locked block or set a field the run's execution, trace or billing reads (such as `cost`, `tokens`, `model` or a field starting with `_`), and the run records only which blocks were mocked, so a rerun passes `run.mocks` again, while the run's log shows a mocked block's output like any other block's. `run.mocks` names at most 50 blocks. Manual runs are synchronous or streamed, never `async`; a dry run is synchronous only.
170170

171171
<Tabs items={['curl', 'CLI']}>
172172
<Tab value="curl">

‎apps/docs/openapi-v2-workflows.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17758,7 +17758,7 @@
1775817758
"minLength": 1
1775917759
},
1776017760
"dry": {
17761-
"description": "Dry run: every tool call not declared `read` (sends, table writes, HTTP calls, custom and MCP tools) is not sent; it returns a placeholder shaped like the tool's output and is listed in `sideEffects.stubbed` with the request it would have sent, credentials, secrets and (when the workspace redacts it) PII redacted. Reads, model calls and credential resolution run for real, and so does code (a Function block's, a Condition's expressions, a While or Do While loop's condition, or code an Agent's model writes), listed in `sideEffects.unchecked`. Child workflows inherit it. Custom, Mothership, Pi, Human in the loop and Wait blocks are answered whole with placeholders. Agents read their memory but write none, and nothing else beyond the run's own log is kept: it raises no workspace event and does not count as a run of the workflow. Logged under the `test` trigger. Synchronous only: cannot be combined with `stream` or `waitTimeoutSeconds`.",
17761+
"description": "Dry run: every tool call not declared `read` (sends, table writes, HTTP calls, custom and MCP tools) is not sent; it returns a correctly shaped placeholder (a table write echoes the row it would have written, secrets masked) and is listed in `sideEffects.stubbed` with the request it would have sent, credentials, secrets and (when the workspace redacts it) PII redacted. Reads, model calls and credential resolution run for real, and so does code (a Function block's, a Condition's expressions, a While or Do While loop's condition, or code an Agent's model writes), listed in `sideEffects.unchecked`. Child workflows inherit it. Custom, Mothership, Pi, Human in the loop and Wait blocks are answered whole with placeholders. Agents read their memory but write none, and nothing else beyond the run's own log is kept: it raises no workspace event and does not count as a run of the workflow. Logged under the `test` trigger. Synchronous only: cannot be combined with `stream` or `waitTimeoutSeconds`.",
1776217762
"type": "boolean"
1776317763
},
1776417764
"allowBlocks": {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ export interface StubbedToolCall extends SideEffectSite {
347347
toolId: string
348348
/** The request with credentials, secrets and PII redacted; null when that cannot be vouched for. */
349349
request: Record<string, unknown> | null
350+
/**
351+
* The output the tool's `dryRunOutput` derives from that request, redacted like it; null when
352+
* the tool declares none or that cannot be vouched for, so the placeholder is the sample alone.
353+
*/
354+
echoed: Record<string, unknown> | null
350355
}
351356

352357
/** A block the run answers instead of running its handler. */

‎apps/sim/lib/api/contracts/v2/workflows.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,7 @@ export const v2WorkflowRunSelectionSchema = z.discriminatedUnion('source', [
17091709
.boolean()
17101710
.optional()
17111711
.describe(
1712-
"Dry run: every tool call not declared `read` (sends, table writes, HTTP calls, custom and MCP tools) is not sent; it returns a placeholder shaped like the tool's output and is listed in `sideEffects.stubbed` with the request it would have sent, credentials, secrets and (when the workspace redacts it) PII redacted. Reads, model calls and credential resolution run for real, and so does code (a Function block's, a Condition's expressions, a While or Do While loop's condition, or code an Agent's model writes), listed in `sideEffects.unchecked`. Child workflows inherit it. Custom, Mothership, Pi, Human in the loop and Wait blocks are answered whole with placeholders. Agents read their memory but write none, and nothing else beyond the run's own log is kept: it raises no workspace event and does not count as a run of the workflow. Logged under the `test` trigger. Synchronous only: cannot be combined with `stream` or `waitTimeoutSeconds`."
1712+
"Dry run: every tool call not declared `read` (sends, table writes, HTTP calls, custom and MCP tools) is not sent; it returns a correctly shaped placeholder (a table write echoes the row it would have written, secrets masked) and is listed in `sideEffects.stubbed` with the request it would have sent, credentials, secrets and (when the workspace redacts it) PII redacted. Reads, model calls and credential resolution run for real, and so does code (a Function block's, a Condition's expressions, a While or Do While loop's condition, or code an Agent's model writes), listed in `sideEffects.unchecked`. Child workflows inherit it. Custom, Mothership, Pi, Human in the loop and Wait blocks are answered whole with placeholders. Agents read their memory but write none, and nothing else beyond the run's own log is kept: it raises no workspace event and does not count as a run of the workflow. Logged under the `test` trigger. Synchronous only: cannot be combined with `stream` or `waitTimeoutSeconds`."
17131713
),
17141714
allowBlocks: z
17151715
.array(z.string().min(1, 'run.allowBlocks entries cannot be empty'))

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

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import {
9898
import { readWorkflowRun } from '@/lib/workflows/application/read-workflow-run'
9999
import { resumeWorkflowRun } from '@/lib/workflows/application/resume-run'
100100
import { runFromBlockFromCopilot } from '@/lib/workflows/application/run-workflow-from-copilot'
101+
import { sampleToolOutput } from '@/lib/workflows/dry-run'
101102
import type { ExecuteWorkflowServiceRun } from '@/lib/workflows/executor/execute-service'
102103
import { getWorkflowExecutionLogStatus } from '@/lib/workflows/executor/execution-state'
103104
import { POST as v2Execute } from '@/app/api/v2/workflows/[workflowId]/execute/route'
@@ -206,6 +207,7 @@ async function createTable(): Promise<string> {
206207
columns: [
207208
{ id: 'col_email', name: 'email', type: 'string', required: true, unique: true },
208209
{ id: 'col_score', name: 'score', type: 'number' },
210+
{ id: 'col_note', name: 'note', type: 'string' },
209211
],
210212
},
211213
})
@@ -484,6 +486,52 @@ describe('a dry run', () => {
484486
expect(stubbed[2].request).toMatchObject({ data: { email: 'child@b.co' } })
485487
})
486488

489+
it('answers a table write with the row it would have written, its secrets masked', async () => {
490+
const tableId = await createTable()
491+
const workflowId = await saveWorkflow(
492+
graph(
493+
[
494+
block('start', 'start_trigger'),
495+
block('save', 'table', {
496+
operation: 'upsert_row',
497+
tableSelector: tableId,
498+
data: JSON.stringify({ email: 'a@b.co', score: 82, note: 'key={{DRY_SECRET}}' }),
499+
}),
500+
notify('notify'),
501+
block('read', 'function', {
502+
language: 'javascript',
503+
code: 'return { score: <save.row.data.score>, email: <save.row.data.email>, note: <save.row.data.note>, notified: <notify.status> }',
504+
}),
505+
],
506+
[
507+
['start', 'save'],
508+
['save', 'notify'],
509+
['notify', 'read'],
510+
]
511+
).state
512+
)
513+
514+
const result = await run(workflowId, { dry: true, selectedOutputs: ['read.result'] })
515+
516+
expect(result.status, JSON.stringify(result.error)).toBe('completed')
517+
expect(await tableRows(tableId)).toEqual([])
518+
const read = toRecord(result.blockOutputs?.['read.result'])
519+
expect(read).toMatchObject({
520+
score: 82,
521+
email: 'a@b.co',
522+
note: expect.stringContaining('key='),
523+
})
524+
expect(JSON.stringify(result)).not.toContain(SECRET)
525+
const [save, sent] = result.sideEffects?.stubbed ?? []
526+
expect(toRecord(save.returned.row).data).toEqual({
527+
email: 'a@b.co',
528+
score: 82,
529+
note: read.note,
530+
})
531+
expect(sent).toMatchObject({ tool: 'http_request', returned: sampleToolOutput('http_request') })
532+
expect(read.notified).toBe(sampleToolOutput('http_request').status)
533+
})
534+
487535
it('keeps nothing beyond its own log: no run count and no workspace event', async () => {
488536
const { parentId } = await parentFixture()
489537
const subscriber = await saveWorkflow(graph([block('start', 'start_trigger')], []).state)
@@ -758,7 +806,10 @@ describe('a dry run', () => {
758806

759807
expect(result.status, JSON.stringify(result.error)).toBe('completed')
760808
const [write] = result.sideEffects?.stubbed ?? []
761-
expect(write).toMatchObject({ tool: 'knowledge_create_document' })
809+
expect(write).toMatchObject({
810+
tool: 'knowledge_create_document',
811+
returned: { data: { documentName: 'notes.txt' } },
812+
})
762813
const [document] = toArray<unknown>(toRecord(write.request).documents)
763814
const fileUrl = String(toRecord(document).fileUrl)
764815
const content = Buffer.from(fileUrl.slice(fileUrl.indexOf(',') + 1), 'base64').toString('utf8')

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isPlainRecord } from '@sim/utils/object'
12
import { getEffectiveBlockOutputs } from '@/lib/workflows/blocks/outputs'
23
import { generateMockPayloadFromOutputsDefinition } from '@/lib/workflows/triggers/mock-payload'
34
import { isRunControlledOutputField } from '@/executor/utils/mock-output'
@@ -21,8 +22,42 @@ export function sampleBlockOutput(block: {
2122
)
2223
}
2324

24-
/** Placeholder output shaped like a tool's declared outputs; empty for a tool that declares none. */
25-
export function sampleToolOutput(toolId: string): Record<string, unknown> {
25+
/**
26+
* `value` with what it leaves out taken from `sample`: a record field by field, and each item of
27+
* an array from the sample's first item.
28+
*/
29+
function fillFromSample(sample: unknown, value: unknown): unknown {
30+
if (value === undefined) return sample
31+
if (Array.isArray(value)) {
32+
const item = Array.isArray(sample) ? sample[0] : undefined
33+
return value.map((entry) => fillFromSample(item, entry))
34+
}
35+
if (!isPlainRecord(value) || !isPlainRecord(sample)) return value
36+
return Object.fromEntries([
37+
...Object.entries(sample),
38+
...Object.entries(value).map(([key, entry]) => [
39+
key,
40+
fillFromSample(Object.hasOwn(sample, key) ? sample[key] : undefined, entry),
41+
]),
42+
])
43+
}
44+
45+
/**
46+
* Placeholder output shaped like a tool's declared outputs; empty for a tool that declares none.
47+
* `echoed`, what the tool's `dryRunOutput` derived from the request it would have sent, fills each
48+
* declared output it names, and the sample everything else.
49+
*/
50+
export function sampleToolOutput(
51+
toolId: string,
52+
echoed: Record<string, unknown> | null = null
53+
): Record<string, unknown> {
2654
const outputs = getToolOutputsMetadata(toolId)
27-
return outputs ? generateMockPayloadFromOutputsDefinition(outputs) : {}
55+
const sample = outputs ? generateMockPayloadFromOutputsDefinition(outputs) : {}
56+
if (!echoed) return sample
57+
return Object.fromEntries(
58+
Object.entries(sample).map(([field, value]) => [
59+
field,
60+
Object.hasOwn(echoed, field) ? fillFromSample(value, echoed[field]) : value,
61+
])
62+
)
2863
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ class RecordedList<T> {
114114

115115
/**
116116
* The side-effect policy of a dry run (`run.dry`) and of a workflow test's unmocked writes: every
117-
* write tool call is answered with a placeholder shaped like the tool's output and recorded with
117+
* write tool call is answered with a placeholder shaped like the tool's output, holding what the
118+
* request determines where the tool declares it (`dryRunOutput`), and recorded with
118119
* the request it would have sent, except an allowed block's, which are sent and recorded once per
119120
* block and tool. Reads always run, and code runs and is listed unchecked. Custom blocks and
120121
* {@link PAUSING_BLOCK_TYPES} are answered whole, as is a block that acts outside the tool seam
@@ -192,7 +193,7 @@ export class WriteStubPolicy implements SideEffectPolicy {
192193
}
193194

194195
stubWrite(call: StubbedToolCall): Record<string, unknown> {
195-
const returned = sampleToolOutput(call.toolId)
196+
const returned = sampleToolOutput(call.toolId, call.echoed)
196197
this.stubbed.add({ ...recordedSite(call), tool: call.toolId, request: call.request, returned })
197198
return returned
198199
}

‎apps/sim/tools/file/write.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ export const fileWriteTool: InternalToolConfig<FileWriteParams, ToolResponse> =
9292
},
9393
},
9494

95+
/**
96+
* A dry run's placeholder names the file the call asks for (a write that would collide is
97+
* suffixed live) and sizes the text it writes; a stored file's name and size stay placeholders.
98+
*/
99+
dryRunOutput: (params) => ({
100+
name: params.fileName,
101+
size:
102+
params.content === undefined ? undefined : new TextEncoder().encode(params.content).length,
103+
}),
104+
95105
transformResponse: async (response) => {
96106
const data = await response.json()
97107
if (!response.ok || !data.success) {

‎apps/sim/tools/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,6 +2269,7 @@ async function executeToolImplementation(
22692269
registry: resolvedSecretTraceRegistry,
22702270
describe: (maskedParams: Record<string, unknown>) =>
22712271
describeToolRequest(unsentTool, maskedParams),
2272+
echo: unsentTool.dryRunOutput,
22722273
}
22732274
if (normalizedToolId !== mcpRunOperationTool.id || !tool.operation) {
22742275
return await answerUnsentWrite(unsentWrite, unsent)

0 commit comments

Comments
 (0)