fix(web): unblock new drafts during environment reconnect#11646

closed6
main
GitHub fork: fix/10548-new-local-reconnecting
openedSep 13, 2026byCcoygeek
View on GitHubTwo-way sync enabledPR last imported 2d ago

Fixes https://github.com/pingdotgg/t3code/issues/10548

Opening a web or desktop draft could wait indefinitely for optional t3.json defaults while its environment reconnected. Only read the file when the target environment is connected, and interrupt a read after three seconds if the connection drops or the query stays pending. The existing settings resolver supplies the fallback; draft navigation guards and invested content are preserved.

Continues @coygeek’s work in #11646, fixing #10548. Main was merged without rewriting contributor history. #20183 handles startup route selection separately.

Verification at 2237c7381b:

  • Cut 16 PR-added test cases to six in existing hook and file-query suites; removed the one-off helper test file. Preserved all main coverage. The first merged harness had duplicate registry mocks (19 passing / 34 failing); the rewritten harness uses the real settings resolver. Final: 43 passing across three files. Replacing only production files with main produces four expected regressions and 39 passing controls.
  • Web typecheck, targeted lint, formatting and diff checks pass.
  • One independent full-diff review round: Claude Opus 5.5 and GPT-6-Sol found no blockers. Retained the original minimal production approach after tracing cancellation, shared cache behavior, settings precedence and web/desktop entry points.
  • Actual isolated Linux Chromium app, real server interruption: stopped only this worktree’s server process, confirmed the environment was reconnecting, and clicked New thread. Integrated main stayed on the old conversation after five seconds; this head opened a draft while still reconnecting. Empty drafts were reused; an invested draft kept its prompt and context while a separate draft opened.
  • The real browser helper returned null after 3,001 ms while its connection query remained pending. After restarting the server and reconnecting, a temporary actual t3.json worktree default selected New worktree. The fixture file was restored afterward. No provider turn was started.

Same isolated data and 1280 × 800 viewport, integrated main 62d98096ca versus this head:

Recording: opening the draft while reconnecting

Tradeoff: if a worktree default exists only in t3.json, an unavailable environment or expired read uses the existing fallback, usually Current checkout. Explicit project/environment settings retain priority. The mode is visible and editable; late file results do not revise a created draft. Connected but slow reads may still delay opening up to three seconds of active browser time, and suspension can pause the timer.

Not verified here: macOS, Windows, Electron desktop shell, iOS, Android, relay/tunnel connections, or an actual transport loss timed precisely between the connected check and the file-read response. The pending-query interruption is covered by a real registry test and the browser helper; mobile has its own flow and is outside this PR’s scope.

CI follow-up: all executed build, typecheck, lint and test jobs passed on this head. Macroscope Correctness passed, but Macroscope Approvability is neutral with Needs Human Approval: the fallback behavior requires a maintainer eligibility/product decision. This PR remains unmerged and is awaiting that human approval. CodeRabbit reported its review rate limit; its success status is not a new code review.

Implementation: GPT-6.1-Sol in the Codex harness through T3 Code. Tests: GPT-6-Astra; independent reviews: Claude Opus 5.5 and GPT-6-Sol, delegated through T3 Code.

Checks

22 successful · 14 skipped · 1 neutral
All checks passed
2237c73
Synced from GitHub

Approvability

Verdict: Needs Human Approval

Macroscope's review found this PR requires human approval — This targeted reconnect fix is well-covered and keeps connected environments unchanged, but it changes the effective new-thread default when a t3.json read is unavailable or times out. Because that product-default behavior requires explicit human review, it should not be auto-approved.

You can add or adjust custom eligibility rules. Learn more.

Synced from GitHub

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Path: .coderabbit.config.ts
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3ebd3247-390b-498d-b5bf-43b644c5b1de
📥 Commits

Reviewing files that changed from the base of the PR and between b4aff7e909fee37181f0d2253ee0ca89d885ee90 and 0eb6846776ce5702a5789fb279c0c045461f07ad.

📒 Files selected for processing (4)
  • apps/web/src/hooks/useHandleNewThread.test.ts
  • apps/web/src/hooks/useHandleNewThread.ts
  • apps/web/src/lib/t3ProjectFileDefaults.test.ts
  • apps/web/src/lib/t3ProjectFileDefaults.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

The new-thread flow checks environment connectivity before it reads project-file defaults. The project-file query now has a three-second timeout. Tests cover connection phases, draft-context preservation, timeout fallback, and successful default parsing.

Changes: New thread connection handling

