Skip to content

Fix: Send a new session's one-shots to the agent's server - #1360

Merged
huang195 merged 1 commit into
rossoctl:mainfrom
huang195:fix/router-new-session-aside
Oct 11, 2026
Merged

huang195 merged 1 commit into
rossoctl:mainfrom
huang195:fix/router-new-session-aside

Conversation

@huang195

@huang195 huang195 commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

Problem

After routing claude-code to a server and starting a new session (/clear), the session's first request went to the provider the agent had been routed away from:

  1. A new Claude Code session sends its title request ("You are naming a coding session…", no tools) before its first prompt's turn — 2s earlier in the live case.
  2. With no pin and no history, the router reads each Claude Code request's turn to decide the session. A one-shot (no tools) cannot say whether the session is new, so it decides nothing — and, when addressed to a server's host, was also left where Claude Code sent it.
  3. So every new session's title went to ete with Claude Code's own model, while the opening turn that followed pinned the session to glm.

Captured one-shots (addressed to a host no server has) were already routed to the agent's server (3eb673b); only the uncaptured ones stayed behind.

Change

unpinned, step 4: a main-agent one-shot goes to the agent's current server and still pins nothing, so the opening turn decides the session exactly as before.

  • A conversation already running is unaffected wherever it has history: history is read before this rule, and a one-shot's own row is skipped as history.
  • A subagent's request to a server's host stays unrouted: it is a conversation of its own, and a /clear carries running background subagents onto the new session id.
  • The trade-off, pinned by a test: a running conversation the router has no record of (no archive, after a restart) gets its one-shots answered by the new server until its next turn, which still keeps it where it was.

Tests

  • TestRouter_AClaudeCodeOneShotGoesToItsAgentsServer — new; failed before the change (skip/not_routed turn:aside, ete host, client key).
  • TestRouter_AfterASideRequestTheConversationDecides — the live sequence: title then opening turn, both on glm, pinned glm; and title then continuation, which stays on ete.
  • TestRouter_AClaudeCodeSubagentRequestDecidesNothing — the old side-request test, narrowed to subagents.

go test ./... in core, go vet and gofmt -l clean.

Live-verified with make dev-install from this branch: a new /clear session's title request was modify/routed server:glm pin:none to litellm.cb.ete.res.ibm.com, the opening turn pinned glm, and no request reached ete.

Docs: package doc, docs/plugin-catalog.md, docs/agents/claude-code.md.

Assisted-By: Claude (Anthropic AI) [email protected]

Summary by CodeRabbit

  • New Features
    • Claude Code one-shot requests, including title and auto-mode classifier requests, are now sent to the agent’s configured server even before a session is pinned. These requests do not determine where the conversation is pinned.
    • Subagent requests that have not been captured remain at their client-addressed destination, while captured subagent requests are sent to the configured server.

…server

A Claude Code one-shot (the title request, auto mode's classifier, the
permission monitor) in a session with no pin and no history was left where
Claude Code sent it when that was a server's host. A new session's title
request reaches the router before its opening turn, so every new session sent
its title to the provider the agent had been routed away from: after routing
claude-code to glm and a /clear, the title went to ete with Claude Code's own
model while every later request went to glm.

A one-shot now goes to the agent's current server and still pins nothing, so
the opening turn decides the session as before. A conversation already running
is unaffected where it has history, which is read first. A subagent's request
to a server's host stays unrouted: it is a conversation of its own, and a
/clear carries running background subagents onto the new session id.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bca57aa8-faca-460d-8775-9030ca5e1675

📥 Commits

Reviewing files that changed from the base of the PR and between 96fa7ad and 70d1e29.


📒 Files selected for processing (4)
  • core/plugins/inferencerouter/plugin.go
  • core/plugins/inferencerouter/plugin_test.go
  • docs/agents/claude-code.md
  • docs/plugin-catalog.md

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



📝 Walkthrough

Walkthrough

The inference router now sends Claude Code one-shot requests to the configured server without pinning the session. Uncaptured subagent requests remain at the client-addressed destination. Tests and documentation describe these behaviors.

Changes

Claude Code side-request routing

