{"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":null,"httpStatus":500,"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/3aec848f2885144aa8f1e53b9731a04310d5d558/server/models/scheduledJobRun.js#L294-L330","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Confirm you are passing the run's id, not the parent job's id","Verify the run exists first: `await ScheduledJobRun.get({ id: Number(runId) })`","If the database was reset or retention pruned the run, trigger the job again to produce a new run and use that id","Check retention/prune settings that delete old scheduled_job_runs rows"],"exampleFix":"// before\nconst result = await ScheduledJobRun.continueInThread(runId);\n\n// after\nconst run = await ScheduledJobRun.get({ id: Number(runId) });\nif (!run) throw new Error(`No scheduled job run ${runId}`);\nconst result = await ScheduledJobRun.continueInThread(run.id);","handlingStrategy":"validation","validationCode":"const runIdNum = Number(runId);\nif (!Number.isInteger(runIdNum) || runIdNum <= 0) {\n  throw new Error('runId must be a positive integer');\n}\nconst run = await ScheduledJobRun.get({ id: runIdNum });\nif (!run) {\n  return res.status(404).json({ error: 'Run not found' });\n}\nconst result = await ScheduledJobRun.continueInThread(run.id);","typeGuard":"const isRunId = (v) => Number.isInteger(Number(v)) && Number(v) > 0;","tryCatchPattern":"try {\n  await ScheduledJobRun.continueInThread(runId);\n} catch (err) {\n  if (err.message === 'Run not found') {\n    // refresh the run list / return 404 instead of surfacing a crash\n  } else throw err;\n}","preventionTips":["Always pass the run id, never the job id, to continueInThread","Validate the id is a positive integer before calling (Number(undefined) is NaN)","Disable or lengthen retention on scheduled_job_runs if users need to continue old runs"],"tags":["scheduled-jobs","lookup","anythingllm"],"backgroundTag":"record-not-found","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}