# Hangs, idle frames and long-session memory Operator report: the web app sometimes hangs until it is reopened, and animations sometimes feel slow. The app stays open all day. ## Causes and fixes - **Hang: a dead socket blocks every request in turn (confirmed in code and tests).** Requests go out one at a time; each waits for the previous reply, and the server answers them in order on one lane. A socket that outlived a laptop sleep or a network change usually still looks open: the browser is not told until TCP gives up, which can take minutes. Each queued request then waited its own 30 s timeout, one after another, and nothing replaced the socket. Reopening the page was the only fix. `PipelinesClient` (`lib/core/transport/pipelines_client.dart`) now: - replaces the socket when a request times out and nothing arrived while it waited, or when two requests in a row time out (a stuck request lane). Queued requests fail at once and the fresh connection resubscribes as on any reconnect; - sends a `ping` probe outside the queue with the first request after 30 s of quiet (wall clock, so a sleep counts) and when the app returns to the foreground (`pipelines_app.dart`). If it hears nothing within 10 s, it replaces the socket. No standing timer is used. `replaceSilentSocket: false` keeps the old behaviour for widget-test fakes that answer nothing. - **Idle frames: the terminal's blinking cursor ran a Ticker (confirmed in code and a widget test).** While a focused terminal showed a blinking cursor (DECSCUSR 1/3/5), the page asked for a frame on every vsync, all day. `ChatShellCursorBlink` now flips the phase with a 530 ms timer: one frame per phase. - **Markdown cache flushing (confirmed in a unit test).** Every streamed delta cached its intermediate text, so one long reply filled the 1M-character budget and evicted every finished answer. Those answers were then parsed again on scroll. A text that extends the newest entry now replaces it. ## Measurements `tool/perf/idle_session_bench.mjs` (new) runs on the profile full-app fixture in headless Chromium with CPU raster (no GPU). It counts `requestAnimationFrame` calls while the page is idle. `--session N` simulates a long session: open 6 rich chats (one streaming each round), the terminal panel, Runs, Pipelines and Search. After each round it forces a GC and reports the heap. `--census` diffs heap snapshots by constructor. - Idle frames in 5 s (before = after; the blink case is covered by the widget test): Runs 0, run detail 0, Pipelines 0, Settings 0, a rich 80-message chat 0, chat plus terminal panel 0. A chat with a running turn or a running chat in the list animates by design (running border, spinners). - Heap over 10 rounds: 47.5 MB at round 1, 57.2 MB at round 10, with growth slowing. A snapshot diff between rounds 2 and 8 shows +4.6 MB of V8 compiled code and engine-native memory. Dart objects grew by a few KB: 35 cached images (bounded ImageCache), about 70 markdown blocks and a few hundred map cells. No unbounded Dart-side growth was found. - Markdown parse of a 30 KB reply: about 2 ms on the VM. Incremental parsing is not justified. ## Left open (suspected, not measured) - A large `chat_messages` page (200 messages with tool output) is decoded on the main thread. No evidence yet that it exceeds a frame budget; a web worker is not justified without a real-page measurement.