Repository navigation
Keep Archive in one place on thread rows with sub-threads - #2
Closed
alexandre-vl wants to merge 2 commits into
Closed
alexandre-vl wants to merge 2 commits into
alexandre-vl wants to merge 2 commits into
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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,
useDisclosureActionsClearancemeasures 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):SubThreadToggleputs 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-describedbyadds "3 threads, 2 working, Claude Code". The coarse-pointer hit area stays 36 px tall.SubThreadCountsits 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,measureDisclosureClearanceand the inlineSidebarChildToggleChevronare gone from thread rows. Project and section rows keep the chevron component.thread-activity.ts:getCollapsedChildActivityalso returnsworkingCount.sidebar/Thread list/Sub threads, with and without provider icons, on neutral fixtures.SIDEBAR_HOVER_ACTIONS_MASK_CLASSand 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.ThreadRow.tsxandthread-activity.ts, and pass here. They cover:workingCount.Fixes get-bb#5909