Layer / File(s)Summary
Connection-phase gate
apps/web/src/hooks/useHandleNewThread.ts, apps/web/src/hooks/useHandleNewThread.test.ts
resolveDefaultEnvMode reads project-file defaults only when the project has no configured mode and its environment is connected. Tests cover non-connected phases, connected lookup, and preserving draft context when user content exists.
Project-file query timeout
apps/web/src/lib/t3ProjectFileDefaults.ts, apps/web/src/lib/t3ProjectFileDefaults.test.ts
The project-file query uses a three-second timeout. Tests verify timeout fallback and successful parsing of defaultThreadEnvMode.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: juliusmarminge

Merge Risk: ⚪ Minimal · up to 0eb68

New-thread creation no longer waits indefinitely for project-file defaults when the remote environment is unavailable. No actionable merge-blocking risk remains.

Security architecture risk: 🔵 Low · up to 0eb68

The change bounds an optional defaults read while preserving the selected environment and configured permissions. No introduced security issue was established. Interruption of the waiting operation is supported, but cancellation of the underlying remote read remains unconfirmed.

Retained concerns No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The reviewed change affects optional default selection and subsequent draft state for the selected project. It does not broaden the reader's environment, workspace, or filename inputs: the connectivity gate adds a precondition to the existing read rather than introducing a broader read target.

Trust Boundaries and Controls

  • observed — Project-file contents pass through the existing schema decoder, which treats invalid contents as absent. File-backed settings fill only unset higher-priority settings. The reader rejects truncated data and preserves the existing environment-and-workspace-scoped optimistic-data overlay.

Resilience and Maintainability Implications

  • observed — The timeout signal reaches Effect.runPromiseExit around a scoped atom mount and query wait. The added regression uses the real interruptible wait with a deliberately pending atom. This supports caller settlement and scoped-wait cleanup, but does not establish cancellation of an already-started remote transport request.
Pre-merge checks: Passed 4
Check nameStatusExplanation
Linked Issues checkPassedThe changes satisfy the coding requirements in [#10548]. useNewThreadHandler skips the optional t3.json read unless the target environment is connected. readT3ProjectFile applies a three-second …
Out of Scope Changes checkPassedThe changes stay within [#10548]. The implementation and tests modify the web new-thread default resolution path and its optional project-file read. The summary shows no unrelated changes to mobile, p…
Title checkPassedThe title clearly and concisely identifies the main fix: allowing new drafts to open during environment reconnects.
Description checkPassedThe description clearly explains the problem, implementation, scope, tradeoffs, verification results, limitations, linked issue, and approval status. It does not use the template headings and does not…
Full details: Linked Issues check

Explanation

The changes satisfy the coding requirements in [#10548]. useNewThreadHandler skips the optional t3.json read unless the target environment is connected. readT3ProjectFile applies a three-second timeout, which prevents an in-flight read from blocking draft creation indefinitely. The handler tests cover reconnecting, unavailable, offline, error, and connected environments. The tests also cover timeout settlement, connected defaults, local creation, and preservation of draft content.

Full details: Out of Scope Changes check

Explanation

The changes stay within [#10548]. The implementation and tests modify the web new-thread default resolution path and its optional project-file read. The summary shows no unrelated changes to mobile, providers, wire contracts, or automatic environment retargeting.

Full details: Description check

Explanation

The description clearly explains the problem, implementation, scope, tradeoffs, verification results, limitations, linked issue, and approval status. It does not use the template headings and does not include an explicit maintainer approval comment, but it provides sufficient equivalent information and identifies that human approval is still pending.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

Synced from GitHub

Bugbot is paused — on-demand spend limit reached

Bugbot uses usage-based billing for this team and has hit its on-demand spend limit.

A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue.

Added 3 commits

  • docs(web): document reconnect default resolution26b681c
  • fix(web): unblock new drafts during environment reconnectcb8e5cb
  • test(web): cover reconnect guard under the project settings resolver0eb6846

Taking over this one as maintainer. This remains scoped to reconnecting environments and a bounded optional t3.json read; the startup route selection fix in #20183 is separate. I will preserve your commits and credit, resolve current-main conflicts, and push here without merging.

Added 3 commits

  • Merge remote-tracking branch 'origin/main' into fix/10548-new-local-reconnecting2b640ad
  • test(web): focus reconnecting draft coverage4515169
  • refactor(web): clarify optional project defaults deadline2237c73

Note

🤖 Claude Opus 5.5 responding on behalf of Theo

Superseded by #23967, which makes the same change in useHandleNewThread.ts: read the project file only when the environment is connected. The extra 3s abort for a drop during the read did not land; open a small follow-up if you still see that case.