Skip to content

fix(client): keep the tree index across streaming deltas - #179

Merged
lg2m merged 1 commit into
mainfrom
fix/eng-927-client-index-churn
Sep 25, 2026
Merged

lg2m merged 1 commit into
mainfrom
fix/eng-927-client-index-churn

Conversation

@lg2m

@lg2m lg2m commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Linear: ENG-927. Unblocks #176 (and any PR) — the fmt, clippy, tests job fails on main itself since #162 landed.

What CI was hitting

state::tests::streaming_deltas_keep_the_tree_index in qq-client — a pointer-equality assertion:

assertion `left == right` failed
  left: 0x7f1538002220
 right: 0x7f1538001f20

It failed on main at 536a817 and on #176 (which changes only website/ and two markdown files). Locally it passes 30/30. It is not a flaky test; it is a flaky detector of a real bug.

The bug

SessionStore keeps a derived tree index (sidebar order, depth, children) in a OnceCell. get_mut drops it — correct for summary changes — while body_mut exists specifically so streaming deltas don't rebuild the sidebar on every frame. But five body-only paths still went through get_mut: push_message, complete_streamed_turns, warm_empty, mark_focused, evict_cold_bodies. So every AssistantMessageStarted and TextAppended threw the index away — exactly the per-frame rebuild the doc comment on body_mut says we avoid.

The test compared thread_order().as_ptr() before and after. The index was being rebuilt; the new Vec just usually landed in the block the old one had freed. On CI's allocator state it didn't.

The fix

  • Those five sites use body_mut.
  • Under cfg(test), the store counts index rebuilds; the test asserts exactly one after the streaming events. Against the old code this fails deterministically (2 vs 1), verified by reverting the fix hunk with the new assertion in place.

Verification

  • cargo test -p qq-client --lib 22/22
  • fmt, clippy -D warnings
  • Full workspace: one unrelated failure while the box was at load 22 (wall_clock_budget_settles_a_hanging_provider…, a wall-clock test), which passes alone; not touched here.

Impact

Fewer sidebar rebuilds per frame during streaming — the intended behavior of body_mut, now actually in effect for messages.

`SessionStore::push_message`, `complete_streamed_turns`, `warm_empty`,
`mark_focused`, and `evict_cold_bodies` mutate body state only, but went
through `get_mut`, which drops the derived tree index. Every
`AssistantMessageStarted` and `TextAppended` therefore rebuilt the sidebar
order — exactly the per-frame rebuild `body_mut` exists to avoid. They
now use `body_mut`.

The test guarding this compared the order `Vec`'s pointer before and
after, which passes whenever the allocator hands the rebuilt index the
freed block; it failed on CI for main at 536a817 and for #176. The store
now counts index rebuilds under `cfg(test)` and the test asserts exactly
one, which fails deterministically against the old code (2 vs 1).

Closes ENG-927.
@lg2m
lg2m merged commit c6df04b into main Sep 25, 2026
4 checks passed
@lg2m
lg2m deleted the fix/eng-927-client-index-churn branch September 25, 2026 15:31
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