Skip to content

perf(move): a moved chat opens in about two seconds; its files arrive behind it - #2714

Merged
AbirAbbas merged 23 commits into
devfrom
perf/snappy-chat-move
Nov 17, 2026
Merged

AbirAbbas merged 23 commits into
devfrom
perf/snappy-chat-move

Conversation

@AbirAbbas

@AbirAbbas AbirAbbas commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Why

Moving a chat to another computer ("continue here" on Home, the chat that comes over by itself at launch, or agents.take / agents.open in the app) took 12–30 s before the conversation appeared. A 117 MB folder took minutes. Everything ran in series before the chat was drawn: three directory reads, a serial fetch of the transcript AND every workspace file, the hold, materialize, the vault pull, git status and the local-edits scan.

Measured, by hand, between a Linux PC and a Mac over the hosted dev relay

Times are from the engine's own continue <id> phases line (shown=). On that relay one request costs 0.25–1 s.

move before after (this branch)
Home → continue here, warm 2,538-file chat (Mac) 13.1 s (fetch 11.4 s) 1.94–2.26 s, 2 serial requests
Chat that comes over at launch (PC) 24.2 s 1.49 s, 2 serial requests
Chat that comes over at launch (Mac) 24.2 s 2.22 s
Files finished behind the open chat n/a (all before the open) 3–14 s, shown as files arriving · N KB
Fresh chat, first open on the PC (nothing local yet) n/a 2.89 s, files byte-identical at 6.7 s
That chat back to the Mac, with an unsaved local edit there (final head) n/a 1.20 s, 2 serial requests; edit kept as a copy with your unsaved edits here were kept as 1 turn from mac-test; the PC's README arrived at 8.3 s

The bottom line is never blank during a move: it reads opening conversation… N KB until the chat opens. Text typed on Home during a move lands in the arriving chat's box, after that chat's own saved draft if it has one. It is never sent.

