feat: move chats to the cloud per agent, sync chat history, and search sessions

Closed
HA
13d ago
+26121-32

Move a Claude chat between a laptop and a cloud workspace, in either direction, keeping the same chat id, its history (Postgres), the agent's own session files (R2) and the uncommitted work (a snapshot branch). Also: continuous chat sync from cloud boxes, and search over your chats in the command palette and the CLI. Supersedes #8780.

Page with the design, screenshots and recordings: https://app.superset.sh/page/teleport-moving-a-chat-between-laptop-and-cloud-0exajn

How a move works

Every attempt is a chat_moves row, pending → copying → restoring → ready, or failed with the reason. The control plane owns it; the sandbox knows nothing about moves.

  1. Leaving host (asked by the desktop): teleport.prepare checks chat sync and that the push URL is GitHub, stops the agent if it is busy, pushes the worktree to superset/teleport-…, syncs the chat to Postgres and uploads Claude's session bundle. It then keeps pushing that chat until it has moved, so a turn taken there later is seen.
  2. Into a cloud workspace: cloudWorkspace.create({ move: { chatSessionId } }) records the move; once the box answers, a queued job (/api/chat-moves/run) calls the box's teleport.importChat with the history and a presigned bundle link, switches the chat's home in one transaction (ready), calls teleport.continueChat, and stops the old copy with teleport.markMoved.
  3. To a computer: the control plane cannot reach a laptop (it is on the relay only when "expose via relay" is on), so the desktop there runs the copy: chatMove.start → claim → events (paged) → its own host's importChat → complete → continueChat. The control plane still alone decides ready and stops the old copy.
  4. The chat switches before its agent starts, so the agent never runs in two places; a chat whose agent did not start resumes when its pane opens. A failure leaves the chat where it was; the destination pane shows the reason and Try again. A move that stops changing state for 6 minutes shows as failed. A chat that took a new turn after the move began is refused ("move it again").

What changes

Database: chat_items, chat_turns (latest state per item and turn; first_seq keeps display order), chat_transcripts (one row per session bundle, bytes in R2 as a files row), chat_moves, and sync columns on chat_sessions. One migration, 0188_chat_storage, with two hand-written parts around the generated statements: chat_search_text (splits paths and camelCase for the generated search column) and a guarded lakebase_bm25 index that plain Postgres skips.

API

  • chatHistory: push (folds a host's journal events; newest version wins; session status and title follow only a newer session event), createTranscriptUpload / completeTranscriptUpload (plain session ids only), search (owner only, one result per conversation, BM25 where available, full text otherwise).
  • chatMove: latest, start, retry, claim, events, complete, fail. A chat only moves into a cloud workspace its owner started; boxes cannot start or run moves.
  • cloudWorkspace.create takes move; provisioning queues the move once the box answers and fails it if the workspace never starts or is deleted.
  • A box pushing a chat that is still moving to it gets a retryable PRECONDITION_FAILED; a box whose chat moved away gets CONFLICT and stops syncing it.
  • Box allowlist: chatHistory.push, createTranscriptUpload, completeTranscriptUpload.
  • chat.deleteSession reaps the chat's bundles.

chat-runtime: importSession writes a chat from another host under a new epoch, each event at its first seq; continueSession resumes an existing chat quietly under the same id; onAppend reports each append.

host-service: chat sync (boxes push continuously with backoff; batches the server rejects are split and then skipped; unsent chats catch up at start), the Claude TeleportProvider (packs <id>.jsonl and <id>/, rewrites cwd and paths, refuses bundles with links, .. entries or unexpected ids, caps the unpacked size), and the teleport router (prepare, importChat, continueChat, markMoved, fetchBranch).

Desktop: Move to cloud (environment and machine size pickers, checked against the chat's repository before anything is stopped), Move to this computer from a cloud workspace, the destination pane's progress and retry, and a Chats section in Cmd+Shift+K. The shared pickers and choice helpers move to routes/_authenticated/. Strings are translated in all 17 locales.

CLI: superset sessions search <query>.

Tested

  • Unit suites: trpc 858, chat-runtime 457, cli 480, db 23, desktop 2626 (affected areas), host-service move and sync tests 31. Typecheck (42/42), lint and i18n pass.
  • chat-history.integration.ts on real Postgres, 16 pass: both move paths, refusals (a teammate's cloud workspace, a box, an unknown host, a second move), a failed move leaving the chat in place, retry, a chat that went on, stale moves, search across long chats, stale session metadata, CONFLICT for an old box.
  • End to end on a local dev stack driven over CDP, with a real Claude and a stand-in box (this branch's host-service.js in sandbox mode, a local bare repository for GitHub and an S3 mock for R2): laptop → cloud reached ready in 3.5 s and cloud → laptop in 2.2 s; Claude recalled a codeword given before the move on each side, the old copy got its "moved" notice, and Postgres picked up the box's new epoch.

Not covered yet

  • A real Vercel sandbox, and the box side needs a sandbox bundle release.
  • BM25 ranking: needs a Neon project with Lakebase Search; only the full-text path ran.
  • Codex and pi have no teleport provider; their chats don't show the move buttons.
  • Known gaps: no prompt lock on the source during a move (a turn taken there is detected and the move refused, not prevented); the move uses the default agent account rather than the one the chat started under; Windows paths in Claude session files are not rewritten.