mirror of
https://github.com/block/buzz.git
synced 2026-11-25 02:31:36 +00:00
Long-lived renderer sessions accumulate heap and timer churn until GC pauses queue behind input, degrading scroll and click latency. The Cmd+R clean-teardown reload clears it without touching the native engine or its child agents, but relies on the user noticing and acting. Add an idle backstop that performs the same reload automatically once a session is ~12h old and the user is provably away (OS idle >= 30 min and the window unfocused). It withholds the reload while any reload-destroyed volatile work is outstanding: a starting/active huddle, a foreground or background media upload including its completion settling window, queued local file attachments a draft cannot serialize, or any in-flight send/mutation/native operation. Persisted draft text survives via localStorage, so it is deliberately not a blocker. The reload primitive is one idempotent requestRendererReload() shared by Cmd+R and the backstop: a module-level in-flight promise collapses overlapping triggers so the native WebSocket teardown never runs twice, teardown is bounded to 500 ms, and a rejecting or hung teardown is swallowed so the reload always runs -- a rejection can no longer win the race and strand the renderer on a stale heap. All fire/withhold logic is a pure, exhaustively tested predicate; the hook only wires live signals, arms after the session-age threshold, and serializes overlapping checks. Signals are read imperatively at check time (once a minute) so the hook holds no reactive subscription and never re-renders. The controller mounts inside the ready main-window shell only, guarded so Huddle companion windows and every onboarding/blocking/reset/ keyring/relaunch screen are ineligible by construction. Outstanding volatile work is tracked through one app-global registry (volatileWorkRegistry) that owns acquire/release; the native multi-file picker seam registers at the choke point via withVolatileWork so every caller is covered by construction. The deferred paperclip path is deliberately left unregistered: useFilePicker's hidden input has no cancel signal, so acquiring on open risks a hold that never releases. Co-authored-by: Will Pfleger <pfleger.will@gmail.com> Signed-off-by: Will Pfleger <pfleger.will@gmail.com>