Mintplex-Labs/anything-llm · error

Run not found

Error message

Run not found

What it means

Thrown by ScheduledJobRun.continueInThread(runId) when `this.get({ id: Number(runId) }, { job: true })` returns no row. The numeric run ID supplied does not exist in the scheduled_job_runs table, so there is no job result to continue into a workspace thread. Number(undefined) is NaN, which also matches nothing.

Solutions

  1. Confirm you are passing the run's id, not the parent job's id
  2. Verify the run exists first: `await ScheduledJobRun.get({ id: Number(runId) })`
  3. If the database was reset or retention pruned the run, trigger the job again to produce a new run and use that id
  4. Check retention/prune settings that delete old scheduled_job_runs rows

Example fix

// before
const result = await ScheduledJobRun.continueInThread(runId);

// after
const run = await ScheduledJobRun.get({ id: Number(runId) });
if (!run) throw new Error(`No scheduled job run ${runId}`);
const result = await ScheduledJobRun.continueInThread(run.id);
Defensive patterns

Strategy: validation

Validate before calling

const runIdNum = Number(runId);
if (!Number.isInteger(runIdNum) || runIdNum <= 0) {
  throw new Error('runId must be a positive integer');
}
const run = await ScheduledJobRun.get({ id: runIdNum });
if (!run) {
  return res.status(404).json({ error: 'Run not found' });
}
const result = await ScheduledJobRun.continueInThread(run.id);

Type guard

const isRunId = (v) => Number.isInteger(Number(v)) && Number(v) > 0;

Try / catch

try {
  await ScheduledJobRun.continueInThread(runId);
} catch (err) {
  if (err.message === 'Run not found') {
    // refresh the run list / return 404 instead of surfacing a crash
  } else throw err;
}

Prevention

When it happens

Trigger: Calling continueInThread with the parent job's id instead of the run's id; a run id from a database that was reset, migrated, or pruned; passing undefined or a non-numeric string that Number() turns into NaN.

Common situations: A 'continue in thread' UI action rendered from a stale run list; scripts replaying recorded run ids against a fresh instance; confusing scheduled_tasks ids with scheduled_job_runs ids.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/8723654c3eff534e. Report an issue: GitHub.

Appendix: source

Thrown at server/models/scheduledJobRun.js:312

      return 0;
    }
  },

  /**
   * Continue a run in a workspace thread.
   * This will create a new workspace and thread specific for the run if they do not exist, and add the run's response to the thread.
   * @param {number} runId - The ID of the run to continue.
   * @returns {Promise<{workspace: import("@prisma/client").workspaces | null, thread: import("@prisma/client").workspace_threads | null, error: string | null}>} A promise that resolves to an object containing the workspace, thread, and an error message if applicable.
   */
  continueInThread: async function (runId) {
    try {
      const { Workspace } = require("./workspace");
      const { WorkspaceThread } = require("./workspaceThread");
      const { WorkspaceChats } = require("./workspaceChats");
      const { safeJsonParse } = require("../utils/http");

      const run = await this.get({ id: Number(runId) }, { job: true });
      if (!run) throw new Error("Run not found");

      const result = safeJsonParse(run.result, {});
      const responseText = result?.text || "No response was generated.";

      // Get or create the "Scheduled Jobs" workspace
      const { workspace, error: workspaceError } = await Workspace.upsert(
        { slug: "scheduled-jobs" },
        {
          name: "Scheduled Jobs",
          slug: "scheduled-jobs",
          chatMode: "automatic",
        }
      );
      if (workspaceError)
        throw new Error(workspaceError || "Failed to create workspace");

      const { thread, message: threadError } =
        await WorkspaceThread.new(workspace);

View on GitHub (pinned to 3aec848f28)