GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@simonklee

@simonklee simonklee commented Nov 23, 2026 •
edited by opencodejr Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

In a long session, press Home, then hold Page Down: the Rust client grew by
about 200 KiB per key and never gave the memory back. On a real session of
13,415 messages it held 1.02 GiB by the bottom and 1,026 MiB back at the top.
The transcript's window only grew. Each row passed on the way down stayed
mounted, with its Rust widgets (about 170 MiB) and its OpenTUI nodes, text
buffers and Markdown models (about 720 MiB). The CPU per key grew with what
was mounted, from 0.9 to 6.7 ms. When the window collapsed back to the tail,
glibc kept the 808 MiB it freed resident, because live chunks sat above it
in the heap.

Now:

  • The window drops rows far from the view. When it grows on one side,
    rows more than 60 (by weight) past the view on the other side unmount.
    Rows dropped above come out of the scroll offset in the same frame. Rows
    dropped below go after the next layout, in a render of their own, so
    dropping below never moves the view. Message navigation searches the
    mounted rows and mounts the next chunk only when its target is not among
    them. A jump mounts 60 rows on each side of its target.
  • What a reader opened stays open. A shell's output, a failed call's
    error and a turn's token table keep their expanded state in the
    transcript's Toggles, keyed by call or message ID, instead of in each
    widget. Before, they came back collapsed whenever the window collapsed to
    the tail.
  • Freed memory goes back to the system. After at least 100 rows drop,
    malloc_trim(0) runs 2 s after the last drop, at most once every 30 s.
    This runs on glibc Linux only; elsewhere it does nothing, and it adds no
    dependency.
  • While a mouse selection holds text, no row drops, so the selection
    copies whole. Any key clears it, as before.

On the same session, same walk (Home, Page Down to the end, Page Up to the
top, idle), release builds, MiB:

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:

  • Rows dropped on the way down are built again on the way back up.
    scroll_all allocates 2% more often and 15% more bytes. Total work still
    falls, because a key no longer walks every mounted row. A key that mounts
    a chunk takes about two frames.
  • It differs from the TypeScript TUI, whose window only grows, so it has a
    deviation file, MS1-bounded-transcript-window.md. Nothing on screen
    differs. A plugin reading the published transcript sees fewer rows;
    above still counts every message above the window. One test changed for
    it: session.message.next no longer mounts every row.
  • The store still loads every page from Home: 84 MiB of the 182. That is the
    only cost left that grows with the session's length, and it is not in this
    PR.

What reviews found:

  • Confirmed (low): a frame of unrelated rows on "previous user message"
    over turns longer than about 60 rows. Two extends ran in one animation
    pass, and the second's Pin read the content height from before the
    first's drop. The transcript now records the height of what it drops, by
    frame, and a pin set before the next layout takes it off. The reviewer's
    repro is a test. With the correction zeroed, it fails with 16 stray
    frames.
  • Plugin-claimed rows remount. No plugin in the repo claims tool rows.
    The claim docs now say that a part can mount many times and that each
    mount starts with an empty memo. The TranscriptView docs describe the
    bounded window.
  • A resize in the same frame as a key already moved a step by more than
    a page before this change. A new test pages 150 times with a resize before
    each frame and checks that no rows are skipped.

The 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 session
  • eea70b13cc fix(cli-rs): drop transcript rows far from the view
  • 6abcc6d885 fix(cli-rs): give freed transcript memory back to the system
  • 0cbb942bc0 test(cli-rs): check message navigation and the wheel over dropping rows
  • 49bfbb8faf fix(cli-rs): hold the view when rows drop before a pin's layout
  • faef972254 docs(cli-rs): describe the bounded transcript window to plugins
  • 34b6c20740 test(cli-rs): page with a resize in the frame of each key
  • 4bd6858f1d test(cli-rs): measure Home, End and message navigation in a long session

Added 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
simonklee added 15 commits November 23, 2026 12:35
@simonklee
chore(cli-rs): regenerate the API for v2.4.0
bfe0cc6
dev ungated video generation, added model speeds, and added the
opencode_api experimental flag for Code Mode's opencode:// fetch.
@simonklee
feat(cli-rs): offer a model's service tiers as a speed
eaba060
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.
@simonklee
fix(cli-rs): end a cancelled plugin RPC event subscription at once
fd3097a
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.
@simonklee
fix(cli-rs): drop finished subagents from the active list
a485546
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.
@simonklee
fix(cli-rs): measure the test binary, not the first executable
99d2691
`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`).
@simonklee
test(cli-rs): run the perf scenarios with an experimental key
f17cac1
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.
@simonklee
fix(cli-rs): stop copying the config on every frame
854c441
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.
@simonklee
test(cli-rs): measure memory while scrolling a long session
f4ecff7
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.
@simonklee
fix(cli-rs): drop transcript rows far from the view
eea70b1
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.
@simonklee
fix(cli-rs): give freed transcript memory back to the system
6abcc6d
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.
@simonklee
test(cli-rs): check message navigation and the wheel over dropping rows
0cbb942
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.
@simonklee
fix(cli-rs): hold the view when rows drop before a pin's layout
49bfbb8
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.
@simonklee
docs(cli-rs): describe the bounded transcript window to plugins
faef972
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.
@simonklee
test(cli-rs): page with a resize in the frame of each key
34b6c20
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.
@simonklee
test(cli-rs): measure Home, End and message navigation in a long session
4bd6858
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%.
Base automatically changed from native-fixes to dev November 23, 2026 14:25
opencodejr[bot]
opencodejr Bot reviewed Nov 23, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for 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:

  • Rows dropped above come out of the scroll offset in the same frame, and rows dropped below wait for the next layout, so the view doesn't move. A pin set before that layout takes off the height of the dropped rows.
  • The end of the window follows its last row by key, so an older page loading or a regrouping doesn't shift it.
  • Navigation now searches only the mounted rows. When the target isn't there it mounts the next chunk and looks again after layout. This replaces mounting every row.
  • Expanded state lives in 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.
  • The new tests run on the app's simulated clock, so timing shouldn't make them flaky.

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.
  • A claimed tool part can mount more than once, each mount starting with an empty memo and sharing the call's 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@simonklee
simonklee enabled auto-merge (squash) November 23, 2026 14:28
@simonklee
test(cli-rs): fix flaky tests and a JS host settlement defect (#65827)
0d52030
@simonklee
simonklee merged commit 0089ba9 into dev Nov 23, 2026
10 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@simonklee
simonklee deleted the native-memory branch November 23, 2026 14:33
beyondChang pushed a commit to beyondChang/opencode that referenced this pull request Nov 24, 2026
@simonklee @beyondChang
fix(cli-rs): bound the transcript window so scrolling stops growing m…
7d982a5
…emory (anomalyco#65826)
@simonklee simonklee mentioned this pull request Nov 25, 2026
fix(cli-rs): bring the Rust client level with the TUI #66470
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@opencodejr opencodejr[bot] opencodejr[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@simonklee
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.