Problem#
Worktree-backed threads are persisted before Git work starts. That order is intentional because worktree creation can be slow. If Git then fails, the server soft-deletes the new thread, but the web draft keeps its spent ThreadId. Pressing Enter again sends thread.create with the same ID and hits the global uniqueness invariant.
This is an alternative to #7608. Deleted thread IDs remain single-use instead of being resurrected.
Fix#
- Keep thread.create before worktree preparation.
- Mark the existing dispatch error only after the compensating thread.delete completes.
- Keep the same visible DraftId and restored composer content, but rotate it to a fresh ThreadId after that confirmed deletion.
- Do not rotate after interrupts, connection failures, old-server responses, or failed cleanup where server state is uncertain.
- Preserve branch, environment, start-from-origin, runtime, and interaction choices across the retry.
The optional error field is wire-compatible. Old clients ignore it, and new clients connected to old servers keep the current conservative behavior. Web and desktop use the new recovery path. Normal online mobile submissions already mint a fresh ThreadId per explicit submit; queued mobile retries remain unchanged.
Verification#
- 251 focused tests passed across server bootstrap behavior, the orchestration contract, the client error classifier, and the web draft store.
- Targeted formatting and lint passed.
- Server, contracts, and client-runtime typechecks passed. The web package typecheck is currently blocked by two unrelated conditionalUI fixture errors in electronPasskeys.test.ts.
Generated with GPT-5.6 Sol in the Codex harness through T3 Code.
Note
[Cursor Bugbot](https://cursor.com/bugbot) is generating a summary for commit 3381651e0563dbb9d964f7078250b2bbe261be19. Configure [here](https://www.cursor.com/dashboard/bugbot).
Note
Retry failed thread bootstraps with a fresh thread ID on web client#
- Extends
OrchestrationDispatchCommandError with an optional bootstrapThreadDisposition: "deleted" field. The server sets this when a failed bootstrap thread is successfully deleted during cleanup.
- The web client detects this disposition via a new
wasBootstrapThreadDeleted guard. It rotates the draft's logical project thread ID via setLogicalProjectDraftThreadId and preserves the draft content for a fresh retry.
- Risk:
dispatchBootstrapTurnStart in ws.ts wraps cleanup in Effect.uninterruptible and only sets the disposition field on successful deletion. If cleanup fails, it returns the original dispatch error without the field.
Macroscope summarized 3381651.
Summary by CodeRabbit#
Bug Fixes
- Improved recovery when sending from a draft fails because its temporary thread was deleted.
- Draft sessions now automatically reset and retry with a fresh thread identifier while preserving their settings.
- Cleanup failures no longer hide the original worktree error.
Tests
- Added coverage for successful cleanup, cleanup failures, error reporting, and draft retry behavior.
Documentation
- Exposed additional error details indicating when a temporary thread was deleted.
📝 Walkthrough
Walkthrough#
Bootstrap failure cleanup now reports deleted bootstrap threads and preserves the original error when cleanup fails. The client detects deleted threads and resets the matching draft session for retry.
Changes#
Bootstrap thread recovery
packages/contracts/src/orchestration.ts,packages/contracts/src/orchestration.test.ts,packages/client-runtime/src/errors/orchestration.ts,packages/client-runtime/src/errors/orchestration.test.ts,packages/client-runtime/src/errors/index.tsOrchestrationDispatchCommandErroraccepts an optional"deleted"disposition. The client runtime exports and testswasBootstrapThreadDeleted.apps/server/src/ws.ts,apps/server/src/server.test.ts"deleted"after successful deletion.apps/web/src/components/ChatView.tsx,apps/web/src/composerDraftStore.test.tsEstimated code review effort: 3 (Moderate) | ~20 minutes
Merge Risk: 🔵 Low · up to
33816The PR adds fresh-ID recovery only after confirmed cleanup and preserves conservative behavior otherwise. One focused server test does not verify that cleanup dispatches thread.delete, so a regression could pass the test; the change is mergeable with that minor follow-up.
Sequence Diagram(s)#
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share