windmill-labs/windmill · error · Error

Job ID not set

Error message

Job ID not set

What it means

getRootJobId resolves the root job of the current flow execution via the Windmill API. It needs a job id either from its jobId argument or from the WM_JOB_ID environment variable that the Windmill worker injects. When neither exists the function throws this Error before making any API call.

Source

Thrown at backend/windmill-runtime-nativets/src/windmill-client.js:9887

      workspace,
      path,
    });
  } catch (e) {
    if (undefinedIfEmpty && e.status === 404) {
      return void 0;
    } else {
      throw Error(
        `Resource not found at ${path} or not visible to you: ${e.body}`
      );
    }
  }
}
async function getRootJobId(jobId) {
  !clientSet && setClient();
  const workspace = getWorkspace();
  jobId = jobId ?? getEnv("WM_JOB_ID");
  if (jobId === void 0) {
    throw Error("Job ID not set");
  }
  return await JobService.getRootJobId({ workspace, id: jobId });
}
async function runScript(
  path = null,
  hash_ = null,
  args = null,
  verbose = false
) {
  args = args || {};
  if (verbose) {
    console.info(`running \`${path}\` synchronously with args:`, args);
  }
  const jobId = await runScriptAsync(path, hash_, args);
  return await waitJob(jobId, verbose);
}
async function waitJob(jobId, verbose = false) {
  while (true) {

View on GitHub (pinned to e474e8803c)

Solutions

  1. Call getRootJobId(jobId) with an explicit job id when running outside a Windmill job
  2. Run the code inside a Windmill script/flow so the worker sets WM_JOB_ID
  3. Check `echo $WM_JOB_ID` / process.env in the executing context to confirm injection
  4. If wrapping in tests, stub getRootJobId or set process.env.WM_JOB_ID to a real job id

Example fix

// before
const root = await getRootJobId(); // throws outside a job
// after
const root = await getRootJobId(jobId ?? process.env.WM_JOB_ID); // explicit fallback
Defensive patterns

Strategy: validation

Validate before calling

const jobId = explicitId ?? process.env.WM_JOB_ID;
if (jobId === undefined) throw new Error('WM_JOB_ID unavailable: not running inside a Windmill job');

Type guard

function isJobContext(env) { return typeof env.WM_JOB_ID === 'string' && env.WM_JOB_ID.length > 0; }

Try / catch

try {
  root = await getRootJobId();
} catch (e) {
  if (e.message === 'Job ID not set') root = null; // outside job context
  else throw e;
}

Prevention

When it happens

Trigger: Calling getRootJobId() with no argument in a context where WM_JOB_ID is unset — i.e. code executed outside a Windmill job (plain node script, unit test, non-job CLI run) or in an environment where the variable was stripped.

Common situations: Running the script locally with `node`/`bun` instead of inside a Windmill worker; embedding the client in a service that never receives WM_JOB_ID; passing undefined explicitly while env is absent; older worker versions that did not inject WM_JOB_ID into the execution sandbox.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03). Data as JSON: /api/errors/ac9af7c45cb741fe. Report an issue: GitHub.