Repository navigation
feat(sync): one message uid on both planes, and a synced thread keeps its owner's key - #130
Merged
Merged
Conversation
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.
… a watcher is one window behind
…r's key, its message under one uid
# Conflicts: # crates/seq-shell/src/live.rs
…y that holds it, not the error's
…message its watcher saw
…ontract changed with the sweep's fold)
…d, once per batch
…t streams, not by the runner's clock
… rule and the watch guard
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.
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:
Store::coalesce_replygave 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.threadop 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_comingtimed a 300 ms gap on the runner's clock and failed on loaded runners.Cause
msg_loggedminted 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_ownerstored onlydeviceandproject.coalesce_replycould not rewrite a search entry that already covered the rows it folds, so it stopped there.Streamer::tickcut a batch a full window after its first pending event, whether or not the source had already waited a window.thread_foldtookoriginfrom the newestthreadop, whoever sent it, and cleared the key when the device changed.Change
sync_msg_uidand 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)andStore::reply_uid(thread)read it.Live.taps.watch(thread, tap)hands each event of a thread's runs to its watchers asStamped { ev, uid }until theWatchit returns is dropped. In JSON that is the event's own fields withuidbeside 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.Emitand its 48 callers are unchanged.fold_ended_replies, inmsg_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.sync_thread_owner.keyis 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.ThreadOwnergainskey. 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.coalesce_replynow 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.Streamersends 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".--include-partial-messagesflag. 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.rsandscripts/two-computers-check.mjsgain acopiesstep. 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.FAKE_PARTIAL_TOOL_UNTIL: it streams the tool call's input until that file exists (FAKE_PARTIAL_TOOL_MSat most) and names the calllateif its time ran out first. The test writes the file once it has every word and asserts the call isls. It checks order, not the runner's clock.Scope
Changed:
crates/core: the store, the op log and searchcrates/seq-shell: the live pump and the device sync's roundcrates/seq-peer: the stream's windowcrates/seq-providers: the held-words test, andtests/fixtures/fake-bins/fake-claudedocs/CORE-API.md: themsguid binding and folds,ThreadOwner.keyand the owner rule, "A run watched live" and the window ruleLeft alone on purpose:
Emittype.open_withinlive.rs(the warm session's start and handoff).Nothing sends
Stampedevents over the network yet. Watching and driving a run from another computer (shell_watch/thread_watchover the env channel) is the next pull request. Delivering a waiting request when a computer comes back waits on #126 (LinkEvent::PeerUpinSocial::on_link,devices://changedfromMachine::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):
cargo test -p seq-shell --features peers --test two_computers --no-run.node scripts/two-computers-check.mjs maker --node target/debug/deps/two_computers-<hash>. Carry the device code it prints to the second computer.node scripts/two-computers-check.mjs joiner --node target/debug/deps/two_computers-<hash>, then paste the code.PASS copiesamong 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.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 nocopiesstep, 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 failscopies.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 withoutunwatchstayed (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 withlateinstead ofls.Contract changes and the tests that moved with them:
crates/core/tests/rev1100.rsexpected 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.seq-peerstream 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_waysgainscopies_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: 0cargo clippy --locked -p sequence-core -p seq-shell -p seq-peer -p seq-clis -p seq-guards -p seq-providers --all-targets -- -D warnings: 0cargo 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-targetsstops ontwo_computers.rs:579(&[project.clone()]). That line comes from an earlier commit, and CI does not lint that target. It is left alone.