Skip to content

Route a thread's first turn to a provider/model by task tier - #1592

Merged
currentbits merged 4 commits into
mainfrom
coder/model-routing-pick-provider-model-per-ta-16ce1e
Oct 11, 2026
Merged

currentbits merged 4 commits into
mainfrom
coder/model-routing-pick-provider-model-per-ta-16ce1e

Conversation

@currentbits

Copy link
Copy Markdown
Owner

What

A thread can now hold a pending route that its first turn uses up: auto, or one of the tiers fast / balanced / strong. The route chooses the thread's provider, model and reasoning effort from an agent profile before anything reads thread.provider. It never changes the permission mode. A tier is about cost and capability, not about how much the agent may do unattended.

  • electron/routing.js (new):
    • classifyPrompt: auto picks a tier using keywords plus prompt length. It makes no model call.
      • strong: prompts that mention things like refactor, debug, security or performance, or are ≥1500 chars.
      • fast: short chores like typo, rename, lint or bump, ≤400 chars.
      • balanced: everything else.
    • applyRoute: maps the tier to an agent profile through the project's new modelRouting setting and applies it.
      • It never throws. If the tier has no profile, the profile's CLI isn't installed, or applying it fails, the thread keeps its current model.
    • Every outcome writes a transcript event saying what was picked and why, or why nothing changed.
  • runner.js: calls applyRoute before the first turn runs.
  • services-threads.js:
    • New setRoute service. It refuses to route a thread that already has a session.
    • createThread uses route: "auto" when the project has opted into Auto. It skips this for automations, memory consolidation and ask threads, threads with an explicit provider, and threads that opt out of project defaults.

Entry points

  • Composer: the model picker shows an Auto row before the first turn. Picking a model by hand clears it. Auto can't be starred as a favourite.
  • Edit Project: a profile select for each tier, plus "Start new threads on Auto" (modelRouting on the project).
  • Automations: an optional tier. The automation's provider/model is still the fallback. An invalid tier is rejected.
  • thread_fork (orchestrator MCP): an optional tier argument (auto|fast|balanced|strong). A pinned (force) worker pool still takes priority.

Tests

  • electron/test/model-routing-tiers.test.js: covers classification and route application.
  • test/modelPicker.test.ts: covers the Auto row.

🤖 Generated with Claude Code

A thread can carry a pending route ("auto" or fast/balanced/strong) that
its first turn consumes. Auto classifies the prompt with a keyword and
length heuristic. The tier maps to an agent profile through the project's
new modelRouting setting. The profile's provider, model and effort are
applied, but never its permission mode. The transcript gets an event that
says what was picked and why, or why nothing changed.

Entry points:
- Composer: an Auto row in the model picker before the first turn. A
  manual pick clears it.
- Projects: per-tier profile selects plus "Start new threads on Auto".
- Automations: an optional tier; provider/model stays as the fallback.
- thread_fork: an optional tier for orchestrators. A pinned pool still
  wins.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 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-10-11T09:23:34.504437Z 13ac882 PR opened
ℹ️ 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.

@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: 13ac8821e7

ℹ️ 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 electron/routing.js
provider: profile.provider,
model: profile.model,
});
if (profile.reasoningEffort) {

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 Reset effort when the routed profile requests default

When a project also supplies a non-null threadDefaults.reasoningEffort, a routed profile whose reasoningEffort is null never applies its documented provider-default setting because this conditional skips the setter. setProvider preserves the old effort whenever the routed provider/model supports it, so a fast profile can unexpectedly run at high effort and cost, or a strong profile can retain a lower effort. Call setReasoningEffort with null as well.

Useful? React with 👍 / 👎.

Comment thread electron/runner.js
Comment on lines +1764 to +1765
if (thread.route != null) {
const routed = applyRoute(store, threadId, prompt);

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 Consume pending routes when a workflow starts

This applies routing only through startRun, but a fresh thread can take its first turn through startWorkflowRun (electron/runner.js:2243). Workflow sessions are stored on phase agents rather than thread.sessionId, so after the workflow finishes the route remains pending and the composer still shows Auto; the next ordinary message is then incorrectly classified and routed even though it is not the thread's first turn. The workflow entry point should consume or explicitly clear the pending route.

Useful? React with 👍 / 👎.

Comment thread electron/routing.js
Comment on lines +127 to +129
const { parseProviderRef } = require("./providerInstances.js");
const base = parseProviderRef(profile.provider).provider;
if (!services.providerInstalledFor(project, base)) {

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 Reject named provider instances for remote routes

When a remote project maps a tier to a named-instance profile such as claude:work, providerInstalledFor deliberately returns true for every remote provider and setProvider accepts the local instance, so routing reports success and consumes the route. The same startRun then rejects any providerInstance when crossesBoundary(projectForGate) is true, causing every routed first turn to fail instead of retaining the fallback model as promised. Detect the parsed instance for remote/WSL projects before applying the profile.

Useful? React with 👍 / 👎.

@currentbits
currentbits enabled auto-merge (squash) October 11, 2026 09:31
…ick-provider-model-per-ta-16ce1e

# Conflicts:
#	electron/services-settings.js
#	src/components/AutomationsView.tsx
#	src/shared/ipc.ts
@currentbits
currentbits merged commit c9cd5f3 into main Oct 11, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant