diff --git a/open-sse/services/antigravityProjectPersistence.ts b/open-sse/services/antigravityProjectPersistence.ts new file mode 100644 index 0000000000..fa2084c38b --- /dev/null +++ b/open-sse/services/antigravityProjectPersistence.ts @@ -0,0 +1,36 @@ +/** + * Reorder Antigravity provider connections so ones with an already-known + * Cloud Code `projectId` are tried first. + * + * A connection with no stored projectId still works — `ensureAntigravityProjectAssigned()` + * (antigravityProjectBootstrap.ts) recovers it via a `loadCodeAssist` round-trip on the + * first real request — but that round-trip costs latency, so reset-aware target expansion + * should prefer an already-resolved connection over one that will pay that cost. + * + * Fail-open: this only reorders, it never drops a connection. #8894 added the import for + * this module to quotaStrategies.ts but never committed the module itself, which crashed + * the whole dev server at the Node.js instrumentation-hook boot step (module not found). + */ + +function hasStoredProjectId(connection: Record): boolean { + const direct = connection.projectId; + if (typeof direct === "string" && direct.trim().length > 0) return true; + + const providerSpecificData = connection.providerSpecificData; + if (providerSpecificData && typeof providerSpecificData === "object") { + const nested = (providerSpecificData as Record).projectId; + if (typeof nested === "string" && nested.trim().length > 0) return true; + } + return false; +} + +export function preferAntigravityConnectionsWithStoredProject>( + connections: T[] +): T[] { + const withProject: T[] = []; + const withoutProject: T[] = []; + for (const connection of connections) { + (hasStoredProjectId(connection) ? withProject : withoutProject).push(connection); + } + return [...withProject, ...withoutProject]; +} diff --git a/src/lib/db/migrations/134_ccr_blocks.sql b/src/lib/db/migrations/141_ccr_blocks.sql similarity index 100% rename from src/lib/db/migrations/134_ccr_blocks.sql rename to src/lib/db/migrations/141_ccr_blocks.sql diff --git a/src/lib/db/migrations/137_agentic_conversations.sql b/src/lib/db/migrations/142_agentic_conversations.sql similarity index 100% rename from src/lib/db/migrations/137_agentic_conversations.sql rename to src/lib/db/migrations/142_agentic_conversations.sql diff --git a/src/lib/db/migrations/138_conversation_turn_nodes.sql b/src/lib/db/migrations/143_conversation_turn_nodes.sql similarity index 100% rename from src/lib/db/migrations/138_conversation_turn_nodes.sql rename to src/lib/db/migrations/143_conversation_turn_nodes.sql