Repository navigation
perf(protocol): page complete turns and bot history from the tail - #301
Merged
Merged
Conversation
nixuuu
marked this pull request as ready for review
November 6, 2026 20:38
nixuuu
force-pushed
the
perf/tail-first-2
branch
from
November 6, 2026 21:04
9ea1dd0 to
9000462
Compare
nixuuu
added a commit
that referenced
this pull request
Nov 9, 2026
Overview, sidebar and watch paths repeatedly read large settings/configuration or whole turn/journal collections to obtain small metadata. This layer stores metadata projections, bounds page and turn reads, batches scratch workspace reconciliation and avoids unrelated watch refreshes. ## Cost | Path | Before | After | How measured | | --- | --- | --- | --- | | Scratch overview, 101 workers | 106 SQL statements on an unchanged listing | 6; only missing/changed workspaces write | Real SQL spans and owner/root-change assertions | | Worker profile-name lookup | 20,971,600-byte saved config | 23-byte stored name map | Synthetic large config, actual JSON sizes; listing preserves names | | Thread list/header/watch metadata | Up to 40 MiB of instructions/title context in the fixture | Stored UI settings only | Oversized fields plus successful list, header, broadcast and paged snapshot reads | | Activity timestamp | Scan all turns per listed thread | One indexed row | 10,000-turn fixture, `EXPLAIN ANALYZE` | | History page IDs | 10,000 IDs / 360,000 ID bytes | 24 IDs / 864 ID bytes | Real PostgreSQL window query; fork/target/from/reset tests | | Turn broadcast/enqueue confirmation | Read every turn and input, then find one | Read the requested turn only | 10,000-turn fixture with an unrelated 20 MiB input; real broadcast | | Moved history version | Hash 8 MiB on every snapshot | Read a stored 32-byte hash | Generated-column backfill/update checks and query plan | | Mirror journal | Transfer 1,000 repeated changes to JS; unrelated changes copied per watch | One distinct sync key; zero unrelated per-thread delta keys | Real journal fixture, continuity/gap checks | | Watch heartbeat | Any owner revision could reopen every watch | Relevant thread/fork/shared metadata only | Unrelated/relevant/pruned-journal regression; linked liveness suite | Migration 0098 adds stored thread settings, worker profile names and moved-history hashes, plus activity and mutable-source indexes. PostgreSQL backfills them and maintains them on every write. Before building indexes it validates deferred constraint events from earlier data repairs in the same upgrade transaction; the migration-0096 upgrade fixture covers this path. Metadata polling no longer detoasts the full saved configuration. Workspace grouping is linear. Update snapshots project status fields and omit install-command decoding. Mirror publishers coalesce keys in SQL and leave retention to the existing commit trigger, removing a redundant DELETE every 250 ms per subscriber. ## Audit boundaries - Existing `PeerReads`, workspace-origin caches and update-center single-flight work are already bounded; their freshness and invalidation behavior is retained. - Complete thread indexes still return the required metadata rows; no silent truncation changes list semantics. Normal history pages cap at 100 turns, while explicit target/from requests intentionally expand a window. - A cold durable mirror reset and applying a content delta still need complete content. They remain distinct from metadata-only reads. Very large direct snapshot reads retain the SQL driver's wire-message limit; this layer does not claim to remove every content serialization cost. Focused PostgreSQL cost, paging, upgrade and linked-liveness checks pass. Top-of-stack validation passed: `bun install`, `bun run gen:check`, `bun run typecheck`, `bun run lint`, `bun run format:check`, `bun run check:tmp`, and the web production build. The full test run finished with **1,904 passed, 161 skipped, 0 failed across 339 files** (982.19 s), with nothing left in the private disk-backed temp directory. Multi-gateway files ran sequentially. All three stack heads have green CI; the stack is ready for review and has not been merged. Copy audit §8: no UI text changes. Related: #301 Related: #386
This was referenced Nov 13, 2026
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.
Uncached thread, bot chat and exchange reads can now start at the tail. Additive protobuf fields request a page and return a stable older-page boundary, continuation flag and reset metadata; generated code is included.
Thread pages contain complete turns, including inherited fork history, work segments and footers. Bot/exchange pages use immutable message sequence boundaries. Current approvals, queue, goal and header configuration remain complete. Existing journal cursors resume deltas; the loaded-window reducers ignore edits outside the window until that older page is read. Older-page merges preserve newer live rows and replay from the pre-read checkpoint so concurrent edits cannot be lost.
Online linked-computer reads pass the client's cursor/page request to the owner-scoped home. The top stage also pages the offline mirror. Fork/moved-history changes, missing boundaries and journal gaps reset safely. Older clients request page size zero and receive full history; older gateways ignore the added fields and continue returning full snapshots. No link-version bump or migration is needed.
Measurements
Same real gateway/Postgres fixture: 1,500 completed turns, one input and one answer per turn, approximately 2 KiB of answer/tool-like text, 3,000 messages total. Client stage defaults are 24 turns / 50 bot messages.
These are single loopback development measurements, not a production percentile benchmark. Web SSE JSON bytes exclude framing and differ from mobile protobuf bytes. Cold route compilation was slower (1,541.6 ms after); warm code is used for the web comparison. Client integration and device evidence belong to the top stage.
Verification
dev, including feat(mobile): float composers and extend layouts edge to edge #292, feat(mobile): add reanimated motion layer on the web's tokens #297/feat(mobile): animate ui state changes with reanimated #298 and ci(release): publish nightlies every 4 hours during the day #304. Install, generated-code consistency, typecheck, lint, formatting and Expo lint passed on this stage.Whole-turn pages intentionally do not split one unusually large turn. Target-item navigation may fetch more than one normal page to retain a contiguous loaded window.