Skip to content

feat(sync): one message uid on both planes, and a synced thread keeps its owner's key - #130

Merged
naidx0 merged 22 commits into
mainfrom
feat/live-between-1b
Dec 3, 2026
Merged

naidx0 merged 22 commits into
mainfrom
feat/live-between-1b

Conversation

@naidx0

@naidx0 naidx0 commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

TL;DR

Every message Nova writes now has one portable id from the moment it is written. The live event and the synced log both carry that id, so a computer watching a run live can match each message when the sync brings it. A copy of another computer's thread now stores the owner computer's key. A long reply is saved as the one message its live events named: even when search reached it while it streamed, an error came in the middle, or the person wrote while it streamed. Only the computer that owns a thread can name another owner for it. A watcher sees text at most one 50 ms window behind, not two.

Problem

Part 1 of letting one computer watch and drive a run on another ran into these gaps:

  • A run's live events carried no id. The message's id was only made later, when the sync logged it. A computer that watched a reply live had no way to match it with the message the sync delivered a moment later, so it would show that message twice.
  • A synced copy of another computer's thread named its owner only by device name, looked up later in the device circle. Nothing tied the copy to the owner's key.
  • Store::coalesce_reply gave up once search had indexed the first rows of a streaming reply (indexed >= first). A search during a long reply left that reply as dozens of rows in history, and as dozens of messages in the sync log.
  • Claude's reader holds text for 50 ms. The peer stream then held it for another 50 ms, so a watcher on a direct link could be up to 100 ms behind.
  • Any linked computer's thread op could name a thread's owner, both on a copy and on a thread this computer owns.
  • claude::tests::held_words_go_out_on_time_while_lines_that_are_no_event_keep_coming timed a 300 ms gap on the runner's clock and failed on loaded runners.

Cause

  • msg_logged minted a message's uid when the sync first offered it, which happens after the row is written and after its live event has gone out. A streamed reply's rows had none until the fold. The fold kept the last row, so a uid bound to the first row would have been lost.
  • sync_thread_owner stored only device and project.
  • coalesce_reply could not rewrite a search entry that already covered the rows it folds, so it stopped there.
  • Streamer::tick cut a batch a full window after its first pending event, whether or not the source had already waited a window.
  • thread_fold took origin from the newest thread op, whoever sent it, and cleared the key when the device changed.
  • When the test's reader fell behind, the fake's 600 ms of tool input ran out while it waited on a full pipe, so the words and the call came close together.

Change

  • One uid per message, bound when it is written. A new table sync_msg_uid and an insert trigger bind a uid to every row written here: a streamed reply's at its first row, other rows at their own. Imported threads are skipped. The fold moves the reply's binding onto the row it keeps, taking only a binding of that thread's own rows. The sync logs the bound uid and drops the binding. Store::message_uid(id), Store::reply_uid_of(id) and Store::reply_uid(thread) read it.
  • Live events carry it. Live.taps.watch(thread, tap) hands each event of a thread's runs to its watchers as Stamped { ev, uid } until the Watch it returns is dropped. In JSON that is the event's own fields with uid beside them. Every piece of a reply carries the reply's uid, and a stored event carries its row's. The uid is read in the store lock that wrote the event, once per batch of text, so no other write comes between. Nothing is read when nobody watches. Emit and its 48 callers are unchanged.
  • A reply a person's message ended. When the person writes while a reply streams, the reply's pieces before that message are folded into one row under the bound uid before the log takes them (fold_ended_replies, in msg_pending). The log then carries the one message the watcher saw. It folds only rows of one run that a row from outside that run ended.
  • The owner's key. sync_thread_owner.key is added (by ALTER on older stores). After each round, the device sync fills it from the device circle (Store::key_thread_owners). It is kept while the owner stays the same device. ThreadOwner gains key. The op that first brings a thread names its owner. After that, only an op from the owner names another. An op from any other computer leaves the owner and its key as they were, and a thread this computer owns stays its own.
  • The fold past the search mark. When search has indexed part of a reply, coalesce_reply now rewrites that search entry (search::refold) and folds anyway. The result is one row, one sync op and one search hit. The entry it rewrites is the one that holds the rows: the entry that starts at the newest text row at or before the reply's first. An error's own entry in between stays as it was.
  • One window. The peer Streamer sends an event at once when it comes a window or more after the last batch. A faster event waits until one window after that batch. Claude's text, already held 50 ms, passes straight through. A CLI's per-token deltas are still held to one batch per window. The window rule is in CORE-API, "A run watched live".
  • The --include-partial-messages flag. Claude Code has had it since 1.0.109. Nova's minimum Claude is 2.1.0 (seq_clis::MIN_VERSIONS), so no supported Claude refuses it, and no session needs to restart without it. A test keeps the minimum at or above 1.0.109. An unsupported older Claude still gets the existing below-minimum row.
  • Two computers. two_computers.rs and scripts/two-computers-check.mjs gain a copies step. Each computer makes a thread with a message. The other computer must hold a copy that names the first computer's key, with the message under the uid it was written under.
  • The held-words test. fake-claude gains FAKE_PARTIAL_TOOL_UNTIL: it streams the tool call's input until that file exists (FAKE_PARTIAL_TOOL_MS at most) and names the call late if its time ran out first. The test writes the file once it has every word and asserts the call is ls. It checks order, not the runner's clock.

Scope

Changed:

  • crates/core: the store, the op log and search
  • crates/seq-shell: the live pump and the device sync's round
  • crates/seq-peer: the stream's window
  • crates/seq-providers: the held-words test, and tests/fixtures/fake-bins/fake-claude
  • docs/CORE-API.md: the msg uid binding and folds, ThreadOwner.key and the owner rule, "A run watched live" and the window rule
  • tests and the two-computers script

Left alone on purpose:

  • The Emit type.
  • open_with in live.rs (the warm session's start and handoff).
  • The app's screens.

Nothing sends Stamped events over the network yet. Watching and driving a run from another computer (shell_watch / thread_watch over the env channel) is the next pull request. Delivering a waiting request when a computer comes back waits on #126 (LinkEvent::PeerUp in Social::on_link, devices://changed from Machine::note_presence). This pull request adds no presence signal of its own.

Before and after

On two real computers (each with this build, linked as one person's computers; the check prints PASS or FAIL per step):

  1. On each computer, build the node once: cargo test -p seq-shell --features peers --test two_computers --no-run.
  2. On the first: node scripts/two-computers-check.mjs maker --node target/debug/deps/two_computers-<hash>. Carry the device code it prints to the second computer.
  3. On the second: node scripts/two-computers-check.mjs joiner --node target/debug/deps/two_computers-<hash>, then paste the code.
  4. Both print PASS copies among the steps. Each computer holds the other's thread under the other's key, with the message under the uid it was written under there.
Before After
The copy names its owner by device name only. A message has no uid until the sync logs it, and its live event carries none. A reply that search reached mid-stream stays as one row per streamed piece, in history and in the sync log. A watcher on a direct link can be 100 ms behind. The copy carries the owner's key. A message's uid is fixed when it is written and rides its live event. The reply is folded into one row whatever search did. A watcher is at most 50 ms behind.

Verification

Tests that failed before their change:

  • sequence-core search::tests::a_reply_indexed_while_it_streams_is_still_folded_into_one_row. Before: a reply searched mid-stream stayed as 5 rows and 6 sync ops (left: (false, 5, 6, ...)). Now it is 1 row and 1 op, and search still finds it once.
  • sequence-core store::tests::a_replys_uid_is_bound_with_its_first_row_and_survives_the_fold. Before: the reply had no uid until the sync logged it.
  • sequence-core store::tests::a_row_has_the_uid_it_travels_under_when_it_is_written. Before: a step's row had no uid when it was written (left: None).
  • sequence-core memlayers::oplog::threads_tests::a_copy_keeps_the_key_of_the_computer_that_owns_it. Before: no key was stored.
  • seq-shell peers::sync::tests::a_thread_from_the_other_computer_keeps_that_computers_key. Before: the copy's key stayed empty after a real sync between two engines.
  • seq-shell live::tests::a_watched_runs_events_carry_the_uids_their_messages_travel_under. Before: a watcher got nothing (left: 0, right: 5). Now the stamped uids equal the sync log's msg uids, in order. It covers both the batched text path and the single-event path.
  • seq-peer stream::tests::text_after_a_quiet_window_goes_at_once_and_faster_text_waits_for_it. Before: the first piece waited for the window (head 0).
  • scripts/two-computers-check.test.mjs. Before: the step list had no copies step, and a copy without its owner's key did not fail. The step also has a negative control: a fake copy that names no owner fails copies.
  • sequence-core search::tests::a_reply_after_an_error_is_folded_into_the_entry_that_holds_it. It indexes after the first piece, after the second, or not at all. Before: the error's entry was rewritten with the reply's words, so "the tool failed on a badger" was gone from search, and the reply's words were doubled or split. Now each is found once, and the reply is one row.
  • sequence-core store::tests::a_fold_never_takes_another_threads_uid. Two threads write in turn, and one reply's first row holds no binding. Before: that reply's fold took the other thread's uid, so the other reply travelled under a uid its live events never carried.
  • sequence-core store::tests::a_reply_a_persons_message_ended_travels_as_one_message. It runs with search indexing between the pieces and without. Before: the pieces before the person's message travelled as 2 messages (3 uids where 2 were expected).
  • seq-shell live::tests::a_message_written_mid_reply_leaves_every_stamp_matching_the_log. Before: the log held a message (2ee7...) that no live event had carried.
  • seq-shell live::tests::a_batch_carries_the_uid_decided_with_its_write. A person's message lands while the first piece is handed out. Before: the second piece of the same batch carried no uid (left: None).
  • sequence-core memlayers::oplog::threads_tests::only_the_computer_that_owns_a_thread_names_another_owner. Before: a third computer's op moved the copy to itself and dropped the owner's key. Now the copy keeps its owner and key, the owner's own thread stays its own, and an op from the owner still hands the thread over.
  • seq-shell live::tests::a_dropped_watch_stops_watching. Before: a watcher dropped without unwatch stayed (left: 2, right: 1).
  • seq-providers claude::tests::held_words_go_out_on_time_while_lines_that_are_no_event_keep_coming. With 40 busy loops on 10 cores, the old test failed 2 of 12 runs (263 ms and 293 ms against its 300 ms bound). The new one passed 12 of 12 under the same load. Negative control: without the reader's per-line window check, it fails with late instead of ls.

Contract changes and the tests that moved with them:

  • crates/core/tests/rev1100.rs expected 5 rows for a reply searched mid-stream. It now expects 1, in its own commit, which says why. Its interleaved-threads case now expects the reply a person's message ended as one row (xy), in its own commit too.
  • Four seq-peer stream tests (deadlines, the window with boundaries, the caps, the outcome on the terminal batch) assumed the first piece waits for the window. Each now opens with a piece that goes at once, then makes its original check. The outcome test now also asserts that the opening batch carries no outcome.

Guards:

  • seq-clis pure::claudes_minimum_has_the_partial_messages_flag. Claude's minimum (2.1.0) is at or above 1.0.109. Its control: 1.0.108 compares lower.
  • seq-shell --features peers --test two_computers two_processes_link_and_sync_both_ways gains copies_both_ways (two OS processes over a local relay). Negative control: with the expected key swapped to the receiving computer's, it fails with "Laptop never held "a copy from Home" as Home's".

Commands (exit codes):

  • cargo fmt --all -- --check: 0
  • cargo clippy --locked -p sequence-core -p seq-shell -p seq-peer -p seq-clis -p seq-guards -p seq-providers --all-targets -- -D warnings: 0
  • cargo nextest run --locked -p sequence-core -p seq-shell -p seq-peer -p seq-clis -p seq-guards -p seq-providers: 0 (4456 passed)
  • cargo nextest run --locked -p seq-shell --features peers -E 'test(/peers::|two_computers|sync/)': 0 (300 passed)
  • node --test scripts/two-computers-check.test.mjs: 0 (9 passed)
  • node --test scripts/fake-claude-stream.test.mjs: 0 (5 passed)

Not verified:

  • node --test 'scripts/*.test.mjs' locally: 588 passed. The 5 that failed are the workflow-YAML tests, because this machine's Python has no PyYAML. CI runs them.
  • cargo clippy -p seq-shell --features peers --all-targets stops on two_computers.rs:579 (&[project.clone()]). That line comes from an earlier commit, and CI does not lint that target. It is left alone.
  • The two real-computer run in Before and after. The loopback run covers the same node commands.
  • The native app. No screen changes.

naidx0 added 22 commits December 3, 2026 02:29
The old expectation was that a search mid-stream stops the fold (five rows). The fold now rewrites the search segment that holds the reply, so the reply is one row either way; the test's other checks are unchanged.
…arch reached mid-stream still folds

The uid rides with the reply until it is logged: the fold moves it onto the kept row and the msg operation takes it. A fold over rows search had indexed rewrites the segment that holds them in the same transaction.
The sync fills the key from the device circle's entry for the owner's device after each pass; once stored it stays, and it changes only when the thread changes owner.
…s it is written

The binding covers every row, not only a reply's first, so a step's or an error's live event can carry its uid before the log takes the row.
@naidx0
naidx0 merged commit 70f1f5d into main Dec 3, 2026
20 checks passed
@naidx0
naidx0 deleted the feat/live-between-1b branch December 3, 2026 10:06
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