@@ -536,7 +536,36 @@ describe("tool-loop-detection", () => {
536536 expect ( escapeResult . stuck ) . toBe ( false ) ;
537537 } ) ;
538538
539- it ( "normalizes built-in write results that only differ by echoed path" , ( ) => {
539+ it ( "normalizes built-in write no-ops that only differ by echoed path" , ( ) => {
540+ const state = createState ( ) ;
541+ const content = "same content" ;
542+ const paths = [ "/tmp/a.md" , "/tmp/b.md" ] ;
543+
544+ for ( const [ index , targetPath ] of paths . entries ( ) ) {
545+ recordSuccessfulCall (
546+ state ,
547+ "write" ,
548+ { path : targetPath , content } ,
549+ {
550+ content : [
551+ {
552+ type : "text" ,
553+ text : `No changes made to ${ targetPath } . The file already has identical content.` ,
554+ } ,
555+ ] ,
556+ details : { changed : false } ,
557+ } ,
558+ index ,
559+ ) ;
560+ }
561+
562+ const hashes = state . toolCallHistory ?. map ( ( record ) => record . resultHash ) ;
563+ expect ( hashes ?. [ 0 ] ) . toBeTypeOf ( "string" ) ;
564+ expect ( hashes ?. [ 0 ] ) . toBe ( hashes ?. [ 1 ] ) ;
565+ expect ( state . toolCallHistory ?. every ( ( record ) => record . noProgress === true ) ) . toBe ( true ) ;
566+ } ) ;
567+
568+ it ( "preserves target identity for successful write outcomes" , ( ) => {
540569 const state = createState ( ) ;
541570 const content = "same content" ;
542571 const paths = [ "/tmp/a.md" , "/tmp/b.md" ] ;
@@ -564,9 +593,9 @@ describe("tool-loop-detection", () => {
564593 ) ;
565594 }
566595
567- const hashes = state . toolCallHistory ?. map ( ( record ) => record . resultHash ) ;
568- expect ( hashes ?. [ 0 ] ) . toBeTypeOf ( "string" ) ;
569- expect ( hashes ?. [ 0 ] ) . toBe ( hashes ?. [ 1 ] ) ;
596+ const history = state . toolCallHistory ?? [ ] ;
597+ expect ( history [ 0 ] ?. resultHash ) . not . toBe ( history [ 1 ] ?. resultHash ) ;
598+ expect ( history . every ( ( record ) => record . noProgress === undefined ) ) . toBe ( true ) ;
570599 } ) ;
571600
572601 it ( "uses the supplied warning threshold when reconciling rewritten calls" , ( ) => {
@@ -640,28 +669,28 @@ describe("tool-loop-detection", () => {
640669 } ) ;
641670 } ) ;
642671
643- it ( "does not treat distinct stable successful outcomes as semantic no-progress" , ( ) => {
672+ it ( "does not treat generic stable successes as semantic no-progress" , ( ) => {
644673 const state = createState ( ) ;
645674 const paths = [ "/tmp/a.md" , "/tmp/b.md" , "/tmp/a.md" , "/tmp/a.md" , "/tmp/b.md" ] ;
646675
647- for ( let index = 0 ; index < GLOBAL_CIRCUIT_BREAKER_THRESHOLD ; index += 1 ) {
676+ for ( let index = 0 ; index < CRITICAL_THRESHOLD ; index += 1 ) {
648677 const targetPath = paths [ index % paths . length ] ! ;
649678 recordSuccessfulCall (
650679 state ,
651- "write " ,
652- { path : targetPath , content : "same content" } ,
680+ "side_effect " ,
681+ { path : targetPath } ,
653682 {
654- content : [ { type : "text" , text : `wrote ${ targetPath } ` } ] ,
655- details : { ok : true , path : targetPath } ,
683+ content : [ { type : "text" , text : "done" } ] ,
684+ details : { ok : true } ,
656685 } ,
657686 index ,
658687 ) ;
659688 }
660689
661690 const loopResult = detectToolCallLoop (
662691 state ,
663- "write " ,
664- { path : "/tmp/a.md" , content : "same content" } ,
692+ "side_effect " ,
693+ { path : "/tmp/a.md" } ,
665694 enabledLoopDetectionConfig ,
666695 ) ;
667696
@@ -675,6 +704,39 @@ describe("tool-loop-detection", () => {
675704 }
676705 } ) ;
677706
707+ it ( "keeps repeated stable errors eligible for argument-churn liveness" , ( ) => {
708+ const state = createState ( ) ;
709+ const paths = [ "/tmp/a.md" , "/tmp/b.md" , "/tmp/a.md" , "/tmp/a.md" , "/tmp/b.md" ] ;
710+
711+ for ( let index = 0 ; index < CRITICAL_THRESHOLD ; index += 1 ) {
712+ const targetPath = paths [ index % paths . length ] ! ;
713+ const toolCallId = `failed-${ index } ` ;
714+ const params = { path : targetPath } ;
715+ recordToolCall ( state , "side_effect" , params , toolCallId , enabledLoopDetectionConfig ) ;
716+ recordToolCallOutcome ( state , {
717+ toolName : "side_effect" ,
718+ toolParams : params ,
719+ toolCallId,
720+ error : new Error ( "permission denied" ) ,
721+ config : enabledLoopDetectionConfig ,
722+ } ) ;
723+ }
724+
725+ const loopResult = detectToolCallLoop (
726+ state ,
727+ "side_effect" ,
728+ { path : "/tmp/a.md" } ,
729+ enabledLoopDetectionConfig ,
730+ ) ;
731+
732+ expect ( loopResult ) . toMatchObject ( {
733+ stuck : true ,
734+ level : "warning" ,
735+ detector : "argument_churn" ,
736+ livenessSignal : "argument_churn" ,
737+ } ) ;
738+ } ) ;
739+
678740 it ( "keeps generic critical repeats ahead of warning-only argument churn" , ( ) => {
679741 const state = createState ( ) ;
680742
0 commit comments