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