Mintplex-Labs/anything-llm · error · 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 null — i.e. no scheduled_job_runs row matches the supplied id. The function is meant to resume a finished scheduled-job run inside a workspace thread, so a missing run is a hard precondition failure. Number(runId) means non-numeric input becomes NaN and also matches nothing.

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 526360e320)

Solutions

  1. Confirm the runId exists: query scheduled_job_runs for the id before calling continueInThread.
  2. Ensure runId is a parseable integer (Number.isFinite).
  3. Distinguish run id from job id — continueInThread wants the run id.
  4. Handle the returned { error: 'Run not found' } gracefully in the caller.

Example fix

// before
const { error } = await ScheduledJobRun.continueInThread(req.params.id);
// after
const runId = Number(req.params.id);
if (!Number.isFinite(runId)) return res.status(400).json({ error: 'Invalid run id' });
const { error } = await ScheduledJobRun.continueInThread(runId);
Defensive patterns

Strategy: validation

Validate before calling

const runId = Number(input.runId);
if (!Number.isFinite(runId)) throw new Error('runId must be a finite integer');
const run = await ScheduledJobRun.get({ id: runId }, { job: true });
if (!run) throw new Error(`No scheduled run with id ${runId}`);

Type guard

function isValidRunId(v) {
  const n = Number(v);
  return Number.isInteger(n) && n > 0;
}

Try / catch

const { workspace, thread, error } = await ScheduledJobRun.continueInThread(runId);
if (error === 'Run not found') return res.status(404).json({ error });

Prevention

When it happens

Trigger: Calling continueInThread with a runId that was deleted, never existed, or is not a valid number (NaN). Also when the run exists but the query's { job: true } join filter excludes it.

Common situations: Stale UI referencing a run deleted by cleanup; an id parsed from a URL string that included a prefix; race where the run was pruned between listing and continue; passing a job id instead of a run id.

Related errors


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