GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix(cli-rs): bound the transcript window so scrolling stops growing memory by simonklee · Pull Request #65826 · anomalyco/opencode Conversation
|
| before | after | |
|---|---|---|
| Page Down, 800 keys | 319 | 175 |
| Page Down, 4,000 keys | 946 | 182 |
| bottom, idle | 1,019 | 161–164 |
| back at the top, idle | 1,026 | 166 |
| peak | 1,026 | 180–182 |
| CPU per key | 0.9 → 6.7 ms, growing | flat, median 1.15 ms |
| latency p50 / p99, down | 16 / 37 ms | 16 / 39 ms |
Jumps, medians of 3 runs on the same session:
| key | before | after |
|---|---|---|
| Home, first (loads every message) | 540 ms | 535 ms |
| Home, later / End | 36 / 13 ms | 36 / 13 ms |
| Page Up, per key | 1.9 ms | 2.0 ms |
| previous user message, first | 1,012 ms, RSS 808 MiB | 21 ms, RSS 158 MiB |
| previous user message, later | 279 ms | 23 ms |
"Previous user message" used to mount every loaded row first and then
search them all. Home and End moved by less than the run-to-run spread.
Two perf scenarios guard it. scroll_all pages the long fixture end to end
both ways and records glibc's in-use bytes as well as Rust's, so OpenTUI's
native memory counts. jump_home_end runs Home, End, Home, End and ten
message steps back:
bun run perf |
before → after |
|---|---|
scroll_all Rust peak |
52.6 → 8.2 MiB (−84%) |
scroll_all malloc peak / kept |
244 → 19.4 / 244 → 16.8 MiB |
scroll_all instructions |
29.5 → 20.3 G (−31%) |
scroll Rust peak / instructions |
49.8 → 7.5 MiB / 5.54 → 1.83 G |
jump_home_end instructions / allocations |
2,242 M → 250 M / 666,380 → 88,258 |
What it costs:
scroll_all allocates 2% more often and 15% more bytes. Total work stillMS1-bounded-transcript-window.md. Nothing on screenrows;above still counts every message above the window. One test changed forsession.message.next no longer mounts every row.What reviews found:
Pin read the content height from before theTranscriptView docs describe theThe tests in tests/all/navigate.rs were written before the change. They
page away and back for 1 to 130 pages from both ends, check that every page
moves by a page, keep the mounted rows under half the transcript, follow a
streaming reply, land jumps on their target, keep opened rows open, and keep
a selection's text. Against the old code, the bounded-window test and the
open-rows test failed. Mutations: without the scroll compensation, both
paging tests fail; without the selection guard, the selection test fails;
without the 30 s bound, the release test fails.
Look first at crates/tui/src/routes/session/messages/list.rs (the window,
Model::dropped), then routes/session/navigation.rs and
features/release.rs.
Commits:
f4ecff757d test(cli-rs): measure memory while scrolling a long sessioneea70b13cc fix(cli-rs): drop transcript rows far from the view6abcc6d885 fix(cli-rs): give freed transcript memory back to the system0cbb942bc0 test(cli-rs): check message navigation and the wheel over dropping rows49bfbb8faf fix(cli-rs): hold the view when rows drop before a pin's layoutfaef972254 docs(cli-rs): describe the bounded transcript window to plugins34b6c20740 test(cli-rs): page with a resize in the frame of each key4bd6858f1d test(cli-rs): measure Home, End and message navigation in a long sessionAdded by the opencode bot (AI-generated).
Public API: plugin transcript view covers only rows near the view, and claimed tool parts can remount with an empty memo (no shape change; backwards compatible)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
dev ungated video generation, added model speeds, and added the opencode_api experimental flag for Code Mode's opencode:// fetch.
Port of #65749. A model the server marks as another model served faster or slower (experimental.speed) is no longer an entry of its own in the model and free model pickers: it is a speed of its standard model. /speed (alias /fast) and speed.cycle switch speeds, only while the current model has some; the dialog lists them slowest first with their price against the standard speed. model.json remembers each model's speed, and recents and favorites saved at a speed stand for the model. The prompt shows the speed after the variant, lays the row out at its measured width, and a switch between speeds reads "Switched speed to ...". Adds the E.16 speed dialog fixture and the E.16/speed-prompt P-APP scenario, and the speed ops to the F.5 model.json interop oracle.
Port of #65441, which makes the TS client's event subscriptions honor an aborted signal before handing out queued events. The JS host's client.rpc(...).events.subscribe() returned the events queued before the abort; it now ends as the TS client's does.
A subagent counts as active while its session runs or while a job in its tree runs. The store added jobs from the job list and removed them only on `experimental.job.updated`. Servers before f15ed39, such as the installed v2.3.2, list jobs but never send that event. So a subagent job that a mount or reconnect listed stayed running until the client restarted, and its child stayed in the footer's count and the Subagents tab after it went idle. A child that was resumed while such a read ran got stuck this way. A subagent job runs one busy period of its child: the server settles it when the child's execution ends. The store now ends the child's subagent jobs when that execution ends, except on a shutdown, which keeps the job for the restart. Current servers announce the same end right after, and that event then changes nothing.
`bun run perf` took the first executable that cargo reported for each test build. For the TUI, `--test all` also builds its `plugin-launch-witness` binary. When cargo reported that binary first, the script listed scenarios from it, so it found no TUI scenarios and the regression check skipped them. The binary also wrote a file named `--list` into the package directory. Cargo reports artifacts in the order they finish. With free job slots, the small binary finishes before the test binary. With one free slot, from a low CARGO_BUILD_JOBS or a busy machine, cargo builds the test binary first. So some runs today found the TUI scenarios and others did not. The script now takes the artifact that cargo built as a test (`profile.test`).
Users' cli.json files carry experimental keys, and a copy of the config then allocates. The scenarios ran with none, so a per-frame copy of the config cost them nothing and went unseen.
The session sidebar read its setting through Live::info(), which clones the whole cli_config::Info, and it does so on every sync. The clone costs nothing for an empty config, but an experimental map allocates, so any experimental key added about one copy of it per frame: 2.1% of the allocations of a streaming reply. The sidebar and the title's setting now borrow the config instead.
Paging through a long session holds every row it passes: Home, then Page Down to the end, took a real session of 13,415 messages to a 1.07 GB peak. The scroll_all scenario replays it on the long fixture: Home, Page Down until the view stops moving, Page Up back to the head. Most of a mounted row's memory is OpenTUI's native side, which the counting allocator does not see, so the scenario also samples glibc's mallinfo2 after every step and reports the process's malloc peak and what malloc still holds at the end. perf.ts shows both and judges the malloc peak like the other peaks; the kept bytes are for information. Today: 1,971 steps, Rust peak 52.6 MiB, malloc peak 244 MiB, all of it still held at the end.
The transcript's window only grew away from the tail: paging down from Home kept every row passed, and Page Up from the tail mounted every row again. On a 13,415-message session that held 1.02 GiB, most of it OpenTUI's native nodes, and CPU per key grew with the rows mounted. Message navigation and jumps mounted every loaded row first (ensureAllRows). A move that mounts rows on one side of the view now drops the rows more than MARGIN past the other side. Rows dropped above take the scroll offset with them, so the rows on screen stay; rows dropped below wait for the next layout, since the rows mounted above hold the view by how much the content grows. The window's end follows its last row by key, as older pages move indices. Navigation looks among the mounted rows and mounts the next chunk only when its target is not there; a jump mounts the rows around its target. No row drops while a mouse selection holds text. What the reader opened in a row (a tool's output, a failed call's error, a thought, a turn's tokens) now lives in the transcript, keyed by call or message ID, so a row that drops and comes back opens as it was left. That was already lost whenever the window returned to the tail. The tests in navigate.rs check the outcomes: paging away and back returns to the same screen, every page moves by a page, the window stays under half the transcript, a streaming reply moves no reader and is followed at the bottom, jumps land wherever the window is, opened rows come back open, and a selection keeps its text. Deviation MS1.
Rows the transcript drops free their memory into glibc's heap, which returns pages only from its top: after a long scroll most of what the rows held stayed resident. Before the window was bounded, a return to the tail left 808 MiB free but resident, and malloc_trim(0) took RSS from 1,027 to 247 MiB in 19 ms. Once at least 100 rows have dropped since the last release (by a render, or with a closing transcript), a release runs 2 s after the last drop, and at most once every 30 s. The call is glibc's malloc_trim(0), in opencode-util behind cfg(all(target_os = "linux", target_env = "gnu")); elsewhere it does nothing. No new dependency: opencode-util already links libc.
From the review of mem-scroll (78ed06a407). Stepping back by user message over replies longer than a chunk extends the window twice in one animation pass. The first extend's drop below renders before the second one's mount above, whose pin takes the content height from before the drop, so the view shows unrelated rows for a frame before it lands. The repro fails here and passes on native-next. The wheel test covers the drop path without a selection: every step moves by three rows end to end, and the way back ends where it started.
A pin holds the view by how much the content grows once the rows mounted above are laid out, from the content's height when it is set. Rows dropped since the last layout are still in that height. Message navigation over long turns drops rows below in one continuation and mounts rows above in the next, in the same animation pass, so the pin under-counted the growth and the view showed unrelated rows for a frame. The transcript now notes the height of rows it drops, by frame number, and a pin set before the next layout takes it off.
TranscriptView said it covers the tail of the session the transcript revealed. The window now holds only the rows near the view: it reaches the newest row only while the view is near it, offset, extent and rows are within it, and nothing counts the messages after it. A claimed part is mounted again each time its row comes back into the window: a new generation and an empty memo, and its view is called again. No plugin in this repo claims tool rows or keeps state by mount, and the ABI already ends what a mount owned with its generation. The claim docs now say to keep a call's state under the mount's key, the call's ID. MS1 records both.
From the review of mem-scroll. A resize in the same frame as a key that drops rows pins the reader's row from rects the key's move and drop have not moved yet. The resize then moves the view by more than a page, as it does on native-next, but each step must still overlap the one before, and paging back must return to the head: a drop the view missed would jump by its whole height. Without the drop's scroll compensation, 54 of the 150 steps jump.
The jump_home_end scenario runs Home (which loads every older page), End, Home and End again, then ten steps back by user message from the bottom, on the long fixture. A navigation step used to mount every row before it looked for its target; it now mounts the next chunk only when the target is not among the mounted rows. On 00c38f38e3: 2,242 M instructions, 666,380 allocations, a 49.9 MiB peak. On 764744952b: 250 M, 88,258 and 7.5 MiB. Both repeat within 0.01%.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I couldn't run this one: the review environment has no Rust toolchain, so I couldn't build packages/cli-rs, run tests/all/navigate.rs or perf.rs, or reproduce the memory growth on the base. I only read the code.
The approach looks sound and I found nothing blocking:
Toggles, keyed by call or message ID. It is cleared when the session changes.malloc_trim only runs on glibc Linux, is debounced, and has a SAFETY comment.Public API: nothing changes shape, but plugins see different behaviour.
TranscriptView now covers only the rows near the view. rows no longer grows to every row the reader has passed, above still counts every message above the window, and nothing counts the messages below it.MountId::key.Existing plugins keep working, but one that kept state per mount ID would lose it when its row comes back. No plugin in the repo claims tool rows.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.