Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/docs/content/docs/cli/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ b8c0d247-9e13-4a86-97f5-2ad4e1638c09 Weekly digest /Reporting no 18
sim workflows run 3a9e21d8-5f47-4c0b-b2ea-91d7c6034ef8 --input '{"ticketId":"T-4821"}'
```

Ordinary execution runs the active deployment. Deploy from the workflow builder or with `sim workflows deploy <workflowId>`. To execute the current saved workflow state, use `sim workflows run <workflowId> --manual`. To test it without sending its writes, use `--dry`: each write is answered with a placeholder and listed with its request under `sideEffects` in the result.
Ordinary execution runs the active deployment. Deploy from the workflow builder or with `sim workflows deploy <workflowId>`; its first line, `live`, says which version serves, and while a new version activates it names the version still serving. To run an earlier deployed version, pass `--deployment-version <n>`; it needs workspace write access, through a full-access API key or an OAuth token with `api:write`, and child workflows still run their own active deployment. To execute the current saved workflow state, use `sim workflows run <workflowId> --manual`. To test it without sending its writes, use `--dry`: each write is answered with a placeholder and listed with its request under `sideEffects` in the result.

## How commands are shaped

Expand Down
3 changes: 2 additions & 1 deletion apps/docs/content/docs/cli/reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8516,6 +8516,7 @@ sim workflows run <workflowId> [options]
| `--base64-max-bytes <value>` | No | Maximum total bytes of file content to inline as base64, lowering but never raising the server limit of 16 MiB. Rejected when `async` is true. |
| `--run-id <value>` | No | One-shot identifier for this run; NOT an idempotency key — reusing a claimed value fails with RUN_ID_CONFLICT instead of replaying the first result, and a fresh value starts another run. |
| `--manual` | No | Run the current saved workflow state instead of the active deployment. |
| `--deployment-version <n>` | No | Run this deployed version instead of the active one (a version number from `sim workflows versions list`); a Workflow block in it still runs its child workflow's active deployment. Needs workspace write access, through a full-access API key or an OAuth token with api:write. Not with --manual or any flag that runs the draft. |
| `--dry` | No | Dry run of the saved draft (implies --manual): writes are not sent but answered with placeholders and listed with their request payloads in sideEffects; reads, model calls and code run for real. Logged as a test run. Not with --follow, --async or --wait-timeout. |
| `--allow <block>` | No | Send this block's writes for real during a --dry run (its id, display name or key); for an Agent, only its own tool calls, not a workflow or custom block it calls; repeatable. |
| `--mock <block>=<json\|@file>` | No | Answer this block with the given JSON object instead of running it during a --dry run (its id, display name or key), to steer a branch or give a stubbed write a realistic result. Not a locked block; data only, so no cost, tokens, model or other field the run’s trace or billing reads, and no field starting with _. The run records only which blocks were mocked, so a rerun passes it again (its log shows the output like any other block’s); repeatable. |
Expand All @@ -8532,7 +8533,7 @@ sim workflows run <workflowId> [options]

</CommandTable>

Without --manual (or a flag that implies it) this runs the active deployment; a workflow never deployed has none. --manual runs the saved draft, as the source loop leaves it.
Without --manual (or a flag that implies it) this runs the active deployment; a workflow never deployed has none. --deployment-version &lt;n&gt; runs that deployed version instead, as a pin for comparing or reproducing (it needs workspace write access, through a full-access API key or an OAuth token with api:write); the child workflows it calls still run their own active deployment. --manual runs the saved draft, as the source loop leaves it.

--dry runs the saved draft without its side effects: every tool call not declared read (sends, table writes, HTTP calls, custom and MCP tools) returns a placeholder and is listed in sideEffects.stubbed with the request it would have sent; check those payloads. Code (a Function block's, a Condition's expressions, a While or Do While loop's condition, or code an Agent's model writes) runs and is listed in sideEffects.unchecked. Child workflows run dry too; custom, Human in the loop and Wait blocks are answered whole, so the run never pauses. Agents read memory but write none, and the run raises no workspace event. --allow &lt;block&gt; sends that block's writes for real (use a test resource); allowing an Agent sends only its own tool calls, not a workflow or custom block it calls. --mock &lt;block&gt;=&lt;json&gt; answers a block with fixed output, to steer a branch; a locked block cannot be mocked, and a mock is data, so it cannot set a field the run's execution, trace or billing reads (such as cost, tokens, model or a field starting with _). A dry run is the --source-run only of another dry run, and is never resumed.

Expand Down
3 changes: 2 additions & 1 deletion apps/docs/content/docs/cli/workflows.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ sim workflows run <workflowId> [options]
| `--base64-max-bytes <value>` | No | Maximum total bytes of file content to inline as base64, lowering but never raising the server limit of 16 MiB. Rejected when `async` is true. |
| `--run-id <value>` | No | One-shot identifier for this run; NOT an idempotency key — reusing a claimed value fails with RUN_ID_CONFLICT instead of replaying the first result, and a fresh value starts another run. |
| `--manual` | No | Run the current saved workflow state instead of the active deployment. |
| `--deployment-version <n>` | No | Run this deployed version instead of the active one (a version number from `sim workflows versions list`); a Workflow block in it still runs its child workflow's active deployment. Needs workspace write access, through a full-access API key or an OAuth token with api:write. Not with --manual or any flag that runs the draft. |
| `--dry` | No | Dry run of the saved draft (implies --manual): writes are not sent but answered with placeholders and listed with their request payloads in sideEffects; reads, model calls and code run for real. Logged as a test run. Not with --follow, --async or --wait-timeout. |
| `--allow <block>` | No | Send this block's writes for real during a --dry run (its id, display name or key); for an Agent, only its own tool calls, not a workflow or custom block it calls; repeatable. |
| `--mock <block>=<json\|@file>` | No | Answer this block with the given JSON object instead of running it during a --dry run (its id, display name or key), to steer a branch or give a stubbed write a realistic result. Not a locked block; data only, so no cost, tokens, model or other field the run’s trace or billing reads, and no field starting with _. The run records only which blocks were mocked, so a rerun passes it again (its log shows the output like any other block’s); repeatable. |
Expand All @@ -849,7 +850,7 @@ sim workflows run <workflowId> [options]

</CommandTable>

Without --manual (or a flag that implies it) this runs the active deployment; a workflow never deployed has none. --manual runs the saved draft, as the source loop leaves it.
Without --manual (or a flag that implies it) this runs the active deployment; a workflow never deployed has none. --deployment-version &lt;n&gt; runs that deployed version instead, as a pin for comparing or reproducing (it needs workspace write access, through a full-access API key or an OAuth token with api:write); the child workflows it calls still run their own active deployment. --manual runs the saved draft, as the source loop leaves it.

--dry runs the saved draft without its side effects: every tool call not declared read (sends, table writes, HTTP calls, custom and MCP tools) returns a placeholder and is listed in sideEffects.stubbed with the request it would have sent; check those payloads. Code (a Function block's, a Condition's expressions, a While or Do While loop's condition, or code an Agent's model writes) runs and is listed in sideEffects.unchecked. Child workflows run dry too; custom, Human in the loop and Wait blocks are answered whole, so the run never pauses. Agents read memory but write none, and the run raises no workspace event. --allow &lt;block&gt; sends that block's writes for real (use a test resource); allowing an Agent sends only its own tool calls, not a workflow or custom block it calls. --mock &lt;block&gt;=&lt;json&gt; answers a block with fixed output, to steer a branch; a locked block cannot be mocked, and a mock is data, so it cannot set a field the run's execution, trace or billing reads (such as cost, tokens, model or a field starting with _). A dry run is the --source-run only of another dry run, and is never resumed.

Expand Down
54 changes: 51 additions & 3 deletions apps/docs/openapi-v2-workflows.json
Original file line number Diff line number Diff line change
Expand Up @@ -6197,6 +6197,7 @@
},
"mintedIds": {},
"notes": [],
"deployedVersion": 3,
"needsRedeployment": false
}
}
Expand Down Expand Up @@ -6393,6 +6394,7 @@
},
"mintedIds": {},
"notes": [],
"deployedVersion": 3,
"needsRedeployment": false
}
}
Expand Down Expand Up @@ -6583,6 +6585,7 @@
"start": "a3f1c0b2-7a44-4c1d-9d3a-2b8e5f0a1c77"
},
"notes": [],
"deployedVersion": null,
"needsRedeployment": false
}
}
Expand Down Expand Up @@ -20468,9 +20471,22 @@
},
"description": "Non-fatal notes about the write."
},
"deployedVersion": {
"anyOf": [
{
"type": "integer",
"exclusiveMinimum": 0,
"maximum": 9007199254740991
},
{
"type": "null"
}
],
"description": "The live deployment version `needsRedeployment` compares the draft against, or null when the workflow is not deployed."
},
"needsRedeployment": {
"type": "boolean",
"description": "Whether the draft now differs from the live deployment; apply never deploys."
"description": "Whether the draft now differs from the live deployment; apply never deploys. False when nothing is deployed, so read it beside `deployedVersion`."
}
},
"required": [
Expand All @@ -20485,6 +20501,7 @@
"base",
"mintedIds",
"notes",
"deployedVersion",
"needsRedeployment"
],
"additionalProperties": false,
Expand Down Expand Up @@ -20546,6 +20563,7 @@
},
"mintedIds": {},
"notes": [],
"deployedVersion": 3,
"needsRedeployment": false
}
}
Expand Down Expand Up @@ -21435,9 +21453,22 @@
},
"description": "Non-fatal notes about the write."
},
"deployedVersion": {
"anyOf": [
{
"type": "integer",
"exclusiveMinimum": 0,
"maximum": 9007199254740991
},
{
"type": "null"
}
],
"description": "The live deployment version `needsRedeployment` compares the draft against, or null when the workflow is not deployed."
},
"needsRedeployment": {
"type": "boolean",
"description": "Whether the draft now differs from the live deployment; apply never deploys."
"description": "Whether the draft now differs from the live deployment; apply never deploys. False when nothing is deployed, so read it beside `deployedVersion`."
}
},
"required": [
Expand All @@ -21452,6 +21483,7 @@
"base",
"mintedIds",
"notes",
"deployedVersion",
"needsRedeployment"
],
"additionalProperties": false,
Expand Down Expand Up @@ -21513,6 +21545,7 @@
},
"mintedIds": {},
"notes": [],
"deployedVersion": 3,
"needsRedeployment": false
}
}
Expand Down Expand Up @@ -22378,9 +22411,22 @@
},
"description": "Non-fatal notes about the write."
},
"deployedVersion": {
"anyOf": [
{
"type": "integer",
"exclusiveMinimum": 0,
"maximum": 9007199254740991
},
{
"type": "null"
}
],
"description": "The live deployment version `needsRedeployment` compares the draft against, or null when the workflow is not deployed."
},
"needsRedeployment": {
"type": "boolean",
"description": "Whether the draft now differs from the live deployment; apply never deploys."
"description": "Whether the draft now differs from the live deployment; apply never deploys. False when nothing is deployed, so read it beside `deployedVersion`."
}
},
"required": [
Expand All @@ -22395,6 +22441,7 @@
"base",
"mintedIds",
"notes",
"deployedVersion",
"needsRedeployment"
],
"additionalProperties": false,
Expand Down Expand Up @@ -22464,6 +22511,7 @@
"start": "a3f1c0b2-7a44-4c1d-9d3a-2b8e5f0a1c77"
},
"notes": [],
"deployedVersion": null,
"needsRedeployment": false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ const applied = {
base: source.base,
mintedIds: {},
notes: [],
deployedVersion: 3,
needsRedeployment: true,
sdkMajor: 1,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const created = {
},
mintedIds: { start: 'b-1' },
notes: [],
deployedVersion: null,
needsRedeployment: false,
sdkMajor: 1,
}
Expand Down
3 changes: 3 additions & 0 deletions apps/sim/lib/api/contracts/v2/openapi/workflow-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export const workflowSourceOpenApiRoutes = [
base: WORKFLOW_SOURCE_EXAMPLE.base,
mintedIds: {},
notes: [],
deployedVersion: 3,
needsRedeployment: false,
},
},
Expand Down Expand Up @@ -192,6 +193,7 @@ export const workflowSourceOpenApiRoutes = [
base: WORKFLOW_SOURCE_EXAMPLE.base,
mintedIds: {},
notes: [],
deployedVersion: 3,
needsRedeployment: false,
},
},
Expand Down Expand Up @@ -259,6 +261,7 @@ export const workflowSourceOpenApiRoutes = [
base: WORKFLOW_SOURCE_EXAMPLE.base,
mintedIds: { start: BLOCK_ID },
notes: [],
deployedVersion: null,
needsRedeployment: false,
},
},
Expand Down
12 changes: 11 additions & 1 deletion apps/sim/lib/api/contracts/v2/workflow-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,19 @@ const applyWorkflowSourceDataSchema = z
'Block key → id for new blocks whose id was minted rather than taken from the lock.'
),
notes: z.array(z.string()).describe('Non-fatal notes about the write.'),
deployedVersion: z
.number()
.int()
.positive()
.nullable()
.describe(
'The live deployment version `needsRedeployment` compares the draft against, or null when the workflow is not deployed.'
),
needsRedeployment: z
.boolean()
.describe('Whether the draft now differs from the live deployment; apply never deploys.'),
.describe(
'Whether the draft now differs from the live deployment; apply never deploys. False when nothing is deployed, so read it beside `deployedVersion`.'
),
})
.describe('The outcome of applying workflow source.')

Expand Down
1 change: 1 addition & 0 deletions apps/sim/lib/workflows/api/source-presenters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function presentSourceOutcome(outcome: SourceOutcome): SourceOutcomeData
base: outcome.base,
mintedIds: outcome.mintedIds,
notes: outcome.notes,
deployedVersion: outcome.deployedVersion,
needsRedeployment: outcome.needsRedeployment,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ vi.mock('@/lib/workflows/deployment-status', async (importOriginal) => {
const actual = await importOriginal<typeof import('@/lib/workflows/deployment-status')>()
return {
...actual,
checkNeedsRedeployment: (workflowId: string) => {
readDeploymentDrift: (workflowId: string) => {
draftDeploymentChecks.count += 1
return actual.checkNeedsRedeployment(workflowId)
return actual.readDeploymentDrift(workflowId)
},
}
})
Expand Down Expand Up @@ -2530,7 +2530,7 @@ export default workflow('Fresh', {}, () => {
await db.insert(workflowDeploymentVersion).values({
id: generateId(),
workflowId,
version: 1,
version: 2,
state: deployed,
isActive: true,
})
Expand All @@ -2546,17 +2546,37 @@ export default workflow('Fresh', {}, () => {
expect(draftDeploymentChecks.count).toBe(1)
const applied = await apply(source, changed)

expect(unchangedDryRun.needsRedeployment).toBe(false)
expect(changedDryRun.needsRedeployment).toBe(true)
expect(applied.needsRedeployment).toBe(true)
// Each answer names the live version it compared the draft against.
expect(unchangedDryRun).toMatchObject({ deployedVersion: 2, needsRedeployment: false })
expect(changedDryRun).toMatchObject({ deployedVersion: 2, needsRedeployment: true })
expect(applied).toMatchObject({ deployedVersion: 2, needsRedeployment: true })

const edited = await getSource(workflowId)
const reverted = edit(edited.files, 'return 2', 'return 1')
const revertDryRun = await apply(edited, reverted, { dryRun: true })
const revert = await apply(edited, reverted)

expect(revertDryRun.needsRedeployment).toBe(false)
expect(revert.needsRedeployment).toBe(false)
expect(revertDryRun).toMatchObject({ deployedVersion: 2, needsRedeployment: false })
expect(revert).toMatchObject({ deployedVersion: 2, needsRedeployment: false })
}
)

check(
'a workflow never deployed reports no live version, which is not a draft matching one',
async () => {
const start = seedBlock('start_trigger', 'Start')
const score = seedBlock('function', 'Score', { code: ['code', 'return 1'] })
const workflowId = await seedGraph([start, score])
const source = await getSource(workflowId)
const changed = edit(source.files, 'return 1', 'return 2')

for (const answer of [
await apply(source, source.files, { dryRun: true }),
await apply(source, changed, { dryRun: true }),
await apply(source, changed),
]) {
expect(answer).toMatchObject({ deployedVersion: null, needsRedeployment: false })
}
}
)

Expand Down
6 changes: 3 additions & 3 deletions apps/sim/lib/workflows/application/source-pipeline/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
PlanBindingError,
type PlannedSource,
} from '@/lib/workflows/application/source-pipeline/plan'
import { checkNeedsRedeployment } from '@/lib/workflows/deployment-status'
import { readDeploymentDrift, UNDEPLOYED } from '@/lib/workflows/deployment-status'

const logger = createLogger('ApplyWorkflowSource')

Expand Down Expand Up @@ -67,7 +67,7 @@ export async function commitSource(
diff: plan.diff,
diagnostics: plan.diagnostics,
wroteSourceMeta: sourceMetaChanged,
needsRedeployment: await checkNeedsRedeployment(workflowId),
...(await readDeploymentDrift(workflowId)),
})
}

Expand Down Expand Up @@ -95,7 +95,7 @@ export async function commitSource(
mintedIds: plan.mintedIds,
workflowName: committed.name,
notes: committed.warnings,
needsRedeployment: target.kind === 'new' ? false : await checkNeedsRedeployment(workflowId),
...(target.kind === 'new' ? UNDEPLOYED : await readDeploymentDrift(workflowId)),
})
})
}
Loading
Loading