René's URL Explorer Experiment


Title: [BUG] Variable references not injected into execution context, causing ReferenceError · Issue #2798 · simstudioai/sim · GitHub

Open Graph Title: [BUG] Variable references not injected into execution context, causing ReferenceError · Issue #2798 · simstudioai/sim

X Title: [BUG] Variable references not injected into execution context, causing ReferenceError · Issue #2798 · simstudioai/sim

Description: Bug Description When function/condition blocks reference undefined block variables (e.g., when webhook block hasn't executed), the variable reference is substituted into the code but the actual variable is neve...

Open Graph Description: Bug Description When function/condition blocks reference undefined block variables (e.g., when webhook block hasn't executed), the variable reference is substituted into ...

X Description: Bug Description When function/condition blocks reference undefined block variables (e.g., <webhook1.conversation.id> when webhook block hasn't executed), the variable reference is substit...

Opengraph URL: https://github.com/simstudioai/sim/issues/2798

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[BUG] Variable references not injected into execution context, causing ReferenceError","articleBody":"## Bug Description\n\nWhen function/condition blocks reference undefined block variables (e.g., `\u003cwebhook1.conversation.id\u003e` when webhook block hasn't executed), the variable reference is substituted into the code but the actual variable is never injected into the execution context, causing \"ReferenceError: variable is not defined\" at runtime.\n\n**This issue was discovered as a consequence of fixing #2794** - while the nullish coalescing fix addressed the substitution syntax, it revealed this deeper IPC serialization bug.\n\n## Root Cause\n\nThe variable substitution process has a multi-layer issue:\n\n1. **Code Substitution Layer**: `\u003cwebhook1.conversation.id\u003e` is correctly replaced with `__tag_webhook1_conversation_id` in the code\n2. **Context Variable Storage**: The variable IS added to `contextVariables` map with `undefined` value\n3. **IPC Serialization Layer**: When `contextVariables` is serialized via IPC to the worker thread, `JSON.stringify()` **strips keys with undefined values**, causing those variables to not be transmitted\n4. **Execution Layer**: The worker receives an empty `contextVariables` object and can't inject the missing variables into the VM\n\nResult: Code references `__tag_webhook1_conversation_id` but it's never defined in the execution context.\n\n## Error Manifestation\n\n```\nReferenceError: __tag_webhook1_conversation_id is not defined\n```\n\nThis occurs in:\n- E2B JavaScript execution path\n- E2B Python execution path\n- Isolated-VM execution path\n\n## Reproduction Steps\n\n1. Create a workflow with Start trigger and Webhook trigger\n2. Add Extract Context function block with: `const x = \u003cwebhook1.optional_field\u003e ?? \"default\";`\n3. Execute workflow using **Start trigger** (webhook doesn't execute)\n4. Function block fails with \"ReferenceError: __tag_webhook1_optional_field is not defined\"\n\n## Root Issue: IPC Serialization\n\nThe key problem occurs in `apps/sim/lib/execution/isolated-vm.ts`:\n\n```javascript\n// BROKEN - undefined values are stripped during JSON serialization in IPC\nworker!.send({ type: 'execute', executionId, request: req })\n```\n\nWhen `req.contextVariables` contains `{ __tag_webhook_id: undefined }`, the IPC serialization strips it, resulting in an empty object on the worker side.\n\n## Solution Applied\n\n### File 1: `apps/sim/lib/execution/isolated-vm.ts`\n\nAdd explicit sanitization BEFORE IPC transmission:\n\n```diff\n+  // Convert undefined values to null in contextVariables before IPC serialization.\n+  // JSON.stringify() strips keys with undefined values, which would cause ReferenceErrors\n+  // when user code references variables that weren't properly injected into the VM context.\n+  const sanitizedContextVariables: Record\u003cstring, unknown\u003e = {}\n+  for (const [key, value] of Object.entries(req.contextVariables)) {\n+    sanitizedContextVariables[key] = value === undefined ? null : value\n+  }\n+  const sanitizedReq = { ...req, contextVariables: sanitizedContextVariables }\n\n   return new Promise((resolve) =\u003e {\n     // ...\n     try {\n-      worker!.send({ type: 'execute', executionId, request: req })\n+      worker!.send({ type: 'execute', executionId, request: sanitizedReq })\n     } catch {\n```\n\n### File 2: `apps/sim/app/api/function/execute/route.ts`\n\nFix E2B JavaScript and Python paths:\n\n```diff\n // E2B JavaScript path (around line 745)\n for (const [k, v] of Object.entries(contextVariables)) {\n-  prologue += `const ${k} = JSON.parse(${JSON.stringify(JSON.stringify(v))});\\n`\n+  // Convert undefined to null so JSON.stringify produces valid output\n+  const safeValue = v === undefined ? null : v\n+  prologue += `const ${k} = JSON.parse(${JSON.stringify(JSON.stringify(safeValue))});\\n`\n   prologueLineCount++\n }\n\n // E2B Python path (around line 817)\n for (const [k, v] of Object.entries(contextVariables)) {\n-  prologue += `${k} = json.loads(${JSON.stringify(JSON.stringify(v))})\\n`\n+  // Convert undefined to null so JSON.stringify produces valid output\n+  const safeValue = v === undefined ? null : v\n+  prologue += `${k} = json.loads(${JSON.stringify(JSON.stringify(safeValue))})\\n`\n   prologueLineCount++\n }\n```\n\n### File 3: `apps/sim/lib/execution/isolated-vm-worker.cjs`\n\nAdd defensive handling in worker:\n\n```diff\n for (const [key, value] of Object.entries(contextVariables)) {\n-  await jail.set(key, new ivm.ExternalCopy(value).copyInto())\n+  // Convert undefined to null to ensure the variable is properly set in the VM\n+  const safeValue = value === undefined ? null : value\n+  await jail.set(key, new ivm.ExternalCopy(safeValue).copyInto())\n }\n```\n\n## Why This Fix Works\n\nThis ensures:\n- All variables are transmitted via IPC (null is serializable, undefined is not)\n- Worker receives all variables and can inject them into the VM context\n- User code can use nullish checks (`??`) on the received null values\n\n## Related Issues\n\n- #2794: Variable substitution breaks nullish coalescing operator - **this bug was discovered as a follow-up to that fix**\n\n## Testing\n\nVerify with:\n1. Start trigger + Extract Context referencing non-existent webhook fields\n2. Confirm `??` operator fallback works correctly\n3. Test all three execution paths (E2B JS, E2B Python, Isolated-VM)","author":{"url":"https://github.com/PlaneInABottle","@type":"Person","name":"PlaneInABottle"},"datePublished":"2026-01-13T21:31:31.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/2798/sim/issues/2798"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:0fe68b31-486b-f6a6-c6ef-05b8246f4887
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC860:27025E:291C27:34BEEA:696B8037
html-safe-nonce2a5cf5aea3361f3986a07a8350b472b09dee0d4defce45ef6df86e5700268325
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDODYwOjI3MDI1RToyOTFDMjc6MzRCRUVBOjY5NkI4MDM3IiwidmlzaXRvcl9pZCI6IjU3MzQ5MzcyMTk0NDUyMjgwNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac834620ff11a612558d2a31c1593efe4460b2b80c98868b31a550ed9bbfa6f0b9
hovercard-subject-tagissue:3810673515
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/simstudioai/sim/2798/issue_layout
twitter:imagehttps://opengraph.githubassets.com/3c53d55a47447570451e2ab838b182180b242e932cbf88721ce69ff484098c6c/simstudioai/sim/issues/2798
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/3c53d55a47447570451e2ab838b182180b242e932cbf88721ce69ff484098c6c/simstudioai/sim/issues/2798
og:image:altBug Description When function/condition blocks reference undefined block variables (e.g., when webhook block hasn't executed), the variable reference is substituted into ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamePlaneInABottle
hostnamegithub.com
expected-hostnamegithub.com
None5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d
turbo-cache-controlno-preview
go-importgithub.com/simstudioai/sim git https://github.com/simstudioai/sim.git
octolytics-dimension-user_id199344406
octolytics-dimension-user_loginsimstudioai
octolytics-dimension-repository_id912559512
octolytics-dimension-repository_nwosimstudioai/sim
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id912559512
octolytics-dimension-repository_network_root_nwosimstudioai/sim
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release82560a55c6b2054555076f46e683151ee28a19bc
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/simstudioai/sim/issues/2798#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fissues%2F2798
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fissues%2F2798
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=simstudioai%2Fsim
Reloadhttps://patch-diff.githubusercontent.com/simstudioai/sim/issues/2798
Reloadhttps://patch-diff.githubusercontent.com/simstudioai/sim/issues/2798
Reloadhttps://patch-diff.githubusercontent.com/simstudioai/sim/issues/2798
simstudioai https://patch-diff.githubusercontent.com/simstudioai
simhttps://patch-diff.githubusercontent.com/simstudioai/sim
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Fsimstudioai%2Fsim
Fork 3.2k https://patch-diff.githubusercontent.com/login?return_to=%2Fsimstudioai%2Fsim
Star 25.7k https://patch-diff.githubusercontent.com/login?return_to=%2Fsimstudioai%2Fsim
Code https://patch-diff.githubusercontent.com/simstudioai/sim
Issues 98 https://patch-diff.githubusercontent.com/simstudioai/sim/issues
Pull requests 46 https://patch-diff.githubusercontent.com/simstudioai/sim/pulls
Actions https://patch-diff.githubusercontent.com/simstudioai/sim/actions
Projects 0 https://patch-diff.githubusercontent.com/simstudioai/sim/projects
Security Uh oh! There was an error while loading. Please reload this page. https://patch-diff.githubusercontent.com/simstudioai/sim/security
Please reload this pagehttps://patch-diff.githubusercontent.com/simstudioai/sim/issues/2798
Insights https://patch-diff.githubusercontent.com/simstudioai/sim/pulse
Code https://patch-diff.githubusercontent.com/simstudioai/sim
Issues https://patch-diff.githubusercontent.com/simstudioai/sim/issues
Pull requests https://patch-diff.githubusercontent.com/simstudioai/sim/pulls
Actions https://patch-diff.githubusercontent.com/simstudioai/sim/actions
Projects https://patch-diff.githubusercontent.com/simstudioai/sim/projects
Security https://patch-diff.githubusercontent.com/simstudioai/sim/security
Insights https://patch-diff.githubusercontent.com/simstudioai/sim/pulse
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/simstudioai/sim/issues/2798
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/simstudioai/sim/issues/2798
[BUG] Variable references not injected into execution context, causing ReferenceErrorhttps://patch-diff.githubusercontent.com/simstudioai/sim/issues/2798#top
https://github.com/PlaneInABottle
https://github.com/PlaneInABottle
PlaneInABottlehttps://github.com/PlaneInABottle
on Jan 13, 2026https://github.com/simstudioai/sim/issues/2798#issue-3810673515
#2794https://github.com/simstudioai/sim/issues/2794
[BUG] Variable substitution breaks nullish coalescing operator (??) in function blocks #2794https://github.com/simstudioai/sim/issues/2794
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.