Repository navigation
feat(clients): balance new threads across connected environments - #105
Conversation
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8c36d86bd2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6f64881ccd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 37f893f883
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| [activeProviderStatus, usageSelectedModel, placementModelOptions], | ||
| ); | ||
| const draftPlacement = useLoadBalancedDraft({ | ||
| draftId: isServerThread ? null : draftId, |
There was a problem hiding this comment.
Route “Start in a new chat” through placement
When a user opens the send menu on an existing server thread and chooses “Start in a new chat,” isServerThread makes this hook receive a null draft ID, so Auto placement never runs; the target === "new-chat" path later creates and launches the new thread directly on the current environment. Thus even a plain, unpinned prompt ignores the enabled balancing setting through this user-facing new-thread entry point.
AGENTS.md reference: AGENTS.md:L71-L73
Useful? React with 👍 / 👎.
| } | ||
| var canAutomaticallyPlace: Bool { | ||
| connectionState == .live && prompt.isEmpty && initialImageUploads.isEmpty && attachments.drafts.isEmpty | ||
| && workspaceMode == "local" && branch.isEmpty && launchAttempt == nil |
There was a problem hiding this comment.
Release unprepared launch attempts before enabling Auto
If assets.persistChatAttachments fails after launchAttempt is created but before its attachments field is assigned, clearing the prompt and failed attachment still leaves launchAttempt != nil, permanently disabling the Auto menu. The current code provides fresh evidence beyond the earlier historical-pin report: it creates the attempt before the preparation RPC, while hasPendingLaunch only treats an attempt with prepared attachments as pending and manual transfer already permits moving an unprepared attempt. Clear or otherwise permit this pre-dispatch attempt when its binding content is removed.
AGENTS.md reference: AGENTS.md:L77-L77
Useful? React with 👍 / 👎.
What Changed
New threads currently require a manual machine choice even when the same project is connected to several environments. This adds opt-in Auto placement across those environments on web, Electron desktop, and native iOS.
Auto selects an authenticated, compatible provider on an active binding to the same company project, using available CPU, memory, and per-client machine preferences. An on-demand host RPC shares a five-second cache and adds no idle polling. Settings default off, and every automatic choice shows its destination and supports manual recovery.
Explicit account, workspace, branch, attachment, and dispatched-draft choices pin the environment. Inherited custom accounts stay pinned on web/desktop; persisted Auto account provenance preserves later rechecks. The current checkout is retained on its machine, and ambiguous remote checkouts require manual selection. Stale asynchronous results cannot move changed drafts. Native probes read snapshots directly without issue subscriptions and require effective orchestration:operate permission. Read-only direct connections cannot participate in Auto or prepare a new-thread launch. Empty, unbound native drafts can explicitly return to Auto, with an account-change explanation and preserved model/options/access mode. Native launch validation refreshes eligibility and closes temporary probe connections; uncertain launch retries retain their destination and command. Existing threads keep their current routing.
Why
Adapted from t3code #9895, with Pathway's cloud project bindings, environment-local provider IDs, durable draft state, and native creation flow. This PR covers environment placement; subscription pooling and account failover remain separate work. Research and source references.
UI Changes
Before/after evidence uses the actual selector and settings components in an isolated harness with synthetic machines. The harness supplies the selected destination; these images do not establish full-app routing or native UI correctness.
Phone-width screenshot · Interaction recording
Validation
Latest launch-safety follow-up: 147 focused tests passed across four command/web files; client-runtime and web typechecks and targeted lint passed. Dispatch notification runs only after attachment persistence; preparation failures remain movable, and uncertain launches remain pinned even if Auto was off.
325 tests passed across 12 focused files: sampler, authorization, contracts, selector, draft/hook/picker behavior, settings, and desktop persistence.
Scoped typechecks passed for contracts, client-runtime, server, web, and desktop. Targeted lint passed with four existing unused-variable warnings.
Real macOS sampler returned a 143-byte snapshot and reused its cached sample.
Browser component checks passed for toggle reversal, weights, persistence, Auto selection, and 390px layout; no page errors.
Changed Swift files parse. A Swift 6 harness compiled the actual selector/resolver/environment client with surrounding type stubs and passed 11 shared fixtures, three zero-subscription probe cleanup cases, two checkout-selection cases, and five scope/read-only probe cases.
Full app testing, Xcode build, and native test-suite execution remain unrun. The maintainer will perform these checks; this Mac lacks completed Xcode license setup and the documented Clerk development configuration. Native tests and a manual verification checklist are included.
Checklist
Model: GPT-6. Harness: Codex.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.