@@ -251,7 +251,8 @@ function App() {
251251 } )
252252 local . model . set ( { providerID, modelID } , { recent : true } )
253253 }
254- if ( args . sessionID ) {
254+ // Handle --session without --fork immediately (fork is handled in createEffect below)
255+ if ( args . sessionID && ! args . fork ) {
255256 route . navigate ( {
256257 type : "session" ,
257258 sessionID : args . sessionID ,
@@ -269,10 +270,36 @@ function App() {
269270 . find ( ( x ) => x . parentID === undefined ) ?. id
270271 if ( match ) {
271272 continued = true
272- route . navigate ( { type : "session" , sessionID : match } )
273+ if ( args . fork ) {
274+ sdk . client . session . fork ( { sessionID : match } ) . then ( ( result ) => {
275+ if ( result . data ?. id ) {
276+ route . navigate ( { type : "session" , sessionID : result . data . id } )
277+ } else {
278+ toast . show ( { message : "Failed to fork session" , variant : "error" } )
279+ }
280+ } )
281+ } else {
282+ route . navigate ( { type : "session" , sessionID : match } )
283+ }
273284 }
274285 } )
275286
287+ // Handle --session with --fork: wait for sync to be fully complete before forking
288+ // (session list loads in non-blocking phase for --session, so we must wait for "complete"
289+ // to avoid a race where reconcile overwrites the newly forked session)
290+ let forked = false
291+ createEffect ( ( ) => {
292+ if ( forked || sync . status !== "complete" || ! args . sessionID || ! args . fork ) return
293+ forked = true
294+ sdk . client . session . fork ( { sessionID : args . sessionID } ) . then ( ( result ) => {
295+ if ( result . data ?. id ) {
296+ route . navigate ( { type : "session" , sessionID : result . data . id } )
297+ } else {
298+ toast . show ( { message : "Failed to fork session" , variant : "error" } )
299+ }
300+ } )
301+ } )
302+
276303 createEffect (
277304 on (
278305 ( ) => sync . status === "complete" && sync . data . provider . length === 0 ,
0 commit comments