@@ -152,9 +152,9 @@ import {
152152 ASK_DIRECTOR_MAX_BYTES ,
153153 ASK_DIRECTOR_MAX_QUESTIONS ,
154154 createAskDirectorState ,
155+ createDeferredContinuation ,
155156 handleAskDirector ,
156157 resetAskDirectorTurn ,
157- skipStallContinuationWhileAskPending ,
158158} from "./ask-director.js" ;
159159import {
160160 abortError ,
@@ -625,6 +625,8 @@ async function runSubAgentInner(
625625 let turnToken = params . tier === "leaf" ? generateSessionId ( ) : undefined ;
626626 const submitResultState = createSubmitResultState ( ) ;
627627 const askDirectorState = createAskDirectorState ( ) ;
628+ const compactContinue = createDeferredContinuation ( ) ;
629+ let deliverCompactContinue = ( ) : void => undefined ;
628630 const spawnRegistry = createSubAgentSpawnRegistryPlugin ( ) ;
629631 // Assigned inside the try once the agent handle exists; before that (or after
630632 // close) a completion is dropped, matching the continuation contract.
@@ -862,12 +864,16 @@ async function runSubAgentInner(
862864 "Record the question under Blockers and finish with the markdown report envelope."
863865 ) ;
864866 }
865- return handleAskDirector ( {
866- question : rawArgs . question ,
867- state : askDirectorState ,
868- port,
869- signal,
870- } ) ;
867+ try {
868+ return await handleAskDirector ( {
869+ question : rawArgs . question ,
870+ state : askDirectorState ,
871+ port,
872+ signal,
873+ } ) ;
874+ } finally {
875+ compactContinue . flush ( askDirectorState , deliverCompactContinue ) ;
876+ }
871877 } ,
872878 } ) ,
873879 ] ;
@@ -1038,13 +1044,14 @@ async function runSubAgentInner(
10381044 ReturnType < typeof createAgentWithLiveToolDispatch >
10391045 > | null = null ;
10401046 const requestContinuation = ( ) : void => {
1041- skipStallContinuationWhileAskPending ( askDirectorState , ( ) => {
1042- try {
1043- agentHandle ?. deliver ( buildCompactionContinuationMessage ( ) ) ;
1044- } catch {
1045- // Agent may be closing; a dropped continuation is harmless.
1046- }
1047- } ) ;
1047+ compactContinue . request ( askDirectorState , deliverCompactContinue ) ;
1048+ } ;
1049+ deliverCompactContinue = ( ) : void => {
1050+ try {
1051+ agentHandle ?. deliver ( buildCompactionContinuationMessage ( ) ) ;
1052+ } catch {
1053+ // Agent may be closing; a dropped continuation is harmless.
1054+ }
10481055 } ;
10491056
10501057 // modelFamilyPolicy is resolved above at the skill mount so the
0 commit comments