Skip to content

fix(tui): reply-step rows, CJK wrap, pasted mentions; drop the rail's search line - #1417

Merged
huichen merged 24 commits into
mainfrom
pr/huichen
Oct 29, 2026
Merged

huichen merged 24 commits into
mainfrom
pr/huichen

Conversation

@huichen

@huichen huichen commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Six commits land on the TUI workbench and on the two test harnesses that were failing on timing rather than on behaviour.

The visible changes: a running reply's newest step now gets its own row, the mention menu no longer swallows a pasted ![]() marker, Chinese text wraps at the column width instead of at a stray space, the footer's cache rate reads the prompt alone rather than the prompt plus the reads, and the rail loses its search line while folded workspaces still remember their state.

The harness changes name what they were actually waiting for. The host's remote-peer tests wait until the broker has registered the events lane before publishing on it (connect_with_emitter returns when the SUB leaves the client, not when the broker applies it, and NATS Core does not replay), and the agent's shutdown test gives the drain 30 s instead of 3 s — the old bound measured the runner, not the invariant it was there to protect. No assertion was weakened in either case.

Commits

  • fix(tui): keep a running reply's newest step on its own row
  • fix(tui): keep the mention menu out of a pasted image marker
  • test(host,agent): publish after the event lane exists; give the stop budget room
  • fix(tui): read the cache rate off the prompt, not the prompt plus the reads
  • fix(tui): break Chinese lines at the width, not at a stray space
  • refactor(tui): drop the rail's search line

Verification

Local, rustc/clippy 1.99.1 from ~/.rustup, ulimit -n 8192:

  • cargo fmt --all -- --check — clean
  • cargo clippy -p future-tui -p future-host -p future-agent --all-targets -- -D warnings — clean
  • cargo test -p future-tui --lib — 1515 passed / 3 ignored at 5cb4d4978, then 1508 passed / 3 ignored in a detached worktree at the frozen tip fd66bec97 (the last three commits landed while the first pass was running)
  • cargo test -p future-tui --test i18n_guard — 8 passed
  • cargo test -p future-host --lib -- remote_peer — 130 passed
  • cargo test -p future-agent --lib -- service::approval — 1 passed
  • packages/remote-client: tsc --noEmit clean, jest 683 passed / 31 suites

Notes

The fence lane is worth its one open connection only because the cost is
bounded and compensated: a read that does not queue behind the ordered writer
cannot see a write that is still queued, so a session whose placeholder commit
is waiting reads missing. This asserts that lag directly — the fence answers
while the writer is held, the queued create is not visible yet, and the same
question answers present once it commits — so a later change that puts the
fence back on the writer lane, or a caller that trusts missing without
confirming it, has a test to fail.

The desktop half of that contract is covered by
agent_bridge::tests::presence_fence_tests (missing asked twice, deleted and
present once).
recovery_is_ordered_after_already_accepted_appends asserts the order of two
entries, not the latency of the commit between them, but it waited only 5 s for
that commit to land. Every writer commits with `synchronous = FULL`, so a suite
running 32 databases at once can spend longer than that in fsync alone: the full
`cargo test -p future-agent` at 32 threads failed here with `Timeout` on
2026-10-29 while the same suite at 8 threads (CI-like) was green twice.

The wait stays bounded — a real deadlock still fails — but at 60 s it measures
scheduling rather than the disk. No assertion changed.
Four tests register a reset-race hook, and the registry held exactly one. Under
parallel execution the last registration replaced the others, so a reset found no
hook for its own id and succeeded where the test expected `history_changed` — the
id gate was there, the storage was not. Measured 2026-10-29: the full
`cargo test -p future-agent` failed here with 32 test threads and passed with 8.

The registry is now a map keyed by session id, and the hook is removed before it
runs: it writes through the same manager, so holding the registry across that
work would serialize every other test's reset. Test-only (`#[cfg(test)]`); no
production path changes.
A focused rail kept the keys while printable characters, pastes and the
clipboard chord still reached the draft, so the `enter` that followed one
of them opened the rail's selected conversation instead of sending the
prompt. On the launchpad that read as "the first message was never sent —
the screen jumped to somebody else's streaming session".

Editing chords and a second `escape` now blur the rail too, so the keys
land where the typing did. The search line keeps its own `escape`: the
first one clears the filter, the next one leaves the rail.
A focused rail answered the plain left/right arrows by switching between
最近 and 工作区. The rail can hold the keys while the prompt is still on
screen — a click on a tab, a conversation opened from a row, `ctrl+d` —
and a reader standing in the draft reads those two keys as the caret's,
so the rail moved under a caret that never did.

The tabs are now `shift+left`/`shift+right` alone (`Action::PanelPrev` /
`PanelNext`), which already worked from anywhere. Inside a focused rail
the plain arrows are swallowed rather than handed to the editor: that
caret is not the reader's, and moving one they cannot see is the same
surprise one layer down.
`get_session_entries` counts a backward `limit` in user exchanges, but the
canonical branch of `read_display_page` capped the row range at 64 on top of
that window. One busy run is far more than 64 display rows on its own (an
assistant step and a tool entry per call), so a ten-exchange tail page came
back as whatever fitted, the client's missing-user-prefix fetch pulled that
run's question in, and the transcript opened on the newest exchange alone —
everything above it looked like it had been lost, with no page of it loaded
and no sign that any existed.

A backward read now takes the window it named. The row ceiling stays on the
forward branch, where `limit` counts rows and `nextOffset` resumes them. The
canonical page is still bounded: its rows carry no bodies, so the bound moves
to the materializer that reads them — the same eight-megabyte budget every
other page has, which happens to be exactly what the compatibility branch was
already using for its inline bodies.

Measured on a real 784-row session: a `limit: 10` tail read returned 64 rows
(one exchange) before and 783 rows across all ten exchanges after.
…budget room

Two required checks were red on #1415 (2026-10-29), and both still fail on the
same tests today:

- Rust macOS test / host-remote: `remote_peer::runtime_tests::
  a_burst_of_events_reaches_the_emitter_in_order` — "the burst never fully
  arrived".
- Rust Windows test / agent: `service::approval_tests::
  shutdown_releases_a_blocking_tool_approval` — "Agent shutdown deadline
  exceeded during journal compactor and SQLite".

The burst is a lost-publish race, not a slow stream. `connect_with_emitter`
returns once the `SUB` has left the client, not once the broker has applied it:
async-nats' `Client::flush()` only flushes the write buffer and awaits no
acknowledgement (0.50 has no ping/pong call, contrary to the comment that sat in
`session::subscribe` and said an "ordered PONG" was waited for). A publish from
the host's *other* connection that reaches the fake broker first is then lost,
and NATS Core has no replay — the emitter legitimately never sees it. Held open
as a hypothesis only until it was made to fail on purpose: registering the events
`SUB` 300 ms late in the fake broker reproduces the CI message verbatim, and
`FakeNats::wait_for_sub` in the test turns it green. Two sibling tests in the
same file published the same way with the same exposure, so all three now wait
for the lane the way the rest of the file already did. The misleading comment in
`remote-client/src/session.rs` now says what `flush` does and what it does not
buy (production is unchanged: a gap across a reconnect is still healed by
`get_events_since`).

The shutdown test's 3 s budget was a bound on the Windows runner, not on the
drain: its assertions are all final state (approval released, caller joined,
`Stopped`), and the slow-lane measurement that landed with #1415 has one writer
job holding storage for 18-30 s. The budget moves to 30 s, matching
`cli_prompt_and_follow_up_use_real_run_finalization_without_dequeuing_on_shutdown`.

No production behaviour changes.
Pasting an image writes `[Image #1]` into the draft. Its `#1]` is the
marker's own text, but the mention reader takes the token after the last
space and only checks that it starts with a sigil, so the paste opened the
conversation list with `1]` as the query — and the reader had to dismiss it
before sending.

A sigil inside a paste-written span (an `[Image #N]` marker or a
`[Pasted Content … chars #N]` placeholder) is now part of that token
instead of the start of a mention. A `#` typed after the marker still
opens the list.
The transcript is bottom-anchored: its window is the last rows, so a row that
disappears at the tail pulls every line above it down, and the next event pushes
them back up. The live fold did that once per step — the `▸ thinking…` marker
became a count the moment reasoning ended, and each finished call folded into
the burst above it — so a turn of eighteen calls jittered the whole conversation
36 times (measured: 8→6→7→8→6… rows per event; the screenshot's 思考… row was
the row being removed).

A running reply now keeps its newest step — the call in flight or just finished,
the reasoning slice being written — on its own row until the next step takes it
over, so the transcript only ever grows while a reply streams. Prose keeps the
old shape: the summary moves onto the answer, in the row the step vacated. A
reasoning slice also shows its marker as soon as it starts, not on its first
token.

