Hmbown/CodeWhale · error · Error
is unavailable in Workflow scripts: runs must be…
Error message
${name} is unavailable in Workflow scripts: runs must be deterministic for record/replay What it means
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.
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.
Example fix
// before
const id = Math.random().toString(36).slice(2);
// after
const { id } = await task({ kind: "new_id" }); Defensive patterns
Strategy: try-catch
Validate before calling
const NONDETERMINISTIC = [/Date\.now\s*\(/, /Date\.parse\s*\(/, /Date\.UTC\s*\(/, /Math\.random\s*\(/];
if (NONDETERMINISTIC.some(rx => rx.test(scriptSource))) {
throw new Error('script uses banned nondeterministic builtins');
} Try / catch
try {
await runWorkflow(script, input);
} catch (e) {
if (e.message.includes('unavailable in Workflow scripts')) {
console.error(`nondeterministic builtin used: ${e.message.split(' is unavailable')[0]}`);
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- new Date()/Date() is unavailable in Workflow scripts: runs…
- Cloud agent harness execution failed
- Cloud agent harness exited with code
- Cloud agent repository clone failed
- Cloud agent sandbox disappeared before it was ready.
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/71bab292858eda19.
Report an issue: GitHub.
Appendix: source
Thrown at crates/workflow-js/src/vm.rs:1425
"explore" | "explorer" | "scout" | "plan" | "planner" | "review" | "reviewer"
| "verify" | "verifier" => Some(TaskRoleKind::ReadOnly),
"general" | "worker" => Some(TaskRoleKind::General),
"implement" | "implementer" | "builder" => Some(TaskRoleKind::Implementer),
_ => None,
}
}
/// The JS prelude injected before every script: determinism bans, the
/// `task`/`parallel`/`pipeline`/`log`/`phase` stdlib (design §7), and the
/// `budget` global.
fn prelude() -> String {
PRELUDE_TEMPLATE.replace("__MAX_ITEMS__", &PARALLEL_MAX_ITEMS.to_string())
}
const PRELUDE_TEMPLATE: &str = r#""use strict";
(() => {
const banned = (name) => () => {
throw new Error(name + " is unavailable in Workflow scripts: runs must be deterministic for record/replay");
};
const BannedDate = function Date() {
throw new Error("new Date()/Date() is unavailable in Workflow scripts: runs must be deterministic for record/replay");
};
BannedDate.now = banned("Date.now()");
BannedDate.parse = banned("Date.parse()");
BannedDate.UTC = banned("Date.UTC()");
globalThis.Date = BannedDate;
Math.random = banned("Math.random()");
// Capture temporary host bindings into this closure, then strip them from
// globalThis so scripts only see the documented Workflow surface (#4129).
const hostTask = __workflow_task;
const hostLog = __workflow_log;
const hostEverySlotFailed = __workflow_every_slot_failed;
const hostSlotDropped = __workflow_slot_dropped;
const hostPhase = __workflow_phase;
const hostBudgetTotal = __workflow_budget_total;View on GitHub (pinned to 73e0f67d83)