@@ -35,6 +35,7 @@ import {
3535 activeRuns ,
3636 cancelPendingBridgeStates ,
3737 cancelPendingBridgeStatesById ,
38+ codeModeAbortedResult ,
3839 codeModeWaitingReason ,
3940 createCodeModeBridgeDispatchState ,
4041 createPendingBridgeStates ,
@@ -295,16 +296,7 @@ async function settleCodeModeResult(params: {
295296 // rounds; maxPendingToolCalls stays a per-batch concurrency cap enforced in
296297 // the worker.
297298 const settleDeadline = ( ) => params . deadlineMs + params . approvalWait . pausedMs ;
298- const abortedResult = ( ) => ( {
299- status : "failed" as const ,
300- error : "code mode execution aborted" ,
301- code : "aborted" as const ,
302- failurePhase : params . bridgeDispatch . started ? ( "bridge" as const ) : ( "host" as const ) ,
303- bridgeDispatchStarted : params . bridgeDispatch . started ,
304- output : output . slice ( deliveredOutputCount ) ,
305- replaySafe : params . replaySafe ,
306- telemetry : telemetry ( params . runtime ) ,
307- } ) ;
299+ const abortedResult = ( ) => codeModeAbortedResult ( { ...params , output, deliveredOutputCount } ) ;
308300 // Bridge tool calls (search/describe/call/namespace) run through the same
309301 // policy-checked executor whether the model awaits them one at a time or in a
310302 // batch, so resolve them inline within the exec deadline and resume the VM
@@ -408,6 +400,7 @@ async function settleCodeModeResult(params: {
408400 output,
409401 deliveredOutputCount,
410402 bridgeDispatch : params . bridgeDispatch ,
403+ signal : params . signal ,
411404 } ) ;
412405 }
413406 // Deliver the settled frontier only. Unresolved sibling promises remain
@@ -524,6 +517,7 @@ async function settleCodeModeResult(params: {
524517 output,
525518 deliveredOutputCount,
526519 bridgeDispatch : params . bridgeDispatch ,
520+ signal : params . signal ,
527521 } ) ;
528522 } catch ( error ) {
529523 cancelPendingBridgeStates ( pending ) ;
@@ -612,22 +606,27 @@ export async function runWait(params: {
612606 // pending calls, the resume worker, and the inline settle phase.
613607 const deadlineMs = Date . now ( ) + state . config . timeoutMs ;
614608 const approvalWait = observeAgentRunApprovalWait ( state . ctx ) ;
609+ // Snapshot closure wakes an observing wait even if its guest budget just expired.
610+ // Transfer releases this signal; worker execution keeps its normal per-call signal.
611+ const parkedSignal = params . signal
612+ ? AbortSignal . any ( [ params . signal , state . ownerSignal ] )
613+ : state . ownerSignal ;
615614 let releaseActiveRunSlot : ( ( ) => void ) | undefined ;
616615 try {
617616 const ready = await waitForPending (
618617 state . pending ,
619618 state . settlementMode ,
620619 Math . max ( 1 , deadlineMs - Date . now ( ) ) ,
621620 approvalWait ,
622- params . signal ,
621+ parkedSignal ,
623622 ) ;
624623 const resumeBudgetMs = ready
625624 ? usableResumeBudgetMs ( deadlineMs + approvalWait . pausedMs , state . config )
626625 : undefined ;
627626 if ( ! ready || resumeBudgetMs === undefined ) {
628627 // An aborted wait drops the suspended run: nothing will resume it, and
629628 // parking it would pin a process-global active-run slot until TTL expiry.
630- if ( params . signal ? .aborted ) {
629+ if ( parkedSignal . aborted ) {
631630 disposeCodeModeRun ( state . runId ) ;
632631 return {
633632 status : "failed" as const ,
0 commit comments