Skip to content

fix(workflow-code): staging QA fixes and a cheaper agent path - #10220

Merged
waleedlatif1 merged 64 commits into
stagingfrom
fix/workflow-code-staging-qa
Nov 20, 2026
Merged

waleedlatif1 merged 64 commits into
stagingfrom
fix/workflow-code-staging-qa

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Fixes from end-to-end testing of workflows/workspace as code (#10129) on staging, plus the changes that make the code path cheaper for agents than the operations path.

Summary

Bugs found on staging

  • CLI output piped past 64 KB was truncated with exit 0 (all commands): every exit now flushes stdout/stderr first.
  • source check failed on unedited get output when a workflow's catalog differs from the workspace's (hidden/preview types): catalogs are cached by content hash and check uses the one the get printed with; workspace check too.
  • Offline check let a new cycle through as a warning: the get records the stored edges, so only stored cycles stay warnings.
  • Workspace blob batches exceeded the 10 MiB proxy body ceiling and never converged: batches fit the ceiling, oversized bodies answer 413.
  • Ctrl-C during apply committed but stranded the directory: the CLI waits for the in-flight write and saves it.
  • Promote overwrote edits made in the target: promotes keep a per-target record and use it as the base.
  • Column keys changed across a get, and promoted rows never converged (same cause): keys are recorded on the table.
  • Renaming a block's name and const while rewiring it deleted and recreated it: identity binds by settings, neighbours or renamed references; otherwise the apply refuses it as a delete and the plan names it.
  • Writes could place block types the caller cannot see (unrevealed preview, kill switch): source apply, operations and state replace refuse new placements; existing blocks stay editable.
  • Agent custom tools whose title has a space failed on Anthropic: provider tool names are sanitized and mapped back.
  • Diagnostics: undeclared Start input references, the hidden-field message, $ref warnings on renames, precise locations, a warning when a renamed column is still used by a workflow, dead loop config no longer printed.

Agent experience

  • get prints a short primer with snippets for the builders in use; sim workflows source params <builder> replaces grepping the SDK.
  • A directory holds only the block types it uses (31 files / ~208 KB instead of 530 files / 15 MB); the full SDK lives in the shared cache.
  • Large v2 source responses are brotli/gzip encoded (catalog 8.7 MB → ~0.8 MB).
  • Commands act on the directory's workspace; created ids are printed; apply --deploy; apply without --yes prints the plan (exit 14); each finding prints once and W_JSON_REF_UNTYPED only fires where the edit wrote it.

Changes outside the workflow-code flag

  • The block visibility gate on operations / state replace / Copilot edits.
  • The CLI flush fix and exit-code messages for all commands.
  • Custom tool provider names.

Type of Change

  • Bug fix
  • Improvement

Testing

Every fix has a regression test that fails before it. Local gate: package suites, apps/sim units, real-Postgres integration (migrated and push DBs), goldens, check:audits, check:test-types, docs compatibility, lint, block registry. Several fixes were verified live on staging with the CLI from this branch.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

A workflow holding a type the workspace catalog withholds (table_v2 behind a preview gate on
staging) is printed and dry-run against its own per-workflow source catalog, but the get never
cached that catalog, so the offline check compiled against the workspace catalog: table.insertRow
became E_UNKNOWN_BUILDER and the branch wired to it W_BRANCH_UNWIRED, while the dry run was clean.

The get now caches the per-workflow catalog beside the workspace one, and check and the tsconfig
refresh use it when its hash is the one .sim/base.json records, else the workspace catalog.
…en bound blocks

Offline (storedUnread), compile took any edge between two blocks the lock binds as one the stored
workflow may hold, so a cycle or container error edge an edit added between known blocks was only
W_EDGE_CYCLE / W_ERROR_PORT_STORED and check exited 0 even with --strict, while the dry run
refused it with E_EDGE_CYCLE.

A get, apply or create now compiles the printed source and records its edges by lock key with the
base fingerprint in .sim/stored-edges.json (a CLI-only record). Check passes them as
storedUnreadEdges, and compile counts an edge between bound blocks as possibly stored only when it
is one of them, mapping a block renamed in source to its vacated lock key, so a printed cycle stays
a warning and a new one is the server's error. Without a record for the current base (an older
directory, a workspace directory) the old rule holds. CompileResult gains edges, the accepted
edges even when the compile fails elsewhere (a printed stored() secret).
Each catalog is cached once at source-catalog/<hash>.json (verified against its hash on read), and
each workspace records its current catalog's hash in source-catalog/workspaces/<id>.json for ETag
revalidation. Check and apply resolve the catalog by the hash .sim/base.json records, and a get
reuses a cached workflow catalog of that hash instead of fetching it again, so the cache grows
with distinct catalogs rather than with workflows. The per-workspace and per-workflow copies an
older CLI wrote are removed on the next catalog read.
…ase names

A workspace get or apply now fetches, once per distinct hash, the catalog of each workflow folder
whose base names one other than the workspace catalog (a workflow holding a type the workspace
withholds) and caches it by hash; the offline workspace check compiles each folder against the
catalog its base names. Each workflow folder also gets its .sim/stored-edges.json, so an edit's new
cycle between bound blocks is E_EDGE_CYCLE in a workspace directory too. The record is a CLI file:
never sent, not listed as ignored, and removed with its workflow.
A result past the 64 KiB a pipe buffers was cut short with exit 0: Bun drops
console writes once process.stdout exists, and process.exit (every error
path) ended the process before Node or Bun drained the pipe. Lines go through
the stream under Bun, refused writes are tracked until they drain, and the
terminal entrypoint is the only place that exits, after flushing; exitCli
now throws CliExit for it.
…names

A custom tool's canonical id is custom_<title>, and the title is free text, so an agent
using a tool titled with a space failed on Anthropic (tools.0.custom.name must match
^[a-zA-Z0-9_-]{1,128}$). The wire id now replaces every character outside that alphabet
with _, aliasing on collision; the canonical id keeps the title, which execution resolves
by, and the existing wire-to-canonical map projects calls back.
The source catalog hides an unrevealed preview block or one the block-visibility kill
switch names, but the write paths only checked the allowlist and deployment availability,
so source apply (generic block() form) and editing operations placed a kill-switched
table_v2 for a non-admin. A VISIBLE_TYPE placement gate in BLOCK_GATES now refuses a new
placement or type change to a type isHiddenUnder hides, for both writers; state replace
refuses a hidden type the stored graph does not already hold on that block. Placed
blocks of a hidden type stay editable.
An interrupt while workflows/workspaces source apply (or create) was
committing exited 130 at once: the server still stored the write, and the
directory, never saved, was stranded as a conflict on both sides. The send
and the write-back now run with interrupts deferred: the first Ctrl-C waits
(up to 60s) for the answer, saves it, then ends by the signal; a second one,
or the bound, stops at once and prints that it may have been written and how
to recover. Staging and lock cleanup handlers wait for the deferral.
…yped for

The starter wrote no record of its workspace and printed a create command
without --workspace, so the create silently went to the profile's default
workspace. The starter now writes .sim/starter.json, prints the create with
--workspace, and a create into another workspace is refused
(SOURCE_OTHER_WORKSPACE) unless --workspace names it; the record goes once
the workflow is created.
…s and hints

- workflows/workspaces source status without a login exited 0 (or 11):
  statusExitCode now returns 13 when the server was not checked for that.
- Ctrl-D at a confirmation or login prompt hung (Node) or printed Bun's
  AbortError stack: askLine resolves null when input ends, so the prompt
  cancels cleanly (exit 1).
- A refusal in a display format no longer points at details.diagnostics,
  a JSON field: it says each finding is printed above.
- status, diff and apply on a starter no workflow was created from name
  the create to run (with its workspace), not a get.
- A key the server refuses from SIM_API_KEY (or --api-key) says to fix or
  unset it, since sim login cannot override it.
… tsc as a step

The directory guides and the workflow SDK README listed only some exit
codes (no 8, 10-12 or 130, and the README no 13). Both guides now print one
table built from exit-codes.ts, the README carries the same rows, and the
apply/create help and the scripting page add 13 and 130 and that a locked
block exits 1. The guides and README make tsc a firm step after every edit
and pass --workspace to create. CLI reference pages regenerated.
Next.js truncates a proxied /api body past 10 MiB, so a 24 MB staging batch reached the
route as a broken multipart prefix (400, never converging). Batches now carry at most
8 MB framing included, a file up to the 10 MB blob limit goes alone, the route caps the
body below the proxy ceiling and answers 413 PAYLOAD_TOO_LARGE naming the limit, and the
CLI maps that 413 to the upload it refused and the fix. Server hashing keeps its own
24 MB budget.
…t in the target

apply --to read the target's live base at promote time and used it as the three-way base,
so a target edit since the last promotion could never look changed and was overwritten.
Each promotion now records the target's base entries and promoted workflow folders in
.sim/targets/<workspaceId>.json; the next promotion uses a recorded entry in place of the
live one for the same id, sends a workflow folder unchanged since as its base alone, and
an edited one with the recorded fingerprint. A target edit is kept when the directory left
the resource alone and refused as stale (exit 5) when it changed it too. A resource without
a record (the first promotion) takes the target as it stands; docs say so.
… them

A column key lived only in the directory's base, so a fresh get (or a promotion's read of
the target) keyed each column by its name: `note: column.string({ name: 'note_text' })`
came back as `note_text: column.string()`, against the documented promise that the key
stays bound to the column. Every table write now records each declared column whose key is
not its name in metadata.sourceColumnKeys (column id -> key), reads print base binding, then
that record, then the name, and an apply that finds a column a read would key otherwise
records the keys alone.
Managed rows promoted to another workspace planned an update on every run: the target's
read keyed a column whose key is not its name by that name, so the stored rows never
fingerprinted like the directory's. Persisting column keys (previous commit) fixes it;
this pins the promotion round trip.
… keep seed rows

- Each file under a kind folder the CLI does not send (a hidden name, or a character no
  workspace path holds) is a W_PATH_NOT_SENT warning, printed and in the JSON result and
  its warnings count, instead of one unstructured "Not sent" line.
- The per-file findings cap ends a list with I_FINDINGS_TRUNCATED (info) instead of
  E_LIMIT_EXCEEDED, so plain source errors exit 1, not 7 (too large); the offline check
  keeps each rows finding's own severity.
- A table seeded by source records { mode: 'seed' } in metadata.sourceRows, so a get prints
  rows: { mode: 'seed' }, and the CLI keeps the seed rows file beside it; a declaration that
  starts or stops seeding records or clears the mark.
- I_KB_CHUNKING counts the stored documents that keep their chunks, not those the apply
  replaces or deletes.
- A replaced knowledge document keeps its tag values: the SDK docs said they were lost.
…uiet $refs a rename resolves

Three or more blocks renamed at once bind by params; renames nothing ties are refused naming the
look-alike blocks instead of offering --allow-delete. A dangling $ref in a function file is one
warning at the file line in check and dry run alike.
…he stale workflow, and list changed variables

E_NAME_TAKEN, E_WORKFLOW_META_INVALID and E_APPLY_BLOCK_DELETE point at the workflow name (or
description) instead of the SDK header; an unknown MCP tool points at the agent's tools line;
the stale finding names the workflow; the offline check stays quiet on a legacy block the lock
binds, as the server does; the CLI apply result and preview name each changed variable.
…ad from

check, status, diff and apply (workflow and workspace) now take the workspace
recorded in .sim/base.json whatever the profile default, as get already did;
only a --workspace naming another one is refused (SOURCE_OTHER_WORKSPACE).
check refuses a directory without workflow.ts before any catalog lookup, and
every --dir is made absolute before the command runs, so messages name the
directory read wherever the CLI was started.
…eated

With --output json (or yaml) a source check, apply or create prints its
findings only in the document on stdout, no longer also as frames on stderr,
and leaves info findings out unless --verbose. A display format prints the
first warning of each code whole and the rest of that code on one line.
Workflow create and apply, and workspace apply, list what they created as
created: [{ kind, key, id }] (named on one line in a display format), and a
workflow write lists its notes in a machine result.
…and not on typed Function returns

The warning fired on every bare Function-output reference in a JSON field,
untouched blocks included, so one apply of a large workflow printed thousands
of tokens of it. Against a stored workflow (the server's dry run and apply) it
is now raised only for a JSON field the source changed, and an offline check
reports it only on blocks the lock does not bind (--strict: on every block).
A Function result field the JavaScript returns as a number, boolean, array or
object literal (directly, or through a local never reassigned to another kind)
no longer warns; a text field and anything uncertain keep the warning.
--deploy deploys the workflow once the write is saved, through the same
deployWorkflow operation (and so the same server-side permission check) as
`sim workflows deploy`; a failed deploy says the write itself was saved and
names the command to retry. Without it, a write to a deployed workflow whose
draft now differs names that command as next. --deploy with --dry-run is
refused.
…refusing

Where no terminal can ask, workflows source apply/create and workspaces source
apply without --yes now run the dry run, print the plan and its findings, write
nothing, and exit 14 naming the same command with --yes (or exit with the
refusal when the plan has errors), instead of refusing with
CONFIRMATION_REQUIRED and nothing to act on. apply --yes prints the summary of
what it applied, so an agent's loop is edit, then apply --yes.
…nd on any with --strict

A rename's apply already rewrites $ref.<old key> in function files to the new key and writes the
files back; the integration proof now asserts the written-back function file too.
…yped for

Without --workspace, a create now binds to the workspace .sim/starter.json
records, as check, status, diff and apply bind to the one .sim/base.json
records, instead of refusing with SOURCE_OTHER_WORKSPACE when the profile
default differs; --workspace still chooses another.
…nd warn on a probable rename

The diff lists each added and removed block's type; an apply passed --allow-delete that deletes a
block and adds one of the same type and parent warns W_APPLY_PROBABLE_RENAME, since that block
gets a new id. The CLI result and preview name the added and removed blocks.
…low writing the old name

A plan that renames a column scans the stored workflows that use the table and warns
W_TABLE_COLUMN_RENAMED_IN_USE on each Table block that still writes, filters or sorts by the old
name, naming the workflow and block, at the line of the declared workflow's file.
… supersedes

Editing operations store a loop's iterations/loopType inputs beside data.count; the serializer
reads only data, so source no longer prints them under extra. They are preserved state: apply
restores them from the stored block, so a no-op apply stays byte-identical.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@greptile-apps

greptile-apps Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 3/5

[High impact] The PR reaches shared workflow and workspace write paths as well as the source CLI.

Fix the apply save-back gap and preservation of target deletions before merging.

Findings

  1. P1 Committed changes remain unrecorded ▶
  2. P1 Deleted resources come back ▶
  3. P2 Computed keys hide JSON warnings ▶

Summary

This PR improves workflow and workspace source commands, reduces generated SDK files, and fixes several staging failures.

  • Offline checks use the catalog and wiring recorded with the source.
  • Workflow applies preserve block identity and explain likely rename mistakes.
  • Workspace promotions track target edits and table declarations keep their identity.
  • Large source responses compress and workspace blob uploads fit request limits.
  • The CLI gives agents focused workflow examples and on-demand builder details.
  • Writes respect block visibility and provider tool names stay usable.
  • CLI writes show a plan first and preserve output and progress on exit.

Diagram

sequenceDiagram
  participant CLI
  participant API
  participant Disk
  CLI->>API: Apply workspace source
  API-->>CLI: Committed files and base
  CLI->>API: Fetch uncached workflow catalog
  alt Catalog request succeeds
    API-->>CLI: Catalog
    CLI->>Disk: Save files, base, and edge records
  else Catalog request fails
    API-->>CLI: Error
    Note over CLI,Disk: Commit answer is not saved
  end
Loading

Reviews (1) · Last reviewed commit: "Merge branch 'fix/e2e-diag' into fix/wor..." · Reviewed by Greptile

Comment thread packages/workspace-code/src/promote.ts Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 151 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/workflows/editing/gates.ts Resolved
…hen an unchanged reference's Function changed kind
…ext strips the Content-Encoding of

Next's sendResponse drops a route handler's Content-Encoding header (FORBIDDEN_HEADERS in
send-response.js), so a production server sent brotli bytes as plain JSON and every client
failed to parse them (the workflow source e2e: JSON Parse error). The routes answer plain JSON
again; the CLI still offers br and gzip for a server or proxy that compresses.
@waleedlatif1
waleedlatif1 merged commit 6856efa into staging Nov 20, 2026
152 of 154 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/workflow-code-staging-qa branch November 20, 2026 04:12

This branch was successfully deployed

1 active deployment
Preview — 51738fe5 Deployed Nov 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant