@@ -143,10 +143,9 @@ export interface AcpSessionRuntimeStartResult {
143143 | EffectAcpSchema . ResumeSessionResponse ;
144144 readonly modelConfigId : string | undefined ;
145145 /**
146- * Latest `session/update` `available_commands_update` payload captured during
147- * (or after) start. Grok advertises slash commands and skills this way; the
148- * update often arrives before `session/new` resolves, so the runtime must
149- * record it even while start is still in flight.
146+ * Latest root-session `available_commands_update` catalog. Captured during
147+ * start (Grok often emits it before `session/new` resolves) and refreshed on
148+ * subsequent `start()` reads from the live ref so late updates are not lost.
150149 */
151150 readonly availableCommands : ReadonlyArray < EffectAcpSchema . AvailableCommand > ;
152151}
@@ -427,11 +426,17 @@ export const make = (
427426
428427 yield * acp . handleSessionUpdate ( ( notification ) =>
429428 Effect . gen ( function * ( ) {
430- // Capture skill/slash catalogs even while start is in flight. Grok emits
431- // `available_commands_update` before `session/new` resolves; dropping it
432- // here is what left provider status with empty skills (issue #4109).
429+ const startState = yield * Ref . get ( startStateRef ) ;
430+
431+ // Capture skill/slash catalogs during start (Grok emits
432+ // `available_commands_update` before `session/new` resolves). After the
433+ // root session is known, ignore child/foreign session catalogs.
433434 if ( notification . update . sessionUpdate === "available_commands_update" ) {
434- yield * Ref . set ( availableCommandsRef , notification . update . availableCommands ) ;
435+ const acceptCatalog =
436+ startState . _tag !== "Started" || notification . sessionId === startState . result . sessionId ;
437+ if ( acceptCatalog ) {
438+ yield * Ref . set ( availableCommandsRef , notification . update . availableCommands ) ;
439+ }
435440 }
436441
437442 const gate = yield * Ref . get ( sessionLoadGateRef ) ;
@@ -449,7 +454,6 @@ export const make = (
449454 if ( sessionUpdateIsReplay ( notification ) ) {
450455 return ;
451456 }
452- const startState = yield * Ref . get ( startStateRef ) ;
453457 // One runtime projects one root ACP session. Child-session updates need
454458 // explicit lineage routing and must never be flattened into this stream.
455459 if (
@@ -594,6 +598,10 @@ export const make = (
594598 ) ;
595599
596600 const startOnce = Effect . gen ( function * ( ) {
601+ // Each attempt starts with a clean catalog so a failed startup cannot
602+ // leak stale available_commands into a later retry.
603+ yield * Ref . set ( availableCommandsRef , [ ] ) ;
604+
597605 const initializePayload = {
598606 protocolVersion : 1 ,
599607 clientCapabilities : initializeClientCapabilities ,
@@ -743,7 +751,17 @@ export const make = (
743751 const effect = yield * Ref . modify ( startStateRef , ( state ) => {
744752 switch ( state . _tag ) {
745753 case "Started" :
746- return [ Effect . succeed ( state . result ) , state ] as const ;
754+ // Re-read the live ref so post-start available_commands_update is
755+ // visible on subsequent start() calls (not only the one-shot snapshot).
756+ return [
757+ Ref . get ( availableCommandsRef ) . pipe (
758+ Effect . map ( ( availableCommands ) => ( {
759+ ...state . result ,
760+ availableCommands,
761+ } ) ) ,
762+ ) ,
763+ state ,
764+ ] as const ;
747765 case "Starting" :
748766 return [ Deferred . await ( state . deferred ) , state ] as const ;
749767 case "NotStarted" :
@@ -757,6 +775,7 @@ export const make = (
757775 Effect . onError ( ( cause ) =>
758776 Deferred . failCause ( deferred , cause ) . pipe (
759777 Effect . andThen ( Ref . set ( startStateRef , { _tag : "NotStarted" } ) ) ,
778+ Effect . andThen ( Ref . set ( availableCommandsRef , [ ] ) ) ,
760779 ) ,
761780 ) ,
762781 ) ,
0 commit comments