Skip to content

improvement(executor): reserved keyword errors#4482

Merged
icecrasher321 merged 2 commits intostagingfrom
improvement/add-reserved-keyword-errors
May 6, 2026
Merged

improvement(executor): reserved keyword errors#4482
icecrasher321 merged 2 commits intostagingfrom
improvement/add-reserved-keyword-errors

Conversation

@icecrasher321
Copy link
Copy Markdown
Collaborator

Summary

Reserved keyword errors must be surfaced. Fails execution silently otherwise.

Type of Change

  • Bug fix

Testing

Tested manually

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)

@vercel
Copy link
Copy Markdown

vercel Bot commented May 6, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped May 6, 2026 10:39pm

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 6, 2026

PR Summary

Medium Risk
Changes affect workflow start output shaping and function execution error formatting, which could alter runtime behavior for workflows that previously relied on reserved field names or on resolved-code error messages.

Overview
Prevents silent executor routing collisions and improves function error reporting.

Start block output building now rejects reserved execution-control field names (e.g. error, selectedRoute, _pauseMetadata) when they appear in Start inputFormat or runtime inputs, with explicit errors and added test coverage (with exceptions for chat paths).

Function execution now accepts an optional sourceCode and uses it for line-content/error display after block-reference resolution, stripping globalThis noise from messages; the executor passes this original code through the function_execute tool contract, with new tests asserting the behavior.

Reviewed by Cursor Bugbot for commit a1a09bf. Configure here.

@icecrasher321 icecrasher321 changed the title improvment(executor): reserved keyword errors improvement(executor): reserved keyword errors May 6, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 6, 2026

Greptile Summary

This PR fixes two distinct classes of silent failure in the executor: Start blocks that accept reserved field names (e.g. error, selectedRoute) now throw a descriptive error instead of silently overwriting execution-control fields, and function blocks now surface the user's original code (before block-reference resolution) in error messages instead of exposing internal globalThis[\"__blockRef_N\"] expressions.

  • Start-block reserved-field guard: EXECUTION_CONTROL_OUTPUT_FIELD_NAMES is exported from executor/types.ts and checked in two places in buildStartBlockOutput — before the path switch (input-format field names, gated via pathConsumesInputFormat so chat paths are correctly exempted) and after the switch (runtime output keys). Violations throw a descriptive error naming the offending fields.
  • Function-block error display: function-handler.ts reads block.config.params.code as sourceCode and passes it alongside the resolved code; route.ts adds three small helpers (getErrorDisplayCode, getLineContent, getErrorDisplayMessage) that substitute the original source into error messages and lineContent for all three execution paths (ivm, e2b, top-level catch).

Confidence Score: 5/5

Safe to merge; the changes add fail-fast validation and improve error UX with no mutations to execution logic.

Both changes are purely additive: the start-block guards throw before any output is produced, and the function-error-display path only rewrites the message shown to the user, never the execution result. All new code paths have targeted tests, chat paths are correctly exempted from the inputFormat check, and the message cleanup is gated behind __blockRef_ presence so it cannot affect clean executions.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/executor/utils/start-block.ts Core change: adds pre- and post-switch reserved-field guards; pathConsumesInputFormat correctly skips the inputFormat check for chat paths; assertNoReservedStartOutputFields is safely unconditional because chat output never contains reserved keys.
apps/sim/app/api/function/execute/route.ts Adds sourceCodeForErrors tracking and three helpers to swap resolved code references with original user source in error messages; applied consistently across ivm, e2b, and top-level catch paths.
apps/sim/executor/handlers/function/function-handler.ts Extracts readCodeContent helper and passes original sourceCode from block.config.params.code alongside resolved code to the function execute tool.
apps/sim/executor/types.ts Exports EXECUTION_CONTROL_OUTPUT_FIELD_NAMES const array and its derived type; clean addition with no side effects.
apps/sim/tools/function/types.ts Adds optional sourceCode field to CodeExecutionInput with a clear JSDoc explaining its purpose.
apps/sim/lib/api/contracts/hotspots.ts Adds optional sourceCode: z.string().optional() to the function execute contract; straightforward schema extension.
apps/sim/executor/utils/start-block.test.ts Comprehensive new tests covering reserved field detection for all Start block paths, chat path exemptions, legacy starter modes, and malformed field name handling.
apps/sim/app/api/function/execute/route.test.ts Adds test verifying that original source code replaces resolved __blockRef_ references in error messages, with correct HTTP 422 status and lineContent in debug output.
apps/sim/executor/handlers/function/function-handler.test.ts New test confirms sourceCode is included alongside code when calling function_execute, verifying the handler passes original code for error display.
apps/sim/tools/function/execute.ts Passes params.sourceCode through to the request body; if undefined it is serialised away by JSON.stringify, so the optional Zod field handles it correctly.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[buildStartBlockOutput] --> B{pathConsumesInputFormat?}
    B -- yes --> C[assertNoReservedInputFormatFields\nthrows if field names collide]
    B -- no\nchat paths --> D[skip inputFormat check]
    C --> E[deriveInputFromFormat]
    D --> E
    E --> F{resolution.path switch}
    F --> G[UNIFIED / SPLIT_API / SPLIT_INPUT\n/ SPLIT_MANUAL / EXTERNAL_TRIGGER\n/ LEGACY_STARTER]
    G --> H[build output NormalizedBlockOutput]
    H --> I[assertNoReservedStartOutputFields\nthrows if output keys collide]
    I --> J[return output]

    subgraph Function Error Display
        K[FunctionBlockHandler.execute] --> L[readCodeContent block.config.params.code\n= sourceCode]
        L --> M[executeTool function_execute\ncode + sourceCode]
        M --> N[route.ts POST handler]
        N --> O{error?}
        O -- yes --> P[getErrorDisplayCode\nprefer sourceCode over resolvedCode]
        P --> Q[getErrorDisplayMessage\nstrip globalThis refs from message]
        Q --> R[getLineContent\nlook up line in sourceCode]
        R --> S[return user-facing error\nwith original source context]
    end
Loading

Reviews (2): Last reviewed commit: "address comments and make error messages..." | Re-trigger Greptile

Comment thread apps/sim/executor/utils/start-block.ts Outdated
Comment thread apps/sim/executor/utils/start-block.ts
@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

@greptile

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit a1a09bf. Configure here.

@icecrasher321 icecrasher321 merged commit 00c424b into staging May 6, 2026
14 checks passed
waleedlatif1 pushed a commit that referenced this pull request May 7, 2026
* improvment(executor): reserved keyword errors

* address comments and make error messages for func execute make sense block ref accs
@waleedlatif1 waleedlatif1 deleted the improvement/add-reserved-keyword-errors branch May 7, 2026 05:12
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