Also rebuild the transcript when a fold's counts move with its structure
unchanged (a prose slice's reasoning joining the counts above it) — heads alone
said nothing moved, leaving the old numbers and a marker the counts had taken
over on screen.
…budget room

Two required checks were red on #1415 (2026-10-29), and both still fail on the
same tests today:

- Rust macOS test / host-remote: `remote_peer::runtime_tests::
  a_burst_of_events_reaches_the_emitter_in_order` — "the burst never fully
  arrived".
- Rust Windows test / agent: `service::approval_tests::
  shutdown_releases_a_blocking_tool_approval` — "Agent shutdown deadline
  exceeded during journal compactor and SQLite".

The burst is a lost-publish race, not a slow stream. `connect_with_emitter`
returns once the `SUB` has left the client, not once the broker has applied it:
async-nats' `Client::flush()` only flushes the write buffer and awaits no
acknowledgement (0.50 has no ping/pong call, contrary to the comment that sat in
`session::subscribe` and said an "ordered PONG" was waited for). A publish from
the host's *other* connection that reaches the fake broker first is then lost,
and NATS Core has no replay — the emitter legitimately never sees it. Held open
as a hypothesis only until it was made to fail on purpose: registering the events
`SUB` 300 ms late in the fake broker reproduces the CI message verbatim, and
`FakeNats::wait_for_sub` in the test turns it green. Two sibling tests in the
same file published the same way with the same exposure, so all three now wait
for the lane the way the rest of the file already did. The misleading comment in
`remote-client/src/session.rs` now says what `flush` does and what it does not
buy (production is unchanged: a gap across a reconnect is still healed by
`get_events_since`).

The shutdown test's 3 s budget was a bound on the Windows runner, not on the
drain: its assertions are all final state (approval released, caller joined,
`Stopped`), and the slow-lane measurement that landed with #1415 has one writer
job holding storage for 18-30 s. The budget moves to 30 s, matching
`cli_prompt_and_follow_up_use_real_run_finalization_without_dequeuing_on_shutdown`.

No production behaviour changes.
Pasting an image writes `[Image #1]` into the draft. Its `#1]` is the
marker's own text, but the mention reader takes the token after the last
space and only checks that it starts with a sigil, so the paste opened the
conversation list with `1]` as the query — and the reader had to dismiss it
before sending.

A sigil inside a paste-written span (an `[Image #N]` marker or a
`[Pasted Content … chars #N]` placeholder) is now part of that token
instead of the start of a mention. A `#` typed after the marker still
opens the list.
`wrap_text_with_ansi` retreated to the last space whenever a line
overflowed. Chinese may break between any two characters, so a draft with
one space inside an otherwise unspaced run of Chinese (an IME habit, not a
word separator) broke there and sent the rest of the line down: a pasted
paragraph in the composer wrapped into half-empty rows and the box grew a
row for each one.

A break between two wide glyphs now uses the width itself. Closing
punctuation never opens a line (禁则): when the break lands on `,。、`, the
glyph before it comes down with it. ASCII word wrapping and the ASCII fast
path are unchanged.
The transcript is bottom-anchored: its window is the last rows, so a row that
disappears at the tail pulls every line above it down, and the next event pushes
them back up. The live fold did that once per step — the `▸ thinking…` marker
became a count the moment reasoning ended, and each finished call folded into
the burst above it — so a turn of eighteen calls jittered the whole conversation
36 times (measured: 8→6→7→8→6… rows per event; the screenshot's 思考… row was
the row being removed).

A running reply now keeps its newest step — the call in flight or just finished,
the reasoning slice being written — on its own row until the next step takes it
over, so the transcript only ever grows while a reply streams. Prose keeps the
old shape: the summary moves onto the answer, in the row the step vacated. A
reasoning slice also shows its marker as soon as it starts, not on its first
token.

Also rebuild the transcript when a fold's counts move with its structure
unchanged (a prose slice's reasoning joining the counts above it) — heads alone
said nothing moved, leaving the old numbers and a marker the counts had taken
over on screen.
… reads

`cache_percent` divided the cached reads by `cache_read_tokens +
input_tokens`, treating `inputTokens` as the uncached remainder. It is
not: the agent accumulates the provider's `prompt_tokens` there, and the
cached bytes are part of that prompt (`Usage::cached_tokens_exceed_prompt`
exists to reject a block where they are not). Adding the reads a second
time pins every heavily cached session at a 50% ceiling — measured on
this machine's runs, sessions reading 99.5% showed 49.9%, and the
footer's "缓存 50%" was that ceiling rather than a rate.

Divide by the prompt alone, which is the denominator
`models::cache_hit_rate` already uses, and clamp a self-contradicting
provider to 100%.
The rail painted a search row in the blank line under its tabs
(`/ 搜索会话`, and `❯ 搜索会话▏` while it took keys), and `/` on a
focused rail opened it instead of the palette. That row is chrome the
reader pays for on every frame, and searching sessions already has a
door: `ctrl+r` opens the history picker with its own filter line, which
matches the same three fields (title, workspace, id) as the rail did.

So the row goes, and with it the second search implementation:

- `panels::Filter` collapses back into `Folded` — the rail's only view
  state is which workspaces are shut, and `rows_with`/`render_with` take
  it directly; the query/open fields, the needle matching, the
  count-and-heading overrides and the "no matching sessions" empty state
  go with it.
- `/` on a focused rail is the palette's key, exactly as it is from the
  prompt; the full-screen panel (`ctrl+d` on a narrow terminal) keeps
  `esc`/`q`/`↑`/`↓` and nothing else.
- `RailSearch`/`RailSearchHint`/`PanelEmptySearch` leave the copy
  bundles, and the rail footer names only its own chords.

Folds are untouched: `enter` on a workspace heading still folds, and
`foldedWorkspaces` still survives a restart.
@huichen
huichen enabled auto-merge (squash) October 29, 2026 03:38
@huichen
huichen merged commit 01d3919 into main Oct 29, 2026
29 checks passed
@huichen
huichen deleted the pr/huichen branch October 29, 2026 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant