/** * dashboard-client/src/tabs/MaintenanceTab/HealthMitigationCard.tsx — Health * Mitigation card. * * Extracted from MaintenanceTab.tsx (delegate-shell split). Toggles auto- * mitigation for degraded context (forced compaction / prefix break). */ import type React from "react"; import { useState, useCallback, useEffect } from "react"; import { Switch } from "../../components/ui/switch"; import { Card, CardHeader, CardTitle, CardContent, } from "../../components/ui/card"; // --------------------------------------------------------------------------- // Health Mitigation card — toggle auto-mitigation for degraded context // --------------------------------------------------------------------------- export function HealthMitigationCard(): React.ReactElement { const [mitigate, setMitigate] = useState(false); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const [error, setError] = useState(null); const load = useCallback(async () => { try { const { fetchHealthSettings } = await import("../../api/health"); const s = await fetchHealthSettings(); setMitigate(s.mitigate); } catch (e) { setError(e instanceof Error ? e.message : String(e)); } finally { setLoading(false); } }, []); useEffect(() => { void load(); }, [load]); const toggle = useCallback(async () => { setSaving(true); setError(null); try { const { setHealthMitigate } = await import("../../api/health"); const next = !mitigate; await setHealthMitigate(next); setMitigate(next); } catch (e) { setError(e instanceof Error ? e.message : String(e)); } finally { setSaving(false); } }, [mitigate]); return ( Context Health Mitigation {loading ? (

Loading…

) : ( <>
Auto-mitigation {mitigate ? "ON" : "OFF"}

When ON, the extension automatically intervenes when context health degrades:

  • Forced compaction — when the composite health score drops below 0.4 (severe drift or garbled output), a compaction is triggered to flush the degraded context and rebuild from clean checkpoints, even if the context window isn't full.
  • Prefix break — when KV cache poison is detected (score < 0.3), the cached prefix is invalidated to force a cache miss on the next turn, bypassing the corrupted KV state.

WARNING: both interventions have costs — forced compaction discards live context, and prefix breaks kill cache savings. Only enable when you're seeing degraded output (garbled text, hallucinations, loss of coherence) and the Health tab confirms low scores.

Also settable via env var:{" "} MEGACOMPACT_CONTEXT_HEALTH_MITIGATE=1. The dashboard toggle persists to the store and takes precedence.

{error &&

Error: {error}

}
)}
); }