What changes

  • The chat opens on its open state alone. It needs the head frame (which carries the small .cell/ records), plus the hold. When the view is already in hand (Home's row, the launch walk, the resume band, the app), the fetch and the acquire go out together and the directory is not re-read. A stale view is refused by the acquire and falls back to the serial path, so fencing is unchanged.
  • Files arrive behind it. Materialize, the vault, index rebuilds, task copies and arrive run in the background. Workspace tools wait on a ready gate that holds across the client and engine processes. The gate's marker lives in the engine's local store and is never sealed or sent, and a crashed owner never stalls a waiter. The model can still answer in words meanwhile, and nothing runs on a half-arrived tree.
  • No slow local work before the open. The local-edits check uses a stat index. A copy without one gets a cheap check up front and the full check in the background before files are swapped. Local edits are still kept on a branch, never lost. A reader of the chat in another process never holds the open back; only a running turn is waited on.
  • Fetch. Up to 8 batches in flight. Transient failures (5xx, timeouts, resets) are retried with backoff; auth refusals and other 4xx are not. A retry keeps what was already fetched.
  • The phase line gains shown=, files=, open_gets=, open_rounds=, open_seed= and open_path= (every step before the open, with its time).
  • Off switch: CODEAF_MOVE_FILES_FIRST=1 restores the old order (files before opening). The new order is the default.

Fixed after a hand smoke and an independent review of this branch

  • Local edits. The background keep step dropped its own errors. A branch the directory refused, or a failed seal, still let the arriving files replace the folder, with no notice. Any failure now leaves the folder as it is, keeps the files gate shut and offers your unsaved edits here could not be kept yet (…) · retry. A kept edit is said with dev's your unsaved edits here were kept as N turns from <device>. Setting the older copy aside fails closed.
  • Fencing. The lease is asked for beside the fetch only when nobody holds the chat. A held chat is staged first and acquired after, as dev does, so a failed fetch never fences a computer mid-turn. This costs one round more for a held chat. A refused claim never re-aims at a holder the person did not choose. CODEAF_MOVE_FILES_FIRST=1 takes the old order entire.
  • Open state. A local file is reused for the open only when it hashes (BLAKE3, as the engine does) to the chunk the head names. Carried task and artifact records take the head's version. The workspace's AGENTS.md / CLAUDE.md ride the open wave (bounded at 256 KB), and a session opened before its files landed re-reads its page when they arrive.
  • Every door is told. After-work failures and notices reach the app as well as the terminal. The setup card regains what this computer lacks and what is uncommitted once the files land.
  • The files gate has a per-system owner probe; Windows read a live owner as dead before. A failed arrival keeps refusing tools and seals in every process until a fresh fetch, which opening or taking the chat again starts.

No wire format changes and no relay changes. The only new on-disk files are local to one computer (stat-index.json and the arrival marker in the engine's per-chat store). Builds without this change still move chats to and from this one.

Validation

Every contract item has a test named after it (C1–C10, R1–R8, Q1–Q4, F1–F3, R5b–R5d). The ones that matter most:

  • TestR1RealisticColdAndWarmCriticalPathOpensWithinFourRounds: a chat with real shape (300+ conversation objects, 2,500 files) on a fake relay at 400 ms per request opens before its files, and the files land byte-identical.
  • TestQ3LaunchAutoContinueRealisticShape: the launch path went from 8 serial rounds to 3 (now 2). It fails on the earlier head.
  • TestF1*: one or two rounds from a fresh view, the stale-view fallback, and a racing second computer still refused.
  • TestR5cReaderInSeparateProcessDoesNotDelayShown: was 3.05 s, now 25 ms.
  • TestF2* / TestQ4*: under 150 ms of local work before the open on a warm 2,500-file copy, with or without a stat index; a real local edit is still kept.
  • TestF3* / TestR5bCrashedArrivalOwnerDoesNotStallWaiters: nothing reads files before they arrive (this fixed a could not keep … in the key vault line seen mid-move); the marker never travels; a dead owner is ignored at once.
  • TestR6* / TestR5d*: the draft typed during a move is carried and kept.

Local gate: make test-quick green. The make pr-ready touched-package legs are green for internal/session, internal/syncsetup, internal/cellstore, internal/cellsync, internal/handoff, internal/blobstore, internal/cell and the manual. Its first run found four regressions from this branch, all fixed here and re-run by name:

  • TestTakeoverScreenOpensTheChatAndSaysWhatWasKept
  • TestAppTakeMissingWorkspaceW5
  • TestCopyBucket_D3_TenNativeMovesKeepExistingRoots
  • TestThreeRoundTripsBetweenTwoHomesStillOpen

Expect cmd/codeaf to be red in touched packages, for reasons that are not this change. Eight factory/memory tests fail identically on dev a597fdc with exec: "bash": executable file not found in $PATH:

  • TestFactoryWriteUsesJobBaseAcrossAttempts
  • TestFactoryRetryActionsDoNotReportStopped
  • TestFactoryStepRetryWaitsForPreviousLeaseCleanup
  • TestFactoryCommandStepRetryAfterOutOfAttempts
  • TestAppFactoryPlanFilesAnswer
  • the three TestMemoryPause*

That puts the leg over the five-failure re-run limit. Seven more timed out only under eight-shard load and pass by name.

Not in this change, seen while testing

  • A chat whose folder was deleted on this computer fails could not be put in this folder on every launch. This is on dev too.
  • codeaf's own start-up takes about 1.3 s before the take begins on the launch path.
  • A copy kept from local edits can only be discarded, not opened or merged: Options.Branches is never set outside tests. This is on dev too.
  • agents.open on a chat this computer still shows as held does not restart a failed arrival; the gate stays closed (fails safe) until the chat is taken again.

🤖 Generated with Claude Code

AbirAbbas added a commit that referenced this pull request Nov 17, 2026
AbirAbbas and others added 15 commits November 17, 2026 10:59
…nt object failures

A take fetched missing objects one GetMany batch at a time and never retried
a failed request, so a 40 KB chat cost several seconds of serial round trips
and one relay 500 threw away minutes of download. The fetcher now keeps up to
eight batches in flight, retries 5xx, timeouts and resets with backoff (never
auth refusals or other 4xx), and keeps the objects it already stored.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
TakeSeen read the chat's record and Taker.Take read it again, one more serial
relay round trip before the chat could open. The seen record is now passed
down.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…es in behind it

Continuing a chat on another computer waited for every workspace file, the
vault pull, task-copy restore, git status and index rebuilds before drawing the
conversation: 7-12 s for a 40 KB chat and minutes for a large folder. The take
now installs the conversation records, takes the hold and opens the chat after
at most three serial relay round trips; workspace files and the after-work
continue in the background with a files-arriving status line. Workspace tools
wait on a per-chat ready gate so nothing reads a half-arrived tree, the phase
line gains shown= and files=, and CODEAF_MOVE_FILES_FIRST=1 restores the old
order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tinue path

A real two-computer run of the first cut still waited 13 s on a warm 2,538-file
chat that needed only 11 objects: the take seeded the receiver's whole older
tree, hashed it for local edits, and fetched every conversation record before
opening, and the launch and idle auto-continue paths skipped the early open
and fetched serially. The open now fetches only the head frame and open-state
records in one parallel wave, hardlinks just those into place, checks local
edits by size and mtime (full hashing moves behind the open), and the idle,
alt+c and agents.open paths use the same split. A realistic test (300+
conversation objects, 2,500 files, stale and cold receivers, 400 ms per
request) failed at 8 and 6 rounds before and opens in 3 now. The phase line
adds open_gets=, open_rounds= and open_seed=.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…o to the arriving chat

Home's bottom line went blank for twelve seconds during a move, and anything
typed on Home in that time went into Home's own box, where Enter started a new
conversation. The line now says opening conversation with its bytes from the
keypress on, and text typed during a move is held as the arriving chat's
draft and never sent by itself.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y stat alone

A warm receiver already holds most of the conversation's open state and its
earlier transcript chunks, so the open fetch now reuses them instead of asking
the relay again, and caches every open-state object it does fetch. The stat
index also records the sealed transcript's hash, so bookkeeping lines appended
after a seal no longer push the local-edits check onto the slow furrow path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the chat opens

The local reader is asked to let go at the keypress and released concurrently;
the device name for the banner is looked up after the chat is shown; the kept
branch is read only when there is an unshared local turn; local work overlaps
the directory read. The phase line gains open_path=, and every directory request
on the open path counts toward open_rounds. TestQ3 models the launch
auto-continue with its real shape: 8 serial rounds before, 3 after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…iles before they arrive

The move runs in the client process while the session's tools and captures run
in the engine, so the in-memory arrival gate never reached them. The arrival
now also leaves a marker in the engine's local per-cell store (never inside the
cell, so it is never sealed or sent), carrying its owner's PID and start time so
a crashed owner never stalls a waiter. Dirty, SavedState, Restore and the vault
round wait on it, which is what printed "could not keep … in the key vault"
while a moved chat's files were still arriving.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
When Home's row, the launch walk, the resume band or the app already holds the
chat's record, the open-state fetch and the lease acquire go out together and
the directory re-read is skipped; a stale view is refused by the acquire and
falls back to the serial path, so fencing is unchanged. A copy with no stat
index (every copy written before this change) is checked cheaply before the
chat opens and fully in the background before files are swapped in, keeping
any local edits on a branch as before; the stat index is written after every
materialize. The withheld-files policy is seeded before furrow materializes, so
withheld .env files are not unlinked before the vault restores them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…m opening

At launch the chat's journal can be held by a reader in another process (the
launch folder's engine, a preview), and the open path waited for it to let go
for up to five seconds. Only a holder that is running a turn is waited on now,
so there are still never two writers; a reader is retired in the background
before the workspace or journal is swapped. The restore step on the phase line
is split into the sub-steps that make it up.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…raft too

When the arriving chat already had a saved draft, the text typed on Home during
the move took the box, the saved draft stayed unrestored, and quitting refused
to save either one ("this draft could not be saved"). The box now holds the
saved draft, a newline and the carried text, and quits save it as usual.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AbirAbbas
AbirAbbas force-pushed the perf/snappy-chat-move branch from ddfd8e5 to f0b366f Compare November 17, 2026 16:38
AbirAbbas and others added 2 commits November 17, 2026 12:17
On a move that files the chat into a different folder (a copy, a native move
back), the background stage wrote the files under the root it started with, so
the filed folder had no files and the app followed an empty tree. The background
stage now follows the filed root.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AbirAbbas AbirAbbas changed the title perf(move): a continued chat opens on its transcript in about a second; files arrive behind it perf(move): a moved chat opens in about two seconds; its files arrive behind it Nov 17, 2026
@AbirAbbas
AbirAbbas marked this pull request as ready for review November 17, 2026 17:19
@AbirAbbas
AbirAbbas marked this pull request as draft November 17, 2026 17:23
AbirAbbas and others added 6 commits November 17, 2026 13:39
The open-first path checks the older copy here for unsaved edits in the
background, keeps them as a branch, then swaps the files in. Every error in that
keep step was dropped, so a refused branch or a failed seal still replaced the
folder and said nothing. The background stage now stops on any such error: the
files are left as they are, the files gate stays shut, the status line says the
edits could not be kept yet and offers a retry, and the set-aside copy stays for
it. Setting the older copy aside now fails closed, before anything is replaced.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The open-first claim asked for the lease beside the fetch, so a fetch or stage
that then failed had already fenced a live holder mid-turn. The lease is now
asked for beside the fetch only when nobody holds the chat; a held chat is
staged first and acquired after, as before. A refused claim never re-aims at a
holder the person did not choose, a window running a turn is never asked to
step aside before the take is known to proceed, and CODEAF_MOVE_FILES_FIRST=1
takes the old order entire.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The open state was rebuilt in Go from the local older copy wherever it could
be, with only a length check: a same-length stale chunk became part of the new
head, a file the frame did not carry kept its older local bytes, and carried
task and artifact records never took the newer version. A local file is now
reused only when its content hashes to the chunk the head names (BLAKE3, as the
engine does); anything else is fetched, and a carried record still untouched
since the take is replaced by the head's. The workspace's AGENTS.md and
CLAUDE.md now ride the open wave, so a moved chat's first turn has its rules.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n every door

After-work now runs behind the open, so its failures and notices have to reach
the person by another road. The app's take passed no notice sink, so a failed
vault pull, index rebuild or task-copy restore after an app move was dropped;
each line is now filed under its own chat on the app's notice path as well as
the terminal's. The look at this computer that finishes with the files raises
the setup card again with what it lacks and what is uncommitted. A session
opened before its workspace landed re-reads its page once the files arrive, so
the project's AGENTS.md and CLAUDE.md reach the next model call.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The gate's owner check read an unsupported signal as a dead owner, so on
Windows a live move's marker was deleted and tools ran on half-arrived files;
each system now has its own probe, and an owner the probe cannot read counts as
alive. A failed arrival now keeps refusing tools, seals and captures in every
process with its reason instead of giving way after two minutes, even after its
window closes; opening or taking the chat again starts a fresh fetch that
replaces it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ction files

The open wave put AGENTS.md and CLAUDE.md into the chat's work folder by
asking the record it had just swapped in where the chat works. That record is
the head's, and a head the other computer sealed as a copy says "owned", so a
move back into this computer's own folder left a copy of its instruction files
in codeaf's copy folder for the chat. Where the chat works is now read once,
before the take, from this computer's own record.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AbirAbbas
AbirAbbas marked this pull request as ready for review November 17, 2026 19:49
@AbirAbbas
AbirAbbas merged commit 785ffe6 into dev Nov 17, 2026
1 check passed
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