{"record":{"id":"493696f1888c0038","repo":"paperclipai/paperclip","slug":"run-company-mismatch","errorCode":"run_company_mismatch","errorMessage":"Run does not belong to company","messagePattern":"Run does not belong to company","errorType":"http","errorClass":"ToolGatewayHttpError","httpStatus":403,"severity":"error","filePath":"server/src/services/tool-gateway.ts","lineNumber":1485,"sourceCode":"    companyId: string;\n    agentId: string;\n    runId: string;\n    issueId?: string | null;\n    projectId?: string | null;\n  }): Promise<{ issueId: string | null; projectId: string | null }> {\n    const [run] = await db\n      .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);","sourceCodeStart":1467,"sourceCodeEnd":1503,"githubUrl":"https://github.com/paperclipai/paperclip/blob/3f1d897a7c018d76563a21c6e39c3c9b03933622/server/src/services/tool-gateway.ts#L1467-L1503","documentation":"Tenant guard on run resolution: the heartbeatRuns row for runId is missing or its companyId differs from the caller's company. Enforces company scoping for run-context lookups; the foreign runId is at fault.","triggerScenarios":"Thrown at server/src/services/tool-gateway.ts:1063 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a run ID that belongs to the authenticated company; cross-company run access is rejected."],"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"}