Skip to content

Commit 8ba95e2

Browse files
committed
fix(models): show newly authenticated providers after a config reload
The owner-by-snapshot map added in #134361 keys on snapshot identity, and publishPreparedModelRuntimeOwnerSnapshot is its only writer. advancePreparedModelRuntimeOwnerConfig assigned owner.snapshot directly, and the config stamp mints a new frozen snapshot, so the map kept pointing at the retired one. The catalogStale flag survived the advance while the lookup that consumes it no longer resolved its owner, and the next explicit browse served the pre-login catalog. Route that assignment through the writer so the index moves with the stamp, and say on the writer that it is the only permitted assignment site.
1 parent 3e72b59 commit 8ba95e2

2 files changed

Lines changed: 54 additions & 2 deletions

File tree

‎src/agents/prepared-model-runtime.owner.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export function resolvePreparedModelRuntimeOwnerBySnapshot(
4848
return ownersBySnapshot.get(snapshot);
4949
}
5050

51+
// Sole permitted writer of `owner.snapshot`. The map keys on snapshot identity, so any
52+
// assignment that bypasses this leaves the owner unreachable from the snapshot readers hold.
5153
function publishPreparedModelRuntimeOwnerSnapshot(
5254
owner: PreparedModelRuntimeOwner,
5355
snapshot: PreparedModelRuntimeSnapshot,
@@ -261,8 +263,12 @@ export function advancePreparedModelRuntimeOwnerConfig(
261263
owner.input = { ...owner.input, config };
262264
if (owner.snapshot) {
263265
// Existing leases retain their immutable snapshot. New readers receive the same prepared
264-
// generation with only its planner-approved, model-neutral config stamp advanced.
265-
owner.snapshot = stampPreparedModelRuntimeSnapshotConfig(owner.snapshot, config);
266+
// generation with only its planner-approved, model-neutral config stamp advanced. The stamp
267+
// mints a new snapshot identity, so it has to move the owner's snapshot index with it.
268+
publishPreparedModelRuntimeOwnerSnapshot(
269+
owner,
270+
stampPreparedModelRuntimeSnapshotConfig(owner.snapshot, config),
271+
);
266272
}
267273
}
268274

‎src/agents/prepared-model-runtime.reload-auth.test.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import { loadPreparedModelCatalogOwnerSnapshot } from "./prepared-model-catalog.js";
1515
import {
1616
acquireAgentRunPreparedModelRuntime,
17+
advancePreparedModelRuntimeConfig,
1718
loadPublishedGatewayReplyDispatchRuntime,
1819
prepareModelRuntimeSnapshot,
1920
refreshStalePreparedModelRuntimeCatalog,
@@ -810,6 +811,51 @@ describe("prepared model runtime reload auth adoption", () => {
810811
await Promise.allSettled([authWaiter, reload]);
811812
}
812813
});
814+
815+
it("keeps a stale catalog reachable after a model-neutral config stamp advance", async () => {
816+
mocks.configuredAgentIds = ["default"];
817+
const model = {
818+
provider: "catalog-refresh-fixture",
819+
id: "authenticated-model",
820+
name: "Authenticated model",
821+
api: "openai-completions" as const,
822+
};
823+
mocks.runPreparedModelCatalogWorker.mockResolvedValue({
824+
entries: [model],
825+
routeVariants: [model],
826+
});
827+
const input = {
828+
agentId: "default",
829+
agentDir: state.agentDir("default"),
830+
inheritedAuthDir: state.agentDir("default"),
831+
config: {},
832+
};
833+
await refreshPreparedModelRuntimeSnapshots(input.config, {
834+
gatewayLifecycle: true,
835+
catalogMode: "static",
836+
});
837+
await prepareModelRuntimeSnapshot(input);
838+
839+
mocks.mutationListener?.({
840+
agentDir: input.agentDir,
841+
affectsInheritedStores: false,
842+
profileSetChanged: true,
843+
});
844+
await prepareModelRuntimeSnapshot(input);
845+
846+
// A model-neutral runtime config commit re-stamps every published owner in place. The stamp
847+
// mints a new snapshot identity, which must stay resolvable back to the owner holding the
848+
// stale flag; otherwise the next explicit browse silently serves the pre-mutation catalog.
849+
advancePreparedModelRuntimeConfig({});
850+
851+
const advanced = await prepareModelRuntimeSnapshot(input);
852+
mocks.runPreparedModelCatalogWorker.mockClear();
853+
await expect(refreshStalePreparedModelRuntimeCatalog(advanced)).resolves.toMatchObject({
854+
entries: [model],
855+
});
856+
expect(mocks.runPreparedModelCatalogWorker).toHaveBeenCalledOnce();
857+
await expect(refreshStalePreparedModelRuntimeCatalog(advanced)).resolves.toBeUndefined();
858+
});
813859
});
814860

815861
afterEach(async ({ task }) => {

0 commit comments

Comments
 (0)