Repository navigation
Fix: Send a new session's one-shots to the agent's server - #1360
Conversation
…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]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to 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 |
|
esnible
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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`, |
There was a problem hiding this comment.
nit: This line wasn't rewrapped after the insertion: it is 113 columns, against about 80 for the rest of the paragraph.
Problem
After routing
claude-codeto a server and starting a new session (/clear), the session's first request went to the provider the agent had been routed away from: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./clearcarries running background subagents onto the new session id.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 ./...incore,go vetandgofmt -lclean.Live-verified with
make dev-installfrom this branch: a new/clearsession's title request wasmodify/routed server:glm pin:nonetolitellm.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