@@ -67,7 +67,7 @@ const hoisted = vi.hoisted(() => {
6767 async ( _cfg ?: unknown , _options ?: unknown ) => { } ,
6868 ) ;
6969 const loadAgentRuntimePluginRegistryHandle = vi . fn ( ) ;
70- const ensureContextWindowCacheLoaded = vi . fn ( async ( ) => { } ) ;
70+ const prewarmContextWindowCacheAfterReady = vi . fn ( async ( ) => { } ) ;
7171 const scheduleGatewayHandlerPrewarm = vi . fn ( ( ) => ( { stop : vi . fn ( ) } ) ) ;
7272 const clearCurrentProviderAuthState = vi . fn ( ) ;
7373 const warmCurrentProviderAuthStateOffMainThread = vi . fn (
@@ -107,7 +107,7 @@ const hoisted = vi.hoisted(() => {
107107 prepareModelRuntimeSnapshot,
108108 refreshPreparedModelRuntimeSnapshots,
109109 loadAgentRuntimePluginRegistryHandle,
110- ensureContextWindowCacheLoaded ,
110+ prewarmContextWindowCacheAfterReady ,
111111 scheduleGatewayHandlerPrewarm,
112112 clearCurrentProviderAuthState,
113113 warmCurrentProviderAuthStateOffMainThread,
@@ -217,7 +217,7 @@ vi.mock("../agents/runtime-plugins.js", () => ({
217217} ) ) ;
218218
219219vi . mock ( "../agents/context.js" , ( ) => ( {
220- ensureContextWindowCacheLoaded : hoisted . ensureContextWindowCacheLoaded ,
220+ prewarmContextWindowCacheAfterReady : hoisted . prewarmContextWindowCacheAfterReady ,
221221} ) ) ;
222222
223223vi . mock ( "./server-startup-handler-prewarm.js" , ( ) => ( {
@@ -368,8 +368,8 @@ describe("startGatewayPostAttachRuntime", () => {
368368 hoisted . refreshPreparedModelRuntimeSnapshots . mockReset ( ) ;
369369 hoisted . refreshPreparedModelRuntimeSnapshots . mockResolvedValue ( undefined ) ;
370370 hoisted . loadAgentRuntimePluginRegistryHandle . mockReset ( ) ;
371- hoisted . ensureContextWindowCacheLoaded . mockReset ( ) ;
372- hoisted . ensureContextWindowCacheLoaded . mockResolvedValue ( undefined ) ;
371+ hoisted . prewarmContextWindowCacheAfterReady . mockReset ( ) ;
372+ hoisted . prewarmContextWindowCacheAfterReady . mockResolvedValue ( undefined ) ;
373373 hoisted . scheduleGatewayHandlerPrewarm . mockClear ( ) ;
374374 hoisted . clearCurrentProviderAuthState . mockClear ( ) ;
375375 hoisted . warmCurrentProviderAuthStateOffMainThread . mockReset ( ) ;
@@ -1258,32 +1258,34 @@ describe("startGatewayPostAttachRuntime", () => {
12581258
12591259 it ( "defers context-window cache prewarm to a post-ready sidecar" , async ( ) => {
12601260 vi . useFakeTimers ( ) ;
1261- const cfg = { agents : { defaults : { model : "openai/gpt-5.5" } } } as never ;
1261+ const startupConfig = { agents : { defaults : { model : "openai/gpt-5.5" } } } ;
1262+ const currentConfig = { ...startupConfig } ;
12621263 const admission = tryBeginGatewayRootWorkAdmission ( ) ;
12631264 if ( ! admission ) {
12641265 throw new Error ( "Expected request work admission" ) ;
12651266 }
12661267 const sidecar = scheduleContextCachePrewarm ( {
1267- cfgAtStart : cfg ,
1268+ getConfig : ( ) => currentConfig ,
12681269 log : { warn : vi . fn ( ) } ,
12691270 } ) ;
12701271
12711272 try {
1272- // Earlier gateway lifetimes may finish during the fake-clock window;
1273- // this sidecar's captured config identifies its own prewarm precisely.
1274- expect ( hoisted . ensureContextWindowCacheLoaded ) . not . toHaveBeenCalledWith ( cfg ) ;
1273+ expect ( hoisted . prewarmContextWindowCacheAfterReady ) . not . toHaveBeenCalled ( ) ;
12751274 await vi . advanceTimersByTimeAsync ( 4_999 ) ;
1276- expect ( hoisted . ensureContextWindowCacheLoaded ) . not . toHaveBeenCalledWith ( cfg ) ;
1275+ expect ( hoisted . prewarmContextWindowCacheAfterReady ) . not . toHaveBeenCalled ( ) ;
12771276 await vi . advanceTimersByTimeAsync ( 1 ) ;
1278- expect ( hoisted . ensureContextWindowCacheLoaded ) . not . toHaveBeenCalledWith ( cfg ) ;
1277+ expect ( hoisted . prewarmContextWindowCacheAfterReady ) . not . toHaveBeenCalled ( ) ;
12791278
12801279 admission . release ( ) ;
12811280 await vi . advanceTimersByTimeAsync ( 249 ) ;
1282- expect ( hoisted . ensureContextWindowCacheLoaded ) . not . toHaveBeenCalledWith ( cfg ) ;
1281+ expect ( hoisted . prewarmContextWindowCacheAfterReady ) . not . toHaveBeenCalled ( ) ;
12831282 await vi . advanceTimersByTimeAsync ( 1 ) ;
12841283 await vi . dynamicImportSettled ( ) ;
12851284 await waitForGatewayTestState ( ( ) => {
1286- expect ( hoisted . ensureContextWindowCacheLoaded ) . toHaveBeenCalledWith ( cfg ) ;
1285+ expect ( hoisted . prewarmContextWindowCacheAfterReady ) . toHaveBeenCalledWith ( {
1286+ config : currentConfig ,
1287+ isCancelled : expect . any ( Function ) ,
1288+ } ) ;
12871289 } ) ;
12881290 } finally {
12891291 admission . release ( ) ;
@@ -1294,13 +1296,13 @@ describe("startGatewayPostAttachRuntime", () => {
12941296 it ( "cancels context-window cache prewarm when the gateway stops first" , async ( ) => {
12951297 vi . useFakeTimers ( ) ;
12961298 const sidecar = scheduleContextCachePrewarm ( {
1297- cfgAtStart : { } as never ,
1299+ getConfig : ( ) => ( { } ) as never ,
12981300 log : { warn : vi . fn ( ) } ,
12991301 } ) ;
13001302
13011303 await sidecar . stop ( ) ;
13021304 await vi . runAllTimersAsync ( ) ;
1303- expect ( hoisted . ensureContextWindowCacheLoaded ) . not . toHaveBeenCalled ( ) ;
1305+ expect ( hoisted . prewarmContextWindowCacheAfterReady ) . not . toHaveBeenCalled ( ) ;
13041306 } ) ;
13051307
13061308 it ( "keeps provider auth prewarm alive when Gmail post-ready sidecars stop" , async ( ) => {
0 commit comments