Hmbown/CodeWhale · error · Error

new Date()/Date() is unavailable in Workflow scripts: runs m

Error message

new Date()/Date() is unavailable in Workflow scripts: runs must be deterministic for record/replay

What it means

Same invariant as scope_path, enforced independently in the scoped branch of the recent-entries query (native_memory.rs:431). When a Some(MemoryScope::Workspace) filter is applied, the store must resolve the workspace's MEMORY.md path to filter rows by source, and that resolution needs the workspace id. Without it there is no single source to filter on, so the query fails fast instead of guessing.

Source

Thrown at crates/workflow-js/src/vm.rs:1036

        "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 hostPhase = __workflow_phase;
  const hostBudgetTotal = __workflow_budget_total;
  const hostBudgetSpent = __workflow_budget_spent;
  const hostBudgetRemaining = __workflow_budget_remaining;

  const MAX_ITEMS = __MAX_ITEMS__;
  const taskErrorText = (err) => String(err && err.message !== undefined ? err.message : err);

View on GitHub (pinned to 8880682c63)

Solutions

  1. Compute the id up front and skip the workspace filter when it cannot be derived: query with scope None (all scopes) or Some(Global) instead.
  2. Ensure the process cwd is the git checkout and that `git config --get remote.origin.url` succeeds and is non-empty.
  3. In library code, mirror the guard before calling: if scope == Workspace && workspace_id.is_none() { choose a different scope or return your own error }.

Example fix

// before
let hits = store.recent(Some(MemoryScope::Workspace), None, 50)?;

// after
let scope = match NativeMemoryStore::workspace_id(&cwd)? {
    Some(_) => Some(MemoryScope::Workspace),
    None => None, // no origin remote -> include all scopes
};
let hits = store.recent(scope, workspace_id.as_deref(), 50)?;
Defensive patterns

Strategy: validation

Validate before calling

let id = NativeMemoryStore::workspace_id(&cwd)?;
let (scope, ws) = match id.as_deref() {
    Some(id) => (Some(MemoryScope::Workspace), Some(id)),
    None => (None, None), // query across all scopes instead
};
let entries = store.recent(scope, ws, limit)?;

Type guard

fn can_query_workspace_scope(cwd: &Path) -> bool {
    NativeMemoryStore::workspace_id(cwd).map(|id| id.is_some()).unwrap_or(false)
}

Try / catch

match store.recent(Some(MemoryScope::Workspace), ws_id, limit) {
    Ok(rows) => rows,
    Err(e) if e.to_string().contains("workspace scope requires a workspace id") =>
        store.recent(None, None, limit)?, // retry unscoped
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling the recent/recall API with scope=Some(MemoryScope::Workspace) and workspace_id=None — typically the memory-search or memory-recall tool invoked from a directory where git remote.origin.url is absent, so the caller passes None through.

Common situations: Non-git working directories; repositories with no origin remote; scripted or headless use of the memory tool where the workspace root is not a checkout; unit tests calling the store directly with a Workspace scope filter but no id.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16). Data as JSON: /api/errors/df5ef4da0b6d81d1. Report an issue: GitHub.