@@ -123,8 +123,11 @@ vi.mock("../agents/subagent-registry.js", () => ({
123123 scheduleSubagentOrphanRecovery : hoisted . scheduleSubagentOrphanRecovery ,
124124} ) ) ;
125125
126- vi . mock ( "../agents/main-session-restart-recovery.js" , ( ) => ( {
126+ vi . mock ( "../agents/main-session-restart-recovery-marking .js" , ( ) => ( {
127127 markStartupOrphanedMainSessionsForRecovery : hoisted . markStartupOrphanedMainSessionsForRecovery ,
128+ } ) ) ;
129+
130+ vi . mock ( "../agents/main-session-restart-recovery.js" , ( ) => ( {
128131 scheduleRestartAbortedMainSessionRecovery : hoisted . scheduleRestartAbortedMainSessionRecovery ,
129132} ) ) ;
130133
@@ -1812,9 +1815,12 @@ describe("startGatewayPostAttachRuntime", () => {
18121815 } ) ;
18131816 } ) ;
18141817
1815- it ( "marks startup main-session orphans before channel startup" , async ( ) => {
1818+ it ( "marks startup main-session orphans before model runtime and channel startup" , async ( ) => {
18161819 const events : string [ ] = [ ] ;
18171820 let releaseMarking : ( ( ) => void ) | undefined ;
1821+ const prewarmPrimaryModel = vi . fn ( async ( ) => {
1822+ events . push ( "model-runtime" ) ;
1823+ } ) ;
18181824 const startChannels = vi . fn ( async ( ) => {
18191825 events . push ( "channels" ) ;
18201826 } ) ;
@@ -1835,6 +1841,7 @@ describe("startGatewayPostAttachRuntime", () => {
18351841 defaultWorkspaceDir : "/tmp/openclaw-workspace" ,
18361842 deps : { } as never ,
18371843 startChannels,
1844+ prewarmPrimaryModel,
18381845 log : { warn : vi . fn ( ) } ,
18391846 logHooks : {
18401847 info : vi . fn ( ) ,
@@ -1858,11 +1865,54 @@ describe("startGatewayPostAttachRuntime", () => {
18581865 releaseMarking ( ) ;
18591866 await sidecars ;
18601867
1861- expect ( events ) . toEqual ( [ "main-session-mark:start" , "main-session-mark:done" , "channels" ] ) ;
1868+ expect ( events ) . toEqual ( [
1869+ "main-session-mark:start" ,
1870+ "main-session-mark:done" ,
1871+ "model-runtime" ,
1872+ "channels" ,
1873+ ] ) ;
1874+ expect ( prewarmPrimaryModel ) . toHaveBeenCalledTimes ( 1 ) ;
18621875 expect ( startChannels ) . toHaveBeenCalledTimes ( 1 ) ;
18631876 expect ( hoisted . scheduleRestartAbortedMainSessionRecovery ) . not . toHaveBeenCalled ( ) ;
18641877 } ) ;
18651878
1879+ it ( "marks startup main-session orphans before propagating model runtime failure" , async ( ) => {
1880+ const modelRuntimeError = new Error ( "model runtime unavailable" ) ;
1881+ const startChannels = vi . fn ( async ( ) => { } ) ;
1882+ const prewarmPrimaryModel = vi . fn ( async ( ) => {
1883+ throw modelRuntimeError ;
1884+ } ) ;
1885+ hoisted . markStartupOrphanedMainSessionsForRecovery . mockResolvedValueOnce ( {
1886+ marked : 1 ,
1887+ skipped : 0 ,
1888+ } ) ;
1889+
1890+ await expect (
1891+ startGatewaySidecars ( {
1892+ cfg : { hooks : { internal : { enabled : false } } } as never ,
1893+ pluginRegistry : createPostAttachParams ( ) . pluginRegistry ,
1894+ defaultWorkspaceDir : "/tmp/openclaw-workspace" ,
1895+ deps : { } as never ,
1896+ startChannels,
1897+ prewarmPrimaryModel,
1898+ log : { warn : vi . fn ( ) } ,
1899+ logHooks : {
1900+ info : vi . fn ( ) ,
1901+ warn : vi . fn ( ) ,
1902+ error : vi . fn ( ) ,
1903+ } ,
1904+ logChannels : {
1905+ info : vi . fn ( ) ,
1906+ error : vi . fn ( ) ,
1907+ } ,
1908+ } ) ,
1909+ ) . rejects . toBe ( modelRuntimeError ) ;
1910+
1911+ expect ( hoisted . markStartupOrphanedMainSessionsForRecovery ) . toHaveBeenCalledTimes ( 1 ) ;
1912+ expect ( prewarmPrimaryModel ) . toHaveBeenCalledTimes ( 1 ) ;
1913+ expect ( startChannels ) . not . toHaveBeenCalled ( ) ;
1914+ } ) ;
1915+
18661916 it ( "logs startup main-session marker failures and still starts channels" , async ( ) => {
18671917 const log = { warn : vi . fn ( ) } ;
18681918 const startChannels = vi . fn ( async ( ) => { } ) ;
0 commit comments