Repository navigation
Conversation
The inference-router pins each session to its server by name. Renaming a server, by hand or with the agentop server rename that #1907 asks for, left every running session pinned to a name no server had, and each one got a 503 pinned_server_removed until it was moved. A pin now keeps its server's host as well as its name. A host names one server at a time, so decidePin resolves a pin by its host first: to the server on it now, whatever that server is called. A pin whose host no server has follows its name, as a server whose URL was replaced under the same name needs. Host comes before name because an old name can be given to another server, or two names swapped. - serverFor resolves the pin before decideServer rules on it, and only for the pin's own agent. The resolved pin is saved at once, past the once-a-day renewal rule. - followRename carries the session's substitutes and its moved-reasoning record to the new name. The server-wide caches (model lists, refusals, limits) are learned again. - A followed request's modify/routed record carries renamed_from. - A pin saved before this change gets its server's host on its next request. One renamed before that still gets the 503, as today. This works with the proxy running (hot reload) or stopped (the plugin store keeps the host), and needs no reload hook: the store cannot list its keys, and a reload builds a fresh router that never sees the previous config. Refs #1907 Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Alan Cha <Alan.cha1@ibm.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 16 minutes. View limit details
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. |
clawgenti
left a comment
There was a problem hiding this comment.
Summary
Clean, well-tested change: pins now keep their server's host and follow a rename (host first, then name), with substitutes and the reasoning record carried over, and thorough coverage in follow_test.go (rename, name reuse, URL replacement, reload, stopped-proxy store, cross-agent pin ownership). No must-fix findings.
Author: Alan-Cha (MEMBER — maintainer)
Areas reviewed: Go (inferencerouter), docs, tests
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, signed-off: yes
CI status: passing (three jobs still pending: agentop, core peerproc macOS, README demo — all green on the equivalent PR)
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
clawgenti
left a comment
There was a problem hiding this comment.
(Marker for the review-state tracker; the full review is above.)
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
clawgenti
left a comment
There was a problem hiding this comment.
Summary
Host-first pin resolution is a sound design, and decidePin is clean and well covered. serverFor also gets the ordering against sessions: overrides right. I ran go vet and go test -race ./plugins/inferencerouter/... at head and both pass. I found one blocking problem, in the "two names swapped" case that the PR lists as handled. The pin follows correctly in that case, but a session that has already moved carries a reasoning record, and renameInReasoning merges the two servers' entries in it. The session then sends the other server's thinking signatures to its own server. Details and a reproducer are inline.
Author: Alan-Cha (MEMBER, maintainer)
Areas reviewed: Go (inferencerouter: decide, pins, plugin, strip, models), tests, docs
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing (3 Go CI jobs still pending at review time)
| Severity | Count |
|---|---|
| must-fix | 1 |
| suggestion | 1 |
| return | ||
| } | ||
| changed := false | ||
| if rec.Base == oldName { |
There was a problem hiding this comment.
must-fix: a rename onto a name the record already holds merges two servers' reasoning.
This rewrite is one-way, oldName -> newName. Entries that already say newName are left alone. When newName belonged to a different server before the change, the swap case in this PR's own test table, those entries now read as the destination's own, and keepOwnReasoning stops dropping them.
Here is a reproducer against head (drop it in core/plugins/inferencerouter):
func TestProbe_SwapWithMovedSession(t *testing.T) {
store := newStore(t)
onEte := sessionsConfig(`"claude-code": "ete"`, ``)
send(t, store, onEte, history())
send(t, store, onEte, history(thinkingTurn("e1"))) // ete writes e1
onGLM := sessionsConfig(`"claude-code": "ete"`, `"s1": "glm"`)
send(t, store, onGLM, history(thinkingTurn("e1"))) // moved to glm
send(t, store, onGLM, history(thinkingTurn("e1"), thinkingTurn("g1")))
swapped := `{"servers": {
"glm": {"url": "https://ete.example.com", "key": "ete-key", "main": "opus", "helper": "haiku"},
"ete": {"url": "https://glm.example.com:8443", "key": "glm-key", "main": "opus", "helper": "haiku"}},
"agents": {"claude-code": "glm"}, "sessions": {"s1": "ete"}}`
next := send(t, store, swapped, history(thinkingTurn("e1"), thinkingTurn("g1"), thinkingTurn("g2")))
assertRouted(t, next, glmHost, "glm-key") // passes: the pin followed the host
assertSignatures(t, next, "g1", "g2") // fails: got [e1 g1 g2]
}Before the swap the same request correctly yields [g1 g2]. After it, Writers says e1 -> ete, g1 -> ete and Base says ete, so the real ete server's e1 signature goes to the glm host. That is exactly the cross-server artifact keepOwnReasoning exists to strip (the Bedrock 4.6 / invalid-signature failure). Any rename onto a name the record already uses for another server hits the same thing, for example removing ete and then renaming glm to ete.
A minimal fix is to treat the rename as a permutation: in the same pass, map entries that say newName to a tombstone no server can be named, then oldName -> newName. I checked that a tombstone version of this function makes the probe pass and keeps the rest of the package green. If you go that way, apply it only when the record still names oldName. Otherwise two concurrent requests in the session could both follow the rename, and the second would tombstone the entries the first just wrote. Recording the writer's host alongside the name would avoid the name ambiguity altogether.
followRename's substitute copy (len(p.substitutes(pctx, to)) == 0) has the same shape. On a swap, the session may already hold substitutes under newName from when that name was the other server. Those are kept, and the followed server's own substitutes are not copied over.
| // oldName wrote is still read as its destination's. A session that already has | ||
| // substitutes under newName keeps them. The store deletes nothing, so the copies | ||
| // under oldName lapse with their TTL. | ||
| func (p *Router) followRename(pctx *pipeline.Context, oldName, newName string) { |
There was a problem hiding this comment.
suggestion: renaming a server the session has left still loses that server's reasoning.
followRename runs only when the session's own pin follows. Take a session that ran on glm (writes g1), was moved to ete by a sessions: entry, and then glm is renamed zai. Its record still says g1 -> glm and Base: glm. If the session is later moved back with "s1": "zai", g1 reads as another server's and is dropped. I probed this at head: the request to zai carries no signatures, where [g1 ...] would be expected. Base has the same behaviour, and this PR doesn't claim to cover it, so it isn't blocking. Still, "a session moved back keeps its first server's" is something the reasoning record promises. The fix could be to resolve the record's names through hosts as well, or else to note the limitation in the doc's rename bullet.
|
Rebased onto main, the host-first rule breaks: two servers can now share one host. Since #1983, servers:
team-a: {url: https://gw.example.com/litellm, key: ${TEAM_A_KEY}, main: opus, helper: haiku}
team-b: {url: https://gw.example.com/litellm, key: ${TEAM_B_KEY}, main: opus, helper: haiku}
A possible fix: follow the host only when exactly one server has it ( This also affects #1918, whose |
|
Closing this for now. #1918 ( Two things would need to change before this approach could land:
The branch stays, so this can be reopened or picked up later. |
Summary
The inference-router pins each session to its server by name: the pin record, and the session's substitutes and moved-reasoning record, all name the server. Renaming a server, by hand today or with the
agentop server renamethat #1907 asks for, left every running session pinned to a name no server had. Each one got a 503pinned_server_removedon its next request until it was moved.A pin now keeps its server's host as well as its name, and a renamed server keeps its sessions. This is the second of three PRs for #1907. The third adds
agentop server rename, which depends on this one.How a pin finds its server
decidePin(decide.go) is a pure function of the loaded pin and the current config:Decoderefuses two on one), so the server on the pin's host is the one the session ran on, whatever it is called now. Host comes before name because an old name can be given to another server, or two names swapped. A name-first rule would quietly send the session to the wrong backend with the wrong key.agentop server add --yesreplaces a server's URL under the same name, whose sessions the add says follow it. The pin takes the new host.serverForruns this after loading the pin and beforedecideServerrules on it. Running it first means asessions:entry naming the new name keeps the pin (pin: existing) rather than moving it from the old name. It runs only for the pin's own agent, asdecideServeralready requires. A changed pin is saved at once, past the stored pin's once-a-day renewal rule.What a followed pin carries
substitute/<session>/<agent>/<server>), copied to the new name when it has none, so the conversation keeps its model.saveSubstitutesis pulled out ofkeepSubstitutefor this.Base,WritersandLast(renameInReasoning). Without this, every reasoning block the server wrote would read as another server's and be dropped from every later request.renamed_fromdetail on that request'smodify/routedrecord. Thepinvalues are unchanged.What the router learned about the server itself (its model list, refusals and limits) is learned again under the new name. The doc says so, including the brief
skip/no_substitutewindow before the new name's model list is first read.Why not re-key the state on reload
A hot reload builds a fresh router (
plugins.BuildWithDeps) that never sees the previous config, and neither store can list its keys. Resolving lazily per request needs neither. It also covers a rename made while the proxy was stopped, since the plugin store keeps the host.Compatibility
pinRecordgainshost,omitempty. An older proxy reading a newer record ignores the field.TestRouter_APinWithNoHostGetsItsServersOnItsNextRequest).docs/inference-router-plugin.md.Not in this PR
agentop server rename(PR 3 of bug: agentop server cannot undo its first add, and cannot rename a server #1907), and updatingagentop server remove's wording about the 503 to match the host rule.models.go:325-327. That is a separate issue.Test plan
follow_test.go):TestDecidePin(9 rows: rename, old name reused, names swapped, URL replaced, no host, removed)TestRouter_APinFollowsItsServerToANewNameTestRouter_APinFollowsItsHostWhenItsOldNameIsReusedTestRouter_APinFollowsANameWhoseURLChangedTestRouter_APinWithNoHostGetsItsServersOnItsNextRequestTestRouter_AnotherAgentsRequestDoesNotFollowThePinTestRouter_AnOverrideToTheNewNameKeepsThePinTestPinsFollowARenameAcrossAReload(throughplugins.BuildWithDeps)TestRouter_AFollowedPinKeepsItsSubstituteTestRouter_AFollowedSessionKeepsItsOwnReasoningTestRouter_WithAStoreAPinFollowsARenameMadeWhileStopped(file store, reopened)TestRouter_AStoredPinWithNoHostGetsOneOnItsNextRequestTestRouter_ARoutedOneShotsRecordCarriesNoTurnplugin_test.gonow include the host.followRenameskipped: the substitute and reasoning tests fail.keepinstead ofsave: both store tests fail.TestDecidePinand every rename test fail.turnadded to routed records: the one-shot test fails.cortex(full profile) on spare ports, with a Claude-Code-shaped session pinned to servera, thenarenamedbby hand in the config:pinned_server_removed.routed {server: b, pin: existing, renamed_from: a}. The next request is a plainpin: existing.go vet ./...(core);go test -race ./plugins/inferencerouter/...;go test ./plugins/...;gofmt;cmd/cortexbuilds with thefullprofileRefs #1907
Assisted-By: Claude (Anthropic AI) noreply@anthropic.com