The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(memory-status): review follow-ups — incident-keyed dismissal, honest copy, single mobile offset (NS-656)
Shannon Sandsba5dc00bb201
diff --git a/gateway/memory_status.py b/gateway/memory_status.pyindex f440d9ff7b4..76af13bd46b 100644--- a/gateway/memory_status.py+++ b/gateway/memory_status.py@@ -160,6 +160,12 @@ def collect_memory_status("sampled_at": None,"last_boot_unclean": False,"last_boot_suspected_oom": False,+ # Identity of the CURRENT gateway life (the sentinel's started_at).+ # A suspected-OOM restart writes a fresh sentinel, so this changes on+ # every boot — the dashboard keys banner dismissal on it so that+ # acknowledging one OOM restart does not mute reports of the NEXT+ # one (the hourly-restart-loop case is exactly the one that matters).+ "boot_id": None,}heartbeat = _read_heartbeat(home)@@ -190,5 +196,8 @@ def collect_memory_status(status["last_boot_suspected_oom"] = bool(sentinel.get("prior_suspected_oom"))+ started_at = sentinel.get("started_at")+ if isinstance(started_at, str) and started_at:+ status["boot_id"] = started_atreturn statusdiff --git a/tests/gateway/test_memory_status.py b/tests/gateway/test_memory_status.pyindex 0b533bd6325..4d9afa4202e 100644--- a/tests/gateway/test_memory_status.py+++ b/tests/gateway/test_memory_status.py@@ -133,6 +133,7 @@ class TestCollectMemoryStatus:{"phase": "running","pid": 999,+ "started_at": "2026-08-13T01:00:00+00:00","prior_unclean_exit": True,"prior_suspected_oom": True,},@@ -140,6 +141,20 @@ class TestCollectMemoryStatus:status = collect_memory_status(tmp_path, now=_NOW)assert status["last_boot_unclean"] is Trueassert status["last_boot_suspected_oom"] is True+ # boot_id identifies the reporting life so the dashboard can key+ # banner dismissal per incident (a NEW restart re-surfaces it).+ assert status["boot_id"] == "2026-08-13T01:00:00+00:00"++ def test_boot_id_absent_or_malformed_stays_none(self, tmp_path: Path) -> None:+ _write_sentinel(+ tmp_path,+ {"phase": "running", "pid": 999, "started_at": 12345},+ )+ status = collect_memory_status(tmp_path, now=_NOW)+ assert status["boot_id"] is None+ assert collect_memory_status(tmp_path.joinpath("nohome"), now=_NOW)[+ "boot_id"+ ] is Nonedef test_clean_sentinel_has_no_flags(self, tmp_path: Path) -> None:_write_sentinel(diff --git a/web/src/App.tsx b/web/src/App.tsxindex 6f57d434939..bb79cb6a6a4 100644--- a/web/src/App.tsx+++ b/web/src/App.tsx@@ -566,11 +566,16 @@ export default function App() {/>)}+ {/* Single mobile header clearance for the banner stack + content. The+ fixed lg:hidden header is h-14/z-40; previously each banner carried+ its own mt-14 AND the content kept pt-14, so two visible banners+ stacked three offsets (NS-656 review P3). One spacer, applied once. */}+ <div aria-hidden className="h-14 shrink-0 lg:hidden" /><PluginSlot name="header-banner" /><ProfileScopeBanner /><MemoryPressureBanner status={sidebarStatus} />- <div className="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden pt-14 lg:pt-0">+ <div className="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden"><div className="flex min-h-0 min-w-0 flex-1"><asideid="app-sidebar"diff --git a/web/src/components/MemoryPressureBanner.test.tsx b/web/src/components/MemoryPressureBanner.test.tsxindex e92905c85aa..9ac5d5f2c0e 100644--- a/web/src/components/MemoryPressureBanner.test.tsx+++ b/web/src/components/MemoryPressureBanner.test.tsx@@ -76,7 +76,7 @@ describe("MemoryPressureBanner", () => {/>,);expect(banner()?.textContent).toContain(- "restarted after running out of memory",+ "restarted unexpectedly, most likely because it ran out of memory",);});@@ -121,4 +121,82 @@ describe("MemoryPressureBanner", () => {);expect(banner()?.textContent).toContain("almost out of memory");});++ it("a NEW OOM restart (different boot_id) re-opens a dismissed OOM notice", async () => {+ await render(+ <MemoryPressureBanner+ status={statusWith({+ pressure: "ok",+ last_boot_suspected_oom: true,+ boot_id: "2026-08-13T01:00:00+00:00",+ })}+ />,+ );+ const dismiss = container.querySelector(+ '[data-testid="memory-pressure-banner"] button',+ ) as HTMLButtonElement;+ await act(async () => dismiss.click());+ expect(banner()).toBeNull();+ // Same boot: stays dismissed.+ await rerender(+ <MemoryPressureBanner+ status={statusWith({+ pressure: "ok",+ last_boot_suspected_oom: true,+ boot_id: "2026-08-13T01:00:00+00:00",+ })}+ />,+ );+ expect(banner()).toBeNull();+ // The gateway OOM-loops and boots again: new incident, banner returns.+ await rerender(+ <MemoryPressureBanner+ status={statusWith({+ pressure: "ok",+ last_boot_suspected_oom: true,+ boot_id: "2026-08-13T02:00:00+00:00",+ })}+ />,+ );+ expect(banner()?.textContent).toContain("restarted unexpectedly");+ });++ it("recovery to ok resets a dismissed live-pressure banner for the next episode", async () => {+ await render(+ <MemoryPressureBanner status={statusWith({ pressure: "critical" })} />,+ );+ const dismiss = container.querySelector(+ '[data-testid="memory-pressure-banner"] button',+ ) as HTMLButtonElement;+ await act(async () => dismiss.click());+ expect(banner()).toBeNull();+ // Confirmed recovery clears live dismissals...+ await rerender(+ <MemoryPressureBanner status={statusWith({ pressure: "ok" })} />,+ );+ expect(banner()).toBeNull();+ // ...so the NEXT critical episode surfaces again.+ await rerender(+ <MemoryPressureBanner status={statusWith({ pressure: "critical" })} />,+ );+ expect(banner()?.textContent).toContain("almost out of memory");+ });++ it("unknown pressure (stale heartbeat) does NOT reset live dismissals", async () => {+ await render(+ <MemoryPressureBanner status={statusWith({ pressure: "elevated" })} />,+ );+ const dismiss = container.querySelector(+ '[data-testid="memory-pressure-banner"] button',+ ) as HTMLButtonElement;+ await act(async () => dismiss.click());+ await rerender(+ <MemoryPressureBanner status={statusWith({ pressure: "unknown" })} />,+ );+ expect(banner()).toBeNull();+ await rerender(+ <MemoryPressureBanner status={statusWith({ pressure: "elevated" })} />,+ );+ expect(banner()).toBeNull();+ });});diff --git a/web/src/components/MemoryPressureBanner.tsx b/web/src/components/MemoryPressureBanner.tsxindex 9a7ef628ee4..79de451a344 100644--- a/web/src/components/MemoryPressureBanner.tsx+++ b/web/src/components/MemoryPressureBanner.tsx@@ -11,14 +11,47 @@ import { useI18n } from "@/i18n";* `elevated`/`critical` band right now.* 2. Post-mortem — the previous gateway life died uncleanly and its last* heartbeat showed near-exhausted memory (`last_boot_suspected_oom`).+ * This is a heuristic, not proof the OOM killer acted — copy says so.** Both previously died in server-side log files; a hosted agent could be* OOM-killed hourly while the dashboard looked healthy.*- * Dismissal is session-scoped per trigger kind (sessionStorage), so a user- * who acknowledged "restarted after OOM" is not re-nagged on every poll,- * but a NEW escalation (ok → critical) still surfaces.+ * Dismissal semantics (session-scoped, sessionStorage):+ * - OOM-restart dismissal is keyed to the reporting boot (`boot_id`), so a+ * LATER restart — the hourly-loop case this exists for — re-opens the+ * banner in the same tab.+ * - Live-pressure dismissal masks only the dismissed severity; escalation+ * (elevated → critical) re-opens immediately, and a confirmed recovery+ * (pressure back to "ok", not "unknown") clears live dismissals so the+ * NEXT episode surfaces again.*/++const STORAGE_KEY = "memoryBannerDismissed";+const LIVE_TRIGGERS = ["critical", "elevated"];++function readDismissed(): string[] {+ try {+ const parsed: unknown = JSON.parse(+ sessionStorage.getItem(STORAGE_KEY) ?? "[]",+ );+ // Pre-incident-key builds stored a bare trigger string; JSON.parse+ // throws on those, landing in the catch — a clean reset, not a crash.+ return Array.isArray(parsed)+ ? parsed.filter((entry): entry is string => typeof entry === "string")+ : [];+ } catch {+ return [];+ }+}++function writeDismissed(entries: string[]) {+ try {+ sessionStorage.setItem(STORAGE_KEY, JSON.stringify(entries));+ } catch {+ /* ignore */+ }+}+export function MemoryPressureBanner({status,}: {@@ -26,6 +59,28 @@ export function MemoryPressureBanner({}) {const { t } = useI18n();const memory = status?.memory;+ const pressure = memory?.pressure;++ const [dismissed, setDismissed] = useState<string[]>(readDismissed);++ // Recovery reset (render-time state adjustment — the sanctioned React+ // pattern for reacting to prop changes without an effect): once live+ // pressure is demonstrably back to "ok", any dismissed live-pressure+ // entries describe a PAST episode — drop them so the next one isn't+ // silently hidden. "unknown" (stale/absent heartbeat) is absence of+ // evidence, not recovery, and clears nothing.+ const [prevPressure, setPrevPressure] = useState(pressure);+ if (pressure !== prevPressure) {+ setPrevPressure(pressure);+ if (+ pressure === "ok" &&+ dismissed.some((entry) => LIVE_TRIGGERS.includes(entry))+ ) {+ const next = dismissed.filter((entry) => !LIVE_TRIGGERS.includes(entry));+ writeDismissed(next);+ setDismissed(next);+ }+ }// Highest-severity active trigger, or null.const trigger = !memory@@ -38,33 +93,29 @@ export function MemoryPressureBanner({? "elevated": null;- const [dismissed, setDismissed] = useState<string | null>(() => {- try {- return sessionStorage.getItem("memoryBannerDismissed");- } catch {- return null;- }- });+ // OOM-restart dismissal is per incident (boot), live-pressure dismissal is+ // per severity. A missing boot_id (degraded payload) degrades to a shared+ // bucket — old behavior, never a crash.+ const dismissKey =+ trigger === "oom_restart"+ ? `oom_restart:${memory?.boot_id ?? "unknown"}`+ : trigger;- // Dismissal only masks the exact trigger that was dismissed — an- // escalation (elevated → critical) changes `trigger` and therefore- // re-opens the banner without any effect/state churn.- if (!trigger || dismissed === trigger) return null;+ if (!trigger || !dismissKey || dismissed.includes(dismissKey)) return null;const dismiss = () => {- setDismissed(trigger);- try {- sessionStorage.setItem("memoryBannerDismissed", trigger);- } catch {- /* ignore */- }+ setDismissed((prev) => {+ const next = prev.includes(dismissKey) ? prev : [...prev, dismissKey];+ writeDismissed(next);+ return next;+ });};const critical = trigger === "critical";const message =trigger === "oom_restart"? (t.app.memoryOomRestartBanner ??- "Your agent restarted after running out of memory. Long sessions and many concurrent tasks increase memory use.")+ "Your agent restarted unexpectedly, most likely because it ran out of memory. Long sessions and many concurrent tasks increase memory use."): critical? (t.app.memoryCriticalBanner ??"Your agent is almost out of memory and may restart. Consider closing idle sessions or upgrading its memory.")@@ -75,7 +126,7 @@ export function MemoryPressureBanner({<divrole="alert"data-testid="memory-pressure-banner"- className={`mt-14 lg:mt-0 flex items-center gap-2 border-b px-4 py-1.5 text-xs ${+ className={`flex items-center gap-2 border-b px-4 py-1.5 text-xs ${critical? "border-red-500/40 bg-red-500/10 text-red-300": "border-amber-500/40 bg-amber-500/10 text-amber-300"diff --git a/web/src/components/ProfileScopeBanner.tsx b/web/src/components/ProfileScopeBanner.tsxindex 9d5adc2fdfd..23df2496754 100644--- a/web/src/components/ProfileScopeBanner.tsx+++ b/web/src/components/ProfileScopeBanner.tsx@@ -14,10 +14,7 @@ export function ProfileScopeBanner() {if (!profile || profile === currentProfile) return null;return (- // mt-14 on mobile clears the fixed lg:hidden header (h-14, z-40) so the- // scope banner — the main safety signal for scoped writes — is never- // hidden behind it; lg:mt-0 restores desktop flow.- <div className="mt-14 lg:mt-0 flex items-center gap-2 border-b border-amber-500/40 bg-amber-500/10 px-4 py-1.5 text-xs text-amber-300">+ <div className="flex items-center gap-2 border-b border-amber-500/40 bg-amber-500/10 px-4 py-1.5 text-xs text-amber-300"><Users className="h-3.5 w-3.5 shrink-0" /><span>{(diff --git a/web/src/i18n/en.ts b/web/src/i18n/en.tsindex 4fa280106ed..189218f3301 100644--- a/web/src/i18n/en.ts+++ b/web/src/i18n/en.ts@@ -98,7 +98,7 @@ export const en: Translations = {managingProfileBanner:"Managing profile \u201c{name}\u201d \u2014 config, keys, skills, MCPs, model, and new chats apply to that profile.",memoryOomRestartBanner:- "Your agent restarted after running out of memory. Long sessions and many concurrent tasks increase memory use.",+ "Your agent restarted unexpectedly, most likely because it ran out of memory. Long sessions and many concurrent tasks increase memory use.",memoryCriticalBanner:"Your agent is almost out of memory and may restart. Consider closing idle sessions or upgrading its memory.",memoryElevatedBanner: "Your agent is running low on memory.",diff --git a/web/src/lib/api.ts b/web/src/lib/api.tsindex c5b7eb4d0e3..41c2ac45c4c 100644--- a/web/src/lib/api.ts+++ b/web/src/lib/api.ts@@ -1899,8 +1899,12 @@ export interface MemoryPressureStatus {sampled_at?: string | null;/** Previous gateway life died without running any exit path. */last_boot_unclean?: boolean;- /** ...and its final heartbeat showed near-exhausted memory. */+ /** ...and its final heartbeat showed near-exhausted memory. Heuristic —+ * strong evidence of an OOM kill, not proof the kernel OOM killer acted. */last_boot_suspected_oom?: boolean;+ /** Identity of the current gateway life (sentinel started_at). Changes on+ * every restart; keys per-incident banner dismissal. */+ boot_id?: string | null;}export interface SessionInfo {