Layer / File(s) Summary
Select destinations for side requests
core/plugins/inferencerouter/plugin.go, core/plugins/inferencerouter/plugin_test.go, docs/agents/claude-code.md, docs/plugin-catalog.md
The router sends one-shots and captured subagent requests to the configured server. Uncaptured subagent requests remain unrouted. Tests cover routing and session-pin behavior, and the documentation describes these rules.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: abigailgold


Merge Risk: ⚪ Minimal · up to 70d1e

History-free Claude Code one-shots are routed to the configured server without prematurely pinning the session. No actionable merge risk remains.

Pre-merge checks | Passed 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: routing new-session one-shot requests to the agent's configured server.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. (2 skipped: 2 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

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

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@esnible esnible left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A small, well-targeted fix. The behavior change only affects main-role requests with no tools, addressed to a server's host, in a session with no pin and no history. History is still read first, and serverOf already ignores side-request rows, so a routed one-shot can never become evidence that pins a session. The trade-off for a running conversation the router has no record of is stated and tested (AfterASideRequestTheConversationDecides/a continuation). Substitute models are stored separately for main and helper requests, so a helper model given to a title request can't carry over into the conversation. All four branches of the changed turnAside case are covered, including the captured one in models_test.go.

Nothing blocking. The inline comments are about how much the subagent rule actually protects, and about what the record shows.

Author: huang195 (MEMBER — maintainer)
Areas reviewed: Go (core/plugins/inferencerouter), Docs
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, signed off: yes
CI status: passing (Spellcheck skipped)

if captured || pctx.Extensions.Inference.AgentRole == pipeline.AgentRoleMain {
return choice, turnAside, false
}
return "", turnAside, false

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

suggestion: The reason given here (and in the package doc, the catalog and the subagent test's comment) is that a /clear can carry a subagent that is already running. That only holds when the session before the /clear was unrouted. If it was pinned to glm, the background subagent was running on glm: its requests are addressed to ete, and the pin redirected them. In the new, unpinned session, this branch sends it back to ete until the opening turn. The opening turn then pins glm, and the subagent moves again. Either way a carried subagent changes server once.

This branch is unchanged, so it's not a regression, but the comment claims more than the code does. Could the wording say what it actually protects (a subagent carried from an unrouted session, until the new session's opening turn), or name the routed case as a known gap?

// conversation of its own, which may be running already, so it is left where
// Claude Code sent it unless captured: then leaving it would send the user's
// credential to the provider the agent was routed away from.
if captured || pctx.Extensions.Inference.AgentRole == pipeline.AgentRoleMain {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

suggestion: This makes "no tools means one-shot" decide more than it did before. A main conversation that really has no tools (for example, Claude Code started with all built-in tools disabled) counts as a one-shot on every turn. It never pins, and none of its rows count as history. Before this change, such a conversation addressed to a server's host stayed where it was sent. Now every turn follows the agent's current server, so switching that server moves it mid-conversation. Probably rare enough to accept, but worth a line beside the restart trade-off in the package doc.

// Claude Code sent it unless captured: then leaving it would send the user's
// credential to the provider the agent was routed away from.
if captured || pctx.Extensions.Inference.AgentRole == pipeline.AgentRoleMain {
return choice, turnAside, false

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: A one-shot routed from here is recorded as modify/routed server:glm pin:none, with no turn. On the timeline, that looks the same as the other reasons for pin:none (no session, a synthetic session, no store, another agent's pin). The not-routed record already adds turn when pin.turn != "". Doing the same in the routed details() would say why nothing pinned. It would also make the comment on the pinning.turn field accurate again: it says turn is set only when the turn "left an unpinned session unrouted", but it is now also set for a routed one-shot (and already was for a captured one).

session's pin once there is one. Pins are kept in `~/.cortex/plugin-state.json`,
session's pin once there is one. Before then a one-shot goes to the server you
chose, since a new session's title request can arrive before its opening turn, and
a subagent's request addressed to one of the servers stays on it. Pins are kept in `~/.cortex/plugin-state.json`,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: This line wasn't rewrapped after the insertion: it is 113 columns, against about 80 for the rest of the paragraph.

@huang195
huang195 merged commit 52fd3e7 into rossoctl:main Oct 11, 2026
30 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 11, 2026
@huang195
huang195 deleted the fix/router-new-session-aside branch October 11, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants