{"record":{"id":"dd4b8ffeeebcc0ea","repo":"diegosouzapw/OmniRoute","slug":"lease-connection-mismatch","errorCode":"LEASE_CONNECTION_MISMATCH","errorMessage":"Managed lease connection is unavailable","messagePattern":"Managed lease connection is unavailable","errorType":"exception","errorClass":"Error","httpStatus":409,"severity":"error","filePath":"open-sse/handlers/chatCore.ts","lineNumber":577,"sourceCode":"    });\n  });\n  const traceEnabled = process.env.OMNIROUTE_TRACE === \"true\" || process.env.DEBUG === \"true\";\n  // Stage trace extracted to chatCore/stageTrace.ts (#3501); bind the per-request inputs once so the\n  // call sites stay byte-identical.\n  const trace = (label: string, extra?: Record<string, unknown>) =>\n    stageTrace(label, extra, { traceEnabled, startTime, traceId, log });\n  const getCurrentConnectionId = () => {\n    const credentialConnectionId =\n      typeof credentials?.connectionId === \"string\" && credentials.connectionId.trim().length > 0\n        ? credentials.connectionId.trim()\n        : null;\n    return credentialConnectionId || connectionId || null;\n  };\n  const assertManagedLeaseFence = (attemptConnectionId: string | null | undefined) => {\n    if (!managedLease) return;\n    if (!attemptConnectionId) {\n      throw Object.assign(new Error(\"Managed lease connection is unavailable\"), {\n        code: \"LEASE_CONNECTION_MISMATCH\",\n        status: 409,\n      });\n    }\n    const fence = assertExclusiveConnectionLeaseFence({\n      leaseOwnerId: managedLease.context.leaseOwnerId,\n      generation: managedLease.context.generation,\n      apiKeyId: managedLease.apiKeyId,\n      connectionId: attemptConnectionId,\n    });\n    if (fence.kind === \"VALID\") return;\n    const code =\n      fence.kind === \"REQUIRED\"\n        ? \"LEASE_REQUIRED\"\n        : fence.kind === \"STALE\"\n          ? \"LEASE_FENCE_STALE\"\n          : fence.kind === \"AUTHORIZATION_MISMATCH\"\n            ? \"LEASE_AUTHORIZATION_MISMATCH\"\n            : \"LEASE_CONNECTION_MISMATCH\";","sourceCodeStart":559,"sourceCodeEnd":595,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/open-sse/handlers/chatCore.ts#L559-L595","documentation":"Error \"Managed lease connection is unavailable\" thrown in diegosouzapw/OmniRoute.","triggerScenarios":"Thrown at open-sse/handlers/chatCore.ts:577 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"}