Skip to content

perf(threads): resume ui watches from journal checkpoints - #271

Merged
nixuuu merged 1 commit into
devfrom
perf/thread-cache-1
Nov 6, 2026
Merged

nixuuu merged 1 commit into
devfrom
perf/thread-cache-1

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Opening a UI watch can now resume from the snapshot already held by the client. Additive incremental and cursor request fields opt into the existing owner journal; full snapshots carry an atomic checkpoint. Projected item/turn upserts, tombstones and replacement metadata reconstruct the current state without transferring unchanged history.

An unknown, expired, future or other-epoch checkpoint, journal gap, fork reset or moved history falls back to full state. Live events update the client copy without advancing its atomic checkpoint, so reconnect replays projected changes idempotently. Owner authorization remains in the gateway. No migration is needed.

For remote threads, a warm UI cursor passes through to the home. A cold UI retains local mirror-first behavior. Older clients omit the opt-in and keep full snapshots; older gateways ignore the new fields and return snapshots without a cursor. Linked-computer capability negotiation remains unchanged. Related: #264, #265.

Measurements use two synthetic threads, each with 500 completed turns and 3,001 timeline items, including roughly 1.9 KB tool outputs. The stack's client layers measured these changes against a real gateway, scripted worker, isolated Postgres and actual browser/Android app:

Read Before After
Browser first content, median of 3 switches 300.2 ms 110.3 ms
Browser initial SSE JSON payload 6,952,035–6,952,159 B 791–801 B
Android first content, median of 3 switches on Fold 3,119.1 ms full-watch control 653.6 ms warm cache
Native protobuf update received by Android 6,233,091–6,233,101 B 513–523 B delta

Browser warm content appeared before the live response. These are development-mode measurements on shared hardware; payload figures exclude transport/framing overhead. Client-specific Android results and device qualification are recorded in the mobile layer.

Verification: additive proto generated with bun run gen; gen:check, install, typecheck, lint and formatting passed on every layer. Top-of-stack check:tmp: 1,490 passed, 159 skipped, zero failures; web build and Expo lint passed. Real gateway UI integration coverage exercises caught-up reads, upserts/deletions versus full state, old clients, invalid/future/other-epoch cursors, gaps, restart and owner isolation. Existing two-gateway tests also exercise warm UI reads of remote threads. The stack stays draft and must not be merged individually.

@nixuuu
nixuuu added this pull request to stack #274 November 6, 2026 11:25
@nixuuu
nixuuu marked this pull request as ready for review November 6, 2026 11:52
@nixuuu
nixuuu merged commit 3e297c7 into dev Nov 6, 2026
12 checks passed
@nixuuu
nixuuu deleted the perf/thread-cache-1 branch November 6, 2026 11:52
nixuuu added a commit that referenced this pull request Nov 6, 2026
Opening a long bot conversation currently transfers every message again.
This adds durable, owner-scoped checkpoints for bot conversations and
bot-to-bot exchanges, so clients can request only changed messages and
current control state.

The bot tables have their own commit-ordered key journal, following the
thread mirror epoch/cursor design. A checkpoint binds the owner, view
and revision. Message edits, deletion and turn failures produce
upserts/removals. A metadata digest confirms approvals, read state,
pending cards, configuration, streaming text, routines and reminders;
changed control state is replaced atomically. Missing/expired cursors,
gaps, another epoch, rewritten exchange membership and moves fall back
to a full projection.

Linked bot reads pass the cursor to the home through the existing route.
Offline reads retain the existing mirror path and gateway action
enforcement. Proto additions are opt-in: old clients get full snapshots,
and a home ignoring the new fields returns full state that new clients
can apply. No link protocol version change. Migration 0091 is the next
free number on the rebased dev; schema expectations and generated
contracts are included.

### Measurements

Single-run development-server measurements with a real local
gateway/Postgres and 3,000 stored messages, each containing about 2 KB
of long output. Browser first content is measured from route switch to
message DOM appearing. SSE bytes include the ready frame and initial
state, excluding HTTP/TLS headers and unrelated sidebar polling. The
after column uses the whole stack, including the opt-in web client in
the next layer.

| Measurement | Before | After |
|---|---:|---:|
| Web warm switch, first content | 3,819.9 ms | 187.2 ms |
| Initial bot SSE, unchanged reopen | 7,050,627 B | 393 B |
| Web cold route, first content | 4,512.9 ms | 910.2 ms |
| Initially mounted message rows | 3,000 | 100 |
| Android first content / bytes | Unverified | Unverified |

The baseline full protobuf was 6,772,217 B. Cold full history remains
approximately 6.77 MB: this does not add server-side pagination. The
cold browser sample includes development module loading; these are
observations, not statistical latency bounds. Android timing and runtime
visuals are unverified: the device tool's dev-client deep link failed
with `COMMAND_FAILED: adb exited with code 1`, including its advised
debug retry. No SSH/ADB UI fallback was used.

### Verification

- Real-gateway integration and schema tests: 28 passed, including
edits/deletes/failures, control confirmation, gap/epoch/view fallback,
owner isolation, cursor after restart, linked chat/exchange, and a home
ignoring the additive request fields.
- `bun install`, `bun run gen:check`, `bun run typecheck`, `bun run
lint`, `bun run format:check` passed on this stage after rebasing.
- Polish protocol/read-path documentation updated. No new UI copy in
this layer.

The bot mirror publisher still uses its existing full projection
protocol; this stack changes UI reads, not partner journal publishing.
Live control metadata is a complete replacement when changed, rather
than a second journal for approvals and linked thread cards.

Related: #271, #272, #273.
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