fix: stop replayed bootstrap turns from re-running git worktree add#51
Merged
Merged
Conversation
Every worktree-backed thread creation surfaced a "Queued message was rejected: Git command failed in GitVcsDriver.createWorktree" toast. The composer persists each outgoing turn to the outbox before sending, and the outbox drain effect fired while the original bootstrap send was still in flight (worktree creation keeps it pending for seconds), so the same turn was delivered twice. The replay re-ran `git worktree add -b` and failed on the branch the first delivery had just created. Client: track in-flight sends and skip them in the outbox drain. Server: when a bootstrap replay reaches prepareWorktree for a thread that already has a recorded worktree, reuse it instead of re-creating it, and skip the duplicate setup-script run. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Problem
Every worktree-backed thread creation showed a "Queued message was rejected: Git command failed in GitVcsDriver.createWorktree ... git worktree add failed" toast, even though the worktree was created successfully.
Server logs (redacted stderr is kept server-side) show the real error:
Reflog timeline for one occurrence: branch created 16:00:24 (first bootstrap), duplicate
worktree addfailed 16:00:26, rename 16:00:28 — the same bootstrap turn was delivered twice, ~2s apart.Root cause
ChatViewpersists every outgoing turn to the IndexedDB outbox before callingstartThreadTurn, and removes it only after the call settles. A bootstrap turn stays in flight for several seconds (worktree creation, fetch, setup), and in that window the thread projection arrives with no running session — exactly the condition under which the outbox drain effect fires. The drain found the still-pending entry and re-sent the full turn, bootstrap included. On the server,thread.creatededuped ("already exists" → resume remaining bootstrap), butprepareWorktreere-rangit worktree add -bagainst the branch the first delivery had just created, and the replay was rejected with the toast.Fix
ChatView.tsx): track in-flightstartThreadTurnmessage ids in a module-level set; the outbox drain skips turns whose original send has not settled.ws.ts): when a replayed bootstrap reachesprepareWorktreeand the thread already has a recorded worktree, reuse that worktree (refresh its git status) instead of re-creating it, and skip the duplicate setup-script launch. Fresh bootstraps are unaffected.Verification
reuses the existing worktree when a replayed bootstrap already prepared it(replay withprepareWorktree→createWorktreenot called, setup not re-run, turn dispatched).vp test run src/server.test.ts -t bootstrap→ 11 passed;-t worktree→ 3 passed.tsgo --noEmitclean forapps/serverandapps/web.git command failedlog entries and no rejection toast.🤖 Generated with Claude Code