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

1 Commits

Author SHA1 Message Date
Dai Ha fe465cc425 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
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).
2026-10-03 15:54:33 +02:00