Skip to content

feat(native): bounded thread snapshots, history paging, conformance drift alarm, session harness - #16

Merged
rynfar merged 6 commits into
nativefrom
nw/w4-data
Nov 2, 2026
Merged

rynfar merged 6 commits into
nativefrom
nw/w4-data

Conversation

@rynfar

@rynfar rynfar commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Problem

Opening a thread pulled its whole projection over the socket. On real data the largest pruned thread was a 7.8 MB snapshot (33 ms to decode in release builds), and the developer's 31 GB install has far larger ones. Nothing paged older history, nothing checked that the Rust reducers still match the web's, and the session's flow control had no tests.

Approach

Bounded snapshots (#9, TV-HISTORY). Threads subscribe with acceptBoundedSnapshot, acceptCompactTurnItems, acceptCompactIds and acceptDedupedBodies, as threads.ts does when it can page. thread::decode_thread_stream_item undoes each one exactly on the network runtime:

  • the ID table (withRecordIdTable)
  • omitted local turn items (boundedSnapshotProjection), so a row and its turn item share one Arc
  • deduped bodies, both in snapshots and live (orchestrationV2DedupedBodies.ts)

acceptDeferredWork is not adopted: collapsed work needs a transcript control the app does not have yet.

History paging. crates/core/src/history.rs ports threadHistoryMerge.ts and the loadEarlier loop as a pure state machine: begin, merge a page, keep paging while a page holds no user turn, fail, stale. ClientHandle::history_page fetches GET /api/orchestration/threads/:id/history (bearer auth, protocol header, compact IDs) and decodes the page off the UI thread. AppState::load_older_history() drives the loop. Its state is state.thread.history (has_more_history, loading, error, expanded). thread_view.rs gets a 7-line scroll hook. Prepended rows reach the list as splice(0..0, n), and that keeps the scroll anchored.

Drift alarm. apps/native/conformance/generate.ts builds synthetic scenarios from orchestrationV2TestFixtures.ts, the cases in orchestrationV2Projection.test.ts and shellReducer.test.ts, id-collation ties, and 20 seeded fuzz runs. It encodes them with the real server wire code: buildBoundedThreadStreamSnapshot, makeLiveBodyDeduper, history page selection, and the contract codecs. Then it runs the real client reducers, shell reducer and history merge, and writes one case per line to crates/core/tests/conformance/*.jsonl. crates/core/tests/conformance.rs replays every case through the Rust code and compares rows, order, positions, bodies, records, history meta and the shell. --check exits 1 when the fixtures are stale. Intake now runs it (native-sync skill), and it is a factory gate.

Session hardening (CN-SESSION). crates/client/src/test_server.rs is an in-process fake server: the ticket POST and Effect RPC frames over /ws, on one port. Tests cover:

  • batched frames
  • an ack waits until the chunk's values fit the consumer queue
  • interrupt when a stream is dropped
  • a Defect fails every pending call
  • ping timeout
  • reconnect resumes the shell and threads with afterSequence

Divergences found and fixed

Where Divergence Fix
shell project.updated and authoritative snapshots dropped a resolved repository identity (retainRepositoryIdentity) ported
reducer a dropped partial-window update still bumped updatedAt bump only when applied
reducer equal-ordinal ties used byte order, not localeCompare (_, -, and case all differ) exact root collation for ASCII
stream a complete bounded snapshot (hasMoreHistory: false) was treated as a partial window, so events below it were dropped partial only while more history exists or a cursor is open
stream the partial-window watermark never advanced raised on applied turn items
session Defect and protocol errors surfaced as a bare "connection closed" pending calls fail with the server's message
session a dropped stream kept buffering late chunks until the server exited it the entry is released on drop

Reverting any of the four reducer/stream fixes makes the named conformance case fail.

Ledger

  • TV-HISTORY: todo -> partial, native crates/core/src/history.rs, issue #9
  • TV-STREAM: still partial. Gaps below.
  • CN-SESSION: still partial (relay, tunnel and wakeup resubscribe are not covered)

Verification

  • cargo test -p t3-core -p t3-client, cargo clippy --workspace --all-targets -- -D warnings, node scripts/gen-theme.ts --check, node --test parity/sync.test.ts, node conformance/generate.ts --check, cargo build -p t3-native, repo lint on apps/native/conformance

  • Real-data server (14700, read-only): decode_sweep decodes all 59 threads through the bounded path, with 0 errors. Largest threads, full vs bounded snapshot (release decode):

    items full bounded decode full -> bounded
    1855 7.8 MB 435 KB 33 -> 3.0 ms
    1298 5.9 MB 428 KB 14.5 -> 2.0 ms
    909 3.8 MB 119 KB 8.3 -> 0.6 ms

    Paging walks two of them back to exactly their full counts: 1855 rows in 4 pages, 1258 rows in 3, at 18–115 ms per page.

  • Smoke server (14658), probe transcript on a 14-turn devReplay thread:

    thread mcp:5fa7…: snapshot seq=1165 items=75 visible=75 has_more=Some(true) watermark=Some(14000009)
    history page: 52 rows in 27.5ms -> Done
    history: visible=127 has_more=false expanded=true
    

Gaps

  • Not driven in a real window. This environment has neither Screen Recording nor Accessibility permission, so I could not inject scrolls or take screenshots. The hook compiles and the loop is covered by tests, but the scroll trigger and anchoring still need one manual check.
  • The web shows a "Load earlier turns" control and the history error at the top of the timeline (MessagesTimeline.tsx TimelineHistoryControl). That rendering belongs to the transcript owner. The state is exposed in state.thread.history.
  • Collapsed work (acceptDeferredWork, view=work) and throughEntryId targeting (find, citations) are not requested.
  • thread.deleted still replaces the thread instead of clearing it as threads.ts does. That needs a deleted state in the view.

Model: Opus 5.5 (Claude Code), worker W4.

Subscribe threads with acceptBoundedSnapshot, acceptCompactTurnItems,
acceptCompactIds and acceptDedupedBodies, and undo each exactly while
decoding off the UI thread (withRecordIdTable, boundedSnapshotProjection,
restoreSnapshotBodies, live body restore). ThreadState carries the web's
history meta: a window is partial only while it has more history, and
applied turn items raise the watermark. The reducer now leaves activity
untouched for dropped partial updates and orders equal ordinals with
localeCompare collation. History merge and the load-earlier state machine
port threadHistoryMerge.ts and the loadEarlier loop.
ClientHandle fetches GET /api/orchestration/threads/:id/history with
bearer auth, the protocol header and compact IDs, decoding on the network
runtime (threadHistoryHttp.ts). AppState::load_older_history drives the
loadEarlier loop for the open thread, paging on while a page holds no
user turn. ThreadView asks for it when scrolling reaches the top rows;
prepended rows splice at 0, which keeps the scroll anchored. The probe
gains --history to page from the command line.
conformance/generate.ts builds synthetic scenarios, encodes them with the
real server wire code (bounded snapshots, live body dedupe, ID tables,
history pages), runs the real client-runtime reducers, shell reducer and
history merge on what a client decodes, and writes one case per line to
crates/core/tests/conformance/*.jsonl. conformance.rs replays every case
through the Rust reducers and compares rows, order, positions, bodies,
records, history meta and the shell. --check exits 1 when the fixtures
are stale, which is the drift alarm for upstream reducer changes.
The conformance harness found that project.updated deltas and
authoritative shell snapshots dropped a repository identity enrichment
had already resolved, which splits multi-environment grouping until the
next enrichment. Port retainRepositoryIdentity from shellReducer.ts: keep
the prior identity when the update has none and the workspace root is
unchanged.
An in-process server answers the ticket POST and speaks Effect RPC JSON
frames over /ws on one port. Tests cover batched frames, acks that wait
for room in the consumer queue, interrupt on stream drop, Defect failing
every pending call, ping timeout, and reconnect resuming the shell and
threads from the last delivered sequence.

Fixes what it found: a Defect or protocol error now fails pending calls
with the server's message instead of a bare 'connection closed', and a
dropped stream releases its entry so late chunks are not buffered until
the server exits it.
Intake regenerates the fixtures when --check fails and files parity:wire
issues for cases that diverge. TV-HISTORY is partial with the data side
and paging in place.
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XXL labels Nov 2, 2026
@rynfar
rynfar merged commit ff08394 into native Nov 2, 2026
7 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant