Skip to content

refactor(workflow-code): final-state audit cleanup - #10318

Merged
waleedlatif1 merged 25 commits into
stagingfrom
refactor/workflow-code-final-audit
Nov 22, 2026
Merged

waleedlatif1 merged 25 commits into
stagingfrom
refactor/workflow-code-final-audit

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

Final-state audit of workflows/workspace as code (#10129 through #10307). No behaviour change except where a test is listed.

Perf / super-linear regexes (each has a scaling test that fails on the old code)

  • workspaces source diff --server: the filter's trailing-slash strip /\/+$/ was quadratic; it now uses the shared givenFilterPath, which also drops repeated ./ like pathFilter does, so ./././tables/x.ts asks the server only for tables (test)
  • table declarations: COLUMN_CALL scanned to end of file per unclosed column.x( (66x growth at 8n); now head regex plus indexOf, same matches (test)
  • sourceStatus: per-server-change local.find is now two first-seen maps (64x growth at 8n before; test also pins the root-file kind branch)
  • staged blob uploads run 4 at a time instead of one by one (up to 1,000 per request); failure and cleanup behave the same
  • loop-condition check reuses babelMessage instead of a copy with a quadratic \s* strip; SDK stripComments no longer lets \s* cross lines

Dead code / duplication removed

  • utf8Bytes (workflow-code) replaced by @sim/utils/paste utf8ByteLength at every caller
  • normalizeBlockName copy in the CLI replaced by @sim/workflow-types (it is already bundled through workflow-code)
  • memberName (2 copies) moved into babel.ts; printNumber copy in workspace-code; MCP adapter's changedFields copy
  • zonedClockDate (no caller); getSupportedTimezones, CommentaryWriter, resolveWorkflowRunSelection un-exported; unused-exports baseline shrinks by 3
  • embedded SDK text drift tests that duplicated check:workflow-sdk-embedded-text

Hacks replaced

  • REFUSABLE_WARNING_CODES is derived from the refusal rule maps (was a hand-kept copy); rule codes are type-checked
  • strict check warnings live in one STRICT_FINDINGS table (codes checked against DiagnosticCode); check --help and both .sim/AGENTS.md guides build from it
  • subflow repair messages built from the default constants instead of restating 5/1/20

Drift fixed

  • guides, SDK README and workflows/code docs named 5 or 6 of the 13 warnings check fails on
  • SYNTAX.md Diagnostics table lacked 9 codes (e.g. E_APPLY_UNRESOLVED_REF, E_APPLY_VARIABLE_DELETE); a workflow-sdk test now compares it with DIAGNOSTIC_CODES
  • scripting.mdx source exit-code tables are now checked against each command's --help
  • SOURCE_TYPESCRIPT_VERSION is tested against the installed typescript
  • DESIGN.md staged-blob expiry (only staging extends it); workflow guide's workspace.d.ts contents; rule file's stale NOUNS and artifact list

Tests

  • workflow-code scaling cases get a 30s timeout: they are ratio checks but near the source caps they ran past vitest's 5s default under load (staging's own gate failed on one)

Deferred / product decisions (not in this PR)

  • apply bodies are clamped to the 10 MiB proxy limit, so maxRowsBytes (16 MB) and WORKSPACE_SOURCE_REQUEST_MAX_BYTES (58 MB) can't be reached: lower the limits or exempt the source routes from the proxy
  • workflows source check / status write workspace.d.ts and tsconfigs without the source command lock that the workspace versions take
  • holdUnavailable matches the credential placeholder inside the refusal message (pinned by references.integration.ts); a structured id on the gate finding would remove the text match
  • effectiveBatchSize truncates while clampParallelBatchSize does not; the two index-scoped mode-key regexes disagree on malformed keys
  • six local mapWithConcurrency-style copies elsewhere in apps/sim; canonicalJson vs stableStringify need a "which one" note

Type of Change

  • Refactor / cleanup (plus the listed fixes)

Testing

  • Local gate: tsc for every package and apps, all package suites, apps/sim units, realtime units, apps/sim and realtime integration on fresh DBs, goldens, check:audits, check:test-types, check:migrations, docs compatibility, lint:check, root type-check: GATE PASS
  • check-block-registry.ts origin/staging, test:scripts
  • Each scaling, docs-table and version test proven red against the old code or a broken copy

Checklist

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

…hat matches its ratio design

The growth check is a ratio so a slow runner cannot fail it, but the former-block hint case runs
seconds of wall clock and failed on vitest's 5s default under machine load.
…maliser

filteredKinds stripped trailing slashes with /\/+$/, quadratic on a long run of slashes, and
dropped a single leading ./ where pathFilter drops them all. Both now use givenFilterPath.
COLUMN_CALL scanned to the end of the file for every unclosed column.x( call, quadratic on a
2 MB declaration. The head is matched by regex and its ) found with indexOf, resuming after it as
the global regex did, so the same calls match.
…ting it

The restatement said the CLI carries no workspace dependency, but it bundles @sim/workflow-code,
which already imports the helper from @sim/workflow-types.
…matches their ratio design

Two expectLinearGrowth cases near the source caps passed alone but failed vitest's 5s default under
machine load. Replaces the single-case timeout from the previous commit.
…ByteLength

limits.ts carried its own utf8Bytes with the same contract (early stop past the cap, a lone
surrogate as 3 bytes). Every caller now uses the shared helper; its test gains the surrogate cases
the removed test covered.
…sal rules

The set was a hand-kept copy of the four rule maps' keys, so a rule added without it could be hidden
by the warning cap. It is now their union, and each rule's warning code is checked against
CompileDiagnosticCode.
… local copies

values.ts and function-returns.ts each wrote memberName; it now lives in babel.ts beside
memberSegment. The loop-condition check strips Babel's (line:column) with babelMessage instead of a
copy whose \s* prefix ran in quadratic time.
…me default constants

The loop and parallel repair messages restated 5, 1 and 20 in text beside the constants that hold
them, and the parallel default count lived privately in forms/subflow.ts.
…e's printNumber

declaration/print.ts restated it beside the printKey and quoteString it already imports.
…espace scan

stripComments' /^\s*\/\/.*$/gm let \s* run across newlines from every line start, quadratic on
blank lines. Its output is only searched for core type names, so [ \t]* reads the same names.
…ap in sourceStatus

Each server change searched every local change, quadratic in a directory of many changed files.
The first local change of each resource and of each kind is indexed once, which picks the same
entry the search did.
…-sdk-embedded-text already runs

core-text, cookbook-text and two workspace-text cases compared the generated files byte for byte,
as the generator's --check does in check:audits (the cookbook one with its own folder walk). The
dotfile case moves to embedded-files.test.ts, the module it tests.
The .sim/AGENTS.md guides, the SDK README and the workflow code docs named 5 or 6 of the 13
warnings a check fails on. STRICT_FINDINGS (source-strict.ts) now holds each code with its phrase;
check builds STRICT_CODES from it and both guides print every phrase, while the README and docs
point at check --help. The workflow guide also names the skills, custom tools and MCP servers
workspace.d.ts declares.
…names

DESIGN.md said asking for or planning with a staged blob extends its expiry; only staging does
(staging/store.ts). The rule named a NOUNS table that no longer exists and listed the embedded-text
tests instead of check:workflow-sdk-embedded-text and the fixture-catalog pair.
… that it does

The README calls the SYNTAX.md Diagnostics table every code's meaning, but it lacked nine, among
them E_APPLY_UNRESOLVED_REF, E_APPLY_REF_OUT_OF_SCOPE and E_APPLY_VARIABLE_DELETE that the docs and
the primer cite. codes.test.ts compares the table's codes with DIAGNOSTIC_CODES.
…nst --help

scripting.mdx is a hand-written guide page, so check:cli-docs never reads its six source exit-code
tables. Each must now list every code its command's --help names, and only real source codes.
A staging request of up to 1,000 blobs uploaded them one after another while holding its slot.
mapWithConcurrency starts no more after a failure and waits for the running ones, so every
written object is still recorded before the cleanup removes the unrecorded.
… adapter

The MCP adapter's copy was the named one applied to the canonical declarations.
zonedClockDate had no caller since before #10129 moved timezone.ts into @sim/utils, and
getSupportedTimezones, CommentaryWriter and resolveWorkflowRunSelection are used only inside their
files; the unused-exports baseline shrinks by three.
…ipt the repo installs

SOURCE_TYPESCRIPT_VERSION says it is the release the declarations are checked against, but the
devDependency is a caret range: a lockfile bump would send agents to another tsc than CI runs.
Check STRICT_FINDINGS keys against DiagnosticCode, inline the column-call head regex, drop a TSDoc
left on baseOf by the changedFields move, and drop the wall-clock diff-filter test that
source-status.test.ts (linear pathFilter) and the repeated-./ kinds test already cover.
…ty help parse

A secrets.ts change must meet every server change of its kind, the firstOfKind branch the map
rewrite added; the scripting docs case now fails if the help wording stops yielding codes.
… browser-safe workflow-code

workflow-code type-checks without node types, so a test reading SYNTAX.md cannot live there. The
workflow-sdk README is the one that calls the table complete, so its package holds the check.
@waleedlatif1
waleedlatif1 requested a review from a team as a code owner November 22, 2026 21:04
@vercel

vercel Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Nov 22, 2026 9:08pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge; no actionable issues were found.

Summary

This PR removes duplicate helpers and speeds up workspace source reads, status checks, and staged uploads.

  • Workspace status and source checks avoid repeated scans on large inputs.
  • Staging requests upload up to four new blobs at once.
  • Workflow and workspace source tools share byte-counting and parsing helpers.
  • Workflow check warnings and their CLI guides come from shared rules.
  • Unused exports and duplicate audit checks are removed.

waleedlatif1 explicitly deferred these items, so they are not findings: proxy limits below source body limits; missing workflow source command locks; credential placeholder matching in refusal text; differences between effectiveBatchSize and clampParallelBatchSize; inconsistent mode-key regexes; remaining concurrency helper copies; and guidance on choosing canonicalJson versus stableStringify.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Deduplicate blob hashes] --> B[Upload at most four blobs at once]
  B --> C{All uploads succeeded?}
  C -->|Yes| D[Record blobs in one transaction]
  C -->|No| E[Wait for running uploads]
  D --> F[Remove uploaded objects not held by recorded rows]
  E --> F
Loading

Reviews (1) · Last reviewed commit: "test(workflow-sdk): move the SYNTAX.md d..." · Reviewed by Greptile

@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.

No issues found across 57 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 2e40feb into staging Nov 22, 2026
95 checks passed
@waleedlatif1
waleedlatif1 deleted the refactor/workflow-code-final-audit branch November 23, 2026 00:04

This branch was successfully deployed

1 active deployment
Preview — a99c5742 Deployed Nov 22, 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