Skip to content

feat(clients): balance new threads across connected environments - #105

Merged
coreybain merged 4 commits into
mainfrom
research-load-balancing-pr
Sep 8, 2026
Merged

coreybain merged 4 commits into
mainfrom
research-load-balancing-pr

Conversation

@coreybain

@coreybain coreybain commented Sep 8, 2026 •

Copy link
Copy Markdown
Collaborator

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.

Before After
Manual selector Auto selector and settings

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

  • One concern: new-thread environment placement across supported clients (53 files; not a small patch)
  • Explained what changed and why
  • Included before/after component screenshots
  • Included an interaction recording
  • Rebased onto latest main before opening

Model: GPT-6. Harness: Codex.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-08T01:57:27.181261Z 37f893f New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XXL labels Sep 8, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread apps/pathway-ios/Pathway/shared/datalayer/PathwayIssueEnvironmentClient.swift Outdated
Comment thread apps/web/src/hooks/useLoadBalancedDraft.ts Outdated
Comment thread apps/web/src/lib/draftPlacement.ts

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread apps/web/src/components/ChatView.tsx Outdated

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@coreybain
coreybain merged commit c59e371 into main Sep 8, 2026
16 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant