@@ -17,7 +17,6 @@ import {
1717 compactionThresholdFor ,
1818} from "../provider/context-window.js" ;
1919import {
20- COMPACTOR_KEEP_RECENT_TURNS ,
2120 COMPACT_SPACER_TEXT ,
2221 LEGACY_COMPACT_SPACER_TEXT ,
2322 compactorNoOpFloor ,
@@ -149,7 +148,6 @@ const overThreshold = compactionThresholdFor("m") + 1;
149148const wideDelta = compactionWideResumeDeltaFor ( "m" ) ;
150149const inferAction : ReactorAction [ ] = [ { type : "infer" } ] ;
151150const tenTurns = turnsOfLength ( 10 , 1 ) ;
152- const threeTurns = turnsOfLength ( 3 , 1 ) ;
153151
154152describe ( "compaction governor" , ( ) => {
155153 test ( "stays inert below the threshold or with few turns" , ( ) => {
@@ -159,7 +157,7 @@ describe("compaction governor", () => {
159157 governor . interceptActions ( toolDone ( ) , inferAction , capabilities ) ,
160158 ) . toBeNull ( ) ;
161159
162- governor . noteInferenceDone ( inferenceDone ( overThreshold ) , threeTurns ) ;
160+ governor . noteInferenceDone ( inferenceDone ( overThreshold ) , turnsOfLength ( 1 , 1 ) ) ;
163161 expect (
164162 governor . interceptActions ( toolDone ( ) , inferAction , capabilities ) ,
165163 ) . toBeNull ( ) ;
@@ -474,13 +472,12 @@ describe("compaction governor", () => {
474472 } ) ;
475473
476474 test ( "stays inert below the minimum-turn floor no matter how far over threshold" , ( ) => {
477- // Two turns is well under MIN_TURNS_TO_COMPACT. createPruningCompactor
478- // no-ops at the same floor (see session/compactor.ts), so arming here
479- // would spend a reactor cycle that cannot shrink anything.
475+ // A single turn is the compactor no-op floor. Arming here would spend a
476+ // reactor cycle that cannot shrink anything.
480477 const governor = createCompactionGovernor ( ( ) => undefined ) ;
481478 governor . noteInferenceDone (
482479 inferenceDone ( overThreshold * 10 ) ,
483- turnsOfLength ( 2 , 1 ) ,
480+ turnsOfLength ( 1 , 1 ) ,
484481 ) ;
485482 expect (
486483 governor . interceptActions ( toolDone ( ) , inferAction , capabilities ) ,
@@ -514,9 +511,9 @@ describe("compaction governor", () => {
514511
515512 test ( "never arms at the exact turn count createPruningCompactor no-ops on" , ( ) => {
516513 // createPruningCompactor's own no-op floor (session/compactor.ts) is
517- // compactorNoOpFloor(COMPACTOR_KEEP_RECENT_TURNS ). Arming at or below it
518- // would spend a reactor cycle that is guaranteed to shrink nothing.
519- const floor = compactorNoOpFloor ( COMPACTOR_KEEP_RECENT_TURNS ) ;
514+ // compactorNoOpFloor(). Arming at or below it would spend a reactor cycle
515+ // that is guaranteed to shrink nothing.
516+ const floor = compactorNoOpFloor ( ) ;
520517 const governor = createCompactionGovernor ( ( ) => undefined ) ;
521518 governor . noteInferenceDone (
522519 inferenceDone ( overThreshold ) ,
@@ -528,7 +525,7 @@ describe("compaction governor", () => {
528525 } ) ;
529526
530527 test ( "arms one turn past the floor createPruningCompactor no-ops on" , ( ) => {
531- const floor = compactorNoOpFloor ( COMPACTOR_KEEP_RECENT_TURNS ) ;
528+ const floor = compactorNoOpFloor ( ) ;
532529 const governor = createCompactionGovernor ( ( ) => undefined ) ;
533530 governor . noteInferenceDone (
534531 inferenceDone ( overThreshold ) ,
@@ -708,7 +705,7 @@ describe("compaction governor", () => {
708705
709706 test ( "manual compact no-ops below the compactor floor" , ( ) => {
710707 const governor = createCompactionGovernor ( undefined ) ;
711- governor . noteInferenceDone ( inferenceDone ( overThreshold ) , threeTurns ) ;
708+ governor . noteInferenceDone ( inferenceDone ( overThreshold ) , turnsOfLength ( 1 , 1 ) ) ;
712709 expect ( governor . requestManual ( "focus on tests" ) ) . toBe ( "noop" ) ;
713710 expect ( governor . extraInstructions ) . toBeUndefined ( ) ;
714711 expect (
@@ -828,25 +825,23 @@ describe("post-compact above-threshold latch (CL-9006)", () => {
828825 ) . toBeNull ( ) ;
829826 } ) ;
830827
831- test ( "a wide resume gap while still over threshold re-arms " , ( ) => {
828+ test ( "a still-over fold reports non-convergence instead of re-arming on a wide gap " , ( ) => {
832829 const governor = createCompactionGovernor ( ( ) => undefined ) ;
833830 governor . noteInferenceDone ( inferenceDone ( overThreshold ) , tenTurns ) ;
834831 expect (
835832 governor . interceptActions ( toolDone ( ) , inferAction , capabilities ) ,
836833 ) . not . toBeNull ( ) ;
837834
838835 governor . noteInferenceDone ( inferenceDone ( overThreshold ) , tenTurns ) ;
836+ expect ( governor . foldNonConverged ) . toBe ( true ) ;
839837 governor . noteInferenceDone (
840838 inferenceDone ( overThreshold + wideDelta ) ,
841839 tenTurns ,
842840 ) ;
843- const actions = governor . interceptActions (
844- toolDone ( ) ,
845- inferAction ,
846- capabilities ,
847- ) ;
848- expect ( actions ) . not . toBeNull ( ) ;
849- expect ( actions ?. some ( ( a ) => a . type === "compact" ) ) . toBe ( true ) ;
841+ expect (
842+ governor . interceptActions ( toolDone ( ) , inferAction , capabilities ) ,
843+ ) . toBeNull ( ) ;
844+ expect ( governor . foldNonConverged ) . toBe ( true ) ;
850845 } ) ;
851846
852847 test ( "the consecutive-compact cap holds across tool-call occupancy" , ( ) => {
@@ -856,29 +851,17 @@ describe("post-compact above-threshold latch (CL-9006)", () => {
856851 governor . interceptActions ( toolDone ( ) , inferAction , capabilities ) ,
857852 ) . not . toBeNull ( ) ;
858853
854+ // Post-compact measurement still over: the fold is non-converged and the
855+ // cap is spent, even past a wide gap and tool-call occupancy.
859856 governor . noteInferenceDone ( inferenceDone ( overThreshold ) , tenTurns ) ;
860- governor . noteInferenceDone (
861- inferenceDone ( overThreshold + wideDelta ) ,
862- tenTurns ,
863- ) ;
864- expect (
865- governor . interceptActions ( toolDone ( ) , inferAction , capabilities ) ,
866- ) . not . toBeNull ( ) ;
867-
868- // Post-compact measurement still over: tool-call occupancy must not reset
869- // the cap, even past a wide gap.
870- governor . noteInferenceDone (
871- inferenceDone ( overThreshold + wideDelta ) ,
872- tenTurns ,
873- ) ;
857+ expect ( governor . foldNonConverged ) . toBe ( true ) ;
874858 governor . noteInferenceDone (
875859 inferenceDoneWithTools ( overThreshold + 2 * wideDelta ) ,
876860 tenTurns ,
877861 ) ;
878862 expect (
879863 governor . interceptActions ( toolDone ( ) , inferAction , capabilities ) ,
880864 ) . toBeNull ( ) ;
881- // The idle path shares the same cap.
882865 governor . noteIdleTurn (
883866 inferenceDoneWithTools ( overThreshold + 2 * wideDelta ) ,
884867 [ { type : "reply" , content : "done" } ] ,
@@ -942,19 +925,17 @@ describe("post-compact above-threshold latch (CL-9006)", () => {
942925 expect (
943926 governor . interceptActions ( toolDone ( ) , inferAction , capabilities ) ,
944927 ) . toBeNull ( ) ;
928+ expect ( governor . foldNonConverged ) . toBe ( true ) ;
945929
946- // Wide gap re-arms identically to the automatic path.
930+ // Wide gap does not silently re-arm the automatic path after a still-over
931+ // operator fold; the fold already reported non-convergence.
947932 governor . noteInferenceDone (
948933 inferenceDone ( overThreshold + wideDelta ) ,
949934 tenTurns ,
950935 ) ;
951- const actions = governor . interceptActions (
952- toolDone ( ) ,
953- inferAction ,
954- capabilities ,
955- ) ;
956- expect ( actions ) . not . toBeNull ( ) ;
957- expect ( actions ?. some ( ( a ) => a . type === "compact" ) ) . toBe ( true ) ;
936+ expect (
937+ governor . interceptActions ( toolDone ( ) , inferAction , capabilities ) ,
938+ ) . toBeNull ( ) ;
958939 } ) ;
959940} ) ;
960941
@@ -1012,7 +993,7 @@ describe("handoff arming (/handoff)", () => {
1012993
1013994 test ( "requestHandoff noops at or below the fold floor and arms nothing" , ( ) => {
1014995 const governor = createCompactionGovernor ( undefined ) ;
1015- governor . syncFromTurns ( threeTurns ) ;
996+ governor . syncFromTurns ( turnsOfLength ( 1 , 1 ) ) ;
1016997 expect ( governor . requestHandoff ( "now do the UI audit" ) ) . toBe ( "noop" ) ;
1017998 expect ( governor . extraInstructions ) . toBeUndefined ( ) ;
1018999 expect (
@@ -1226,7 +1207,7 @@ describe("handoff arming (/handoff)", () => {
12261207 {
12271208 title : "noop then cancelManual does not wipe extras from a prior fold" ,
12281209 fire : "idle" ,
1229- midRequests : [ { turns : threeTurns , text : "wipe this" , result : "noop" } ] ,
1210+ midRequests : [ { turns : turnsOfLength ( 1 , 1 ) , text : "wipe this" , result : "noop" } ] ,
12301211 } ,
12311212 {
12321213 title :
@@ -1318,7 +1299,7 @@ describe("handoff arming (/handoff)", () => {
13181299 expect (
13191300 governor . interceptIdleContinuation ( emptyMessage ( ) , capabilities ) ,
13201301 ) . not . toBeNull ( ) ;
1321- governor . syncFromTurns ( threeTurns ) ;
1302+ governor . syncFromTurns ( turnsOfLength ( 1 , 1 ) ) ;
13221303 expect ( governor . requestHandoff ( "wipe this" ) ) . toBe ( "noop" ) ;
13231304 governor . cancelManual ( ) ;
13241305 expect (
0 commit comments