{"record":{"id":"d34b7d56bc6b60d8","repo":"diegosouzapw/OmniRoute","slug":"session-limit-exceeded","errorCode":"SESSION_LIMIT_EXCEEDED","errorMessage":"You have reached the maximum number of active sessions (${maxSessions}). Please close unused sessions or wait for them to expire.","messagePattern":"You have reached the maximum number of active sessions \\((.+?)\\)\\. Please close unused sessions or wait for them to expire\\.","errorType":"error_code","errorClass":null,"httpStatus":429,"severity":"error","filePath":"open-sse/services/sessionManager.ts","lineNumber":312,"sourceCode":"  }\n}\n\n/**\n * T08: Check whether adding a new session would exceed the key's max_sessions limit.\n * Returns null if allowed, or an error object to return as a 429 response.\n *\n * @param apiKeyId - The API key's UUID\n * @param maxSessions - The limit from the DB (0 = unlimited)\n */\nexport function checkSessionLimit(\n  apiKeyId: string,\n  maxSessions: number\n): { code: \"SESSION_LIMIT_EXCEEDED\"; message: string; limit: number; current: number } | null {\n  if (!maxSessions || maxSessions <= 0) return null; // unlimited\n  const current = getActiveSessionCountForKey(apiKeyId);\n  if (current < maxSessions) return null;\n  return {\n    code: \"SESSION_LIMIT_EXCEEDED\",\n    message:\n      `You have reached the maximum number of active sessions (${maxSessions}). ` +\n      `Please close unused sessions or wait for them to expire.`,\n    limit: maxSessions,\n    current,\n  };\n}\n\n/**\n * T04: Extract an external session ID from request headers.\n * Accepts both hyphenated and underscore forms for Nginx compatibility.\n * Nginx drops headers with underscores by default — use `underscores_in_headers on`\n * in nginx.conf, or use X-Session-Id (hyphenated) which passes cleanly.\n *\n * Ref: sub2api README + PR #634\n *\n * @param headers - Request headers (Headers object or plain object with .get())\n * @returns External session ID with \"ext:\" prefix, or null","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/open-sse/services/sessionManager.ts#L294-L330","documentation":"Error \"You have reached the maximum number of active sessions (${maxSessions}). Please close unused sessions or wait for them to expire.\" thrown in diegosouzapw/OmniRoute.","triggerScenarios":"Thrown at open-sse/services/sessionManager.ts:312 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","schemaVersion":2},"datasetVersion":"2026-08-25T21:54:21.419Z"}