{"record":{"id":"74753f7f35cfe27d","repo":"paperclipai/paperclip","slug":"session-invalid","errorCode":"session_invalid","errorMessage":"Tool gateway session is expired or invalid","messagePattern":"Tool gateway session is expired or invalid","errorType":"http","errorClass":"ToolGatewayHttpError","httpStatus":401,"severity":"error","filePath":"server/src/services/tool-gateway.ts","lineNumber":1776,"sourceCode":"        401,\n        \"Tool gateway session is expired or invalid\",\n        \"session_run_inactive\",\n      );\n    }\n  }\n\n  async function getActiveSession(\n    sessionToken: string,\n    namedGatewayProtocol?: {\n      gatewayId?: string | null;\n      gatewayPublicId?: string | null;\n      protocolMethod: McpGatewayProtocolMethod;\n      callerHeaders?: Record<string, string | string[] | undefined>;\n    },\n  ): Promise<ToolGatewaySession> {\n    const token = sessionToken.trim();\n    if (!token) {\n      throw new ToolGatewayHttpError(\n        401,\n        \"Tool gateway session is expired or invalid\",\n        \"session_invalid\",\n      );\n    }\n    if (namedGatewayTokenId(token)) {\n      return namedGatewaySessionFromBearer({\n        gatewayId: namedGatewayProtocol?.gatewayId ?? null,\n        gatewayPublicId: namedGatewayProtocol?.gatewayPublicId ?? null,\n        bearerToken: token,\n        protocolMethod: namedGatewayProtocol?.protocolMethod ?? \"tools/call\",\n        callerHeaders: namedGatewayProtocol?.callerHeaders,\n      });\n    }\n\n    const tokenHash = hashGatewayToken(token);\n    const [row] = await db\n      .select()","sourceCodeStart":1758,"sourceCodeEnd":1794,"githubUrl":"https://github.com/paperclipai/paperclip/blob/3f1d897a7c018d76563a21c6e39c3c9b03933622/server/src/services/tool-gateway.ts#L1758-L1794","documentation":"401 sentinel thrown after writeSessionAuthFailure logged a session_run_inactive event: the gateway session token itself is well-formed, but the run it authenticates for is no longer active, so the session is treated as expired/invalid and the client must re-authenticate against a new run.","triggerScenarios":"Thrown at server/src/services/tool-gateway.ts:1264 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Re-establish the tool gateway session (re-authenticate); the session token expired or is invalid."],"exampleFix":null,"handlingStrategy":"try-catch","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"}