tab guardrail (50/200 thresholds) + sidebar action toast

Server side (browser-manager.ts):
Idempotent threshold tracker fires an activity entry exactly once at
each upward crossing of 50 (soft warn) and 200 (hard warn). Re-arms
when the count drops below. Activity-feed surface gives the
audit-trail invariant even with the sidebar closed; the toast UX
lives in the sidebar.

Sidebar side (extension/sidepanel.{html,css,js}):
Every /memory poll evaluates two trigger conditions:
  - Any single tab > 4 GB JS heap (catches the WebGL/video runaway
    case Codex flagged on the eng review).
  - Tab count >= 200.
Toast shows top 5 tabs ranked by max(jsHeap, nodes*1KB + listeners*200)
so a WebGL-heavy tab with small JS heap still surfaces. Default-selected
checkboxes + "Close selected" run \`\$B closetab <id>\` through the
existing /command path — no chrome.tabs.remove bridge needed. "Snooze"
bumps tabsAbove/heapAbove thresholds in chrome.storage.session so the
toast stays hidden until the user accumulates more tabs OR one tab
grows another 2 GB.

Tests: browse/test/tab-guardrail.test.ts pins the server-side
fires-once + re-arms invariants without spinning up Chromium.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-05-27 07:32:26 -07:00
parent 78afd75e72
commit 50387c350c
5 changed files with 458 additions and 0 deletions
+82
View File
@@ -1152,6 +1152,88 @@ footer {
.footer-mem.bad {
color: #ef4444;
}
/* ─── Memory pressure toast ─────────────────────────────────── */
.mem-toast {
position: fixed;
left: 12px;
right: 12px;
bottom: 44px;
z-index: 9999;
background: var(--bg-elevated, #1f1f23);
border: 1px solid #ef4444;
border-radius: var(--radius-md, 6px);
padding: 12px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
font-family: var(--font-sans);
font-size: 12px;
}
.mem-toast-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
}
.mem-toast-header strong {
color: var(--text-heading);
font-size: 13px;
}
.mem-toast-close {
background: transparent;
border: none;
color: var(--text-meta);
cursor: pointer;
font-size: 18px;
line-height: 1;
padding: 0 4px;
}
.mem-toast-close:hover { color: var(--text-heading); }
.mem-toast-body {
margin-bottom: 8px;
color: var(--text-body);
line-height: 1.4;
}
.mem-toast-body .mem-toast-row {
display: flex;
align-items: center;
gap: 8px;
padding: 4px 0;
}
.mem-toast-body .mem-toast-row label {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
cursor: pointer;
}
.mem-toast-body .mem-toast-size {
font-family: var(--font-mono);
font-size: 11px;
color: var(--text-meta);
width: 70px;
text-align: right;
}
.mem-toast-actions {
display: flex;
gap: 8px;
justify-content: flex-end;
}
.mem-toast-btn {
background: var(--bg-base);
border: 1px solid var(--zinc-600);
border-radius: var(--radius-sm, 4px);
color: var(--text-body);
cursor: pointer;
font-size: 12px;
padding: 4px 12px;
}
.mem-toast-btn:hover { background: var(--zinc-700); }
.mem-toast-btn.primary {
background: #ef4444;
border-color: #ef4444;
color: #fff;
}
.mem-toast-btn.primary:hover { background: #dc2626; }
.port-input {
width: 56px;
padding: 2px 6px;