Repository navigation
Timeline delta snapshot ring and pending-turn tool output preview cap (B19, B20) - #1888
Merged
SawyerHood merged 3 commits intoAug 19, 2026
Conversation
This was referenced Aug 19, 2026
Merged
SawyerHood
force-pushed
the
bb/mobile-perf/timeline-delta-ring-and-output-cap
branch
from
August 19, 2026 07:50
440baf0 to
bae7f81
Compare
SawyerHood
marked this pull request as ready for review
August 19, 2026 08:04
SawyerHood
force-pushed
the
bb/mobile-perf/timeline-delta-ring-and-output-cap
branch
from
August 19, 2026 15:59
bae7f81 to
a124d49
Compare
…d clients get deltas The timeline delta cache held one snapshot per request shape. Two viewers of the same streaming thread (a desktop and a phone) poll out of phase: the faster one advances the snapshot, and the slower one never finds the revision it holds, so it receives the full window on every batch. On a phone over a slow link that is the difference between a small row patch and a multi-hundred-KB response per poll. Each params key now keeps a small ring (4) of recent revisions keyed by maxSeq. The route looks up the exact revision the client echoes and only falls back to a full window when it has left the ring. A repeat set of the same revision only refreshes recency. Adds a route test with two interleaved clients that both receive mergeable deltas, and checks the fallback once a revision leaves the ring. Co-Authored-By: Claude <[email protected]>
… window
The latest timeline page collapses completed turns to lazy turn rows, but the
running turn's command/tool rows carried their full inline outputs (up to the
32 K inline cap each). A long tool session accumulated hundreds of kilobytes
there (measured 264 KB across 138 command rows on one thread) and every poll
re-shipped and re-parsed it, although the rows render collapsed. On a phone
this dominated payload bytes and JSON parse time during streaming.
Server: the default window (no `includeNestedRows`) now replaces a top-level
command/tool output longer than 4 000 chars with a 2 000-char head plus a
1 000-char tail and marks the row with `outputPreview: { totalChars }` in the
server contract. Nested-row consumers (CLI verbose log, SDK callers that ask
for it) still receive the full inline output. The existing
turn-summary-details route, scoped to the row's own turnId and
sourceSeqStart..sourceSeqEnd, returns the whole output; that path already
worked for running turns and after the turn completes, and is now covered by
tests.
Client: expanded command/tool rows use `useTimelineWorkRowFullOutput`, which
renders the preview immediately and loads the whole output through
turn-summary-details once the row has finished (a running row's range still
moves and its preview tail is the live part). A short note under the block
explains the preview state and offers a retry when the load fails; nothing
renders once the full output is in place.
Regenerates the plugin SDK bundled declarations and the templates dts embed
for the new optional contract field.
Co-Authored-By: Claude <[email protected]>
Unit-tests the per-params-key ring (revision eviction, repeat-set dedupe, LRU key bound) and adds a tool-row case to the output-preview route test so both previewable work kinds are shown to resolve through row-scoped turn-summary-details. Co-Authored-By: Claude <[email protected]>
SawyerHood
force-pushed
the
bb/mobile-perf/timeline-delta-ring-and-output-cap
branch
from
August 19, 2026 16:13
a124d49 to
b2e4b95
Compare
SawyerHood
deleted the
bb/mobile-perf/timeline-delta-ring-and-output-cap
branch
August 19, 2026 16:23
SawyerHood
added a commit
that referenced
this pull request
Aug 19, 2026
…snippets (B25, B26) (#1887) ## What was wrong `searchThreadsWithPendingInteractionState` ran the full ranking pipeline twice per request, once for active and once for archived threads. Every token `MATCH` and the any-token hydration `MATCH` executed twice (2N+2 FTS scans for N tokens). The FTS5 table had no prefix index, so each `"tok"*` prefix query expanded against the full term list on every keystroke. The response carried up to three full message bodies per thread while the sidebar renders one truncated line (B25, B26 in the mobile perf sweep). ## What changed - New custom Drizzle migration `0101_thread_search_prefix_fts` recreates `thread_search_segments_fts` with `prefix = '2 3'`, rebuilds rows and triggers (same mechanism as 0040). Snapshot and journal regenerated with `drizzle-kit generate --custom`. - `packages/db/src/data/threads.ts`: one SQL statement ranks threads that contain every token, partitions `ROW_NUMBER`/`COUNT(*)` by archived state, keeps the top `limitPerGroup` per group, then joins the any-token `MATCH` once to pull the matching title segments plus the single best message segment per thread. Rows are split by group in JS. Total FTS scans: N+1. - Message matches are cut to a ~160-char snippet around the first highlight (40 chars of lead, word-boundary snapping bounded to 40 chars, surrogate-safe, "…" on each cut side). Highlight ranges are rebased onto the snippet. Titles stay whole so the sidebar can pair them with the display title. - Contract comment on `threadSearchMatchSchema.text` documents the snippet semantics. Response shape is unchanged; the client (`ThreadSearchResultRow`) already picks one message match and one title match. ## How you verified - `pnpm exec turbo run typecheck --filter=@bb/db --filter=@bb/server-contract --filter=@bb/server`: pass. - `pnpm exec turbo run test --filter=@bb/db`: 29 files, 396 tests pass (includes migration journal/snapshot chain checks and query-plan tests). - `pnpm exec turbo run test --filter=@bb/server -- test/public/public-thread-search.test.ts`: pass. - New/updated tests in `packages/db/test/data/thread-search.test.ts` (in-memory SQLite + migrate): one message match per thread; title + title_fallback + one message per thread; per-group limit and totals from one call with mixed active/archived; snippet bounds, ellipses, word-boundary lead, rebased ranges slice to the token; short text returned whole; long unbroken tail keeps hard cut; `sqlite_master` shows `prefix = '2 3'`. Migration backfill test now replays 0039/0040/0101. - `EXPLAIN QUERY PLAN` on the new statement: two `SCAN thread_search_segments_fts VIRTUAL TABLE INDEX` (single token), rowid PK lookups for segments, PK lookup for threads, automatic index for the limited-threads join. Fixes: part of the mobile / iOS Safari performance program (verified sweep report in the bb thread; no single issue). ## Stack context Layer 8 of 22 in the `bb/mobile-perf/*` stack (bottom → top: quick wins first, big rocks last). - Prerequisite (layer below): `bb/mobile-perf/workspace-status-and-pr-cache` (#1886). - Next layer: `bb/mobile-perf/timeline-delta-ring-and-output-cap` (#1888). - Audit findings addressed: see title IDs. Review: approved-with-fixes; 1 review fix commit(s). - Deliberately not done here: B25 optional `group=` query param: not added. It does not simplify the code (the partitioned scan already collapses the double MATCH) and would add contract, SD - Wire/contract: No server<->daemon wire changes (HOST_DAEMON_PROTOCOL_VERSION unchanged). Public API response shape for GET /threads/search is unchanged; semantics changed: `matches[].text` for message kinds is now a bounded snippet (with leading/trailing "…" when cut) and `highlightRanges` are offsets into that snippet; each thread returns at most one message match plus its title/title_fallback matches (previous > AGENT GENERATED: by Claude Code (claude-mangosteen-eap) --------- Co-authored-by: Claude <[email protected]>
SawyerHood
added a commit
that referenced
this pull request
Aug 19, 2026
…B22, D8, I5, J5, B17) (#1889) ## What was wrong - API JSON was gzip-only through hono/compress. It never set Vary and its 1 KB threshold did not apply because Hono JSON has no Content-Length, so every body streamed through gzip. Brotli saves 10-20% on the timeline and sidebar payloads a phone downloads per turn. - Attachment content had no cache headers although stored names are immutable. Host-file responses ignored the sha256/mtime the daemon returns. iOS purges the memory cache on backgrounding, so PWA relaunches re-downloaded multi-megabyte screenshots. The SDK also copied every upload through arrayBuffer() and the composer preview re-downloaded the image it had just uploaded. - index.html and all public icons/manifests were served no-store. no-store blocks the WebKit back/forward cache, and icons were refetched on every favicon flip and never edge-cached. The favicon code re-decoded both PNGs on every badge flip, even in an installed PWA where no tab icon exists. - The plugin-frontend pagehide handler tore everything down even for a bfcache freeze and had no pageshow reboot. - Every thread-list subscriber received every thread's raw events-appended stream (~10 frames/s per streaming thread) and ran cache walks for threads it was not viewing. ## What changed - New apps/server/src/api-response-compression.ts buffers core /api/v1 JSON (not plugin bb.http handlers, not /internal streaming) and sends Brotli q4 or gzip with exact Content-Length and Vary: Accept-Encoding; sub-1 KB bodies stay identity. It runs inside the existing streaming gzip fallback. - Attachment content: private, immutable, max-age=31536000 + ETag + Content-Length + 304. Daemon file responses: ETag (sha256), Last-Modified, Content-Length, default private, no-cache, 304 on If-None-Match; content routes pass If-None-Match through. SDK passes Blob/File to FormData directly. Composer keeps an object URL for a just-picked image (revoked on remove). Images use decoding="async". - index.html: no-cache. Non-HTML public files: public, max-age=86400. Favicon base glyphs memoized; favicon work skipped in standalone display mode. - Plugin frontends tear down only on a non-persisted pagehide; a persisted pageshow reconciles or reboots. - Hub: thread-detail subscribers get every events-appended frame; thread-list-only sockets get the first frame at once and one merged frame per 1 s window per thread. Frames with list-relevant metadata or other change kinds bypass coalescing. ## How you verified - New tests: apps/server/test/app/api-json-compression.test.ts (br + Content-Length + Vary, gzip fallback and q=0, identity below threshold, plugin/internal paths not buffered, real /api/v1/system/config); apps/server/test/hosts/daemon-file-response.test.ts (validators, caller headers kept, 304, If-None-Match matching); apps/server/test/app/hub.test.ts (detail vs list-only fan-out, trailing merged frame, bypass rules, per-thread windows, waiters and listeners); apps/app/src/components/promptbox/AttachmentPreview.test.tsx (object-URL src, fallback URL, decoding=async, revoke on remove); apps/app/src/lib/favicon-color-preference.test.ts (one decode per glyph, standalone skip); apps/app/src/lib/plugin-frontend.test.ts (page lifecycle policy). - Updated tests: static-cache.test.ts (no-cache index, max-age=86400 icons/manifest), public-project-attachments.test.ts (cache headers, ETag, 304). - pnpm exec turbo run typecheck --filter=@bb/app --filter=@bb/sdk --filter=@bb/server: pass. lint: 0 errors. Full @bb/server and @bb/sdk suites: all pass except a pre-existing umask-dependent internal-skill-trees test that also fails on baseline. Fixes: part of the mobile / iOS Safari performance program (verified sweep report in the bb thread; no single issue). ## Stack context Layer 10 of 22 in the `bb/mobile-perf/*` stack (bottom → top: quick wins first, big rocks last). - Prerequisite (layer below): `bb/mobile-perf/timeline-delta-ring-and-output-cap` (#1888). - Next layer: `bb/mobile-perf/boot-shell-quickwins` (#1890). - Audit findings addressed: see title IDs. Review: approved-with-fixes; 2 review fix commit(s). - Reviewer notes / follow-ups: Minor (not fixed, by design/bounded): apps/app/src/lib/attachment-local-previews.ts keeps up to 24 object URLs (and thus the picked File/Blob) alive after a draft is sent; only rem | Behavioral note (documented by implementer): SDK/plugin `thread:changed` subscribers without a threadId (thread-list channel) now receive plain events-appended at leading edge + on | Pre-existing, unrelated: apps/server/src/server.ts fails the root eslint `no-restricted-imports` rule for node:fs/promises (present at base dde6cdd; @bb/server has no lint task s - Wire/contract: None on the server<->daemon wire (HOST_DAEMON_PROTOCOL_VERSION not bumped): daemon-file-response only consumes fields the daemon already returns (sha256, modifiedAtMs). Client-facing HTTP: API JSON may now be Content-Encoding: br with Content-Length + Vary; attachment content and host-file routes gain ETag/Last-Modified/Cache-Control/Content-Length and can answer 304; index.html no-cache; public f > AGENT GENERATED: by Claude Code (claude-mangosteen-eap) --------- Co-authored-by: Claude <[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.
What was wrong
timeline-latest-rows-cache.ts) held one snapshot per params key. Two viewers of a streaming thread (desktop + phone) poll out of phase. The faster client advances the snapshot; the slower one never finds the revision it echoes and gets the full window on every batch (audit B19).What changed
maxSeq.GET /threads/:id/timeline?afterSequence=Nlooks up revision N and only falls back to a full window when N left the ring. Repeat sets of the same revision only refresh recency.timeline-output-preview.ts. In the default window (noincludeNestedRows), a top-level command/tool output longer than 4 000 chars becomes a 2 000-char head + omitted marker + 1 000-char tail, and the row carriesoutputPreview: { totalChars }.includeNestedRows=true(CLI verbose log, SDK callers) still gets full inline output. The existing turn-summary-details route scoped to the row'sturnId+sourceSeqStart..sourceSeqEndreturns the whole output (works for running turns and after the turn completes).outputPreviewon command/tool rows;includeNestedRowsdoc; regenerated plugin SDK bundled d.ts and templates embed.useTimelineWorkRowFullOutput+CommandWorkRowBody/ToolWorkRowBodyinTimelineRowDetails.tsx. Expanded rows render the preview at once and load the whole output through turn-summary-details once the row is not pending (a running row's range still moves; its preview tail is the live part). A short note explains the state and offers Retry on failure; nothing extra renders once the full output is loaded or the row was never previewed.How you verified
apps/server/test/public/public-thread-timeline-delta.test.ts: two interleaved clients both receive mergeable deltas; a revision that left the ring falls back to a full window.apps/server/test/public/public-thread-timeline-output-preview.test.ts: preview cap +outputPreviewmarker; small outputs untouched;includeNestedRows=truefull output; row-scoped turn-summary-details returns full output for a running turn and afterturn/completed.apps/app/src/components/thread/timeline/TimelineRowDetails.output-preview.test.tsx: expanded finished row callssdk.threads.timelineTurnSummaryDetailswith the row's turnId/range and renders the full output; a pending row keeps the live preview and does not fetch; a failed load shows the preview with Retry.pnpm exec turbo run typecheck --filter=@bb/server --filter=@bb/app --filter=@bb/server-contract --filter=@bb/templates --filter=@bb/thread-view --filter=@bb/sdk --filter=@bb/cli: 8/8 successful.pnpm exec turbo run lint --filter=@bb/server --filter=@bb/app --filter=@bb/server-contract: 0 errors; @bb/app warning count unchanged from baseline (147).Fixes: part of the mobile / iOS Safari performance program (verified sweep report in the bb thread; no single issue).
Stack context
Layer 9 of 22 in the
bb/mobile-perf/*stack (bottom → top: quick wins first, big rocks last).bb/mobile-perf/search-fts(Thread search: single partitioned FTS scan, prefix index and bounded snippets (B25, B26) #1887).bb/mobile-perf/http-caching-and-hub-gating(API brotli, cache validators, bfcache-friendly index and hub gating (B22, D8, I5, J5, B17) #1889).pendingwhile the thread is no longer running (e.g. an interrupted item that never got its item/completed before the turn closed) keeps theoutputPreview?: { totalChars: number }ontimelineCommandWorkRowSchemaandtimelineToolWorkRowSchema(new exporttimelineOutputPreviewSchema/TimelineOutputPreview);includeNestedRowsquery doc updated. Behavior change on GET /threads/:id