@@ -512,7 +512,7 @@ describe("disposeExecRuntime", () => {
512512 ) . rejects . toThrow ( "plugin dispose failed" ) ;
513513 } ) ;
514514
515- test ( "cancels every live worker with the close reason before the agent closes " , async ( ) => {
515+ test ( "cancels every live worker with the close reason after toolset dispose " , async ( ) => {
516516 const store = createSubAgentSessionStore ( ) ;
517517 const first = store . start ( { description : "a" , agentId : "w1" , brief : "b" } ) ;
518518 const second = store . start ( { description : "b" , agentId : "w2" , brief : "b" } ) ;
@@ -526,27 +526,29 @@ describe("disposeExecRuntime", () => {
526526 subAgentSessions : store ,
527527 } ) ;
528528
529- // Cancellation must precede teardown so no worker outlives the runtime .
530- expect ( calls ) . toEqual ( [ "cancel:first" , "cancel:second" , "agent" , "toolset "] ) ;
529+ // Posix/toolset first so a hung close cannot skip reap; then cancel, then close .
530+ expect ( calls ) . toEqual ( [ "toolset" , " cancel:first", "cancel:second" , "agent" ] ) ;
531531 expect ( store . get ( first . id ) ?. status ) . toBe ( "cancelled" ) ;
532532 expect ( store . get ( second . id ) ?. status ) . toBe ( "cancelled" ) ;
533533 expect ( store . get ( first . id ) ?. stopReason ) . toBe ( "cancelled — Session closed" ) ;
534534 expect ( store . get ( second . id ) ?. stopReason ) . toBe ( "cancelled — Session closed" ) ;
535535 } ) ;
536536
537- test ( "a failing agent close still disposes the toolset and resolves " , async ( ) => {
537+ test ( "a failing agent close still disposes the toolset and rejects " , async ( ) => {
538538 const store = createSubAgentSessionStore ( ) ;
539539 const worker = store . start ( { description : "bg" , agentId : "w" , brief : "b" } ) ;
540540 store . registerCancel ( worker . id , ( ) => undefined ) ;
541541
542542 let disposed = 0 ;
543- await disposeExecRuntime ( {
544- agent : {
545- close : ( ) => Promise . reject ( new Error ( "close exploded" ) ) ,
546- } ,
547- toolset : { dispose : async ( ) => void ( disposed += 1 ) } ,
548- subAgentSessions : store ,
549- } ) ;
543+ await expect (
544+ disposeExecRuntime ( {
545+ agent : {
546+ close : ( ) => Promise . reject ( new Error ( "close exploded" ) ) ,
547+ } ,
548+ toolset : { dispose : async ( ) => void ( disposed += 1 ) } ,
549+ subAgentSessions : store ,
550+ } ) ,
551+ ) . rejects . toThrow ( "close exploded" ) ;
550552
551553 expect ( store . get ( worker . id ) ?. status ) . toBe ( "cancelled" ) ;
552554 expect ( disposed ) . toBe ( 1 ) ;
0 commit comments