{"record":{"id":"54e4be9770bc2474","repo":"paperclipai/paperclip","slug":"run-agent-mismatch","errorCode":"run_agent_mismatch","errorMessage":"Run does not belong to agent","messagePattern":"Run does not belong to agent","errorType":"http","errorClass":"ToolGatewayHttpError","httpStatus":403,"severity":"error","filePath":"server/src/services/tool-gateway.ts","lineNumber":1492,"sourceCode":"      .select({\n        companyId: heartbeatRuns.companyId,\n        agentId: heartbeatRuns.agentId,\n        status: heartbeatRuns.status,\n        contextSnapshot: heartbeatRuns.contextSnapshot,\n      })\n      .from(heartbeatRuns)\n      .where(eq(heartbeatRuns.id, input.runId))\n      .limit(1);\n\n    if (!run || run.companyId !== input.companyId) {\n      throw new ToolGatewayHttpError(\n        403,\n        \"Run does not belong to company\",\n        \"run_company_mismatch\",\n      );\n    }\n    if (run.agentId !== input.agentId) {\n      throw new ToolGatewayHttpError(\n        403,\n        \"Run does not belong to agent\",\n        \"run_agent_mismatch\",\n      );\n    }\n    if (!ACTIVE_GATEWAY_RUN_STATUSES.has(run.status)) {\n      throw new ToolGatewayHttpError(403, \"Run is not active\", \"run_inactive\");\n    }\n\n    const snapshot = asRecord(run.contextSnapshot);\n    const snapshotIssueId = stringValue(snapshot?.issueId);\n    const snapshotProjectId = stringValue(snapshot?.projectId);\n    if (\n      (input.issueId && snapshotIssueId && input.issueId !== snapshotIssueId) ||\n      (input.projectId &&\n        snapshotProjectId &&\n        input.projectId !== snapshotProjectId)\n    ) {","sourceCodeStart":1474,"sourceCodeEnd":1510,"githubUrl":"https://github.com/paperclipai/paperclip/blob/3f1d897a7c018d76563a21c6e39c3c9b03933622/server/src/services/tool-gateway.ts#L1474-L1510","documentation":"Ownership guard following the company check: the run exists in the right company but belongs to a different agent than the caller. Prevents agents from reading or attaching to other agents' runs; the mismatched agentId/run pair is at fault.","triggerScenarios":"Thrown at server/src/services/tool-gateway.ts:1066 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a run that belongs to the calling agent; an agent cannot act on runs of other agents."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}