{"record":{"id":"71bab292858eda19","repo":"Hmbown/CodeWhale","slug":"name-is-unavailable-in-workflow-scripts-runs-m","errorCode":null,"errorMessage":"${name} is unavailable in Workflow scripts: runs must be deterministic for record/replay","messagePattern":"(.+?) is unavailable in Workflow scripts: runs must be deterministic for record/replay","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/workflow-js/src/vm.rs","lineNumber":1425,"sourceCode":"        \"explore\" | \"explorer\" | \"scout\" | \"plan\" | \"planner\" | \"review\" | \"reviewer\"\n        | \"verify\" | \"verifier\" => Some(TaskRoleKind::ReadOnly),\n        \"general\" | \"worker\" => Some(TaskRoleKind::General),\n        \"implement\" | \"implementer\" | \"builder\" => Some(TaskRoleKind::Implementer),\n        _ => None,\n    }\n}\n\n/// The JS prelude injected before every script: determinism bans, the\n/// `task`/`parallel`/`pipeline`/`log`/`phase` stdlib (design §7), and the\n/// `budget` global.\nfn prelude() -> String {\n    PRELUDE_TEMPLATE.replace(\"__MAX_ITEMS__\", &PARALLEL_MAX_ITEMS.to_string())\n}\n\nconst PRELUDE_TEMPLATE: &str = r#\"\"use strict\";\n(() => {\n  const banned = (name) => () => {\n    throw new Error(name + \" is unavailable in Workflow scripts: runs must be deterministic for record/replay\");\n  };\n  const BannedDate = function Date() {\n    throw new Error(\"new Date()/Date() is unavailable in Workflow scripts: runs must be deterministic for record/replay\");\n  };\n  BannedDate.now = banned(\"Date.now()\");\n  BannedDate.parse = banned(\"Date.parse()\");\n  BannedDate.UTC = banned(\"Date.UTC()\");\n  globalThis.Date = BannedDate;\n  Math.random = banned(\"Math.random()\");\n\n  // Capture temporary host bindings into this closure, then strip them from\n  // globalThis so scripts only see the documented Workflow surface (#4129).\n  const hostTask = __workflow_task;\n  const hostLog = __workflow_log;\n  const hostEverySlotFailed = __workflow_every_slot_failed;\n  const hostSlotDropped = __workflow_slot_dropped;\n  const hostPhase = __workflow_phase;\n  const hostBudgetTotal = __workflow_budget_total;","sourceCodeStart":1407,"sourceCodeEnd":1443,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/workflow-js/src/vm.rs#L1407-L1443","documentation":"Thrown by the Workflow JS prelude (vm.rs) when a script calls a nondeterminism-producing builtin that has been replaced with a stub, e.g. `Date.now()`, `Date.parse()`, `Date.UTC()`, or `Math.random()`. Workflow scripts must be deterministic so runs can be recorded and replayed identically, so these globals are banned at the VM level.","triggerScenarios":"Any workflow script expression calling `Date.now()`, `Date.parse(...)`, `Date.UTC(...)`, or `Math.random()`; the prelude replaces these globals with functions that throw this exact error.","commonSituations":"Porting an existing Node script into a workflow and leaving timestamps or random IDs in place; generating a correlation ID with Math.random; computing an expiry with Date.now.","solutions":["Get time from the host: pass timestamps in as task inputs or read them from a host task result envelope.","Generate randomness/IDs on the host side (inside `task()` work) and return them to the script.","Derive any script-internal values deterministically from inputs (counters, hashing, task results).","Use `new Date(...)`-free formatting: pass pre-formatted strings from the host instead of parsing dates in-script."],"exampleFix":"// before\nconst id = Math.random().toString(36).slice(2);\n// after\nconst { id } = await task({ kind: \"new_id\" });","handlingStrategy":"try-catch","validationCode":"const NONDETERMINISTIC = [/Date\\.now\\s*\\(/, /Date\\.parse\\s*\\(/, /Date\\.UTC\\s*\\(/, /Math\\.random\\s*\\(/];\nif (NONDETERMINISTIC.some(rx => rx.test(scriptSource))) {\n  throw new Error('script uses banned nondeterministic builtins');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runWorkflow(script, input);\n} catch (e) {\n  if (e.message.includes('unavailable in Workflow scripts')) {\n    console.error(`nondeterministic builtin used: ${e.message.split(' is unavailable')[0]}`);\n  } else throw e;\n}","preventionTips":["Never call Date.now/Date.parse/Date.UTC/Math.random in workflow scripts.","Get timestamps and random values from host task results.","Lint workflow sources for these builtins before submission.","Derive all in-script values deterministically from inputs."],"tags":["workflow","determinism","sandbox"],"backgroundTag":"unsupported-operation","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}