{"record":{"id":"aa3b99c32c247b1f","repo":"paperclipai/paperclip","slug":"completion-task-no-longer-exists","errorCode":null,"errorMessage":"Completion task no longer exists.","messagePattern":"Completion task no longer exists\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/src/services/native-runtime/native-completion-feedback.ts","lineNumber":44,"sourceCode":"): Promise<string> {\n  const run = await db\n    .select()\n    .from(heartbeatRuns)\n    .where(eq(heartbeatRuns.id, runId))\n    .then((rows) => rows[0]);\n  if (!run?.nativeIssueId)\n    throw new Error(\"Completion report has no bound task.\");\n  const issue = await db\n    .select()\n    .from(issues)\n    .where(\n      and(\n        eq(issues.id, run.nativeIssueId),\n        eq(issues.companyId, run.companyId),\n      ),\n    )\n    .then((rows) => rows[0]);\n  if (!issue) throw new Error(\"Completion task no longer exists.\");\n  const reviewContext = readNativeReviewAssignmentContext(run.contextSnapshot);\n  if (reviewContext) {\n    const review = await getNativeReviewAssignment(db, {\n      companyId: run.companyId, issueId: issue.id, agentId: run.agentId,\n      contextSnapshot: reviewContext, allowResolvedByRunId: run.id,\n    });\n    if (review?.interaction.status === \"pending\" && result.reportedWorkDisposition !== \"blocked\") {\n      throw new Error(\"Resolve your assigned review with resolve_review before finishing. If you cannot review the work, report the concrete blocker with paperclip_block.\");\n    }\n    return review?.interaction.status === \"pending\"\n      ? \"Review blocker recorded. Paperclip will preserve the task and record the reviewer recovery action.\"\n      : \"Review report accepted. The recorded review decision controls task completion; this report cannot override it.\";\n  }\n  const signals = normalizePrpResultSignals(result);\n  if (\n    result.reportedWorkDisposition === \"done\" &&\n    (!result.completionClaim.objectiveSatisfied ||\n      result.completionClaim.criteria.some(","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/paperclipai/paperclip/blob/3f1d897a7c018d76563a21c6e39c3c9b03933622/server/src/services/native-runtime/native-completion-feedback.ts#L26-L62","documentation":"After resolving the run's nativeIssueId, nativeCompletionFeedback loads the issue row scoped to both issue ID and the run's companyId. If no row matches, the bound task has been deleted (or belongs to a different company) and the completion report is rejected. This keeps reports from mutating tasks that no longer exist or cross company boundaries.","triggerScenarios":"The issue bound to the run was deleted between run start and completion report; the run's companyId changed or the report is issued against a run from a different company; hard-deleted issues via cleanup jobs.","commonSituations":"Users deleting tasks while an agent run is still in flight; company-scoped data migrations or purges; agents resuming queued completion reports after an admin removed the task.","solutions":["Treat the report as obsolete: the task is gone, so discard the queued completion report.","Check whether the issue was deleted (audit/activity log) before assuming a bug.","Verify the run's companyId still matches the issue's companyId; re-run under the correct company if data was moved.","If deletion was unintended, restore the issue and re-submit the report."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const issue = await getIssue(run.nativeIssueId, run.companyId);\nif (!issue) throw new Error(`task ${run.nativeIssueId} no longer exists in company ${run.companyId}; discard report`);","typeGuard":"const issueExists = (i: { id: string; companyId: string } | undefined): i is { id: string; companyId: string } => !!i;","tryCatchPattern":"try { await reportCompletion({ runId, result }); } catch (e) { if (e.message === \"Completion task no longer exists.\") return { status: \"discarded\", reason: \"task deleted\" }; throw e; }","preventionTips":["Subscribe to issue deletion events and cancel in-flight runs' pending reports.","Avoid hard-deleting issues that have active runs; cancel the runs first.","Keep run.companyId and issue.companyId aligned during data migrations."],"tags":["database","entity-lifecycle","completion-report"],"backgroundTag":"entity-not-found","analyzedSha":"3f1d897a7c018d76563a21c6e39c3c9b03933622","analyzedAt":"2026-09-18T08:03:59.046Z","contentChangedAt":"2026-09-18T08:03:59.046Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}