@@ -1500,3 +1500,43 @@ it.effect("keeps the host connected when a background status read times out", ()
15001500 } ) ,
15011501 ) ,
15021502) ;
1503+
1504+ it . effect ( "keeps each thread's current tab when threads share a provider session" , ( ) =>
1505+ Effect . scoped (
1506+ Effect . gen ( function * ( ) {
1507+ const broker = yield * makeBroker ;
1508+ const routed : Array < RoutedRequest > = [ ] ;
1509+ const requests = requestsFrom ( yield * broker . connect ( makeHost ( ) , { preferred : true } ) ) ;
1510+ yield * Stream . runForEach ( requests , ( request ) => {
1511+ routed . push ( request ) ;
1512+ return broker . respond ( {
1513+ clientId : "client-1" ,
1514+ connectionId : request . connectionId ,
1515+ requestId : request . requestId ,
1516+ ok : true ,
1517+ result : { tabId : request . tabId ?? `tab-${ request . threadId } ` } ,
1518+ } ) ;
1519+ } ) . pipe ( Effect . forkScoped ) ;
1520+ yield * Effect . yieldNow ;
1521+ // Codex runs every thread of an instance in one provider session.
1522+ const otherThread = {
1523+ ...scope ,
1524+ thread : { ...scope . thread , threadId : ThreadId . make ( "thread-2" ) } ,
1525+ } ;
1526+
1527+ yield * broker . invoke ( { scope, operation : "open" , input : { } } ) ;
1528+ yield * broker . invoke ( { scope : otherThread , operation : "snapshot" , input : { } } ) ;
1529+ yield * broker . invoke ( { scope, operation : "snapshot" , input : { } } ) ;
1530+ yield * broker . invoke ( { scope : otherThread , operation : "snapshot" , input : { } } ) ;
1531+
1532+ expect ( routed . map ( ( { threadId, tabId } ) => [ threadId , tabId ] ) ) . toEqual ( [
1533+ [ "thread-1" , undefined ] ,
1534+ [ "thread-2" , undefined ] ,
1535+ [ "thread-1" , "tab-thread-1" ] ,
1536+ [ "thread-2" , "tab-thread-2" ] ,
1537+ ] ) ;
1538+ // Each thread's agent owns its own tabs and tab budget.
1539+ expect ( routed [ 0 ] ! . agentSessionId ) . not . toBe ( routed [ 1 ] ! . agentSessionId ) ;
1540+ } ) ,
1541+ ) ,
1542+ ) ;
0 commit comments