@@ -1554,72 +1554,64 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
15541554 } ) ,
15551555 ) ;
15561556
1557- it . effect ( "lists top-level Codex sessions but not the subagents they spawned " , ( ) =>
1557+ it . effect ( "excludes Codex subagents from discovery and the recent-thread budget " , ( ) =>
15581558 Effect . gen ( function * ( ) {
15591559 const path = yield * Path . Path ;
15601560 const nowMs = Date . parse ( "2026-08-24T12:00:00.000Z" ) ;
15611561 yield * TestClock . setTime ( nowMs ) ;
15621562 const claudeHomePath = yield * makeTempDir ( "t3code-claude-home-" ) ;
15631563 const codexHomePath = yield * makeTempDir ( "t3code-codex-home-" ) ;
15641564 const workspace = yield * makeTempDir ( "t3code-workspace-" ) ;
1565- const sessions = [
1566- [ "parent" , "vscode" ] ,
1567- [ "no-source" , undefined ] ,
1568- [ "null-source" , null ] ,
1569- [ "object-source" , { custom : "launcher" } ] ,
1570- [
1571- "spawned" ,
1572- {
1573- subagent : {
1574- thread_spawn : { parent_thread_id : "parent" , depth : 1 , agent_path : "/root/worker" } ,
1575- } ,
1576- } ,
1577- ] ,
1578- [ "review" , { subagent : "review" } ] ,
1579- [ "guardian" , { subagent : { other : "guardian" } } ] ,
1580- [ "compact" , { subAgent : "compact" } ] ,
1581- ] as const ;
1582-
1583- for ( const [ index , [ id , source ] ] of sessions . entries ( ) ) {
1565+ const subagentSources = [
1566+ { subagent : { thread_spawn : { parent_thread_id : "session-100" , depth : 1 } } } ,
1567+ { subagent : "review" } ,
1568+ { subagent : { other : "guardian" } } ,
1569+ { subAgent : "compact" } ,
1570+ ] ;
1571+ // Newer subagents would exhaust the 100-transcript import budget before any parent.
1572+ const sources = [
1573+ ...Array . from ( { length : 100 } , ( _ , index ) => subagentSources [ index % 4 ] ) ,
1574+ "vscode" ,
1575+ undefined ,
1576+ null ,
1577+ { custom : "launcher" } ,
1578+ ] ;
1579+ for ( const [ index , source ] of sources . entries ( ) ) {
15841580 yield * writeTranscript ( {
15851581 filePath : path . join (
15861582 codexHomePath ,
15871583 "sessions" ,
15881584 "2026" ,
15891585 "08" ,
15901586 "24" ,
1591- `rollout-${ id } .jsonl` ,
1587+ `rollout-${ index } .jsonl` ,
15921588 ) ,
15931589 contents : [
1594- encodeTranscriptRecord ( {
1595- type : "session_meta" ,
1596- payload : { id, cwd : workspace , ...( source === undefined ? { } : { source } ) } ,
1597- } ) ,
1598- // Codex repeats the cwd on every turn, so the skip must not fall through to it.
1599- encodeTranscriptRecord ( { type : "turn_context" , payload : { cwd : workspace } } ) ,
1600- encodeTranscriptRecord ( {
1590+ { type : "session_meta" , payload : { id : `session-${ index } ` , cwd : workspace , source } } ,
1591+ // A later cwd must not make an excluded rollout eligible again.
1592+ { type : "turn_context" , payload : { cwd : workspace } } ,
1593+ {
16011594 type : "event_msg" ,
1602- payload : { type : "user_message" , message : `Prompt for ${ id } ` } ,
1603- } ) ,
1604- ] . join ( "\n" ) ,
1605- mtimeMs : nowMs - ( index + 1 ) * 60_000 ,
1595+ payload : { type : "user_message" , message : "Import this prompt" } ,
1596+ } ,
1597+ ]
1598+ . map ( ( record ) => encodeTranscriptRecord ( record ) )
1599+ . join ( "\n" ) ,
1600+ mtimeMs : nowMs - index * 60_000 ,
16061601 } ) ;
16071602 }
16081603
1609- // One scanner instance, so the import reuses the candidates cached by the scan.
1610- const { scan, outcomes } = yield * Effect . gen ( function * ( ) {
1604+ yield * Effect . gen ( function * ( ) {
16111605 const scanner = yield * AgentSessionScanner . AgentSessionScanner ;
16121606 const scan = yield * scanner . scan ;
1607+ expect . soft ( scan . candidates . map ( ( candidate ) => candidate . threadCount ) ) . toEqual ( [ 4 ] ) ;
16131608 const outcomes = yield * Stream . runCollect ( scanner . recentThreads ( workspace ) ) ;
1614- return { scan, outcomes : Array . from ( outcomes ) } ;
1609+ expect (
1610+ outcomes . map ( ( outcome ) =>
1611+ outcome . _tag === "Importable" ? outcome . thread . providerSessionId : outcome . _tag ,
1612+ ) ,
1613+ ) . toEqual ( [ "session-100" , "session-101" , "session-102" , "session-103" ] ) ;
16151614 } ) . pipe ( Effect . provide ( layerScannerTest ( { claudeHomePath, codexHomePath } ) ) ) ;
1616-
1617- expect ( scan . candidates . map ( ( candidate ) => candidate . threadCount ) ) . toEqual ( [ 4 ] ) ;
1618- expect (
1619- outcomes . map ( ( outcome ) =>
1620- outcome . _tag === "Importable" ? outcome . thread . providerSessionId : outcome . _tag ,
1621- ) ,
1622- ) . toEqual ( [ "parent" , "no-source" , "null-source" , "object-source" ] ) ;
16231615 } ) ,
16241616 ) ;
16251617
0 commit comments