@@ -332,8 +332,9 @@ describe("gateway server chat", () => {
332332 expect ( res . payload ?. status ) . toBe ( "ok" ) ;
333333 return res ;
334334 } ;
335- const waitForAgentRunDrained = async ( ) => {
335+ const waitForAgentRunDrained = async ( runId : string ) => {
336336 await waitForFast ( ( ) => expect ( getActiveGatewayRootWorkCount ( ) ) . toBe ( 0 ) ) ;
337+ await waitForAgentRunOk ( runId , 0 ) ;
337338 } ;
338339 const abortChatRun = async ( runId : string ) => {
339340 const res = await rpcReq ( ws , "chat.abort" , {
@@ -394,7 +395,7 @@ describe("gateway server chat", () => {
394395 expect ( res . ok ) . toBe ( true ) ;
395396 expect ( res . payload ?. runId ) . toBe ( "idem-sessions-send-1" ) ;
396397 expect ( res . payload ?. messageSeq ) . toBe ( 1 ) ;
397- await waitForAgentRunDrained ( ) ;
398+ await waitForAgentRunDrained ( "idem-sessions-send-1" ) ;
398399 } finally {
399400 testState . sessionStorePath = undefined ;
400401 await removeTempDir ( dir ) ;
@@ -424,7 +425,7 @@ describe("gateway server chat", () => {
424425 storePath : testState . sessionStorePath ,
425426 } ) ?. sessionId ,
426427 ) . toBeTypeOf ( "string" ) ;
427- await waitForAgentRunDrained ( ) ;
428+ await waitForAgentRunDrained ( "idem-sessions-send-orion" ) ;
428429 } finally {
429430 testState . agentsConfig = undefined ;
430431 testState . sessionStorePath = undefined ;
@@ -453,7 +454,7 @@ describe("gateway server chat", () => {
453454 expect ( res . ok ) . toBe ( true ) ;
454455 expect ( res . payload ?. runId ) . toBe ( "idem-sessions-steer-1" ) ;
455456 expect ( res . payload ?. messageSeq ) . toBe ( 1 ) ;
456- await waitForAgentRunDrained ( ) ;
457+ await waitForAgentRunDrained ( "idem-sessions-steer-1" ) ;
457458 } finally {
458459 testState . sessionStorePath = undefined ;
459460 await removeTempDir ( dir ) ;
@@ -589,7 +590,7 @@ describe("gateway server chat", () => {
589590 idempotencyKey : "idem-sanitized-1" ,
590591 } ) ;
591592 expect ( sanitizedRes . ok ) . toBe ( true ) ;
592- await waitForAgentRunDrained ( ) ;
593+ await waitForAgentRunDrained ( "idem-sanitized-1" ) ;
593594 } ) ;
594595
595596 test ( "handles chat send and history flows" , async ( ) => {
@@ -619,7 +620,7 @@ describe("gateway server chat", () => {
619620 idempotencyKey : "idem-webchat-1" ,
620621 } ) ;
621622 expect ( webchatRes . ok ) . toBe ( true ) ;
622- await waitForAgentRunDrained ( ) ;
623+ await waitForAgentRunDrained ( "idem-webchat-1" ) ;
623624
624625 webchatWs . close ( ) ;
625626 webchatWs = undefined ;
@@ -632,7 +633,7 @@ describe("gateway server chat", () => {
632633 } ) ;
633634 expect ( timeoutRes . ok ) . toBe ( true ) ;
634635 expect ( timeoutRes . payload ?. runId ) . toBe ( "idem-timeout-1" ) ;
635- await waitForAgentRunDrained ( ) ;
636+ await waitForAgentRunDrained ( "idem-timeout-1" ) ;
636637 testState . agentConfig = undefined ;
637638
638639 const sessionRes = await rpcReq ( ws , "chat.send" , {
@@ -642,7 +643,7 @@ describe("gateway server chat", () => {
642643 } ) ;
643644 expect ( sessionRes . ok ) . toBe ( true ) ;
644645 expect ( sessionRes . payload ?. runId ) . toBe ( "idem-session-key-1" ) ;
645- await waitForAgentRunDrained ( ) ;
646+ await waitForAgentRunDrained ( "idem-session-key-1" ) ;
646647
647648 const sendPolicyDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-gw-" ) ) ;
648649 tempDirs . push ( sendPolicyDir ) ;
@@ -736,7 +737,7 @@ describe("gateway server chat", () => {
736737 } ) ;
737738 expect ( imgRes . ok ) . toBe ( true ) ;
738739 expectStringRunId ( imgRes . payload ) ;
739- await waitForAgentRunDrained ( ) ;
740+ await waitForAgentRunDrained ( "idem-img" ) ;
740741 const imgOnlyRes = await rpcReq ( ws , "chat.send" , {
741742 sessionKey : "main" ,
742743 message : "" ,
@@ -752,7 +753,7 @@ describe("gateway server chat", () => {
752753 } ) ;
753754 expect ( imgOnlyRes . ok ) . toBe ( true ) ;
754755 expectStringRunId ( imgOnlyRes . payload ) ;
755- await waitForAgentRunDrained ( ) ;
756+ await waitForAgentRunDrained ( "idem-img-only" ) ;
756757
757758 const historyDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-gw-" ) ) ;
758759 tempDirs . push ( historyDir ) ;
0 commit comments