Skip to content

fix(status-bar): stop the status bar from crashing with a layout loop when chip widths drift - #35506

Draft
OrcaWin wants to merge 4 commits into
mainfrom
crash/s59-statusbar-185
Draft

OrcaWin wants to merge 4 commits into
mainfrom
crash/s59-statusbar-185

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Warning

Do not merge — the bug this fixes hasn't been reproduced outside a mocked layout. Reviewed during the crash-PR scan, which merged the 9 related PRs, and held back:

  • Bug not reproduced in real Chromium. The width drift shows up only in the happy-dom layout model (+2px / -60px). Real headless Chromium measured 0px drift across different widths, display scale factors (DPR) and languages. What caused the drift on the user's machine is unknown.
  • The fix limits the loop instead of removing its cause. What reliably prevents fix: improve scrollbar and file explorer scroll behavior #185 is MAX_SETTLE_UPDATES, a cap on updates. When the cap is hit, the bar falls back to a fixed layout that can be more cramped or more collapsed than it needs to be. The chip-width cache and collapse-tracking logic target the modeled drift only.
  • Reviews: one of 3 independent reviewers called it a band-aid, and the final review rated merge risk MEDIUM.

Needed to unblock: reproduce the drift in a real browser (actual chip CSS, a fractional display scale, the reporter's providers and language), then fix the measurement so collapsed chips measure the same as in-row chips, rather than limiting updates.

Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​273 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​273
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​249 $\color{#cf222e}{\Huge{\mathbf{−}}}$​39 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​210

Description

From the Scan-59 crash report: on macOS v1.4.243, React error #185 ("Maximum update depth exceeded") is thrown from StatusBar. De-minifying StatusBar-C_hs5yr5.js puts the throwing setState at setLevel(nextLevel) inside evaluate() in useStatusBarDensity (src/renderer/src/components/status-bar/status-bar-density.ts), run from its no-deps useLayoutEffect. The breadcrumb (pendingLanes=2 SyncLane, storeWrites=0) fits a chain of layout-effect setStates, not a zustand selector. This is separate from the CombinedDiffViewer loop in #31552.

How the loop can happen

  • recordStatusBarDensityWidth treats a natural-width change over 1px at a level as a content change and wipes every recorded level.
  • At the collapsing levels (3 and 4), the natural width adds back collapsed chips, which are measured while out of flow (invisible absolute).
  • If a collapsed chip measures differently from its in-row width, collapsing reads as a content change. The wipe sends the hook back to level 0, which clears the collapse; it walks back to level 3, collapses, sees the same mismatch, and repeats. Every step is a synchronous layout-effect update, so React hits its nested-update limit.

Fix (status-bar-density.ts, status-bar-usage-collapse.ts)

  1. Collapse-invariant measurement. The hook remembers each chip's in-row width (resolveUsageChipWidth) and measureUsageRow uses it for collapsed chips. naturalWidth, pinnedWidth and pickCollapsedUsageChips therefore see the same widths whatever is collapsed. The memo is reset when the density level or devicePixelRatio changes. If a collapsed chip's out-of-flow width changes after it collapsed (its content changed), its memo is dropped and the measured width is used.
  2. Collapse choice converges. A collapsed set that fits is kept until the available width, the row's natural width, or the chip roster/urgency changes, so it cannot flip back and forth at a fixed level. Urgency is part of that check: a folded chip that turns urgent (with no width change) is re-picked and pinned back into the row, same as on main.
  3. Backstop budget. MAX_SETTLE_UPDATES = levels × 3 = 15 self-caused updates per settle pass (a pass resets on a render the hook did not cause, an available-width change, or an evaluation that changes nothing). If it runs out, the bar goes to the tightest level with every calm chip collapsed, syncs overflowing once more, and logs console.warn('[status-bar] density did not settle within 15 updates; using the tightest layout') (once per bar, so persistent drift cannot spam the log).
  4. The fallback is sticky. Once in the fallback, outside re-renders (usage polling, agent status) cost one commit and do not re-run the probe. The fallback ends only when the available width, the natural width measured in the fallback layout, or the chip roster/urgency changes. That content is recorded from the fallback layout itself, so drift between layouts cannot end it.

The first commit's "only compare widths measured under the same collapsed set" check is gone. With collapse-invariant measurement it is no longer needed, and it had a blind spot: a real content change in the same render as a collapse change did not invalidate stale roomier levels.

Fix evidence

Tests (happy-dom with a layout model: 5 chips, 220px bar):
status-bar-density.layout-loop.test.tsx

  • Without drift: a first render at 220px settles on level 3 with gemini, grok, kimi collapsed, and the rendered row fits. Going 1000px to 220px lands on the same state. These pass on origin/main too, which shows the budget and memo don't change the outcome when there is no drift.
  • With collapsed chips measuring +2px off: settles on the same drift-free result.
  • Content shrinks in the same render as the first collapse: the roomier levels are re-probed and the bar ends at level 0 with nothing collapsed.
  • Synthetic never-settling drift (segment width alternates at roomier levels): no throw, warns, ends at the tightest level with every calm chip collapsed, and the row fits in 220px.
  • A collapsed chip turns urgent at the same 220px width: the collapsed set is re-picked (codex, gemini, grok) so the urgent chip is visible. This passes on main; it fails on the previous PR head, which kept the stale set.
  • Sticky fallback: after the never-settling fallback, 5 outside re-renders at 220px each cause exactly one commit, stay at the tightest level, and warn only once. A chip turning urgent re-runs the fallback with that chip shown, and widening to 1000px ends the fallback at level 0. Fails on the previous PR head and throws fix: improve scrollbar and file explorer scroll behavior #185 on main.
  • Synthetic -60px drift that depends on how many chips are collapsed (a deliberate worst case that defeats the memo, not a measured case): no throw, and the final row fits.

status-bar-usage-collapse.test.ts: unit tests for resolveUsageChipWidth (remembered width while collapsed, a content change while collapsed, a chip never seen in the row).

Tests origin/main first PR commit this PR
+2px drift throws #185 pass pass
content change during collapse pass fails (stays at level 3) pass
never-settling drift fallback throws #185 fails (no fallback) pass
-60px count-dependent drift throws #185 fails pass
drift-free exact outcomes (2) pass pass pass
urgent chip re-picked at same width pass not run (previous head b29038b: fails) pass
sticky fallback across outside renders throws #185 not run (previous head b29038b: fails) pass

Checks: pnpm test src/renderer/src/components/status-bar/ --maxWorkers=2 reports Test Files 68 passed (68), Tests 629 passed (629). oxlint and oxfmt --check are clean on the changed files.

Real-layout evidence (and its limits)

I could not get collapsed chips to measure differently from their in-row width in real Chromium. A headless Chromium scratch page copied the status-bar usage row CSS (relative whitespace-nowrap bar, overflow-clip cluster, shrink-0 usage row, inline-flex gap-3 button, inline-flex chips that turn invisible absolute when collapsed, and the "+N" chip). It measured each chip in row and with 1 to 5 chips collapsed, and checked the row's computed natural width, at device scale factors 1, 1.25, 1.5, 1.75 and 2 and bar widths from 120 to 700px. The difference was 0.000px in every case, both per chip and for the natural width. The only drift came from applying CSS zoom to the root: getComputedStyle gaps stay unzoomed while rects are zoomed, which breaks the natural-width sum by up to about 16px. Orca uses Electron page zoom, not CSS zoom, on the status bar, so that is not shown to be the user's trigger.

So the drift cases in the tests are models, not reproductions. They show the hook can no longer loop for any per-chip collapse drift and is bounded for anything else. They do not show what drifted on the reporter's machine.

What this does NOT fix / trade-offs

  • Root trigger unconfirmed. We don't know what drifted on the user's machine (fonts, locale, specific provider content, DPR change). The fix makes the hook stable against per-chip collapse drift and bounds every other drift.
  • If unexplained drift keeps going, each real width/content/urgency change can still use up to 15 synchronous commits before it falls back again. In the fallback the bar sits at the tightest level, possibly denser than it needs to be, until one of those changes.
  • About half of this change (chip-width memo, collapse basis) targets a drift mechanism that is modeled, not observed. The update budget is the part that verifiably prevents fix: improve scrollbar and file explorer scroll behavior #185.
  • A chip's remembered width can be stale if its content changes in the same render as it collapses. The in-row chips still pick up the content change, and the memo refreshes on the next level change, so this only affects how much space the "+N" chip assumes it frees, and only until the next re-probe.
  • Not verified end-to-end in the Electron app, because the drift could not be reproduced in real Chromium.

ELI5

The status bar tries each layout, roomiest to tightest, until one fits. When it folded away some usage chips, the folded chips could measure a little differently, so the bar thought its content had changed and started over, forever, until React crashed. Now the bar remembers how wide each chip was while it was visible and uses that number while it's folded, so folding never looks like a content change. Once a folded layout fits, it stays put until the window or the content actually changes. As a last resort, if it still can't settle after 15 tries, it picks the tightest layout and logs a warning.

@nwparker
nwparker force-pushed the crash/s59-statusbar-185 branch from 8ebacd8 to b29038b Compare November 3, 2026 06:01
m4air and others added 3 commits November 2, 2026 22:07
…en measurements drift

The density hook re-measures each level in a layout effect and treated any
>1px natural-width difference at a level as a content change, wiping every
level and re-probing from the roomiest one. When a collapsed (out-of-flow)
usage chip measures off its in-row width, level 3 alternates between its
collapsed and uncollapsed measurement forever, chaining synchronous
layout-effect updates until React throws #185 (max update depth) from
StatusBar.

- Only compare widths measured under the same collapsed set.
- Bound consecutive self-caused updates per settle pass as a backstop.
…ant and converge

- Remember each chip's in-row width (per density level and DPR) and use it for
  collapsed chips, so collapsing never reads as a content change. Drops the
  collapsed-key comparison blind spot from the previous commit.
- Keep a fitting collapsed set until the available width or row content changes.
- When the settle budget runs out, fall back to the tightest level with calm
  chips collapsed and console.warn so the drift can be diagnosed.
- Tests: drift-free exact outcomes, content change during a collapse, budget
  exhaustion ends in a fitting state, resolveUsageChipWidth unit tests.
…he density fallback sticky

- The kept collapsed set now also depends on each chip's urgency, so a folded
  chip that turns urgent is pinned back into the row at the same width.
- Once the settle budget runs out, the bar stays on the fallback layout until the
  available width, the row's natural width or a chip's urgency changes, instead
  of re-running a 15-commit probe on every outside re-render. The warning is
  logged once per bar.
@nwparker
nwparker force-pushed the crash/s59-statusbar-185 branch from b29038b to a49de95 Compare November 3, 2026 06:10
@nwparker

nwparker commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Holding this back from merge: the width drift has been reproduced only in the mocked layout model, and real Chromium measured 0px drift. The fix limits the update loop (MAX_SETTLE_UPDATES) rather than fixing the measurement that causes it. I've added a warning to the top of the PR body listing what would unblock it. The 9 related crash PRs (#31552, #35558, #36827, #34447, #36831, #36174, #36180, #36183, #33971) are merged.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants