Skip to content

Keep Archive in one place on thread rows with sub-threads - #2

Closed
alexandre-vl wants to merge 2 commits into
mainfrom
thread-list-sub-thread-rows
Closed

alexandre-vl wants to merge 2 commits into
mainfrom
thread-list-sub-thread-rows

Conversation

@alexandre-vl

Copy link
Copy Markdown
Owner

Human comments

What was wrong

A parent thread row renders its expand chevron inline after the title, under the hover-actions overlay. When the two collide, useDisclosureActionsClearance measures the overlap and adds the chevron's width as margin before the "…" trigger, which moves Archive to the other side of the chevron. So Archive changes position with the title length and sits 2 px from the chevron, and a quick click meant to expand sub-threads hits Archive. That measurement was the compromise between get-bb#3821 (keep the chevron still) and get-bb#5125 (hidden actions must not take title space). get-bb#5909 has the before/after, the measurements and the prior art.

What changed

  • plugins/thread-list/app/rows/SubThreadToggle.tsx (new):
    • SubThreadToggle puts the parent's disclosure in the leading icon slot. It shows the provider icon at rest, and the chevron on row hover, keyboard focus and touch screens (CSS only). Without provider icons, the chevron hangs in the left margin, so parent titles stay aligned with leaves. It keeps main's accessible name ("Expand X threads"); aria-describedby adds "3 threads, 2 working, Claude Code". The coarse-pointer hit area stays 36 px tall.
    • SubThreadCount sits after the title. It shows the number of sub-threads, or busy/total with the busy kind's glyph while some of them work.
  • ThreadRow.tsx: parent rows use the leaf geometry for the trailing slot: status at rest, quick actions and "…" on hover, the same hover-only inset. Archive is in the same place on every row.
    • useDisclosureActionsClearance, measureDisclosureClearance and the inline SidebarChildToggleChevron are gone from thread rows. Project and section rows keep the chevron component.
    • The trailing status glyph is the row's own. Hidden sub-threads still roll up attention on it (needs input, draft). Their work moved to the count.
  • thread-activity.ts: getCollapsedChildActivity also returns workingCount.
  • A Ladle story, sidebar/Thread list/Sub threads, with and without provider icons, on neutral fixtures.
  • No wire, SDK, CLI or setting change.
  • SIDEBAR_HOVER_ACTIONS_MASK_CLASS and its CSS rule lose their only in-tree user. They stay, because the plugin registry publishes them (packages/plugin-registry/r/sidebar-hover-actions.json).

How you verified

  • pnpm exec turbo run typecheck lint test --filter=bb-plugin-thread-list: all pass; 453 tests.
  • pnpm exec turbo run typecheck --filter=@bb/app (for the story): passes.
  • 16 of the new and updated tests fail against main's ThreadRow.tsx and thread-activity.ts, and pass here. They cover:
    • a parent row's title and actions laid out exactly like a leaf's;
    • the toggle in the icon slot, ahead of the title, and its hover, focus and touch swap;
    • the count text and the toggle's description;
    • hidden work shown in the count, not the parent's status;
    • attention rolled up only while collapsed;
    • workingCount.
  • Measured with Playwright in the story, each row hovered in turn. Row kinds: leaf, failed leaf, parents with short and long titles, an expanded parent, a sub-thread. Widths: 220, 288 and 360 px.
    • Archive sits 30 px from the right edge on every row (main: 30 or 58 px, and it swaps sides with the chevron).
    • The chevron is 118, 186 or 258 px from Archive (main: 2 to 98 px).
  • Checked in Chromium:
    • Tab reaches the toggle after the row link, and Enter and Space toggle it.
    • Focus shows the chevron and an unclipped ring.
    • With touch emulation, the chevron shows at rest, and taps 15 px off its centre still toggle.
    • The parent icon matches the leaf icon colour.
  • Not checked: Safari/WebKit, a screen reader.
  • Reviewed independently by a second agent thread before this PR. Its findings are fixed: touch hit area, accessible description, icon colour, focus ring, tests for the focus and touch swap.

Fixes get-bb#5909

AGENT GENERATED

@alexandre-vl

Copy link
Copy Markdown
Owner Author

Superseded by get-bb#5910.

alexandre-vl pushed a commit that referenced this pull request Oct 30, 2026
## Human comments

## What was wrong

Several cache owners wrote a server reply or the thread-detail bootstrap
straight into the React Query cache with `setQueryData` while a fetch of
the same key could still be in flight. React Query writes fetch results
without checking whether they're older than what's cached (query-core
`query.ts`), so the older fetch landed last and put stale data back.
Effects included: an environment or host status that stayed stale after
opening a thread, a plugin settings form resetting its draft to the old
value, a cancelled plugin install flipping back to running, new plugin
update jobs dropping out of the list, an `idle` app update phase
switching off the progress poll, and the AI service selection flickering
back. These are items #2–get-bb#10 from the direct cache write audit
(@thread:thr_fjr5x8dzaz). #1 (thread tabs) is fixed separately in get-bb#6611.

