refactor(web): ChatView's draft machine routing lives in useDraftEnvironmentRouting#22728

merged1
refactor/chatview-activity-banners
refactor/chatview-draft-environment-routing
opened3d agobyJJulius Marminge
View on GitHubTwo-way sync enabledPR last imported 3d ago

Automatic load balancing and the manual machine switch both decide one thing: which machine an unsent draft runs on. That state, its effect, and the in-flight switch refs took about 180 lines of ChatView.

chat/useDraftEnvironmentRouting.ts now holds them. It also owns the useLoadBalancedEnvironment, useProjects and useScratchProject reads that only this flow used. ChatView gets back the auto label, the switch and auto callbacks, the busy flag, and the pending-switch reader that onSend checks.

This layer moves code only and doesn't change render boundaries.

previous layerthis layer
ChatView.tsx lines7,5337,372

Tests: vp test run src/reactCompilerCoverage.test.ts for ChatView and every new file (0 bailouts), tsc-rs --noEmit for apps/web, and oxlint on the changed files.

🤖 Generated with Claude Code

Checks

All checks passed

Added 1 commit

  • refactor(web): ChatView's draft machine routing lives in useDraftEnvironmentRouting7483af8
Synced from GitHub

Thread transfer impact

⚠️ The latest CI run did not produce a thread transfer result for 7483af8.

This comment will update automatically after the next completed run.

Synced from GitHub

Approvability

Verdict: Approved at 7483af8

Macroscope's review found this PR approvable — This PR extracts ChatView’s existing automatic and manual draft-environment routing into a dedicated hook without changing the routing logic or rendered integration points. The diff is localized to that refactor and does not alter product defaults or introduce sensitive configuration changes.

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: Team
  • Run ID: 4b4f545e-d962-4da9-9184-694208686d63
📥 Commits

Reviewing files that changed from the base of the PR and between 08ca07f2b1229c4de2131e514c73b38577e9f3eb and 7483af891cd7a34bc9f3c661a49d3af59b42574b.

📒 Files selected for processing: 2
  • apps/web/src/components/ChatView.tsx
  • apps/web/src/components/chat/useDraftEnvironmentRouting.ts

Limit details: You’ve used all 10 included reviews currently available.

📝 Walkthrough

ChatView now uses useDraftEnvironmentRouting for draft environment routing. The hook handles automatic environment selection, load-balancing status, and guarded manual switching.

Changes: Draft environment routing

Layer / File(s)Summary
Hook contract and ChatView integration
apps/web/src/components/chat/useDraftEnvironmentRouting.ts, apps/web/src/components/ChatView.tsx
The new hook accepts draft, project, environment, provider, and send-state inputs. ChatView replaces its inline routing logic with the hook and removes unused imports and values.
Automatic environment selection
apps/web/src/components/chat/useDraftEnvironmentRouting.ts
Automatic routing filters environments by connection, weight, thread-context compatibility, and provider status. Attachments prevent automatic routing and trigger a warning. The hook updates the draft and exposes balancing status.
Guarded manual environment switching
apps/web/src/components/chat/useDraftEnvironmentRouting.ts
Manual switching applies existing projects or opens a scratch project. Draft and project scope, send state, and superseding requests guard retargeting and busy-state cleanup.

Priority: ⬇️ Low

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

Change: Refactor

Suggested reviewers: t3dotgg, maria-rcks

Merge Risk: ⚪ Minimal · up to 7483a

This refactor moves draft machine routing into its own hook without a stated behavior change. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check nameStatusExplanationResolution
Description checkWarningThe description explains the refactor and lists specific verification commands and results. It does not provide the required Scope and approval information, and it does not clearly state the problem, …Add the Problem section with the affected behavior and context. Add the Scope and approval section with the triaged issue or explicit maintainer approval, or explain why an exemption applies. Add before/after screenshots if this change affe…
Passed Passed checks: 3 passed
Check nameStatusExplanation
Title checkPassedThe title clearly and concisely identifies the main refactor: moving ChatView draft machine routing into useDraftEnvironmentRouting.
Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the refactor and lists specific verification commands and results. It does not provide the required Scope and approval information, and it does not clearly state the problem, expected behavior, or UI verification evidence.

Resolution

Add the Problem section with the affected behavior and context. Add the Scope and approval section with the triaged issue or explicit maintainer approval, or explain why an exemption applies. Add before/after screenshots if this change affects the UI, or state why screenshots are not applicable.

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

Note

This review was completed with usage-based billing: files reviewed beyond your plan's included limits are billed at $0.25/file. View usage-based billing.

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