Skip to content

Commit 6007c0f

Browse files
fix(provider): filter retired instances before appearance updates
Remove retired provider snapshots before reconciliation publishes appearance changes or new snapshots. Keep field removal compatible with React Compiler and cover the first removal emission.
1 parent 7903700 commit 6007c0f

3 files changed

Lines changed: 48 additions & 20 deletions

File tree

‎apps/server/src/provider/ProviderRegistry.test.ts‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,13 +2764,18 @@ it.layer(
27642764
makeInstance(kimiProvider, Ref.get(kimiAppearance)),
27652765
makeInstance(plainProvider),
27662766
];
2767+
const instancesRef = yield* Ref.make<ReadonlyArray<ProviderInstance>>(instances);
27672768
const changes = yield* PubSub.unbounded<void>();
27682769
const layerInstanceRegistry = Layer.succeed(
27692770
ProviderInstanceRegistry.ProviderInstanceRegistry,
27702771
{
27712772
getInstance: (instanceId) =>
2772-
Effect.succeed(instances.find((instance) => instance.instanceId === instanceId)),
2773-
listInstances: Effect.succeed(instances),
2773+
Ref.get(instancesRef).pipe(
2774+
Effect.map((current) =>
2775+
current.find((instance) => instance.instanceId === instanceId),
2776+
),
2777+
),
2778+
listInstances: Ref.get(instancesRef),
27742779
listUnavailable: Effect.succeed([]),
27752780
streamChanges: Stream.fromPubSub(changes),
27762781
subscribeChanges: PubSub.subscribe(changes),
@@ -2838,6 +2843,22 @@ it.layer(
28382843
{ icon: restyled?.icon, badgeLabel: restyled?.badgeLabel },
28392844
{ icon: "codex", badgeLabel: undefined },
28402845
);
2846+
2847+
// The first removal emission must already exclude the deleted
2848+
// instance, even when a retained instance is restyled at once.
2849+
const pullChanges = yield* Stream.toPull(registry.streamChanges);
2850+
yield* Ref.set(instancesRef, [instances[0]!]);
2851+
yield* Ref.set(kimiAppearance, { icon: "initials", badgeLabel: "NEW" });
2852+
yield* PubSub.publish(changes, undefined);
2853+
const removalChanges = yield* pullChanges;
2854+
for (const list of removalChanges) {
2855+
assert.deepStrictEqual(
2856+
list.map((provider) => provider.instanceId),
2857+
["claude_kimi"],
2858+
);
2859+
assert.strictEqual(list[0]?.icon, "initials");
2860+
assert.strictEqual(list[0]?.badgeLabel, "NEW");
2861+
}
28412862
}).pipe(Effect.provide(runtimeServices));
28422863
}),
28432864
);

‎apps/server/src/provider/ProviderRegistry.ts‎

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -774,8 +774,24 @@ export const layer = Layer.effect(
774774
nextAppearance.set(instanceId, yield* instance.appearance ?? Effect.succeed({}));
775775
}
776776
const previousAppearance = yield* Ref.getAndSet(appearanceRef, nextAppearance);
777-
if (!sameAppearance(previousAppearance, nextAppearance)) {
778-
yield* PubSub.publish(changesPubSub, yield* Ref.get(providersRef));
777+
// Remove retired instances before any reconciliation emission, so
778+
// clients never receive them with their configured appearance stripped.
779+
const [previousProviders, providers] = yield* Ref.modify(
780+
providersRef,
781+
(previousProviders) => {
782+
const providers = orderProviderSnapshots(
783+
previousProviders.filter((provider) =>
784+
knownInstanceIds.has(snapshotInstanceKey(provider)),
785+
),
786+
);
787+
return [[previousProviders, providers] as const, providers];
788+
},
789+
);
790+
if (
791+
!sameAppearance(previousAppearance, nextAppearance) ||
792+
haveProvidersChanged(previousProviders, providers)
793+
) {
794+
yield* PubSub.publish(changesPubSub, providers);
779795
}
780796

781797
const rebuiltInstanceIds = new Set(
@@ -835,20 +851,6 @@ export const layer = Layer.effect(
835851
}
836852
yield* Ref.set(liveSubsRef, nextSubs);
837853

838-
const [previousProviders, providers] = yield* Ref.modify(
839-
providersRef,
840-
(previousProviders) => {
841-
const providers = orderProviderSnapshots(
842-
previousProviders.filter((provider) =>
843-
knownInstanceIds.has(snapshotInstanceKey(provider)),
844-
),
845-
);
846-
return [[previousProviders, providers] as const, providers];
847-
},
848-
);
849-
if (haveProvidersChanged(previousProviders, providers)) {
850-
yield* PubSub.publish(changesPubSub, providers);
851-
}
852854
yield* Ref.update(maintenanceActionStatesRef, (previous) => {
853855
const next = new Map(previous);
854856
for (const instanceId of previous.keys()) {

‎apps/web/src/components/settings/ProviderInstanceCard.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,13 @@ export function ProviderInstanceCard({
745745
value: ProviderInstanceConfig[Key] | undefined,
746746
) =>
747747
onUpdate((current) => {
748-
const { [key]: _omit, ...rest } = current;
749-
return (value === undefined ? rest : { ...rest, [key]: value }) as ProviderInstanceConfig;
748+
const next = { ...current };
749+
if (value === undefined) {
750+
delete next[key];
751+
} else {
752+
next[key] = value;
753+
}
754+
return next;
750755
});
751756

752757
const updateDisplayName = (value: string) => {

0 commit comments

Comments
 (0)