{"record":{"id":"e902589d67f0658f","repo":"windmill-labs/windmill","slug":"job-id-not-set-e90258","errorCode":null,"errorMessage":"Job ID not set","messagePattern":"Job ID not set","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"typescript-client/client.ts","lineNumber":154,"sourceCode":"      return undefined;\n    } else {\n      throw Error(\n        `Resource not found at ${path} or not visible to you: ${e.body}`\n      );\n    }\n  }\n}\n\n/**\n * Get the true root job id\n * @param jobId job id to get the root job id from (default to current job)\n * @returns root job id\n */\nexport async function getRootJobId(jobId?: string): Promise<string> {\n  const workspace = getWorkspace();\n  jobId = jobId ?? getEnv(\"WM_JOB_ID\");\n  if (jobId === undefined) {\n    throw Error(\"Job ID not set\");\n  }\n  return await JobService.getRootJobId({ workspace, id: jobId });\n}\n\n/**\n * @deprecated Use runScriptByPath or runScriptByHash instead\n */\nexport async function runScript(\n  path: string | null = null,\n  hash_: string | null = null,\n  args: Record<string, any> | null = null,\n  verbose: boolean = false,\n  tag: string | null = null\n): Promise<any> {\n  console.warn(\n    \"runScript is deprecated. Use runScriptByPath or runScriptByHash instead.\"\n  );\n  if (path && hash_) {","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/typescript-client/client.ts#L136-L172","documentation":"getRootJobId(jobId?) resolves the root (flow-parent) job id for the current run via JobService.getRootJobId. The jobId defaults to the WM_JOB_ID environment variable; if neither the argument nor that env var is available, it throws 'Job ID not set'. This typically means the code ran outside a Windmill job execution context (where WM_JOB_ID is injected).","triggerScenarios":"Calling getRootJobId() (or setFlowUserState/getFlowUserState, which call it) from code running outside a Windmill worker — local dev, plain Node, tests — or inside a job type that does not set WM_JOB_ID (e.g. some hooks/preview contexts).","commonSituations":"Running a script locally with `node`/`tsx` to debug flow user state code; unit tests importing the helper; code shared between Windmill jobs and external tooling executing outside the runner; a container image or executor that drops the WM_JOB_ID env var.","solutions":["Run the code inside a Windmill job (script/flow step) so WM_JOB_ID is injected.","Pass the job id explicitly: getRootJobId('some-job-id') when calling outside a run.","In local dev, set WM_JOB_ID in the environment to a real job id copied from the runs page.","Guard flow-state helpers so they no-op outside Windmill: if (!getEnv('WM_JOB_ID')) return."],"exampleFix":"// before\nconst rootId = await getRootJobId() // throws locally\n// after\nconst rootId = process.env.WM_JOB_ID ? await getRootJobId() : undefined","handlingStrategy":"validation","validationCode":"import { getEnv } from 'windmill-client'\nif (!jobId && !getEnv('WM_JOB_ID')) {\n  console.warn('Not running inside a Windmill job; skipping flow state access')\n  return\n}\nawait getRootJobId(jobId)","typeGuard":"function hasJobContext(jobId?: string): boolean {\n  return Boolean(jobId ?? process.env.WM_JOB_ID)\n}","tryCatchPattern":"try {\n  await setFlowUserState(key, value)\n} catch (e) {\n  if (e?.message === 'Job ID not set') {\n    console.warn('Flow state unavailable outside Windmill jobs')\n  } else throw e\n}","preventionTips":["Only call flow-state helpers from code executed by a Windmill worker.","Gate flow-state code with a WM_JOB_ID presence check for locally-run scripts.","Pass jobId explicitly when invoking from non-job contexts.","Avoid importing these helpers into unit tests without stubbing the env var."],"tags":["windmill-client","env-var","job-context","typescript"],"backgroundTag":"missing-env-var","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}