@@ -482,6 +482,45 @@ describe("agent-control plugin logging and blocking", () => {
482482 expect ( clientMocks . evaluationEvaluate ) . toHaveBeenCalledTimes ( 2 ) ;
483483 } ) ;
484484
485+ it ( "waits for catch-up sync before evaluating joined callers when steps change" , async ( ) => {
486+ // Given one tool call changes the step catalog while a joined caller waits on an in-flight sync
487+ const api = createMockApi ( {
488+ serverUrl : "http://localhost:8000" ,
489+ } ) ;
490+ const syncDeferred = createDeferred < void > ( ) ;
491+ clientMocks . agentsInit
492+ . mockImplementationOnce ( ( ) => syncDeferred . promise )
493+ . mockResolvedValueOnce ( undefined ) ;
494+ resolveStepsForContextMock
495+ . mockResolvedValueOnce ( [ { type : "tool" , name : "shell" } ] )
496+ . mockResolvedValueOnce ( [
497+ { type : "tool" , name : "shell" } ,
498+ { type : "tool" , name : "grep" } ,
499+ ] ) ;
500+
501+ // When the joined caller updates steps before the original sync resolves
502+ register ( api . api ) ;
503+ const first = runBeforeToolCall ( api ) ;
504+ await Promise . resolve ( ) ;
505+ await Promise . resolve ( ) ;
506+ const second = runBeforeToolCall ( api , { toolName : "grep" } ) ;
507+ await Promise . resolve ( ) ;
508+ await Promise . resolve ( ) ;
509+
510+ expect ( clientMocks . agentsInit ) . toHaveBeenCalledTimes ( 1 ) ;
511+ expect ( clientMocks . evaluationEvaluate ) . not . toHaveBeenCalled ( ) ;
512+
513+ syncDeferred . resolve ( undefined ) ;
514+ await Promise . all ( [ first , second ] ) ;
515+
516+ // Then both callers wait until the catch-up sync completes before evaluating
517+ expect ( clientMocks . agentsInit ) . toHaveBeenCalledTimes ( 2 ) ;
518+ expect ( clientMocks . evaluationEvaluate ) . toHaveBeenCalledTimes ( 2 ) ;
519+ expect ( clientMocks . evaluationEvaluate . mock . invocationCallOrder [ 0 ] ) . toBeGreaterThan (
520+ clientMocks . agentsInit . mock . invocationCallOrder [ 1 ] ?? 0 ,
521+ ) ;
522+ } ) ;
523+
485524 it ( "skips resyncing when the step catalog has not changed" , async ( ) => {
486525 // Given a source agent whose step catalog is unchanged across two tool calls
487526 const api = createMockApi ( {
0 commit comments