Repository navigation
refactor(agent): move Bob's session id into agent/bob - #1045
Conversation
The shared proxy.go read the Bob IDE's X-Task-Id header in an if-branch on Bob's route. It now asks the route's agent (agent.Agent.SessionID): agent/bob returns X-Task-Id, and every other route gets the neutral Base. The session code in proxy.go no longer names Bob or X-Task-Id. No behavior change. proxy/bobsession_test.go is unchanged and green. - With no agent id, the request keeps the bare session header, so an agent that does not override SessionID changes nothing on its route. - A panic in an agent gives no id (fail open); the log names the panic's type only, never its message. - agent/bob registers in init() and carries a compile-time check. The import guard now covers agent/bob too. First move of A2. Bob's route setup, profile handling and usage reading are still in proxy.go, for the next moves. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Vitaly Zabershinsky <[email protected]>
vz-ibm
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (claude, user of @vz-ibm) | Claude Code 2.1.316 | offload-review skill, @vz-ibm's session | fresh | 1 of 2 | 1 of 2 | 21ebb9294d21 |
approve |
Verdict: approve
Findings
None. I traced the "no behavior change" claim through every consumer of explicitSess, and it holds.
Non-blocking
-
explicitSessionOfnow returns a different string on one path. The final session stays the same. On Bob's route with noX-Task-Id, the old code returnedapply.ExplicitSession(sess, body, ""). That value is the header, else the bodymetadata.user_id/taskId(trimmed and unwrapped), else "". The new code returns the rawsess. Every consumer runsExplicitSession(o.Session, body)again:apply.go:511(sessionIDFrom)apply.go:517(the alias gate)responses.go:493SessionIDFor/EnforcedSessionIDFor(proxy.go:1455,proxy.go:2074,recctx.go:109)
Each one gets the same final id. The re-run also gives the same result for an unsafe or padded header, and for an already unwrapped
user_id, becausemetaSessionIDof a plain string returns it unchanged. This depends on a fact the code does not state:transformEnvelopenever changesmetadata. The technical note in the PR names this dependence. A comment atsessionIDFrom, or a test that pins "transform keepsmetadata", would protect it if a later component rewritesmetadata. -
proxy/agentsession_test.go:61: the panic tests do not show that the agent was asked. IfexplicitSessionOfstopped callingh.agentFor, both panic tests would still pass, becausegot == want. The PR says they were red first. That covers this commit only. A later regression that skips the agent lookup would not fail them. Add one assertion, for example a counter onpanicky.SessionIDor a log line from the recover. Then the test proves that the recover path ran. -
proxy.go:760: in observe mode a panicking agent logs two times per request.explicitSessionOfruns atproxy.go:1343and again atproxy.go:2074. This is harmless. You could reuseexplicitSessinserveto call the agent one time only, butservedoes not getexplicitSessnow. -
docs/design.md:292namesexplicitSessionOfas the source of theX-Task-Idrule. It is still accurate, but the rule now lives inagent/bob(Bob.SessionID). Update the line to nameagent/bob, so the doc points to the code that owns the rule. -
agent/imports_test.go:21:go list -deps ./...does not list test-only imports. A futureagent/x/x_test.gothat importsproxypasses the guard. This is acceptable for a library rule, but the new comment ("a new agent package is covered") is a little broader than what the guard checks.
What I checked
- I read the full diff
bf80677f..21ebb929(5 files, +274/−19) and the commit message. The PR body says the PR stacks on #1029. The diff base already contains #1029, so the diff is this commit only. - I read
agent/agent.goandagent/registry.go.ForPathnever returns nil (it givesBase{}), soagentSessionIDcannot get a nila. - I compared the old and new
explicitSessionOfon four cases:- non-Bob route
- Bob route with
X-Task-Id - Bob route without
X-Task-Id, with and without body metadata - unsafe header values
- The final session id is the same in each case (see the first non-blocking point).
- I read
session.Explicit,ExplicitID,metaSessionID,apply.ExplicitSession,sessionIDFrom,SessionIDFor,EnforcedSessionIDFor,newRecCtx, and the dashcapture alias closure. - Fail open: the recover in
agentSessionIDgives "", and the request keeps its no-agent session. The log names only the%Tof the agent and of the panic, so no header value gets into the log. - Route paths:
static.path/up.pathis the upstream path (/v1/chat/completionsorbob.ModelPath). This matches what the registry keys on and what the new tests register. Handler.agentForis set inNew. The tests replace it beforeMux()and before any request, so there is no race.bob_test.gouses the default registry.agent.resetDefaultlives in a different test binary, so the two cannot interfere.- The data dependence does not change: the code still uses one header value as a label. No component was added, so
docs/data-dependence.mdneeds no update. - Not done: I ran no Go builds or tests. Live tests are not approved, and Go is not installed here.
vz-ibm
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (claude, user of @vz-ibm) | Claude Code 2.1.316 | offload-review skill, @vz-ibm's session | fresh | 2 of 2 | 1 of 2 | 21ebb9294d21 |
approve |
Verdict: approve
Findings
None. I found no wrong behavior, no broken fail-open path and no missing test for the new behavior.
Non-blocking
- agent/agent.go
Pathscontract vs. the host's lookup key.Pathssays "the model routes this agent owns ... the same trailing slash as the route". The proxy looks up by the upstream path (static.path, for example/v1/chat/completions), not by the client route (/openai/v1/chat/completions). For Bob the two are the same string, so Bob works. The next agent on the OpenAI or Anthropic route would register the route path and never match. The testpanicky{path: upPath}shows the author knows this. Proposal: say "the host's upstream path" in thePathsdoc comment, or pass the route path. (The doc comment is from #1029, but this PR fixes the key that the host uses.) - proxy/proxy.go:759 — the log omits the panic message, but no test proves it. The comment says the message "could hold a header value". The global rules ask for a test for a security invariant: for example, a
panickythat panics with a canary string, and a check that the captured log does not contain it. - proxy/proxy.go:2074 — the agent runs two times per observed shadow request.
explicitSessionOfruns at line 1343 and again inserve. A panicking agent logs the error two times for one request. This costs nothing else. You can passexplicitSessintoservein a later move. Handler.agentForis nil on a&Handler{}literal. Some tests build&Handler{}withoutNew. None of them reachexplicitSessionOftoday. If one does later, it panics on a nil func, not on the agent, soagentSessionIDdoes not catch it. A nil check that falls back toagent.ForPathwould make the seam safe.- docs/design.md:23 and :292. The layout row names
agent/but notagent/bob. Line 292 still says "on Bob's model route only ... (explicitSessionOf)". That is still true, but it can nameagent/bobas the owner now.
What I checked
- The full diff
bf80677f..21ebb929: all 5 files, every changed line. The PR has one commit. - No behavior change, by trace:
- Bob route with
X-Task-Id: oldExplicitSession(sess, body, xtask); new is the same call withid = xtask. - Bob route without
X-Task-Id: oldExplicitSession(sess, body)(it can resolvemetadata.taskId); new returnssess. Every consumer ofexplicitSessre-runsExplicitSession(explicitSess, body):sessionIDFrom(apply.go:1473), the alias check (apply.go:517),responses.go:493,EnforcedSessionIDFor, andnewRecCtxthroughSessionIDFor.ExplicitSessionis idempotent here: a safe header wins in both; an unsafe header is skipped in both, and the body id wins. No code rewritesmetadatabetween the two reads (grep for sjson/Delete onmetadata: none). So the final session is the same. - Other routes:
agentForgivesBase{},SessionIDgives"", so the bare header goes out, as before. X-Task-Idwith only spaces or bad characters:id != "", soExplicitSessionruns with it and drops it insafeExplicit, as before.
- Bob route with
- Route key:
upstreamFor(tenancy.go:716) keepsstatic.path, so hosted mode looks up the same path. Only the Bob route has upstream path/inference/v1/chat/completions. - Fail open:
agentSessionIDrecovers a panic and returns"". Without the recover, net/http drops the connection, andsessionAtfails on a non-200. So the two panic tests prove the recover. They also compare against a no-agent handler, with and without the session header. - The gate change:
TestBobShellTaskIDWithoutTheHeaderIsStillTheSessionandTestAnAgentWithoutItsOwnSessionIDChangesNothingOnItsRoutecover the "no id, no change" gate. - Registration:
proxyimportsagent/bobforbob.ModelPath, soinit()registers Bob in every proxy build.TestInitRegistersBobInTheDefaultRegistrycovers that. A duplicate claim panics at start-up, ascomponents.Registerdoes. - Import guard:
go list -deps ./...fromagent/listsagentandagent/boband their non-test deps.agent/bobimports onlynet/httpandagent. - Hard boundaries: the library packages do not import the proxy. No component was added, so
docs/data-dependence.mdneeds no row. The session id is a header value (metadata), as before. - I did not run Go builds or tests. Live tests are not approved, and Go is not installed here.
The fail-open tests passed even if the host never called the agent, and nothing tested that a panic's message stays out of the log. The test agent now counts its calls and panics with a canary. The test checks that the agent was asked, that the recovery is logged where it reads, and that the canary is not. Logging the message, or never calling the agent, each fails it. Paths() now says it is the upstream path the host forwards to, not the path the client calls. docs/design.md names agent/bob as the owner of the X-Task-Id rule. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Vitaly Zabershinsky <[email protected]>
Round 1: repliesBoth reviews approve, with no findings. I acted on the non-blocking notes that close a real test gap, in R1: the panic tests do not show the agent was asked. Correct: they would pass if R2: no test proves the panic message stays out of the log. Fixed.
With the message logged again (a mutant), it fails with "the log holds the agent's panic message". R2: R1, R2: Non-blocking, no change:
Checks
|
vz-ibm
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (claude, user of @vz-ibm) | Claude Code 2.1.316 | offload-review skill, @vz-ibm's session | resumed | 2 of 2 | 2 of 2 | 4519eeea88a1 |
approve |
Verdict: approve
Findings
None. The new commit adds tests and doc text only. It does not change the code that runs.
Status of earlier notes
Both reviewers approved in round 1 with no findings. These are the non-blocking notes:
- R2:
Pathsvs. the lookup key: fixed.agent/agent.go:16-19now says the path is the upstream path, with/openaias an example of a host prefix that is not in it. - R2: no test that the panic text stays out of the log: fixed.
panickypanics withpanicCanary. The test first checks that the recovery line is in the captured log, then checks that the canary is not. The order is correct: a log that the test never captured fails the first check. - R1: the panic test does not show the agent was asked: fixed in
TestPanickingAgentSessionIDFailsOpenToTheSessionWithoutTheAgent(a call counter,calls.Load() == 0fails). - R1, R2:
docs/design.md: fixed. A newagent/bob/row, and line 293 namesagent/bobthroughagent.Agent.SessionID. - R1, R2: two agent calls per observed request: no change, by the author. I accept the reason. It is harmless, and the fix changes the
servesignature, which fits a later move. - R2:
&Handler{}with a nilagentFor: no change, by the author. I accept it. No test reachesexplicitSessionOfwithoutNewtoday. - R1: the guard does not see test-only imports: accepted by the author. I agree.
- R1: the downstream re-run of
ExplicitSession: agreed, no change needed.
Non-blocking
- proxy/agentsession_test.go — the second panic test does not count calls.
TestPanickingAgentSessionIDFailsOpenToTheDerivedSessionregisterspanicky{path: upPath}withcallsnil. If the host stopped calling the agent, this test would still pass. The first panic test covers the same call path, so the gap is small. Passing a counter here too would make the test prove its own claim.
What I checked
- Last review: round 1,
21ebb9294d21b1bad66c4750c8b6dd42e79a8678, 2026-11-10T12:57:07Z - New commits read: 1 —
4519eeeatest(agent): the agent is asked, and its panic text is not logged - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
- New items since my last review:
- Commit
4519eeea: I read its full diff (3 files, +49/−8) and the code around it. - The author's comment "Round 1: replies" (13:01:58Z): I checked each reply against the diff (see "Status of earlier notes").
- Reviewer 1's round-1 review (12:57:02Z, first read this round): I checked each of its notes and their status above.
- Commit
- The log capture reads the right logger.
agentSessionIDlogs throughlogging.From(r.Context()). The chat handler sets that logger per request fromslog.Default().With(...)(proxy.go:1309-1311).captureDefaultLogruns beforesessionAt, so the request logger writes to the buffer. The cleanup puts back the old default. - No race on the global logger.
agentsession_test.gohas not.Parallel(). Other tests in the package swapslog.Defaultin the same way (auth_test.go:387,keepalivehost_test.go:480).syncBufferalready exists (keepalivehost_test.go:201) and is safe for concurrent writes. - The canary can reach the log only through the panic value. The log line writes
%Tof the panic (string), not its value. So the check fails only when the message itself is logged, as the author's mutant shows. - The
nilcheck onp.callskeeps the second panic test working with no counter. proxy/bobsession_test.gois still unchanged from the base (git diff bf80677f..HEAD -- proxy/bobsession_test.go: empty).- I did not run Go builds or tests. Live tests are not approved, and Go is not installed here.
vz-ibm
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (claude, user of @vz-ibm) | Claude Code 2.1.316 | offload-review skill, @vz-ibm's session | resumed | 1 of 2 | 2 of 2 | 4519eeea88a1 |
approve |
Verdict: approve
Findings
None. The new commit adds tests and changes comments and docs only. It has no defects.
Status of round-1 notes
Both round-1 reviews approved with no findings. Status of the non-blocking notes:
- R1: the panic tests did not show that the agent was asked. Fixed.
panickycounts its calls, andTestPanickingAgentSessionIDFailsOpenToTheSessionWithoutTheAgentfails when the count is 0. - R2: no test proved that the panic message stays out of the log. Fixed. I checked that the capture is real:
captureDefaultLogswapsslog.Default()before the request.proxy.go:1309builds the request logger fromslog.Default()when the request arrives, andproxy.go:1311puts it on the context.agentSessionIDreads it withlogging.From(r.Context()), so the recover line goes to the test buffer.- The test checks the recovery line first, so the canary check cannot pass on an empty log.
- The log has
"panic", fmt.Sprintf("%T", rec), which isstring, never the canary.
- R2: the
Pathscontract. Fixed.agent/agent.go:16now says that the paths are upstream paths, not the client's route. This matchesstatic.pathatproxy.go:1343andupstreamForattenancy.go:716. - R1, R2:
docs/design.md. Fixed. Line 293 namesagent/bob, and the package map has anagent/bob/row. - R1, R2: the agent is called two times per observed request. The author deferred this to a later A2 move. I accept that: it costs one extra log line.
- R2:
&Handler{}withoutNewleavesagentFornil. The author deferred this. I accept that: no test reachesexplicitSessionOfthis way today. - R1: the import guard does not check test-only imports. The author accepted the limit. I agree.
- R1: the downstream re-run of
ExplicitSession. The author agreed, and the PR's technical notes state it. No change is needed.
Non-blocking
proxy/agentsession_test.go: the second panic test does not count the calls.TestPanickingAgentSessionIDFailsOpenToTheDerivedSessionregisterspanickywithoutcalls. It would still pass if the host stopped asking the agent. The first test covers the call, so this is a small gap only.captureDefaultLogchanges a process global. This is safe because no test inagentsession_test.gocallst.Parallel(). Other tests in the package (auth_test.go:387,keepalivehost_test.go:480) use the same pattern.
What I checked
- Last review: round 1,
21ebb9294d21b1bad66c4750c8b6dd42e79a8678, 2026-11-10T12:57:02Z - New commits read: 1
4519eeeatest(agent): the agent is asked, and its panic text is not logged
- Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
- New items since my last review:
- The reviewer 2 round-1 review (12:57:07Z). I checked each of its notes above.
- The author's comment "Round 1: replies" (13:01:58Z). I checked each reply against the code above.
- I read the full diff
21ebb929..4519eeea(3 files, +49/−8):agent/agent.go,docs/design.md,proxy/agentsession_test.go. - I read the code around the change:
internal/logging.Fromandlogging.With- the request logger setup at
proxy.go:1309-1311 syncBufferatkeepalivehost_test.go:201, the same package, so it compiles- the other
slog.SetDefaulttests inproxy/
- The production code (
proxy/proxy.go,agent/bob) did not change since round 1. My round-1 trace of "no behavior change" still holds. - Not done: I ran no Go builds or tests. Live tests are not approved, and Go is not installed here. I did not run the author's mutant checks myself.
The shared proxy decided with a bob flag, in 4 places, whether to read Bob's cache-write fields, and held the parser in proxy/bobusage.go. The parser is now Bob.ReadUsage in agent/bob, and the proxy asks the route's agent through one helper, readAgentUsage. The flag and bobusage.go are gone. No behavior change. proxy/bobusage_test.go is byte-identical; its 5 direct-parser tests compile through a test-only shim, and its end-to-end tests are the proof. - readAgentUsage starts from the shared reading and copies back only the 5 token counts, so every other field stays as it was. - A panic in the agent gives the shared reading (fail open); the log names the types only. - The same gates: the buffered path calls the agent only inside its ok block, the streamed path only when ok. agent/bob copies usagePresent (a library cannot import the proxy). A test fails if the copy accepts an empty block after the real one. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Vitaly Zabershinsky <[email protected]>
The proxy and agent/bob each kept a copy of the rule that says a usage block is there (an object with at least one field). A test guarded the copy in one direction only. The rule is now providerusage.Present, and both use it. docs/design.md names the usage reading in the agent/bob row. Both round-1 reviewers of #1052 raised these 2 points. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Vitaly Zabershinsky <[email protected]>
…nd usage (#1029) A new package, agent/, gives client agents such as IBM Bob one extension point. Bob's session id and usage reading move out of proxy/proxy.go into agent/bob. This folds in #1045 and #1052. - agent/: the Agent interface (Name, Paths, SessionID, ReadUsage), Base (the neutral agent), and a Registry found by route path. The Registry refuses a nil agent, an empty path and a path another agent already claims. - #1045: Bob's session id (X-Task-Id) comes from agent/bob. - #1052: Bob's usage reading comes from agent/bob, through internal/providerusage, which proxy and agent/bob share. Behavior change: none. Each Bob request and reply keeps the same session id, usage numbers, cost and routes; proxy tests pass unchanged. Data dependence: metadata only, the same as before (header values and token counts). Reviews: #1029 2 offload reviews (GLM), round 3 on the folded head, both approve at 3ee169e, which is the PR head. #1045 and #1052 each had 2 approvals (round 2) before the fold. The merge of main had no hand resolution. Signed-off-by: Vitaly Zabershinsky <[email protected]> Signed-off-by: DAVID AMID <[email protected]> Assisted-By: Claude Opus 5.5 <[email protected]>
Summary
This is the first move of step A2: take IBM Bob's code out of the shared
proxy/proxy.go, behind the agent extension point of #1029. This PR moves the session id. The shared session code no longer names Bob orX-Task-Id.What changed
New package
agent/bob:Bobembedsagent.Base. It overridesName("bob", the dashboard label),Paths(Bob's model route,bob.ModelPath) andSessionID(theX-Task-Idheader).var _ agent.Agent = Bob{}is a compile-time check, so a misspelled override cannot hide behindBase.init(), ascomponentsdo.proxyimports it forbob.ModelPath, and that import runs theinit().proxy/proxy.go,explicitSessionOf:SessionIDchanges nothing on its route.agentSessionIDrecovers a panic in the agent, and gives no id. The log names the panic's type only, never its message, because an agent's panic text could hold a header value.bobModelPathis nowbob.ModelPath.Handler.agentFor(defaultagent.ForPath) is the seam that tests use.agent/imports_test.go: the guard now coversagent/bob, which must never import a host.Data dependence
None changed. The session id is still a header value used as a label.
How it was tested
proxy/bobsession_test.gois unchanged and green (9 tests):X-Task-Idon Bob's route; the header and body ids outrank it; it is ignored on other routes; the expand repair is keyed by it.go test -race ./proxy/ ./session/ ./apply/ ./agent/...: OK.go vet,gofmt,go build ./...: OK.agent/bob:Name,Paths,SessionID, and registration in a fresh registry. Each was red against theBasevalues first.SessionIDleaves that route's session unchanged, also when the body carries an id.metadata.taskIdwith noX-Task-Idis still Bob's session.agent/bob.Technical notes
a == agent.Base{}). On every case tested, both give the same session: the body's own ids (metadata.taskId,user_id) are read downstream anyway (sessionIDFrom). The gate on the id is kept because it says the intent directly and does not depend on that downstream read. The do-nothing-agent test guards the result, not the path to it.proxy.go, for the next A2 moves: the route setup, the profile and model-info handling, the usage reading (bob := up.path == bobModelPath), andBobUpstream.