{"record":{"id":"2339bf69962c3714","repo":"paperclipai/paperclip","slug":"gateway-bearer-token-is-expired-or-invalid","errorCode":null,"errorMessage":"Gateway bearer token is expired or invalid","messagePattern":"Gateway bearer token is expired or invalid","errorType":"http","errorClass":"ToolGatewayHttpError","httpStatus":401,"severity":"error","filePath":"server/src/services/tool-gateway.ts","lineNumber":3654,"sourceCode":"              }\n            }\n          } catch {\n            for (const { reject } of pending.values()) {\n              reject(stdioProtocolError(\"Local stdio MCP server returned invalid JSON\", {\n                connectionId: input.connection.id,\n                catalogEntryId: input.entry?.id ?? null,\n              }));\n            }\n            pending.clear();\n          }\n        }\n        newline = stdout.indexOf(\"\\n\");\n      }\n    });\n    child.stderr.on(\"data\", (chunk: string) => {\n      stderr = `${stderr}${chunk}`.slice(-4_000);\n    });\n    const exitPromise = new Promise<void>((resolve, reject) => {\n      child.on(\"error\", (error) => {\n        const gatewayError = new ToolGatewayHttpError(502, \"Local stdio MCP command failed to start\", \"local_stdio_spawn_failed\", {\n          connectionId: input.connection.id,\n          templateId: input.template.templateId,\n          message: error.message,\n        });\n        for (const { reject: rejectPending } of pending.values()) {\n          rejectPending(gatewayError);\n        }\n        pending.clear();\n        reject(gatewayError);\n      });\n      child.on(\"exit\", (code, signal) => {\n        if (pending.size === 0) {\n          resolve();\n          return;\n        }\n        for (const { reject: rejectPending } of pending.values()) {","sourceCodeStart":3636,"sourceCodeEnd":3672,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/server/src/services/tool-gateway.ts#L3636-L3672","documentation":"recordNamedGatewayAuthFailure is the shared failure recorder for named-gateway bearer authentication: it resolves the gateway by id/public id, derives the token identity (id or hash) for the failure counter, and always throws so callers get a 401-style terminal result. The message itself is the generic invalid-expired-token sentinel used after the failure has been counted and audited.","triggerScenarios":"Thrown at server/src/services/tool-gateway.ts:3513 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Obtain a fresh gateway bearer token; the current token is expired or invalid."],"exampleFix":null,"handlingStrategy":"try-catch","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-14T00:17:10.932Z"}