{"record":{"id":"43e80e5fcc829db3","repo":"paperclipai/paperclip","slug":"run-context-mismatch","errorCode":"run_context_mismatch","errorMessage":"Supplied run context does not match stored heartbeat context","messagePattern":"Supplied run context does not match stored heartbeat context","errorType":"http","errorClass":"ToolGatewayHttpError","httpStatus":403,"severity":"error","filePath":"server/src/services/tool-gateway.ts","lineNumber":1095,"sourceCode":"          isWrite: catalogEntry.isWrite,\n          isDestructive: catalogEntry.isDestructive,\n        },\n        onDemandTools,\n      };\n      return {\n        name: gatewayToolName,\n        displayName: catalogEntry.title ?? catalogEntry.toolName,\n        description: catalogEntry.description ?? `Connected MCP tool ${catalogEntry.toolName} from ${connection.name}.`,\n        parametersSchema: inputSchema,\n        pluginId: `mcp:${applicationKey ?? application.id}`,\n        providerType: connection.transport === \"local_stdio\" ? \"mcp_local_stdio\" : \"mcp_remote_http\",\n        risk,\n        applicationId: application.id,\n        applicationKey,\n        applicationDisplayName: application.name,\n        connectionId: connection.id,\n        catalogEntryId: catalogEntry.id,\n        upstreamToolName: catalogEntry.toolName,\n        providerMetadata,\n      };\n    });\n  }\n\n  async function connectedMcpToolsForConnection(companyId: string, connectionId: string): Promise<ToolGatewayDescriptor[]> {\n    return (await connectedMcpToolsForCompany(companyId))\n      .filter((tool) => tool.connectionId === connectionId);\n  }\n\n  async function assertAgentInCompany(companyId: string, agentId: string): Promise<void> {\n    const [agent] = await db\n      .select({\n        companyId: agents.companyId,\n      })\n      .from(agents)\n      .where(eq(agents.id, agentId))\n      .limit(1);","sourceCodeStart":1077,"sourceCodeEnd":1113,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/server/src/services/tool-gateway.ts#L1077-L1113","documentation":"Guard in the tool gateway run-context check: the companyId/agentId supplied with the gateway request do not match the heartbeat run stored for that runId, or the run is not in an active gateway status. It fires when a client reuses a runId belonging to a different company/agent or after the run finished, protecting against cross-tenant or stale-session tool execution.","triggerScenarios":"Thrown at server/src/services/tool-gateway.ts:1077 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Supply the same run context (runId, etc.) that was stored at heartbeat/session creation; do not mix contexts from different runs."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ad8584922b5d85292b1723cae71fa0d9b07a19","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}