@@ -920,6 +920,51 @@ describe("chat pane connection lifecycle", () => {
920920 expect ( state . chatIsProgrammaticScroll ) . toBe ( false ) ;
921921 } ) ;
922922
923+ it ( "retires pending model selection state when the Gateway owner changes" , ( ) => {
924+ const client = { request : vi . fn ( ) } as unknown as GatewayBrowserClient ;
925+ const setModelOverride = vi . fn ( ) ;
926+ const sessions = { setModelOverride } as unknown as SessionCapability ;
927+ const { pane, state } = createTestChatPane ( { client, sessions } ) ;
928+ state . sessionKey = "global" ;
929+ state . chatModelSwitchPromises = {
930+ global : new Promise < boolean > ( ( ) => { } ) ,
931+ } ;
932+
933+ pane . applyGatewaySnapshot ( {
934+ ...pane . context . gateway . snapshot ,
935+ client,
936+ phase : "reconnecting" ,
937+ hello : null ,
938+ } ) ;
939+
940+ expect ( state . chatModelSwitchPromises ) . toEqual ( { } ) ;
941+ expect ( setModelOverride ) . toHaveBeenCalledWith ( "global" , undefined ) ;
942+ } ) ;
943+
944+ it ( "retires pending global model selection state when the selected agent changes" , ( ) => {
945+ const client = { request : vi . fn ( ) } as unknown as GatewayBrowserClient ;
946+ const setModelOverride = vi . fn ( ) ;
947+ const sessions = { setModelOverride } as unknown as SessionCapability ;
948+ const { pane, state } = createTestChatPane ( { client, sessions } ) ;
949+ const snapshot = {
950+ ...pane . context . gateway . snapshot ,
951+ client,
952+ phase : "connected" as const ,
953+ assistantAgentId : "work" ,
954+ } ;
955+ pane . applyGatewaySnapshot ( snapshot ) ;
956+ state . sessionKey = "global" ;
957+ state . chatModelSwitchPromises = {
958+ global : new Promise < boolean > ( ( ) => { } ) ,
959+ } ;
960+ setModelOverride . mockClear ( ) ;
961+
962+ pane . applyGatewaySnapshot ( { ...snapshot , assistantAgentId : "main" } ) ;
963+
964+ expect ( state . chatModelSwitchPromises ) . toEqual ( { } ) ;
965+ expect ( setModelOverride ) . toHaveBeenCalledWith ( "global" , undefined ) ;
966+ } ) ;
967+
923968 it ( "refreshes the transcript before secondary hydration after a same-client reconnect" , ( ) => {
924969 const request = vi . fn ( ( ) => new Promise < never > ( ( ) => { } ) ) ;
925970 const client = {
0 commit comments