PR #9729 review: workspace move state fixes
Summary
The PR fixes seven ways a workspace move ("teleport") can stall until the 6-minute stale sweep, or leave chats half-moved. In the MoveBook state machine, abandon now ends moves that already have a destination, begin refuses while something is arriving in the workspace, and retry works only from the newest move. On the control plane, a lost claim answer now fails the move, and one failed publish in attach no longer strands the other chats. On the host and desktop, open chats behind closed ones still move, and chats are released when a move ends mid-prepare. There are no tRPC schema or protocol changes.
Verdict
Minor issuesThe fixes are sound and scoped. All CI checks and the changed suites pass. One change turns a transient claim error into a permanent failure, and the new retry and cap rules are a little stricter than the intent.
Findings
mediumpackages/trpc/src/router/chat-move/utils/runChatMove/runChatMove.ts:50
What is wrong: every claim error now fails the move, including errors where the claim never reached the MoveBook. callRealtime throws "Moves are unreachable" when fetch fails (a connection error, or the 10 s timeout) and "Moves refused the call (5xx)" for a 5xx. Before this PR, the route threw, QStash redelivered, and the next claim succeeded. Now, if the follow-up fail call gets through, the chat move is failed for good, and the pane shows "Moves are unreachable". Only the timeout case can really be a lost answer.
Fix: let the redelivery take back its own claim instead of failing on doubt. For example, store the QStash message id (Upstash-Message-Id) as a claim token on claim, and let a claim with the same token return the copying move (this overlaps follow-up #7). A smaller step: fail only on the timeout/abort error, and rethrow without failing on a connection error or a 5xx.
lowpackages/host-service/src/trpc/router/teleport/teleport.ts:193
What is wrong: the 50-chat cap counts open sessions, not movable ones. Open chats that are unsupported_agent or not_started use up slots. Example: 10 open chats with an unsupported harness, then 50 supported ones. Only 40 move, and 10 are reported as too_many, but attach would have taken all 50.
Fix: check movable.length >= MAX_MOVED_CHATS just before movable.push, and do not use index.
lowpackages/shared/src/move-book/MoveBook.ts:384-391
What is wrong: a later attempt that never got a destination still blocks retry of an earlier move's failed chats. Example: a move to the cloud ends partial. The person tries to move the source again, the agent is busy, and that attempt is abandoned before attach. The per-chat retry in the cloud pane is then refused with "This workspace moved again after this move". Nothing was superseded, because the chat is still in the source. Probe output below. The PR's own test asserts this, so it may be intended. But the stated aim (#6, do not send a chat to an old destination) only needs later moves that have a destination.
Fix: add AND later.to_workspace_id IS NOT NULL to the later query. With that change, the newer in-flight check above it still covers a later move that has not been attached yet.
nitpackages/shared/src/move-book/MoveBook.ts:293-296
What is wrong: the new begin refusal also fires for a workspace move with no chats that is waiting for its cloud destination to finish provisioning (to_workspace_id set, status pending). In that case the message "Chats are still moving into this workspace" is wrong, because no chats are moving.
Fix: use wording that covers both cases, for example "This workspace is still being moved into. Try again when that finishes.", or use a different message for each branch of the UNION.
nitTest coverage: workspace-move.ts:51, teleport.ts:186, desktop hooks
Three changes have no regression test: the per-chat startChatMove catch in attach, the closed-first filter and too_many cap in prepareWorkspace, and the released-once logic in the aborted branch of the desktop hooks. A small test for the prepareWorkspace session selection would catch the cap issue above. Also, the PR body says attach uses "the same pattern" as queueChatMovesTo. It does not: queueChatMovesTo logs the error and leaves the move pending, but attach now fails the move. Failing it is the better choice; only the description is off.
Evidence
Surfaces changed: the MoveBook (Durable Object logic in packages/shared), the API (packages/trpc), the host-service (teleport.prepareWorkspace) and the desktop move hooks. None of them changes visible UI. The desktop change is on an error path (a move ending while prepare runs).
MoveBook probes (a scratch test against the PR's MoveBook with in-memory SQLite, deleted afterwards):
retry after a later attempt that was abandoned before attach
RETRY {"ok":false,"code":"precondition","message":"This workspace moved again after this move. Move it again instead."}
abandon after attach, with chat a already ready
PARENT {..."toWorkspaceId":"cloud","status":"partial","error":null,"finishedAt":1000000}
B failed <- abandon fails only the in-flight chat; the ready one stays ready
begin out of a cloud workspace whose move (0 chats) waits for provisioning
BEGIN {"ok":false,"code":"conflict","message":"Chats are still moving into this workspace"}
The first and third results support the findings above. The second shows that abandon is safe after part of a move finished: the ready chat stays ready, and the parent settles as partial.
Not run: a live workspace move on the desktop or in the cloud. The server checks the workspace-moves PostHog flag (assertMovesEnabled, which fails closed). A move also pushes a superset/teleport-* branch to GitHub, and a cloud destination boots a billed sandbox. Changing a shared flag or starting billed resources is outside a review run, so I did not drive the move UI. The PR author reports the same limit. The behaviour of the desktop hooks was checked by reading the code against keepMoveAlive: a heartbeat-ended move rejects at once, the outer catch releases empty lists, and the aborted branch then releases the chats and terminals once. A user abort runs the aborted branch first and then the catch with empty lists, so terminals are no longer released twice.
Questions for the author
- Is it intended that an attempt abandoned before
attachblocks retry of the previous move's chats? The testretries a chat only from the newest move of its workspaceasserts this. - For the claim change: did you consider a claim token tied to the QStash message id, so that a redelivery takes back its own
copyingmove instead of failing a move whose claim may never have landed? - Should unsupported and not-started open chats count toward the 50-chat cap?
Test / CI notes
| What | Result |
|---|---|
GitHub CI at d0e8c269 (Lint, Typecheck, Test, Sherif, Page storage integration, deploy previews) | all pass (CodeRabbit pending) |
bun test src/move-book in packages/shared | 13 pass, 0 fail |
bun test in packages/trpc | 928 pass, 0 fail |
bun test src/trpc/router/teleport in packages/host-service | 3 pass (no test covers prepareWorkspace) |
bun run typecheck: shared, trpc, host-service, desktop | clean |
biome check on the 10 changed files | clean |
chat-history.integration.ts | not run here (needs Postgres and the Neon proxy); the author reports 36 pass and 1 fail, which also fails on main |