{"record":{"id":"8723654c3eff534e","repo":"Mintplex-Labs/anything-llm","slug":"run-not-found","errorCode":null,"errorMessage":"Run not found","messagePattern":"Run not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/models/scheduledJobRun.js","lineNumber":312,"sourceCode":"      return 0;\n    }\n  },\n\n  /**\n   * Continue a run in a workspace thread.\n   * 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.\n   * @param {number} runId - The ID of the run to continue.\n   * @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.\n   */\n  continueInThread: async function (runId) {\n    try {\n      const { Workspace } = require(\"./workspace\");\n      const { WorkspaceThread } = require(\"./workspaceThread\");\n      const { WorkspaceChats } = require(\"./workspaceChats\");\n      const { safeJsonParse } = require(\"../utils/http\");\n\n      const run = await this.get({ id: Number(runId) }, { job: true });\n      if (!run) throw new Error(\"Run not found\");\n\n      const result = safeJsonParse(run.result, {});\n      const responseText = result?.text || \"No response was generated.\";\n\n      // Get or create the \"Scheduled Jobs\" workspace\n      const { workspace, error: workspaceError } = await Workspace.upsert(\n        { slug: \"scheduled-jobs\" },\n        {\n          name: \"Scheduled Jobs\",\n          slug: \"scheduled-jobs\",\n          chatMode: \"automatic\",\n        }\n      );\n      if (workspaceError)\n        throw new Error(workspaceError || \"Failed to create workspace\");\n\n      const { thread, message: threadError } =\n        await WorkspaceThread.new(workspace);","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/models/scheduledJobRun.js#L294-L330","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Confirm the runId exists: query scheduled_job_runs for the id before calling continueInThread.","Ensure runId is a parseable integer (Number.isFinite).","Distinguish run id from job id — continueInThread wants the run id.","Handle the returned { error: 'Run not found' } gracefully in the caller."],"exampleFix":"// before\nconst { error } = await ScheduledJobRun.continueInThread(req.params.id);\n// after\nconst runId = Number(req.params.id);\nif (!Number.isFinite(runId)) return res.status(400).json({ error: 'Invalid run id' });\nconst { error } = await ScheduledJobRun.continueInThread(runId);","handlingStrategy":"validation","validationCode":"const runId = Number(input.runId);\nif (!Number.isFinite(runId)) throw new Error('runId must be a finite integer');\nconst run = await ScheduledJobRun.get({ id: runId }, { job: true });\nif (!run) throw new Error(`No scheduled run with id ${runId}`);","typeGuard":"function isValidRunId(v) {\n  const n = Number(v);\n  return Number.isInteger(n) && n > 0;\n}","tryCatchPattern":"const { workspace, thread, error } = await ScheduledJobRun.continueInThread(runId);\nif (error === 'Run not found') return res.status(404).json({ error });","preventionTips":["Parse and validate runId as a positive integer before calling continueInThread.","Distinguish run id from job id.","Handle the returned error string rather than letting it surface raw."],"tags":["scheduled-jobs","not-found","database","id-validation"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}