From cb4e8f4b6150e32ae53bc537acd736e625ca6875 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 10 Jun 2026 23:40:03 +0000 Subject: [PATCH] fix: filter synthetic 'default' service tier and close registry sync probe race Bug 1: getCodexServiceTierOptionValue now returns undefined when the persisted serviceTier value is the synthetic 'default' id used only as a UI select option. Previously this forwarded 'default' to the API, which overrides project-level routing settings. Standard routing should omit the tier entirely (matching pre-change behavior). Bug 2: Add a deferred re-read of instance snapshots after the forked stream consumers have had time to subscribe. The managed provider updates its snapshot ref before publishing to its PubSub, so re-reading after a yield captures any probe result that landed between the initial getSnapshot and the subscriber becoming active. --- apps/server/src/codexModelOptions.ts | 7 ++++--- .../src/provider/Layers/ProviderRegistry.ts | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/apps/server/src/codexModelOptions.ts b/apps/server/src/codexModelOptions.ts index 43b8a3c184..fd07b0c36c 100644 --- a/apps/server/src/codexModelOptions.ts +++ b/apps/server/src/codexModelOptions.ts @@ -7,8 +7,9 @@ import { export function getCodexServiceTierOptionValue( modelSelection: ModelSelection | null | undefined, ): string | undefined { - return ( + const tier = getModelSelectionStringOptionValue(modelSelection, "serviceTier") ?? - (getModelSelectionBooleanOptionValue(modelSelection, "fastMode") === true ? "fast" : undefined) - ); + (getModelSelectionBooleanOptionValue(modelSelection, "fastMode") === true ? "fast" : undefined); + if (tier === "default") return undefined; + return tier; } diff --git a/apps/server/src/provider/Layers/ProviderRegistry.ts b/apps/server/src/provider/Layers/ProviderRegistry.ts index 2df63e5383..00c719986e 100644 --- a/apps/server/src/provider/Layers/ProviderRegistry.ts +++ b/apps/server/src/provider/Layers/ProviderRegistry.ts @@ -569,6 +569,26 @@ export const ProviderRegistryLive = Layer.effect( }).pipe(Effect.ignoreCause({ log: true })), { concurrency: "unbounded", discard: true }, ); + + // Re-read snapshots after yielding to close the race between + // subscription establishment and the initial read. The managed + // provider updates its snapshot ref before publishing to the + // PubSub, so this second read captures any probe that landed + // after the first getSnapshot but before the forked subscriber + // became active. The subscriber then handles all future updates. + yield* Effect.yieldNow; + yield* Effect.forEach( + newlyAdded, + ([, instance]) => + Effect.gen(function* () { + const source = buildSnapshotSource(instance); + const provider = yield* source.getSnapshot; + yield* correlateSnapshotWithSource(source, provider).pipe( + Effect.flatMap(syncProvider), + ); + }).pipe(Effect.ignoreCause({ log: true })), + { concurrency: "unbounded", discard: true }, + ); yield* upsertProviders(unavailableProviders, { persist: false, replace: true,