fleetd #637: scale LeadContextGauge's HIGH threshold with the effective auto-compact window #657

Closed
agent wants to merge 1 commits from worker/637-context-gauge-threshold-466eb5-16 into main
Member

Fixes fleetd #637.

LeadContextGauge.HIGH_THRESHOLD_TOKENS was a hardcoded 200_000, while the event it warns about (auto-compaction) is configured per profile via autoCompactWindow and can legally go as low as 100_000 — making HIGH unreachable before a compaction on such a profile.

Fix:

  • LeadContextGauge.read gains an optional effective-window argument (the pre-existing 3-arg read() delegates with null, unchanged behaviour). HIGH fires at 2/3 of that window, falling back to the fixed 200_000 when no window is resolvable.
  • FleetConfig.Profile.effectiveAutoCompactWindow() resolves the window the way a launched Claude Code session actually reads it: env.CLAUDE_CODE_AUTO_COMPACT_WINDOW wins over the autoCompactWindow launch flag when both are set.
  • Wired into both real consumers: fleet_list's context row (FleetMcp.LeadConfigDirSource, widened with a back-compat constructor so no unrelated call site changes) and the lead heartbeat's context-high nudge (Fleetd.leadContextLookup/leadContextSource, widened the same way).

Tests:

  • LeadContextGaugeHighThresholdTest — pins the 2/3 fraction, the OK/HIGH boundary on both sides, and the fixed-200000 fallback. The first assertion (effective window 100000 reports HIGH at 90000 tokens) failed to compile against the pre-fix code (no 4-arg read() existed) — confirmed RED before the fix.
  • FleetConfigProfileEffectiveAutoCompactWindowTest — pins env-vs-yaml precedence on effectiveAutoCompactWindow().
  • FleetdLeadContextWindowLookupTest — pins the new per-lead-name window-lookup factory.

Build: mvn -o clean install — Tests run: 1917, Failures: 0, Errors: 0, Skipped: 0, BUILD SUCCESS.

Fixes fleetd #637. `LeadContextGauge.HIGH_THRESHOLD_TOKENS` was a hardcoded `200_000`, while the event it warns about (auto-compaction) is configured per profile via `autoCompactWindow` and can legally go as low as `100_000` — making HIGH unreachable before a compaction on such a profile. **Fix:** - `LeadContextGauge.read` gains an optional effective-window argument (the pre-existing 3-arg `read()` delegates with `null`, unchanged behaviour). HIGH fires at 2/3 of that window, falling back to the fixed `200_000` when no window is resolvable. - `FleetConfig.Profile.effectiveAutoCompactWindow()` resolves the window the way a launched Claude Code session actually reads it: `env.CLAUDE_CODE_AUTO_COMPACT_WINDOW` wins over the `autoCompactWindow` launch flag when both are set. - Wired into both real consumers: `fleet_list`'s `context` row (`FleetMcp.LeadConfigDirSource`, widened with a back-compat constructor so no unrelated call site changes) and the lead heartbeat's context-high nudge (`Fleetd.leadContextLookup`/`leadContextSource`, widened the same way). **Tests:** - `LeadContextGaugeHighThresholdTest` — pins the 2/3 fraction, the OK/HIGH boundary on both sides, and the fixed-200000 fallback. The first assertion (effective window 100000 reports HIGH at 90000 tokens) failed to compile against the pre-fix code (no 4-arg `read()` existed) — confirmed RED before the fix. - `FleetConfigProfileEffectiveAutoCompactWindowTest` — pins env-vs-yaml precedence on `effectiveAutoCompactWindow()`. - `FleetdLeadContextWindowLookupTest` — pins the new per-lead-name window-lookup factory. **Build:** `mvn -o clean install` — `Tests run: 1917, Failures: 0, Errors: 0, Skipped: 0`, `BUILD SUCCESS`.
agent added 1 commit 2026-10-03 15:54:55 +02:00
fleetd #637: scale LeadContextGauge's HIGH threshold with the effective auto-compact window
CI / shell-tests (pull_request) Failing after 8s
CI / contract (pull_request) Successful in 1m3s
CI / build (pull_request) Failing after 2m2s
fe465cc425
HIGH_THRESHOLD_TOKENS was a hardcoded 200_000, while the event it warns about
(auto-compaction) is configured per profile via autoCompactWindow and can legally go
as low as 100_000 — making HIGH unreachable before a compaction on such a profile.

LeadContextGauge.read now takes an optional effective window and fires HIGH at 2/3 of
it, falling back to the fixed 200_000 when no window is resolvable (unresolved callers,
including the pre-existing 3-arg read(), keep today's behaviour exactly).

FleetConfig.Profile.effectiveAutoCompactWindow() resolves that window the way a
launched Claude Code session actually reads it: env.CLAUDE_CODE_AUTO_COMPACT_WINDOW
wins over the autoCompactWindow launch flag when both are set.

Wired into both real consumers: fleet_list's context row (FleetMcp.LeadConfigDirSource,
widened with a back-compat constructor so no unrelated call site changes) and the lead
heartbeat's context-high nudge (Fleetd.leadContextLookup/leadContextSource, widened the
same way).
Owner

Closing without merging. PR #660 supersedes this one and is merged into main as 136bec8.

PR #660 carries this PR's commit (436b026) unchanged, plus the revision commit (ae94d51) that fixes the two gaps my adjudication found on #637: the unguarded fleet_list window wiring, and the gauge cache key that ignored the threshold. Nothing from this PR is lost.

Closing without merging. PR #660 supersedes this one and is merged into `main` as `136bec8`. PR #660 carries this PR's commit (`436b026`) unchanged, plus the revision commit (`ae94d51`) that fixes the two gaps my adjudication found on #637: the unguarded `fleet_list` window wiring, and the gauge cache key that ignored the threshold. Nothing from this PR is lost.
ltms closed this pull request 2026-10-03 16:30:50 +02:00
Some checks are pending
CI / shell-tests (pull_request) Failing after 8s
CI / contract (pull_request) Successful in 1m3s
CI / build (pull_request) Failing after 2m2s

Pull request closed

Sign in to join this conversation.