Skip to content

Commit f2f90bc

Browse files
committed
fix(models): refresh stale catalogs after config updates
Publish config-stamped snapshots through the existing owner registry for config-only updates as well as ordinary and batch builds. Existing leases stay immutable and retain their auth bindings. Extend the stale-catalog regression; all 65 related tests pass. Related: #130324, #134361.
1 parent 113805d commit f2f90bc

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ export function resolvePreparedModelRuntimeOwnerBySnapshot(
5151
function publishPreparedModelRuntimeOwnerSnapshot(
5252
owner: PreparedModelRuntimeOwner,
5353
snapshot: PreparedModelRuntimeSnapshot,
54-
): void {
54+
): PreparedModelRuntimeSnapshot {
55+
const published = stampPreparedModelRuntimeSnapshotConfig(snapshot, owner.input.config);
5556
if (owner.snapshot) {
5657
ownersBySnapshot.delete(owner.snapshot);
5758
}
58-
owner.snapshot = snapshot;
59-
ownersBySnapshot.set(snapshot, owner);
59+
owner.snapshot = published;
60+
ownersBySnapshot.set(published, owner);
61+
return published;
6062
}
6163

6264
export type {
@@ -262,7 +264,7 @@ export function advancePreparedModelRuntimeOwnerConfig(
262264
if (owner.snapshot) {
263265
// Existing leases retain their immutable snapshot. New readers receive the same prepared
264266
// generation with only its planner-approved, model-neutral config stamp advanced.
265-
owner.snapshot = stampPreparedModelRuntimeSnapshotConfig(owner.snapshot, config);
267+
publishPreparedModelRuntimeOwnerSnapshot(owner, owner.snapshot);
266268
}
267269
}
268270

@@ -608,11 +610,7 @@ export async function publishPreparedModelRuntimeOwnerBatch(params: {
608610
`prepared model runtime snapshot missing after auth refresh for ${candidate.input.agentDir}`,
609611
);
610612
}
611-
const snapshot = stampPreparedModelRuntimeSnapshotConfig(
612-
result.snapshot,
613-
candidate.owner.input.config,
614-
);
615-
publishPreparedModelRuntimeOwnerSnapshot(candidate.owner, snapshot);
613+
const snapshot = publishPreparedModelRuntimeOwnerSnapshot(candidate.owner, result.snapshot);
616614
results.set(candidate.owner, { ...result, snapshot });
617615
candidate.owner.pluginGeneration = result.pluginGeneration;
618616
candidate.owner.needsRefresh = false;
@@ -682,8 +680,7 @@ export async function publishModelRuntimeSnapshot(
682680
`prepared model runtime publication was superseded for ${input.agentDir}`,
683681
);
684682
}
685-
const snapshot = stampPreparedModelRuntimeSnapshotConfig(result.snapshot, owner.input.config);
686-
publishPreparedModelRuntimeOwnerSnapshot(owner, snapshot);
683+
const snapshot = publishPreparedModelRuntimeOwnerSnapshot(owner, result.snapshot);
687684
owner.pluginGeneration = result.pluginGeneration;
688685
owner.pendingPluginGeneration = undefined;
689686
owner.pending = undefined;

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

Lines changed: 9 additions & 3 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,
@@ -68,8 +69,8 @@ describe("prepared model runtime reload auth adoption", () => {
6869
profileSetChanged: true,
6970
});
7071

71-
const published = await prepareModelRuntimeSnapshot(input);
72-
expect(published).toMatchObject({
72+
const authPublished = await prepareModelRuntimeSnapshot(input);
73+
expect(authPublished).toMatchObject({
7374
modelCatalog: { entries: [] },
7475
});
7576
expect(
@@ -78,9 +79,14 @@ describe("prepared model runtime reload auth adoption", () => {
7879
expect(mocks.buildPreparedModelCatalogSnapshot).not.toHaveBeenCalled();
7980
expect(mocks.runPreparedModelCatalogWorker).not.toHaveBeenCalled();
8081

82+
const nextConfig = { logging: { level: "debug" as const } };
83+
advancePreparedModelRuntimeConfig(nextConfig);
84+
const readInput = { ...input, config: nextConfig };
85+
const published = await prepareModelRuntimeSnapshot(readInput);
86+
8187
let requestReadSettled = false;
8288
const requestRead = loadPreparedModelCatalogOwnerSnapshot({
83-
...input,
89+
...readInput,
8490
readOnly: true,
8591
}).then(() => {
8692
requestReadSettled = true;

0 commit comments

Comments
 (0)