@@ -44,13 +44,16 @@ it.effect.each(
4444 [ true , "with interrupting native steering" ] ,
4545 [ true , "settled only" ] ,
4646 [ false , "during continuation" ] ,
47+ [ "question" , "during delivery" ] ,
4748 ] as const
48- ) . map ( ( [ mailbox , timing ] ) => ( {
49- mailbox,
49+ ) . map ( ( [ kind , timing ] ) => ( {
50+ mailbox : kind === true ,
51+ question : kind === "question" ,
5052 timing,
51- label : mailbox ? "mailbox notification" : "steering" ,
53+ label :
54+ kind === "question" ? "delegated task question" : kind ? "mailbox notification" : "steering" ,
5255 } ) ) ,
53- ) ( "delivers $label when completion wins $timing" , ( { mailbox, timing } ) =>
56+ ) ( "delivers $label when completion wins $timing" , ( { mailbox, question , timing } ) =>
5457 Effect . scoped (
5558 Effect . gen ( function * ( ) {
5659 const cwd = yield * checkpointWorkspace ( `steering-completion-${ timing . replaceAll ( " " , "-" ) } ` ) ;
@@ -255,6 +258,21 @@ it.effect.each(
255258 ] ,
256259 } ) ;
257260 }
261+ if ( question ) {
262+ const { thread } = yield * orchestrator . getThreadProjection ( threadId ) ;
263+ yield * ( yield * EventSink . EventSinkV2 ) . write ( {
264+ events : [
265+ {
266+ id : EventId . make ( "event:composer-selection" ) ,
267+ type : "thread.model-selection-updated" ,
268+ threadId,
269+ providerInstanceId : instanceId ,
270+ occurredAt : yield * DateTime . now ,
271+ payload : { ...thread , modelSelection : composerSelection } ,
272+ } ,
273+ ] ,
274+ } ) ;
275+ }
258276 const dispatchSteer = orchestrator . dispatch ( {
259277 type : "message.dispatch" ,
260278 commandId : CommandId . make ( "steer" ) ,
@@ -270,11 +288,21 @@ it.effect.each(
270288 sizeBytes : 10 ,
271289 } ,
272290 ] ,
273- dispatchMode : mailbox
274- ? { type : "queue_after_active" }
275- : { type : "steer_active" , targetRunId : first . runId } ,
276- createdBy : mailbox ? "agent" : "user" ,
277- creationSource : mailbox ? "server" : "web" ,
291+ dispatchMode :
292+ mailbox || question
293+ ? { type : "queue_after_active" }
294+ : { type : "steer_active" , targetRunId : first . runId } ,
295+ createdBy : mailbox || question ? "agent" : "user" ,
296+ creationSource : mailbox || question ? "server" : "web" ,
297+ ...( question
298+ ? {
299+ notification : {
300+ source : { kind : "delegated_task" , taskIds : [ taskId ] } ,
301+ outcome : "updated" ,
302+ summary : "Delegated task has a question" ,
303+ } ,
304+ }
305+ : { } ) ,
278306 ...( mailbox
279307 ? {
280308 delegatedCompletion : {
@@ -340,6 +368,8 @@ it.effect.each(
340368 if ( delivery !== null ) {
341369 yield * Deferred . succeed ( rejectSteer , undefined ) ;
342370 yield * Fiber . join ( delivery ) ;
371+ }
372+ if ( delivery !== null && ! question ) {
343373 const requeued = yield * orchestrator . getThreadProjection ( threadId ) ;
344374 const item = requeued . turnItems . find (
345375 ( item ) => item . type === "user_message" && item . messageId === messageId ,
@@ -399,7 +429,11 @@ it.effect.each(
399429 ] ) ;
400430 assert . equal ( steerCalls , timing === "during delivery" ? 1 : 0 ) ;
401431 const final = yield * orchestrator . getThreadProjection ( threadId ) ;
402- if ( ! mailbox ) {
432+ if ( question ) {
433+ assert . deepEqual ( final . thread . modelSelection , composerSelection ) ;
434+ assert . deepEqual ( started [ 1 ] ?. modelSelection , composerSelection ) ;
435+ }
436+ if ( ! mailbox && ! question ) {
403437 assert . equal (
404438 final . turnItems . find (
405439 ( item ) => item . type === "user_message" && item . messageId === messageId ,
@@ -414,7 +448,7 @@ it.effect.each(
414448 ) ;
415449 assert . equal (
416450 final . turnItems . filter ( ( item ) =>
417- mailbox
451+ mailbox || question
418452 ? item . type === "notification"
419453 : item . type === "user_message" && item . messageId === messageId ,
420454 ) . length ,
@@ -617,6 +651,65 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*
617651 return { cwd, events, started, steered, interrupted, layer, startFirstTurn } ;
618652} ) ;
619653
654+ it . effect ( "steers a delegated task question notice into the running parent turn" , ( ) =>
655+ Effect . scoped (
656+ Effect . gen ( function * ( ) {
657+ const { started, steered, layer, startFirstTurn } = yield * nextTurnSelectionHarness (
658+ "delegated-question-steer" ,
659+ ) ;
660+ yield * Effect . gen ( function * ( ) {
661+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
662+ const worker = yield * EffectWorker . OrchestrationEffectWorkerV2 ;
663+ const threadId = yield * startFirstTurn ;
664+ const { thread } = yield * orchestrator . getThreadProjection ( threadId ) ;
665+ yield * ( yield * EventSink . EventSinkV2 ) . write ( {
666+ events : [
667+ {
668+ id : EventId . make ( "event:composer-selection" ) ,
669+ type : "thread.model-selection-updated" ,
670+ threadId,
671+ providerInstanceId : instanceId ,
672+ occurredAt : yield * DateTime . now ,
673+ payload : { ...thread , modelSelection : composerSelection } ,
674+ } ,
675+ ] ,
676+ } ) ;
677+ const messageId = MessageId . make ( "message:delegated-task-question:child-question" ) ;
678+ const notification = {
679+ source : {
680+ kind : "delegated_task" as const ,
681+ taskIds : [ NodeId . make ( "task:question" ) ] ,
682+ childThreadId : ThreadId . make ( "thread:question-child" ) ,
683+ } ,
684+ outcome : "updated" as const ,
685+ summary : "Delegated task has a question" ,
686+ } ;
687+ yield * orchestrator . dispatch ( {
688+ type : "message.dispatch" ,
689+ commandId : CommandId . make ( "question-wake" ) ,
690+ threadId,
691+ messageId,
692+ text : "Delegated task asked a question" ,
693+ notification,
694+ attachments : [ ] ,
695+ dispatchMode : { type : "queue_after_active" } ,
696+ createdBy : "agent" ,
697+ creationSource : "server" ,
698+ } ) ;
699+ yield * worker . drain ( ) ;
700+ const after = yield * orchestrator . getThreadProjection ( threadId ) ;
701+ assert . deepEqual ( steered , [ "Delegated task asked a question" ] ) ;
702+ assert . lengthOf ( started , 1 ) ;
703+ assert . isFalse ( after . runs . some ( ( run ) => run . status === "queued" ) ) ;
704+ const message = after . messages . find ( ( candidate ) => candidate . id === messageId ) ;
705+ assert . equal ( message ?. runId , started [ 0 ] ?. runId ) ;
706+ assert . deepEqual ( message ?. notification , notification ) ;
707+ assert . deepEqual ( after . thread . modelSelection , composerSelection ) ;
708+ } ) . pipe ( Effect . provide ( layer ) ) ;
709+ } ) ,
710+ ) ,
711+ ) ;
712+
620713it . effect ( "sends a selected held message once and preserves the remaining queue order" , ( ) =>
621714 Effect . scoped (
622715 Effect . gen ( function * ( ) {
0 commit comments