Skip to content

fix(native): controller-level deletion, per-op conformance, off-thread history merge - #21

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

rynfar merged 2 commits into
nativefrom
nw/w4-followup

Conversation

@rynfar

@rynfar rynfar commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Follow-up to #16, fixing the four findings from the independent review.

1. Deletion modeled at the controller level (P2)

Problem. The oracle fed thread.deleted through the projection reducer. The real controller (threads.ts applyEvent / setDeleted, and the loadEarlier page check) intercepts it instead.

Fix.

  • The oracle now clears the projection and history and ignores later events. A page that lands after the delete is stale, begin returns nothing, and a new snapshot revives the thread (setThread doesn't check deleted).
  • ThreadState does the same in Rust (deleted, EventBody::ThreadDeleted).
  • The app deselects a deleted open thread, which shows the workspace's no-thread state. That is the web's behavior: resolveThreadRouteRenderState returns missing and the route goes home. The stale transcript is no longer shown.
  • New cases: snapshot → begin paging → delete → page response (stale) → fail (stale) → begin (none) → events ignored → new snapshot revives. Also deletion before any snapshot. Removing the Rust interception makes 22 checks fail, starting at the delete op.

2. Compare after every operation, every modeled field

Problem. Only final states were compared, and only a hand-picked subset of fields.

Fix.

  • Every reducer step, thread operation and shell item records the TypeScript state. States share a per-case table of distinct records, which keeps the fixtures at 2.7 MB.
  • After each operation the replay serializes the Rust state (the wire types now derive Serialize) and compares every field the Rust types model. That includes nodeId, messageId, inputIntent, thread modelSelection, and all item bodies and records.
  • Vacuity guards:
    • every case has operations and one state per operation
    • every thread case shows at least one row
    • every shell case holds a snapshot
    • each family meets a minimum count of compared states
    • a modeled field no fixture sends fails the run: a misnamed Rust field would otherwise pass as null == null. Renaming senderThreadId in Rust makes the run fail.
  • To meet the coverage guard, the scenarios now set every optional field the native types model (the rich builders).
  • Shell states use sequential deltas. The generator separately asserts that batched deltas give the same result, which is shell.ts's own invariant.

3. History merges off the UI thread

Problem. Pages were merged inside this.update on the UI thread, and the merge indexed the whole transcript and cloned ids on every page.

Fix.

  • ThreadState::begin_history_merge checks the projection out (a move, O(1)) and applies the history meta at that moment, as the web's single update does.
  • HistoryMerge::run runs on the background executor.
  • finish_history_merge swaps the result back in one update and replays, in order, the live events that arrived meanwhile. These events arrived after the merge point in TypeScript terms too, so the ordering is exact.
  • A snapshot or deletion during the merge drops it. A process-wide generation counter keeps a merge for one thread from ever matching another thread's state.
  • The merge now indexes the page: the transcript is scanned once by borrowed key, and transcript ids are never cloned.
  • While a merge is out, ThreadView keeps its rows: sync returns early and the loading placeholder is suppressed. These are the only thread_view.rs edits, 4 lines.
  • Unit tests check that events during a merge give the same state as an instant merge, and that a snapshot or deletion during a merge wins.

4. History control state for the transcript (for W1)

  • state.thread.history_control() -> Option<HistoryControl { has_more, loading, error }> mirrors TimelineHistoryControl: None hides the control. It stays up and loading while the last page is still merging, so the spinner never ends before the rows land.
  • AppState::load_older_history() is both the click and the retry (loadEarlier clears the error).
  • New AppEvent::History fires on meta-only changes (begin, failure, merge start). AppEvent::Thread still fires when rows change.

Verification

  • cargo test -p t3-core -p t3-client, cargo clippy --workspace --all-targets -- -D warnings, node conformance/generate.ts --check, node scripts/gen-theme.ts --check, node --test parity/sync.test.ts, repo lint on apps/native/conformance, cargo build -p t3-native. Rebased onto feat(native): drive agents from the composer: new threads, pickers, approvals #20 (one additive conflict in app_state.rs).
  • The probe pages the smoke devReplay thread (75 → 127 rows) and a real 1855-row thread on the read-only server (4 pages, back to exactly 1855 rows) through the new merge path.

Gaps

  • No real-window check: this environment still has no Screen Recording or Accessibility permission, so the background merge in the app is covered by unit tests and the probe only.

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

thread.deleted now does what threads.ts does: the projection and history
clear, later events and pages are ignored, and a new snapshot revives the
thread. The app treats a deleted open thread as missing and deselects it,
as the web goes home, instead of showing the stale transcript.

A history page merges on the background executor: the UI thread checks
the projection out, the merge runs off-thread, and one update swaps it
back and replays events that arrived meanwhile, in order. A snapshot or
deletion during the merge drops it. The merge indexes the page, not the
transcript, and never clones transcript ids. ThreadState::history_control
and AppEvent::History expose the load-earlier control's state for the
transcript view.
The oracle models deletion at the controller level, as threads.ts does,
including a page that lands after the delete. Every case records the
TypeScript state after each operation, interned per case, and the replay
serializes the Rust state after each one and compares every field the
Rust types model (now Serialize). A modeled field no fixture sends fails
the run, so a misnamed or unexercised field cannot pass as null == null.
@rynfar
rynfar merged commit 1de8747 into native Nov 2, 2026
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