Skip to content

Commit 43d2b8c

Browse files
authored
improvement(workflows): agent-benchmark fixes for JSON refs, export, subflow moves and rerun-from-block (#10399)
* fix(workflow-code): print an inferred-text JSON ref as a template so upstream code edits cannot flip its storage A stored quoted token in a JSON field printed as the bare reference whenever refValueKind typed it a string, including when that type was only inferred from a Function's code or a child workflow's Response data. The printed source then left the field's storage to code in another block: an edit there that made the type unreadable compiled every unedited reader bare, so a string value broke the JSON at run time. The printer now prints a quoted token bare only when a declaration types it a string (refDeclaresString), and as t`${ref}` otherwise, which stores quoted whatever the code returns. The local check scoped W_JSON_REF_UNTYPED to blocks the lock does not bind, while the server reports it for any field that compiles differently than stored; it now reports it on any block the edit changed, including one an edit elsewhere makes compile differently. * fix(executor): a bare string reference in a JSON field splices as a JSON string A reference outside any string literal in JSON text (a Response body, table row data, an api body) spliced a string value raw, so `{"error": <check.message>}` produced invalid JSON for any message that was not itself JSON. Such a string now lands JSON-encoded; a string that already reads as one JSON value (an agent's JSON answer, a numeric env var) still splices as written, and a reference inside a string literal keeps its existing escaping. The api block's request retry params now say what they retry (timeouts, connection resets, 429 and 5xx, for GET/HEAD/PUT/DELETE unless non-idempotent retries are on), what fails at once (an unresolvable or refusing host, other 4xx), and that the block retry setting is separate and reruns the whole block after any failure. Their titles read "Request retries", "Request retry delay (ms)" and "Max request retry delay (ms)". * improvement(cli): self-sufficient workflow export, atomic subflow moves, documented table columns - `sim workflows export` keeps workspace bindings (table, knowledge base, child workflow ids) by default, so a table block prints its tableId; `--no-include-workspace-bindings` clears them for a copy to share. The stderr note pointing at `workflows outline` is gone. - Moving a block into or out of a loop or parallel removes the stored edges the move leaves crossing the boundary and names them in `warnings`, instead of recording them as skipped items that made `atomic` refuse the batch. Edges the batch itself asks for across a boundary are still refused. Operations help states this. - `tables create --schema` and `tables columns create --column` list every column field (required, unique, options, multiple, currencyCode, id, position) generated from the shape the server validates. * improvement(cli): make rerun-from-block a first-class run loop - A failed run (workflows run, runs get, runs wait) whose failure names a block now carries `next`: `sim workflows run <workflowId> --from-block <blockId> --source-run <runId>`, so an agent fixes the block, applies, and reruns only the failing part on that run's upstream outputs. Parallel-branch ids and ids outside the issued format get no command. - The raw hidden `--run` JSON flag is gone; the run selection is built only from --manual, --trigger, --mock-payload, --from-block, --source-run and --stop-after. - `workflows run --help` and the --from-block/--source-run descriptions say what the rerun reuses; both source primers name the rerun flags in Run and debug, within the 4096-byte budget. - paused-run.ts becomes run-next.ts now that it names the next command for failed runs too. * docs(workflow-code): describe the bare-reference splice rule the executor now applies * improvement(workflows): reuse the shared block label, drop the dead flag-hidden option, and align the splice docs * fix(workflows): address review on rerun hints, removed-edge warnings, retry delays and docs - A failed run's error carries rerunFromBlockId: the failed block, or the outermost loop or parallel holding it, since a run cannot start inside one. Execute reads it from the graph the run executed, Get workflow run from the saved draft. The CLI prints next from it instead of the failed block id, so a failure inside a loop no longer prints a rerun the server refuses. - Edge validation names why it dropped an edge (missing block, annotation-only, trigger target, scope); the removed-edge warning adds loop and parallel wiring advice only for a scope crossing. - backoffWithJitter never waits longer than maxMs: jitter at the cap only shortens the wait, so an api block's max request retry delay is a real maximum. - source check help: W_JSON_REF_UNTYPED scope sentence rewritten. - cross-kind integration expects a child-result text ref printed as t`${...}`. - Docs baseline hashes for the operations apply edge help fence. * test(utils): drop the retry test's redundant mock-restore hook * fix(api): keep rerunFromBlockId out of the resume response's error schema
1 parent e49e733 commit 43d2b8c

63 files changed

Lines changed: 1191 additions & 278 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/docs/content/docs/cli/reference.mdx‎

Lines changed: 14 additions & 10 deletions
Large diffs are not rendered by default.

‎apps/docs/content/docs/cli/scripting.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Most successful actions exit 0; API, configuration, or argument failures exit 1.
142142
| `13` | `AUTH_REQUIRED`: the profile has no credential, its OAuth login expired and could not be refreshed, or the server answered `401` (the server's own code is kept when it sends one). Nothing was done: run `sim login` and the same command again. |
143143
| `9` | Rate limited: the API answered `429` and the CLI gave up. Nothing more was sent: wait a minute and run the command again. |
144144

145-
The CLI resends a request the API answers `429` only when sending it twice is safe: every `GET`, and the source writes that are all-or-nothing (`sim workflows source apply` and `create`, `sim workspaces source apply` and its file uploads, dry runs and the dry run `status` sends included). It resends up to 6 times, waiting each time for the longer of the server's `Retry-After` (honoured up to 60 seconds) and a backoff of about 1, 2, 4, 8, 16 and 30 seconds (each ±20%), so one wait is at most a minute. Any other write answered `429` exits 9 at once. Interactive secret entry cancelled with Ctrl-C exits 130. Other outcomes are command-specific:
145+
The CLI resends a request the API answers `429` only when sending it twice is safe: every `GET`, and the source writes that are all-or-nothing (`sim workflows source apply` and `create`, `sim workspaces source apply` and its file uploads, dry runs and the dry run `status` sends included). It resends up to 6 times, waiting each time for the longer of the server's `Retry-After` (honoured up to 60 seconds) and a backoff of about 1, 2, 4, 8, 16 and 30 seconds (each ±20%, never past 30), so one wait is at most a minute. Any other write answered `429` exits 9 at once. Interactive secret entry cancelled with Ctrl-C exits 130. Other outcomes are command-specific:
146146

147147
| Code | `sim whoami` |
148148
| --- | --- |

‎apps/docs/content/docs/cli/tables.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ sim tables create [options]
6868
| --- | --- | --- |
6969
| `--name <value>` | Yes | Identifier: letters, numbers, and underscores; cannot start with a number. |
7070
| `--description <value>` | No | Optional table description. |
71-
| `--schema <json\|@file>` | Yes | Initial table column definitions: &#123;"columns":[&#123;"name":"email","type":"string"&#125;]&#125;. A column's type is one of string, number, currency, boolean, date, json, select; a select column also takes options. (JSON, or @path / @- to read a file or stdin). |
71+
| `--schema <json\|@file>` | Yes | Initial table column definitions: &#123;"columns":[&#123;"name":"email","type":"string","required":true,"unique":true&#125;]&#125;. Column fields: id - Optional client-provided column identifier; name (required) - Column name; type (required) - Column data type; required - Whether inserts must supply a value for this column; unique - Whether values in the column must be unique; options - Select options for select-type columns, as [&#123;"id":"open","name":"Open"&#125;]; multiple - Whether a select column accepts multiple values; currencyCode - ISO 4217 code for currency columns. A column's type is one of string, number, currency, boolean, date, json, select; a select column also takes options. (JSON, or @path / @- to read a file or stdin). |
7272
| `--folder <value>` | No | Folder path as shown in the app; the leading / is optional. |
7373

7474
</CommandTable>
@@ -624,7 +624,7 @@ sim tables columns create <tableId> [options]
624624

625625
| Option | Required | Description |
626626
| --- | --- | --- |
627-
| `--column <json\|@file>` | Yes | Column definition to add: &#123;"name":"status","type":"string"&#125;. A column's type is one of string, number, currency, boolean, date, json, select; a select column also takes options. (JSON, or @path / @- to read a file or stdin). |
627+
| `--column <json\|@file>` | Yes | Column definition to add: &#123;"name":"status","type":"string"&#125;. Column fields: id - Optional client-provided column identifier; name (required) - Column name; type (required) - Column data type; required - Whether inserts must supply a value for this column; unique - Whether values in the column must be unique; options - Select options for select-type columns, as [&#123;"id":"open","name":"Open"&#125;]; multiple - Whether a select column accepts multiple values; currencyCode - ISO 4217 code for currency columns; position - Zero-based insertion position for the column. A column's type is one of string, number, currency, boolean, date, json, select; a select column also takes options. (JSON, or @path / @- to read a file or stdin). |
628628

629629
</CommandTable>
630630

‎apps/docs/content/docs/cli/workflow-sync.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Forking and sync require Enterprise on billing-enabled deployments. Billing-disa
2828

2929
### 1. Export and inspect the workflow
3030

31-
`--include-references` adds a versioned manifest of resource identities and their occurrences. Default export clears registered credential fields and workspace bindings. It does not remove every ordinary variable value or literal configuration; inspect the payload before sharing it. Credentials and secret values are not transferred as destination resources.
31+
`--include-references` adds a versioned manifest of resource identities and their occurrences. `sim workflows export` clears registered credential fields and keeps non-secret workspace bindings, such as table and knowledge base IDs; `--no-include-workspace-bindings` clears those too. It does not remove every ordinary variable value or literal configuration; inspect the payload before sharing it. Credentials and secret values are not transferred as destination resources.
3232

3333
Pin JSON because import does not accept YAML:
3434

@@ -40,7 +40,7 @@ sim --profile destination --workspace "$DESTINATION_WORKSPACE" --output json \
4040
workflows import-preview --workflow @workflow.json > preview.json
4141
```
4242

43-
`--include-workspace-bindings` can preserve non-secret bindings for a same-workspace round trip. Otherwise, configure required bindings reported by import.
43+
With `--include-references`, import preview lists the bindings the destination has to map.
4444

4545
### 2. Map destination resources
4646

‎apps/docs/content/docs/cli/workflows.mdx‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,10 @@ Edges:
343343
or {"source":{"block":"<id>","handle":"<target handle>"}}; "success" is an alias of "source".
344344
An add's connections create the new block's edges. An edit's connections REPLACE every
345345
outgoing edge of that block, on every handle: list again each edge to keep; {} removes them all.
346-
A block moved into or out of a loop or parallel (parentId) loses every edge that would cross the
347-
container's boundary: to leave the loop, wire its loop-end-source (parallel-end-source).
346+
Moving a block into or out of a loop or parallel (parentId) removes each of its existing edges
347+
that would cross the container's boundary, atomic or not, and names them in warnings. Edges the
348+
batch itself asks for across a boundary are refused. Wire into the body from loop-start-source
349+
and onward from loop-end-source (parallel-start-source, parallel-end-source).
348350
To remove one edge, edit its source block with
349351
{"removeEdges":[{"targetBlockId":"<id>","sourceHandle":"source"}]} (sourceHandle defaults to
350352
"source").
@@ -833,8 +835,8 @@ sim workflows run <workflowId> [options]
833835
| `--manual` | No | Run the current saved workflow state instead of the active deployment. |
834836
| `--trigger <blockId>` | No | Enter the run through this runnable trigger, by its block id; runs the current saved workflow state (implies --manual). |
835837
| `--mock-payload` | No | Use the selected trigger's server-derived mock payload; runs the current saved workflow state (implies --manual). |
836-
| `--from-block <block>` | No | Run manually from this saved workflow block: its id, display name or key. |
837-
| `--source-run <runId>` | No | Prior run whose persisted state supplies upstream outputs (requires --from-block). |
838+
| `--from-block <block>` | No | Rerun the saved draft from this block (its id, display name or key), reusing the outputs --source-run produced before it; a failed run prints this command as next. |
839+
| `--source-run <runId>` | No | Earlier run of this workflow, deployed or draft, whose outputs the blocks before --from-block keep (requires --from-block). |
838840
| `--stop-after <block>` | No | Stop the run after this saved block (its id, display name or key), failing it if the run takes a path that skips the block; with --from-block on the same block, re-runs only that block (implies --manual). Unless --select-output names others, blockOutputs holds the output of that block under its key (or id); output stays empty. |
839841
| `--dir <dir>` | No | This workflow's source directory: a failed run names the source file and line of the block that failed, read through its .sim/lock.json. Not with --async or --follow, and not for a run --wait-timeout leaves running. |
840842
| `--wait-timeout <seconds>` | No | Wait at most this many seconds for a synchronous run (0 waits until it settles). A run still going then continues in the background under async limits: the command prints its run record and exits 4, and `sim workflows runs wait` keeps waiting. Not with --async or --follow. |
@@ -848,6 +850,8 @@ Without --manual (or a flag that implies it) this runs the active deployment; a
848850

849851
The result is the run: runId, status (completed, failed, paused or cancelled), error, output (the workflow's final output) and blockOutputs (what --select-output named). It has no success field: branch on status, or on the exit code. With --follow it is the stream's final frame instead: success and output.
850852

853+
A run that failed in a block has next: the command that reruns the saved draft from that block (or from the outermost loop or parallel holding it) with this run as --source-run, so after a fix only that block and those after it run again. Add --stop-after &lt;block&gt; to stop after a block; naming the block next starts from reruns only it.
854+
851855
Exit codes: 0 completed or paused (--async: queued); 1 failed or cancelled (the result is printed first, then the error on stderr), or the command failed; 4 still running when --wait-timeout elapsed.
852856

853857
API request and response schemas: [executeWorkflow](/api-reference/workflows/executeWorkflowV2).
@@ -1155,12 +1159,12 @@ sim workflows export <workflowId> [options]
11551159
| Option | Required | Description |
11561160
| --- | --- | --- |
11571161
| `--include-references` | No | Include non-secret resource identities for mapped import. |
1158-
| `--include-workspace-bindings` | No | Keep non-secret table, knowledge base, document, folder, channel, and other workspace bindings for a same-workspace import. Defaults to false, which clears these IDs. Registered credential fields and opaque table/tool values are cleared either way; environment references and ordinary workflow variables remain included. |
1162+
| `--include-workspace-bindings` | No | Keep table, knowledge base, document, folder, channel and other workspace bindings. On by default; --no-include-workspace-bindings clears them for a copy to share outside this workspace. Credentials are cleared either way. |
11591163
| `--no-include-workspace-bindings` | No | Send --include-workspace-bindings as false. |
11601164

11611165
</CommandTable>
11621166

1163-
Workspace bindings (a table, a child workflow, a knowledge base) print as null unless --include-workspace-bindings, and credentials always do: that is the export, not an unset block. To read what a block is set to, use `sim workflows outline` or `sim workflows state get`.
1167+
A table, child workflow, knowledge base or other workspace binding prints as its id; a credential always prints as null. For a copy to share outside this workspace, pass --no-include-workspace-bindings to clear the bindings too.
11641168

11651169
API request and response schemas: [exportWorkflow](/api-reference/workflows/exportWorkflow).
11661170

@@ -1522,7 +1526,7 @@ Compiles workflow.ts (and the function files it names) with the compiler the ser
15221526

15231527
Exit codes: 0 no errors; 1 errors (each printed as file:line:column with its frame and hint), or no cached catalog (run the get once). With --output json, stdout is one document that also lists every finding under diagnostics.
15241528

1525-
These warnings, which an apply saves as written, fail the check as errors on every block the lock does not bind (a block added since the get, or every block of a new workflow): W_REQUIRED_MISSING, W_UNKNOWN_OPTION, W_UNKNOWN_OUTPUT_PATH, W_VALUE_KIND, W_OUT_OF_RANGE, W_LITERAL_SECRET, W_TABLE_UNKNOWN_COLUMN, W_CHILD_INPUT_UNKNOWN, W_CHILD_RESULT_PATH, W_BRANCH_UNWIRED, W_UNRESOLVED_REF, W_REF_OUT_OF_SCOPE, W_LOOP_CONDITION_SYNTAX. --strict fails on them in every block, except W_BRANCH_UNWIRED on a block the lock binds (the stored workflow may hold it, and the server then stays quiet); --no-strict fails on none of them. In every mode, as the server refuses them: W_REF_OUT_OF_SCOPE is the error E_APPLY_REF_OUT_OF_SCOPE in any file of a block the edit added or changed; W_LOOP_CONDITION_SYNTAX is the error E_APPLY_LOOP_CONDITION_SYNTAX in any file of a block the edit added or changed; W_UNKNOWN_OPTION is the error E_APPLY_INVALID_SUBBLOCK_FIELD in workflow.ts on a block the edit added or changed; W_UNKNOWN_OUTPUT_PATH is the error E_APPLY_UNRESOLVED_REF in workflow.ts on a block the edit added or changed; W_UNRESOLVED_REF is the error E_APPLY_UNRESOLVED_REF in workflow.ts on a block the edit added or changed; W_UNKNOWN_BLOCK_TYPE is the error E_APPLY_INVALID_BLOCK_TYPE in workflow.ts on a block the edit added or changed; W_TYPE_NOT_ADDABLE is the error E_APPLY_TYPE_NOT_ADDABLE in workflow.ts on a block the edit added or changed; W_UNRESOLVED_REF is the error E_APPLY_UNRESOLVED_REF in a function file changed since the get; W_UNKNOWN_OUTPUT_PATH is the error E_APPLY_UNRESOLVED_REF in a function file changed since the get; W_CODE_FILE_REF_SYNTAX is the error E_APPLY_CODE_FILE_REF_SYNTAX in a function file changed since the get. A block counts as changed when the lock does not bind it, when the source moved it into another container, or when it compiles differently than in the source the last get or apply printed (.sim/stored-edges.json records a digest of each block). That last comparison needs the catalog the source was printed with in the cache: without it, a bound block that did not move counts as unchanged, so the server may refuse what the check passes. A $ref in a function file to a block the lock binds that the source no longer declares stays a warning, unless a warning cap left findings out: the server may infer that block was renamed and rewrite the reference, and refuses it otherwise. W_JSON_REF_UNTYPED is reported only on blocks the lock does not bind, and with --strict on every block.
1529+
These warnings, which an apply saves as written, fail the check as errors on every block the lock does not bind (a block added since the get, or every block of a new workflow): W_REQUIRED_MISSING, W_UNKNOWN_OPTION, W_UNKNOWN_OUTPUT_PATH, W_VALUE_KIND, W_OUT_OF_RANGE, W_LITERAL_SECRET, W_TABLE_UNKNOWN_COLUMN, W_CHILD_INPUT_UNKNOWN, W_CHILD_RESULT_PATH, W_BRANCH_UNWIRED, W_UNRESOLVED_REF, W_REF_OUT_OF_SCOPE, W_LOOP_CONDITION_SYNTAX. --strict fails on them in every block, except W_BRANCH_UNWIRED on a block the lock binds (the stored workflow may hold it, and the server then stays quiet); --no-strict fails on none of them. In every mode, as the server refuses them: W_REF_OUT_OF_SCOPE is the error E_APPLY_REF_OUT_OF_SCOPE in any file of a block the edit added or changed; W_LOOP_CONDITION_SYNTAX is the error E_APPLY_LOOP_CONDITION_SYNTAX in any file of a block the edit added or changed; W_UNKNOWN_OPTION is the error E_APPLY_INVALID_SUBBLOCK_FIELD in workflow.ts on a block the edit added or changed; W_UNKNOWN_OUTPUT_PATH is the error E_APPLY_UNRESOLVED_REF in workflow.ts on a block the edit added or changed; W_UNRESOLVED_REF is the error E_APPLY_UNRESOLVED_REF in workflow.ts on a block the edit added or changed; W_UNKNOWN_BLOCK_TYPE is the error E_APPLY_INVALID_BLOCK_TYPE in workflow.ts on a block the edit added or changed; W_TYPE_NOT_ADDABLE is the error E_APPLY_TYPE_NOT_ADDABLE in workflow.ts on a block the edit added or changed; W_UNRESOLVED_REF is the error E_APPLY_UNRESOLVED_REF in a function file changed since the get; W_UNKNOWN_OUTPUT_PATH is the error E_APPLY_UNRESOLVED_REF in a function file changed since the get; W_CODE_FILE_REF_SYNTAX is the error E_APPLY_CODE_FILE_REF_SYNTAX in a function file changed since the get. A block counts as changed when the lock does not bind it, when the source moved it into another container, or when it compiles differently than in the source the last get or apply printed (.sim/stored-edges.json records a digest of each block). That last comparison needs the catalog the source was printed with in the cache: without it, a bound block that did not move counts as unchanged, so the server may refuse what the check passes. A $ref in a function file to a block the lock binds that the source no longer declares stays a warning, unless a warning cap left findings out: the server may infer that block was renamed and rewrite the reference, and refuses it otherwise. W_JSON_REF_UNTYPED is reported only on blocks the edit added or changed, including an unedited block that an edit elsewhere makes compile differently, and with --strict on every block.
15261530

15271531
Exit 10 (busy, retry): another sim workspaces source or workflows source command is using this directory or a workflow folder in it (SOURCE_DIR_BUSY); nothing was read or written. Run this one again once it finished.
15281532

0 commit comments

Comments
 (0)