From a52ca35d343cd89891ce199032bbf876439b1617 Mon Sep 17 00:00:00 2001 From: Dai Ha Date: Sat, 3 Oct 2026 19:26:11 +0200 Subject: [PATCH 1/2] fleetd #663: remove LeadContextGauge.read's 3-arg overload The 3-arg read(configDir, sessionId, agentType) delegated to the 4-arg form with a null window, silently restoring the fixed 200_000 fallback that #637 moved away from. It had zero production callers; both production call sites already use the 4-arg form. Migrate all test call sites to the 4-arg form. For the generic property tests in LeadContextGaugeTest, the window is irrelevant and null is filler. In LeadContextGaugeHighThresholdTest's noEffectiveWindowFallsBackToTheFixed200000Default, null is the meaningful value under test, not filler; the assertion is unchanged. --- .../dev/ltms/fleet/lead/LeadContextGauge.java | 6 ---- .../LeadContextGaugeHighThresholdTest.java | 2 +- .../ltms/fleet/lead/LeadContextGaugeTest.java | 28 +++++++++---------- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/fleetd/src/main/java/dev/ltms/fleet/lead/LeadContextGauge.java b/fleetd/src/main/java/dev/ltms/fleet/lead/LeadContextGauge.java index 4a4925f..09f0008 100644 --- a/fleetd/src/main/java/dev/ltms/fleet/lead/LeadContextGauge.java +++ b/fleetd/src/main/java/dev/ltms/fleet/lead/LeadContextGauge.java @@ -172,12 +172,6 @@ public final class LeadContextGauge { * {@code "claude"} (including {@code null}, meaning undetected) reports * {@link State#UNKNOWN} — this reader only understands Claude Code's own * transcript format - */ - public Reading read(String configDir, String sessionId, String agentType) { - return read(configDir, sessionId, agentType, null); - } - - /** * @param effectiveWindowTokens the caller's resolved effective auto-compact window for this * lead's own profile, or {@code null} when it cannot be resolved. * HIGH fires at {@link #HIGH_THRESHOLD_FRACTION} of this value; diff --git a/fleetd/src/test/java/dev/ltms/fleet/lead/LeadContextGaugeHighThresholdTest.java b/fleetd/src/test/java/dev/ltms/fleet/lead/LeadContextGaugeHighThresholdTest.java index 3fee37a..b59b34d 100644 --- a/fleetd/src/test/java/dev/ltms/fleet/lead/LeadContextGaugeHighThresholdTest.java +++ b/fleetd/src/test/java/dev/ltms/fleet/lead/LeadContextGaugeHighThresholdTest.java @@ -85,7 +85,7 @@ class LeadContextGaugeHighThresholdTest { String legacyConfigDir = writeTranscript(tmp.resolve("legacy"), SESSION_ID, 200_000); LeadContextGauge legacyGauge = new LeadContextGauge(); assertEquals(LeadContextGauge.State.HIGH, - legacyGauge.read(legacyConfigDir, SESSION_ID, "claude").state(), + legacyGauge.read(legacyConfigDir, SESSION_ID, "claude", null).state(), "the 3-arg read() (no window argument at all) must behave exactly like passing a null window"); } diff --git a/fleetd/src/test/java/dev/ltms/fleet/lead/LeadContextGaugeTest.java b/fleetd/src/test/java/dev/ltms/fleet/lead/LeadContextGaugeTest.java index 6d89a65..e4cfde2 100644 --- a/fleetd/src/test/java/dev/ltms/fleet/lead/LeadContextGaugeTest.java +++ b/fleetd/src/test/java/dev/ltms/fleet/lead/LeadContextGaugeTest.java @@ -85,7 +85,7 @@ class LeadContextGaugeTest { usageLine(40_000, 5_000, 3_000)); // last record: 48,000 LeadContextGauge gauge = new LeadContextGauge(); - LeadContextGauge.Reading first = gauge.read(configDir, SESSION_ID, "claude"); + LeadContextGauge.Reading first = gauge.read(configDir, SESSION_ID, "claude", null); assertEquals(48_000L, first.tokens(), "must total input+cache_read+cache_creation of the LAST usage record"); assertEquals(LeadContextGauge.State.OK, first.state()); @@ -93,7 +93,7 @@ class LeadContextGaugeTest { // must change with it, not stay pinned to the first fixture's total. String otherSession = "22222222-2222-2222-2222-222222222222"; writeTranscript(tmp, otherSession, usageLine(100_000, 50_000, 50_000)); // last record: 200,000 - LeadContextGauge.Reading second = gauge.read(configDir, otherSession, "claude"); + LeadContextGauge.Reading second = gauge.read(configDir, otherSession, "claude", null); assertEquals(200_000L, second.tokens()); assertTrue(second.tokens() != first.tokens(), "changing N in the fixture must change the reported number"); } @@ -111,12 +111,12 @@ class LeadContextGaugeTest { compactionLine(), usageLine(3_000, 0, 0)); LeadContextGauge gauge = new LeadContextGauge(); - LeadContextGauge.Reading twoCompactions = gauge.read(tmp.toString(), sessionTwoCompactions, "claude"); + LeadContextGauge.Reading twoCompactions = gauge.read(tmp.toString(), sessionTwoCompactions, "claude", null); assertEquals(2, twoCompactions.compactions()); String sessionZeroCompactions = "44444444-4444-4444-4444-444444444444"; writeTranscript(tmp, sessionZeroCompactions, usageLine(3_000, 0, 0)); - LeadContextGauge.Reading zeroCompactions = gauge.read(tmp.toString(), sessionZeroCompactions, "claude"); + LeadContextGauge.Reading zeroCompactions = gauge.read(tmp.toString(), sessionZeroCompactions, "claude", null); assertEquals(0, zeroCompactions.compactions(), "changing K in the fixture must change the reported count"); } @@ -126,7 +126,7 @@ class LeadContextGaugeTest { @DisplayName("a missing transcript file reports UNKNOWN with no token number") void missingFileIsUnknown(@TempDir Path tmp) { LeadContextGauge gauge = new LeadContextGauge(); - LeadContextGauge.Reading reading = gauge.read(tmp.toString(), SESSION_ID, "claude"); + LeadContextGauge.Reading reading = gauge.read(tmp.toString(), SESSION_ID, "claude", null); assertEquals(LeadContextGauge.State.UNKNOWN, reading.state()); assertNull(reading.tokens()); } @@ -148,7 +148,7 @@ class LeadContextGaugeTest { assumeFalse(Files.isReadable(file), "runs as root (CI container): the read bit does not stop root, so this case cannot be set up here"); LeadContextGauge gauge = new LeadContextGauge(); - LeadContextGauge.Reading reading = gauge.read(configDir, SESSION_ID, "claude"); + LeadContextGauge.Reading reading = gauge.read(configDir, SESSION_ID, "claude", null); assertEquals(LeadContextGauge.State.UNKNOWN, reading.state()); assertNull(reading.tokens()); } finally { @@ -171,7 +171,7 @@ class LeadContextGaugeTest { Files.writeString(file, lastCompleteLine + "\n" + tornLine, StandardCharsets.UTF_8); LeadContextGauge gauge = new LeadContextGauge(); - LeadContextGauge.Reading reading = gauge.read(tmp.toString(), SESSION_ID, "claude"); + LeadContextGauge.Reading reading = gauge.read(tmp.toString(), SESSION_ID, "claude", null); assertEquals(LeadContextGauge.State.OK, reading.state(), "a torn final line must not turn a good earlier reading into UNKNOWN"); assertEquals(6_000L, reading.tokens(), @@ -187,7 +187,7 @@ class LeadContextGaugeTest { "{this is not json at all", "neither is this{{{"); LeadContextGauge gauge = new LeadContextGauge(); - LeadContextGauge.Reading reading = gauge.read(configDir, SESSION_ID, "claude"); + LeadContextGauge.Reading reading = gauge.read(configDir, SESSION_ID, "claude", null); assertEquals(LeadContextGauge.State.UNKNOWN, reading.state(), "every line unparseable is the real format-change signal and must still report UNKNOWN"); assertNull(reading.tokens()); @@ -224,12 +224,12 @@ class LeadContextGaugeTest { AtomicLong now = new AtomicLong(0); LeadContextGauge gauge = new LeadContextGauge(now::get, 5_000); - gauge.read(configDir, SESSION_ID, "claude"); - gauge.read(configDir, SESSION_ID, "claude"); // still inside the TTL window + gauge.read(configDir, SESSION_ID, "claude", null); + gauge.read(configDir, SESSION_ID, "claude", null); // still inside the TTL window assertEquals(1, gauge.diskReadCount(), "two reads inside the TTL must touch disk once"); now.set(6_000); // past the TTL - gauge.read(configDir, SESSION_ID, "claude"); + gauge.read(configDir, SESSION_ID, "claude", null); assertEquals(2, gauge.diskReadCount(), "a read past the TTL must touch disk again"); } @@ -241,8 +241,8 @@ class LeadContextGaugeTest { String configDir = writeTranscript(tmp, SESSION_ID, usageLine(1_000, 0, 0)); LeadContextGauge gauge = new LeadContextGauge(); - assertEquals(LeadContextGauge.State.UNKNOWN, gauge.read(configDir, SESSION_ID, "opencode").state()); - assertEquals(LeadContextGauge.State.UNKNOWN, gauge.read(configDir, SESSION_ID, null).state()); - assertEquals(LeadContextGauge.State.UNKNOWN, gauge.read(configDir, null, "claude").state()); + assertEquals(LeadContextGauge.State.UNKNOWN, gauge.read(configDir, SESSION_ID, "opencode", null).state()); + assertEquals(LeadContextGauge.State.UNKNOWN, gauge.read(configDir, SESSION_ID, null, null).state()); + assertEquals(LeadContextGauge.State.UNKNOWN, gauge.read(configDir, null, "claude", null).state()); } } From 60fa86a107e6233713bb3e61aaa75c123101414a Mon Sep 17 00:00:00 2001 From: Dai Ha Date: Sat, 3 Oct 2026 19:34:47 +0200 Subject: [PATCH 2/2] fleetd #663: remove the dead legacy assertion review flagged on PR 665 noEffectiveWindowFallsBackToTheFixed200000Default's third assertion (legacyConfigDir/legacyGauge) used to call the 3-arg read() to prove it behaved like a null window. With the 3-arg form gone, it is the same call, same input (200_000) and same expectation as the atGauge assertion above it, so it cannot fail unless that one already failed, and its message named a method that no longer exists. Deleted it; the first two assertions (199_999 -> OK, 200_000 -> HIGH) are unchanged. --- .../ltms/fleet/lead/LeadContextGaugeHighThresholdTest.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/fleetd/src/test/java/dev/ltms/fleet/lead/LeadContextGaugeHighThresholdTest.java b/fleetd/src/test/java/dev/ltms/fleet/lead/LeadContextGaugeHighThresholdTest.java index b59b34d..cb964da 100644 --- a/fleetd/src/test/java/dev/ltms/fleet/lead/LeadContextGaugeHighThresholdTest.java +++ b/fleetd/src/test/java/dev/ltms/fleet/lead/LeadContextGaugeHighThresholdTest.java @@ -81,12 +81,6 @@ class LeadContextGaugeHighThresholdTest { assertEquals(LeadContextGauge.State.HIGH, atGauge.read(atConfigDir, SESSION_ID, "claude", null).state(), "the fixed default must still be 200,000 when no window is resolvable"); - - String legacyConfigDir = writeTranscript(tmp.resolve("legacy"), SESSION_ID, 200_000); - LeadContextGauge legacyGauge = new LeadContextGauge(); - assertEquals(LeadContextGauge.State.HIGH, - legacyGauge.read(legacyConfigDir, SESSION_ID, "claude", null).state(), - "the 3-arg read() (no window argument at all) must behave exactly like passing a null window"); } @Test