mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-26 17:12:27 +03:00
fix(sessions): preserve legacy data when exclusive projection fails (#11469)
Validated in a combined sub-batch worktree off release/v3.8.51 tip. - Focused test: exclusive-session-observability.test.ts — part of sub-batch's 165/165 node:test run - typecheck:core, file-size, changelog-integrity, complexity, cognitive-complexity — all OK - Full-repo lint: 228 pre-existing dashboard react-hooks/* findings, unrelated to this diff Thanks for the narrow failure boundary and the privacy-conscious warning (proven not to leak the caught error's sensitive fields) — a projection failure discarding valid legacy data was a real regression from #11389.
This commit is contained in:
@@ -10,32 +10,47 @@ import { getExclusiveLeaseOccupancy } from "@/lib/db/exclusiveConnectionLeases";
|
||||
import { getProviderConnectionDisplayMetadata } from "@/lib/db/providers";
|
||||
import { getAccountDisplayName } from "@/lib/display/names";
|
||||
import { getPendingRequests } from "@/lib/usage/usageHistory";
|
||||
import { buildExclusiveDashboardSessions } from "@/lib/sessionObservability";
|
||||
import {
|
||||
buildExclusiveDashboardSessions,
|
||||
type ExclusiveDashboardSession,
|
||||
} from "@/lib/sessionObservability";
|
||||
|
||||
const EXCLUSIVE_PROJECTION_WARNING = "[SESSIONS] Exclusive session projection unavailable";
|
||||
let exclusiveProjectionWarningEmitted = false;
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const sessions = getActiveSessions();
|
||||
const count = getActiveSessionCount();
|
||||
const byApiKey = getAllActiveSessionCountsByKey();
|
||||
let exclusiveSessions: ExclusiveDashboardSession[] = [];
|
||||
|
||||
// Reuse the hard-lease authority added by #10362. The API-key policy derives
|
||||
// the managed candidate set; SQLite occupancy is the source of truth for
|
||||
// which of those connections are actually leased right now.
|
||||
const managedConnectionIds = Array.from(await getExclusiveLeaseConnectionIds());
|
||||
const occupancy = getExclusiveLeaseOccupancy(managedConnectionIds);
|
||||
const leasedConnectionIds = new Set(occupancy.keys());
|
||||
const connectionNames = new Map(
|
||||
getProviderConnectionDisplayMetadata([...leasedConnectionIds]).map((connection) => [
|
||||
connection.id,
|
||||
getAccountDisplayName(connection),
|
||||
])
|
||||
);
|
||||
const exclusiveSessions = buildExclusiveDashboardSessions(
|
||||
leasedConnectionIds,
|
||||
getPendingRequests().byAccount,
|
||||
sessions,
|
||||
connectionNames
|
||||
);
|
||||
try {
|
||||
// Reuse the hard-lease authority added by #10362. The API-key policy derives
|
||||
// the managed candidate set; SQLite occupancy is the source of truth for
|
||||
// which of those connections are actually leased right now.
|
||||
const managedConnectionIds = Array.from(await getExclusiveLeaseConnectionIds());
|
||||
const occupancy = getExclusiveLeaseOccupancy(managedConnectionIds);
|
||||
const leasedConnectionIds = new Set(occupancy.keys());
|
||||
const connectionNames = new Map(
|
||||
getProviderConnectionDisplayMetadata([...leasedConnectionIds]).map((connection) => [
|
||||
connection.id,
|
||||
getAccountDisplayName(connection),
|
||||
])
|
||||
);
|
||||
exclusiveSessions = buildExclusiveDashboardSessions(
|
||||
leasedConnectionIds,
|
||||
getPendingRequests().byAccount,
|
||||
sessions,
|
||||
connectionNames
|
||||
);
|
||||
exclusiveProjectionWarningEmitted = false;
|
||||
} catch {
|
||||
if (!exclusiveProjectionWarningEmitted) {
|
||||
exclusiveProjectionWarningEmitted = true;
|
||||
console.warn(EXCLUSIVE_PROJECTION_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
count,
|
||||
|
||||
Reference in New Issue
Block a user