musistudio/claude-code-router · error · Error

Media job not found: ${id}

Error message

Media job not found: ${id}

What it means

MediaJobStore.update refuses to patch an id that is not in the underlying Map, keeping records immutable-by-replacement. Any workflow that updates a job after it was deleted (retention cleanup) or in a different store instance hits this.

Source

Thrown at packages/core/src/media/storage.ts:43

  get(id: string): MediaJob | undefined {
    const job = this.jobs.get(id);
    return job ? structuredClone(job) : undefined;
  }

  list(): MediaJob[] {
    return [...this.jobs.values()].map((job) => structuredClone(job));
  }

  put(job: MediaJob): MediaJob {
    this.jobs.set(job.id, structuredClone(job));
    this.flush();
    return structuredClone(job);
  }

  update(id: string, patch: Partial<MediaJob>): MediaJob {
    const current = this.jobs.get(id);
    if (!current) {
      throw new Error(`Media job not found: ${id}`);
    }
    const next: MediaJob = {
      ...current,
      ...patch,
      id: current.id,
      updatedAt: new Date().toISOString()
    };
    this.jobs.set(id, next);
    this.flush();
    return structuredClone(next);
  }

  deleteOlderThan(cutoffMs: number): MediaJob[] {
    const deleted: MediaJob[] = [];
    for (const [id, job] of this.jobs) {
      const timestamp = Date.parse(job.finishedAt ?? job.updatedAt);
      if (["canceled", "failed", "succeeded"].includes(job.status) && Number.isFinite(timestamp) && timestamp < cutoffMs) {
        this.jobs.delete(id);

View on GitHub (pinned to 99f24806c6)

Solutions

  1. Re-check existence immediately before update and skip/ignore if gone
  2. Increase jobRetentionDays so active jobs can't be pruned mid-flight
  3. Ensure updates happen on the same store instance that created the job

Example fix

// before
store.update(job.id, patch);
// after
const current = store.get(job.id);
if (current) store.update(job.id, patch);
Defensive patterns

Strategy: try-catch

Validate before calling

if (!jobStore.get(id)) return; // job already gone

Type guard

const isLiveJob = (id: string, store: MediaJobStore): boolean => Boolean(store.get(id));

Try / catch

try { jobStore.update(id, patch); } catch (e) { if (e instanceof Error && e.message.startsWith("Media job not found")) return; throw e; }

Prevention

When it happens

Trigger: Calling update() with an unknown id — e.g. the job aged out via deleteOlderThan between read and update, or the store was recreated (restart) and ids no longer exist.

Common situations: Race between long-running job completion and retention cleanup; in-memory store not shared across processes after a restart.

Related errors


AI-assisted analysis of musistudio/claude-code-router@99f24806c6 (2026-08-27). Data as JSON: /api/errors/16b28054261e4f1f. Report an issue: GitHub.