Repository navigation
pair: merge a computer's own chats when it joins, instead of replacing them - #2031
Merged
Merged
Conversation
…g them A computer that already has chats and has never been paired now joins by code or link without being asked to replace them. Its full local histories, saved keys, memory and preferences are kept; its histories are published under the shared keys with their original chat ids and holders. Both computers then list both sets of chats, and Continue here moves a chat either way through the existing app protocol and events. The approved switch is recorded before keys are restaged, so a start after an interruption finishes the merge with the same device. Background publication retries failed uploads and reports status for unopened chats through the existing sync.changed reason. A used computer that already shares another set is refused without changing anything. Terminal --replace stays an explicit, confirmed clean slate and now sets the old chat folders aside. Validation: focused internal/pair, internal/identity, internal/syncsetup and cmd/codeaf pairing tests, run serially under an 8 GB cap; one live check that paired two homes with three-turn chats over a loopback relay through the app's JSON lines, checked both inventories after restart, and compared byte-identical histories after Continue here in both directions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The chat manual no longer tells a computer with chats of its own that pairing replaces them. It explains that both computers keep their chats and see each other's, that a computer already sharing another set is refused, and that terminal --replace is the explicit clean slate. Adds the change entry. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A saved-key write that read the old key before pairing switched this computer to the shared keys could replace the resealed file afterwards, leaving saved keys that no longer open. Vault transactions and the pairing switch now take the same per-home file lock, and a transaction re-reads the current key under it. The lock's bookkeeping file does not make a home count as used. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- An interrupted --replace records its phases, so a later start never repeats the reset and never touches state saved after the switch. - Background sharing and opening a chat take the same per-chat lock, so the other computer cannot continue a chat that was just opened here. - Terminal pairing says sharing finishes the next time codeaf runs, and the next start does it. - Only chats still waiting to be shared are retried, with pauses growing from 5 seconds to a minute, outside the chat list's lock. Approving a pairing picks up chats saved after the startup scan. - Keys, memory and preferences are synced only while a merge is unfinished; a merged, idle computer makes no new periodic relay requests. - A computer that was removed and pairs again with --replace by link keeps the shared identity and gets its new device installed. - The tui3 join-line tests compare rendered text with whitespace normalized, since the longer joined line wraps. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The manual states the new pairing lines word for word, that terminal pairing finishes sharing the next time codeaf runs, and that an older chat appears on the other computer once it is opened here. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s first save - A state round refuses to upload a saved-keys envelope sealed under a key other than the one the round started with, so a switch mid-round never sends the new set's keys to the old set. The next round starts on the new binding. - Replace recovery that stops before the destination is installed repeats the reset, so the saved-keys file always opens under the destination afterwards. Recovery after installation still never repeats it. - A chat with nothing saved yet stays waiting without a backoff, and is shared as soon as its first save lands rather than at the next start. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
AbirAbbas
marked this pull request as ready for review
October 29, 2026 17:36
This was referenced Oct 29, 2026
Merged
This was referenced Nov 1, 2026
santoshkumarradha
added a commit
that referenced
this pull request
Nov 3, 2026
…st (#2181) * tests: R2 and R3 wait for the startup publication instead of chats.list #2031 moved the startup pass that publishes existing chats out of chats.list into a background loop, and TestR1_6InventoryDoesNotWaitForPublication pins that chats.list never waits for it. R2 and R3 still called ListChats to join that pass, so with the real engine they read the directory before anything was published. They now wait for the startup pass, and R3's restart observes one whole settled publication round before checking that nothing is released again. * docs: change entry for this pull request
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.
Why
Pairing treats all paired computers as one identity. The computer that enters the code (or opens the link) adopts the identity of the computer that shows it. If that computer already had chats, the only choice was to give them up. The app asked "Replace this computer's chats?", and replacing cleared its preferences, shared memories and saved keys. The terminal refused unless
--replacewas passed.That is the wrong model. Paired computers should share their chats, and pairing should never destroy anything.
What changes
agents.take) moves a chat in either direction, as before.codeaf pair <code>and link joins merge too. They say "Sharing finishes the next time codeaf runs."--replacestays an explicit, confirmed clean slate. It records its phases, so recovery never repeats the reset, and it sets the old chat folders aside.doneand a restart. Arrivals use the existingchat.changedandagent.changedevents, and progress uses the existingsync.changedreason.The desktop needs no change for this. codeaf-desk #67 separately stops older engines' replace question from highlighting Replace.
Validation contract
chats.listagrees on both.--replaceremains opt-in.Review and fixes
A read-only review of the first version found seven items. Six were real, and each was fixed with a reproducing
TestR1_*test:--replacerecovery repeating its resetThe seventh was already handled: opening an older chat converts and publishes it, with no age limit. The manual now says so.
The first GitHub full check found four failures in touched packages, all fixed:
--replacenow gets its new device installedA second review confirmed all seven fixes and found three more, all fixed with reproducing
TestR3_*tests (each fails on the code before the fix):A third, narrow review of that last round confirmed the first two. On the third it noted that the background worker isn't woken by a waiting chat's first save. That save goes through the chat's own drive, which creates the relay record (
Publisher.create), the same path every chat created after pairing uses. The worker does re-check waiting chats locally on each tick while some other chat keeps failing. That is local only, and left as is.Tests (Linux, focused, serial, under an 8 GB memory cap)
go test ./internal/pair ./internal/identity ./internal/keys: 292 pass, 0 fail.go test ./internal/tui3 -run 'Pair|FirstRun|Join|Link': 173 pass, 0 fail.go test ./cmd/codeaf -run 'Pair|Devices|Device|Sync|Chats|Take|OlderChats|Join|Link|Replace|R1_|M[0-9]': 489 pass, 1 existing skip. The 1 failure is the take-back test listed below, unchanged from app/v3.-run 'R3_'ininternal/pairandinternal/syncsetup: 8 pass, 0 fail.go test ./internal/manual/...: 113 pass, 0 fail.internal/syncsetup: all pairing-merge and review tests pass, including real two-home tests over a loopback relay. The 12 failures in the package are furrow-only tests that fail identically on 12dadd6 (checked with the changed files overlaid back to their base versions) and skip on CI.chats.listlisted both chats, each own chathere. Continue here in each direction kept the history byte-identical.CI
GitHub's PR gate and full check are compared against the app/v3 full check at the same base (12dadd6), by failing test names and by the file sites the law tests list (line numbers stripped):
TestTheSourceHoldsEveryRowTheAppLists, a known fixture teardown race, andTestOneTaskReadDoesNotCopyTheWholeGraph, an allocation count ininternal/session, which this change doesn't touch and which passed on the first run.On the final head (a26ce90), the PR gate fails only the same five law tests, with no new sites. Every full-check attempt failed some test outside the baseline, a different one each time, all in packages this change does not touch or flaky on app/v3 too:
TestR26R27C30OpenLearnerIdleAndStateWaketimed out at 31 s on the first attempt. It passed 6/6 locally (1.7–3.1 s), before and after the last fixes, and passed on the second attempt.TestR7PersonalLeaderFallbackAndNoAutomaticRegain/sync-offfailed on the second attempt. It fails 1 in 5 locally on both this head and unmodified 12dadd6, with the same message.TestAppCrewProposalEndsInOneReceiptfailed on the second attempt. It is in Inbox and crew-proposal code this change does not touch.TestAWarmNoSendsBackToThePlanWithTheWordsAndAsksAgainandTestTheSourceHoldsEveryRowTheAppListsfailed on the third attempt. The first also fails on two earlier app/v3 full checks, and the second is the known fixture teardown race.Against a fresh app/v3 full check at the same base (12dadd6, run after the last push): the PR gate fails the same five law tests, the lock law lists the same sites, and the only full-check failure outside it is
TestAWarmNoSendsBackToThePlanWithTheWordsAndAsksAgainininternal/factory/worker, which this change does not touch.On the third attempt, no package this change touches (
internal/pair,keys,identity,vaultsync,syncsetup,tui3) failed.Existing failures, not touched here
TestHostedTakeBackReachesAcquireWithoutSharedUploadsOrReleaseDelayfails 3/3 on unmodified 12dadd6 when furrow is present ("made 1 acquires; want both") and skips on CI. Left as is.Limits
🤖 Generated with Claude Code