@@ -178,6 +178,7 @@ const makeTestRelay = Effect.fnUntraced(function* (
178178 readonly respond ?: ( attempt : number ) => Response ;
179179 readonly failSecretRead ?: ( name : string ) => boolean ;
180180 readonly linked ?: boolean ;
181+ readonly startupThreads ?: ReadonlyArray < OrchestrationV2ThreadShell > ;
181182 readonly readShell ?: ( threadId : ThreadId ) => Effect . Effect < OrchestrationV2ThreadShell | null > ;
182183 readonly domainEvents ?: Stream . Stream < OrchestrationV2DomainEvent > ;
183184 } = { } ,
@@ -220,14 +221,24 @@ const makeTestRelay = Effect.fnUntraced(function* (
220221 Effect . sync ( ( ) => shellReads . push ( threadId ) ) . pipe (
221222 Effect . andThen ( options . readShell ?.( threadId ) ?? Ref . get ( currentShell ) ) ,
222223 ) ,
223- getShellSnapshot : ( ) =>
224+ getShellSnapshot : ( input ) =>
224225 Effect . sync ( ( ) => {
225226 catchUp . shellSnapshotReads += 1 ;
226- return { schemaVersion : 2 , snapshotSequence : 1 , threads : [ ] , archivedThreads : [ ] } ;
227+ return {
228+ schemaVersion : 2 ,
229+ snapshotSequence : 1 ,
230+ threads : ( options . startupThreads ?? [ ] ) . filter ( ( thread ) =>
231+ input ?. threadIds ?. includes ( thread . id ) ,
232+ ) ,
233+ archivedThreads : [ ] ,
234+ } ;
227235 } ) ,
228236 listActiveSubagentThreadIds : unused ,
229237 countThreads : unused ,
230- listActiveShellIndex : ( ) => Effect . succeed ( [ ] ) ,
238+ listActiveShellIndex : ( ) =>
239+ Effect . succeed (
240+ ( options . startupThreads ?? [ ] ) . map ( ( thread ) => ( { ...thread , mayBeLive : true } ) ) ,
241+ ) ,
231242 listOlderSettledThreads : unused ,
232243 readShellSnapshot : unused ,
233244 ensureLegacyTranscript : unused ,
@@ -329,6 +340,42 @@ const makeTestRelay = Effect.fnUntraced(function* (
329340} ) ;
330341
331342describe ( "AgentAwarenessRelay" , ( ) => {
343+ it . effect ( "publishes an approval already waiting at startup" , ( ) =>
344+ Effect . gen ( function * ( ) {
345+ const parent = shell ( { status : "idle" } ) ;
346+ const child = waitingChild ( ) ;
347+ const { relay, publications } = yield * makeTestRelay ( {
348+ startupThreads : [ parent , child ] ,
349+ readShell : ( id ) => Effect . succeed ( id === child . id ? child : parent ) ,
350+ } ) ;
351+ yield * relay . start ( ) ;
352+ yield * TestClock . adjust ( "1 second" ) ;
353+ yield * relay . drain ;
354+ assert . equal ( publications . length , 1 ) ;
355+ assert . equal ( publications [ 0 ] ?. state ?. threadId , THREAD_ID ) ;
356+ assert . equal ( publications [ 0 ] ?. state ?. phase , "waiting_for_approval" ) ;
357+ } ) . pipe ( Effect . scoped ) ,
358+ ) ;
359+
360+ it . effect ( "leaves coordinator-handled child questions out of phone activity" , ( ) =>
361+ Effect . gen ( function * ( ) {
362+ const child = waitingChild ( {
363+ pendingRuntimeRequest : {
364+ id : RuntimeRequestId . make ( "child-question" ) ,
365+ kind : "user_input" ,
366+ createdAt : DateTime . makeUnsafe ( NOW ) ,
367+ } ,
368+ } ) ;
369+ const { relay, publications } = yield * makeTestRelay ( {
370+ readShell : ( id ) => Effect . succeed ( id === child . id ? child : shell ( ) ) ,
371+ } ) ;
372+ yield * relay . publishThread ( THREAD_ID ) ;
373+ yield * relay . publishThread ( CHILD_THREAD_ID ) ;
374+ assert . equal ( publications . length , 1 ) ;
375+ assert . equal ( publications [ 0 ] ?. state ?. phase , "running" ) ;
376+ } ) ,
377+ ) ;
378+
332379 it . effect ( "publishes the parent as needing approval while its subagent waits" , ( ) =>
333380 Effect . gen ( function * ( ) {
334381 const shells = yield * Ref . make (
0 commit comments