koala73/worldmonitor · error · ValidationError

Invalid or missing jobId

Error message

Invalid or missing jobId

What it means

Request validation in getScenarioStatus: req.jobId does not match the JOB_ID_RE pattern (scenario:<timestamp>:<random-suffix> as generated by runScenario's generateJobId). A malformed or missing id is rejected before the premium access check proceeds to any cache read.

Source

Thrown at server/worldmonitor/scenario/v1/get-scenario-status.ts:70

  const r = raw as { affectedChokepointIds?: unknown; topImpactCountries?: unknown; template?: unknown };
  return {
    affectedChokepointIds: Array.isArray(r.affectedChokepointIds)
      ? r.affectedChokepointIds.filter((id): id is string => typeof id === 'string')
      : [],
    topImpactCountries: coerceImpactCountries(r.topImpactCountries),
    template: coerceTemplate(r.template),
  };
}

export async function getScenarioStatus(
  ctx: ServerContext,
  req: GetScenarioStatusRequest,
): Promise<GetScenarioStatusResponse> {
  await requirePremiumRpcAccess(ctx.request, ApiError, 'PRO subscription required');

  const jobId = req.jobId ?? '';
  if (!JOB_ID_RE.test(jobId)) {
    throw new ValidationError([{ field: 'jobId', description: 'Invalid or missing jobId' }]);
  }

  // Worker writes under the raw (unprefixed) key, so we must read raw.
  let envelope: WorkerResultEnvelope | null = null;
  try {
    envelope = await getRawJson(`scenario-result:${jobId}`) as WorkerResultEnvelope | null;
  } catch {
    throw new ApiError(502, 'Failed to fetch job status', '');
  }

  if (!envelope) {
    return { status: 'pending', error: '' };
  }

  const status = typeof envelope.status === 'string' ? envelope.status : 'pending';

  if (status === 'done') {
    const result = coerceResult(envelope.result);

View on GitHub (pinned to eeab0a219f)

Solutions

  1. Pass the jobId exactly as returned by the runScenario response
  2. Do not construct or truncate job ids client-side
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at server/worldmonitor/scenario/v1/get-scenario-status.ts:70 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of koala73/worldmonitor@eeab0a219f (2026-08-21). Data as JSON: /api/errors/2ef8e0e930941d7f. Report an issue: GitHub.