## What changed

Two fixes, depending on whether the data has a version field:

- **Environment and Host keep the newer copy by `updatedAt`** (#2, #3,
get-bb#10). The bootstrap ingest (`thread-detail-cache-owner.ts`), the rename
reply (`applyEnvironmentUpdateResult`), and the
`useEnvironment`/`useHosts` fetches all compare `updatedAt`. The
fetch-side check is what catches a fetch that started before the write
and lands after it. To make it testable, those fetches now live in
`environmentQueryOptions` and `hostsQueryOptions`. Host `status` comes
from live daemon sessions and a disconnect doesn't change `updatedAt`,
so on a tie the cached copy wins over the bootstrap. The bootstrap only
fills an empty cache or replaces strictly older data. Rename replies and
fetch results still win ties.
- **`setQueryDataOverInFlightFetch`** (`cache-effect-utils.ts`) for data
with no version (#4–#9): it writes the value, and if a fetch of the key
is in flight it cancels that fetch (the cache keeps the written value)
and refetches. With nothing in flight it's a plain write. Used by
`applyPluginSettingsView`, `applyPluginInstallJob`,
`applyPluginUpdateJob`, `hydrateAppUpdateStatus`,
`hydrateSystemVersionCache` and `writeCachedAiServices`, so every caller
gets the fix. Where the audit suggested an unconditional
cancel-write-invalidate (#7) or a cancel before the write (#8, #9), this
helper refetches only when a fetch was actually in flight. That avoids
an extra request on every write. Forced version and app-update checks
update the server's cache, so the trailing unforced refetch returns the
forced result.

No wire, CLI or plugin API changes.

Not covered here: audit items get-bb#11 (plugin safe mode) and get-bb#12 (prompt
history), both low risk. Also not covered: a lint rule restricting
direct `setQueryData` calls to the helper, which would stop new call
sites from bringing the race back.

## How you verified

- New tests use real `QueryClient`/`QueryObserver` instances: start a
fetch that resolves late with older data, do the write, let the fetch
land, then check that the newer value survives (and, for the helper,
that the trailing refetch runs).
- `thread-detail-cache-owner.test.ts` (new): late environment and
host-list fetches after a bootstrap, an older bootstrap over a newer
cache, and the equal-`updatedAt` host status case.
- `environment-workspace-cache-owner.test.ts`: a late environment fetch
after a rename, and an older rename reply over a newer cache.
- `in-flight-fetch-writes.test.ts` (new): one row per cache-owner write
for #4–#9, plus helper tests for the no-fetch case (no extra request)
and a fetch of an unobserved query.
- With each source change reverted, every race test failed on the stale
data and passed once the fix was restored.
- `pnpm exec turbo run typecheck lint test --filter=@bb/app`: passed
(647 files, 6515 tests; 0 lint errors, no new warnings). After rebasing
onto `0472409243` I re-ran the three changed test files (21 tests
passed).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

> AGENT GENERATED

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
alexandre-vl pushed a commit that referenced this pull request Nov 9, 2026
…bb#7239)

## Human comments

## What was wrong

When the timeline picked rows for a window, it ran a loop: fetch the
rows of the turns it had found so far, then call
`ensureTimelineWindowParentedRows` to pull in the children of every
delegating tool call. Each call started with an empty "already fetched"
set. So every pass of the loop queried the children of every tool call
in the window again, even though most of those children belong to the
same turn and the turn query had already loaded them. The function then
dropped the duplicates. On thr_u738kqjs29 the latest window read 19,463
rows to end up with 7,665 distinct rows. The child query took about 68
ms of a 210 ms cold build. On top of that, Drizzle mapped every row of
the big turn and child queries one at a time, and the inline-output
truncation column ran `length(data)` on every row. `length()` counts
UTF-8 characters, so it scans the whole payload.

Found in the Nov 7 timeline performance audit (REPORT #2), slice S1.

## What changed

- `apps/server/src/services/threads/timeline.ts`:
`ensureTimelineWindowParentedRows` now takes a `lookups` object that the
group-context loop creates once per selection. It records which tool
calls have already had their children fetched and which missing parents
have already been looked up, so no pass fetches them again. Turn details
pass fresh lookups, so their behaviour doesn't change.
- `packages/db` `listStoredEventRowsByParentToolCallIds` has a new
optional `excludedTurnIds` argument (`turn_id IS NULL OR turn_id NOT IN
(...)`). The selection passes in the turns it has already loaded, and
those turns' children aren't read a second time. The memo's trimmed row
source applies the same filter.
- `listStoredTimelineTurnEventRows` and
`listStoredEventRowsByParentToolCallIds` still build their SQL with
Drizzle, but now select aliased columns and return the better-sqlite3
rows directly, skipping Drizzle's per-row mapping. They already selected
raw `sql<T>` fields, so the values are the same.
- Both hot queries now split their IDs with
`queryInSqliteVariableBatches`, taking the fixed-variable count from the
statement built with an empty batch. Before, the child query bound every
parent ID plus the excluded turns in one statement, and the turn query
assumed 32 fixed variables even though the truncation column binds more
than that. Both raised `too many SQL variables` at around 32k IDs.
- `truncatedEventDataColumn` now checks `octet_length(data) <= max`
before `length(data) <= max`. A string's byte length is never smaller
than its character count, so the output doesn't change. Most rows now
skip the character count.

No wire, CLI or plugin changes.

## How you verified

Measured with the audit harness on an APFS clone of the Nov 7 production
snapshot. Each number is the median of 3 alternating A/B runs (main
55135d1, then this branch), each run itself a median of 3. Load
average was 11–40 because other slices were benchmarking on the same
machine. The first A run (load 40) was the noisiest, so the ranges are
shown.

| case (cold, app latest window) | before ms | after ms | Δ | SQL rows
read (distinct) |
|---|---|---|---|---|
| u738kqjs29 | 222.8 (212–436) | 149.2 (136–156) | −33% | 19,463 → 7,857
(7,665) |
| kdrbtee92b | 36.1 (35–52) | 27.7 (26–31) | −23% | 2,264 → 1,332
(1,299) |
| avim9t7kpe | 129.2 (115–359) | 104.2 (104–109) | −19% | 5,897 → 5,897
(5,890) |
| wg5iwwrezi | 60.3 (60–139) | 53.3 (50–72) | −12% | 3,358 → 2,653
(2,628) |
| d5ej4e2gtv | 49.3 (37–92) | 35.2 (35–36) | −29%* | 662 → 662 |
| u738kqjs29 older-page walk (5 pages) | 1,012 | 678 | −33% | |
| kdrbtee92b walk | 236 | 193 | −18% | |

\* d5ej's baseline is noisy. Its cleanest A run was 36.7 ms, so treat it
as roughly unchanged.

Every other harness thread is 3–16% faster on cold builds and walks.
avim gains less because it has no duplicate reads; its saving comes from
skipping row mapping and the character count, and most of its remaining
time is JSON decode and projection.

Parity:
- Replayed main and this branch over 159 snapshot threads: the 12
harness threads plus 147 sampled from the 947 threads with at least
1,000 events. Each thread ran the app latest window at segment limits 20
and 8, the CLI log, includeNestedRows, summaryOnly, up to 6 older app
pages, up to 3 CLI pages and 2 turn-details pages. All 1,648 response
SHA-256 hashes match: 0 diffs.
- Memo path: on a separate clone, appended 4 events to each of the 12
harness threads (alternating plain items and children of a delegating
call) and compared each memo-served latest window with a fresh build. 48
of 48 match.

Tests:
- New
`apps/server/test/services/threads/timeline-parented-row-reads.test.ts`:
a delegated call with children in its own turn and in a child turn. The
child query runs once and returns only the child-turn rows, and both
outputs render. It fails on main.
- `packages/db/test/data/events.test.ts`: `excludedTurnIds` keeps
null-turn and other-turn children and drops the excluded turn's
children. The unmapped turn and child rows equal the Drizzle-mapped
`listStoredEventRows` rows. Multibyte payloads that are over the cap in
bytes but not in characters come back untouched, and overflows are cut
by characters.
- `packages/db/test/data/events.test.ts`: 40,000 parent IDs with 500
excluded turns, and 33,002 turn IDs, both read correctly. Both raised
`too many SQL variables` before the batching commit.
- `packages/db/test/query-plans.test.ts`: the child read with 300
excluded turns and the truncation column still runs `SEARCH events USING
INDEX events_parent_tool_call_thread_parent_sequence_idx (thread_id=?
AND parent_tool_call_id=? AND sequence>? AND sequence<?)` with no `SCAN
events`.
- After the batching commit, a parity replay of the 12 harness threads
matches main on all 156 responses.
- `pnpm exec turbo run typecheck test --filter=@bb/db
--filter=@bb/server`: db 666 passed; server 3,940 passed, 1 skipped. The
one failure was a timeout in `test/app/install-machine-script.test.ts`
at load average 64–70, which passed in the earlier run and in CI.

Not covered: the remaining small duplicates (tens of rows per thread,
from the context-type and background-task-state queries, plus children
of a child turn that the turn query later reads again), and the SQL-side
truncation work on rows that really are over the cap.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

Sidebar: Archive moves and sits 2 px from the expand chevron on rows with sub-threads

1 participant