Skip to content

Inbox: hold only the watched threads' decisions (memory soak growth doubled by #4016) - #4139

Merged
backnotprop merged 3 commits into
mainfrom
perf/inbox-soak-growth
Nov 27, 2026
Merged

backnotprop merged 3 commits into
mainfrom
perf/inbox-soak-growth

Conversation

@backnotprop

@backnotprop backnotprop commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

The memory soak (tests/e2e/inbox-memory-soak.spec.ts) has failed now and then since 25 Nov and was rerun as a flake. It is not a flake. One merge doubled its growth.

Evidence (main's soak, read from CI logs from 6 Nov on). Growth was 3.4 to 7.0 MB from 6 Nov until 1c60ce1 (25 Nov 18:22: 4.1 MB, open heap 107.3 MB). The next run, on 9d77678 (the merge of #4016), read 13.1 MB, with the open heap at 112.0 MB. All 11 runs since read 8.6 to 13.5 MB, with the open heap at 110.1 to 112.0 MB. The only other commit in between is #4053 (CSS and an HTML frame). Listeners and DOM nodes are the same before and after: the growth is JS data. The roughly 50 listeners per round were already there on 16 Nov. They belong to the open thread's new message, which is on screen.

Cause. #4016 turned decision mode on by default (useDecideSitting.ts, settings.decision_mode.on). Each window then read GET /api/inbox/decisions and kept the whole answer in App.tsx state. That answer is every open decision in the store. On the soak's own seed (scripts/inbox-large-store.ts, measured in process) it is 2,610 decisions over 1,722 threads, or 4.25 MB of JSON. Every window paid for it, whether or not anyone opened decision mode. The read happens again for each message into the open thread. The soak's new step of about 6 MB between samples 150 and 180 falls on message 151, the first question in the open thread, when a changed list was read and swapped in.

Fix. The window draws decisions only for the threads in its existing watched set: a pane's "Decide these N" and the sitting's thread. A read now keeps those threads' decisions (keepWatched in decisions/model.ts) and a count for every thread. A thread just opened therefore still shows its count at once. The filter runs before setDecisions, so no state updater captures the full read. Nothing on screen changes. App.tsx is one line shorter (ceiling 6295 → 6294).

Not in this PR: the server still builds the whole list, and the window still parses it, on each read that touches a watched thread. That memory is freed after the read, but it costs CPU. A ?threads= filter on the route would remove it.

Tests: packages/inbox/decisionsModel.test.ts 17/17 (1 new), tests/inbox-structure.test.ts 5/5, tsc -p packages/inbox clean. The proof is the soak shard in this PR's e2e run.

Round 2 (review). A thread just opened shows its "Decide these N" from the counts, before its own decisions are held. A sitting opened in that gap now:

  • takes its thread's name from its first decision once the read lands;
  • reads again up to three times (1.5 s, then 3 s) and draws again after every read that lands. A thread with nothing left therefore ends the sitting as usual instead of staying on "Reading what waits on you…";
  • after three failed reads, shows the card's existing "Couldn't read the question. Try again". No new words.

The read moved to decisions/keptRead.ts (App.tsx 6294 → 6288 lines, ceiling lowered). The event stream's reconnect does not read the decisions again; its catch-up after a silence does.

Known and left: past 64 watched threads the set starts over. A tucked sitting can then show its loading state for one read until its thread joins again.

New DOM test packages/inbox/decisionSittingWait.test.tsx covers the three outcomes. I checked that each case fails without its fix.

Decision mode turned on by default (#4016), so every window read
GET /api/inbox/decisions, which lists every open decision in the store,
and kept the whole list in state. On the memory soak's store that is
2,610 decisions, 4.25 MB of JSON: the heap at open rose 4.7 MB and the
soak's growth went from 4 to 13 MB, for people who never open decision
mode.

The window draws decisions only for the threads it watches (a pane's
"Decide these N", the sitting's thread). A read now keeps those
threads' decisions and a count for every thread, so a thread just
opened still shows its count at once.
@backnotprop backnotprop added the ci:e2e Run the full browser suite (Inbox window e2e) on this PR label Nov 27, 2026
A thread just opened shows its "Decide these N" from the read's counts,
before its decisions are held. Pressed in that moment, the sitting got
an empty queue and flashed its end screen until the read landed; it now
shows its loading state until a read has kept that thread's decisions.
A thread just opened shows its "Decide these N" from the read's counts,
before its decisions are held. A sitting opened then now:
- takes its thread's name from its first decision once the read lands;
- reads again up to three times, and draws again after each read that
  landed, so a thread with nothing left ends the sitting instead of
  leaving it on "Reading what waits on you…";
- after three failed reads, says so with the card's existing "Couldn't
  read the question. Try again".

The read itself moves out of App.tsx (decisions/keptRead.ts) and returns
whether it landed. App.tsx shrinks by six lines (ceiling 6294 -> 6288).
@backnotprop
backnotprop marked this pull request as ready for review November 27, 2026 12:12
@backnotprop
backnotprop merged commit c8c2443 into main Nov 27, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:e2e Run the full browser suite (Inbox window e2e) on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant