Skip to content

feat(agent): send CG's own model calls on Bob's route to Bob - #1074

Merged
amiddavid merged 11 commits into
mainfrom
feat/agent-bob-model-target
Nov 11, 2026
Merged

amiddavid merged 11 commits into
mainfrom
feat/agent-bob-model-target

Conversation

@vz-ibm

@vz-ibm vz-ibm commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #1029 (which now holds #1045 and #1052). Merge #1029 first. This PR's own change is the one commit feat(agent): send CG's own model calls on Bob's route to Bob.

Behavior change, on IBM Bob's route only. Approved by the repo owner, @vz-ibm, on 2026-11-11.

  • Who: Bob users with a preset that makes model calls (a summary, the sweep). Bob's plugin presets today (off, lossless) make none, so no one is affected by default. It matters for bob-ultrahigh (feat: run the sweep and the LLM parts of ultrahigh on IBM Bob (bob-ultrahigh) #1030 item 3).
  • Old: on Bob's route, Context Guru's own summary call and the sweep's question went to /v1/chat/completions with Bearer. Bob does not serve that path, so the call failed and the request went on unchanged (fail open).
  • New: they go to Bob's model path, /inference/v1/chat/completions, with Authorization: Apikey <the caller's own key>. That is Bob's own server, which already has the conversation.
  • Also new, a security fix on the same route: a Bob request with no key of its own used to fall back to the operator's OpenAI key (--openai-key) for these calls, and so sent that key to Bob's server. Now a route whose agent names its own target makes no model call without the caller's own key. The OpenAI route keeps its fallback.
  • Turn it off: use a preset without model calls.

Summary

This is step A2.4, and #1030 item 4: the incoming model client gets Bob's path and auth. David's #1036 notes that the sweep's question on Bob "still fails open (wrong path and auth) until item 4". This PR is that fix, behind the agent extension point (#1029), with no Bob code in the shared path.

What changed

agent: a new method, ModelTarget() ModelTarget.

  • ModelTarget holds the chat Path and the AuthScheme of the host's own calls to the route's model.
  • Base returns the zero target. A zero field means the host default (/v1/chat/completions, Bearer), so every other route is unchanged.
  • The agent never sees the key. The host builds the header.

agent/bob: Bob.ModelTarget returns {bob.ModelPath, "Apikey"}.

cheapmodel: OpenAI gets a Path field (empty means /v1/chat/completions). Complete (the summary call) and CompletePrefixedChat (the sweep's question, #1036) both post to it.

proxy:

  • incomingModel asks the route's agent for its target. chatPrefixAsker copies that client, so the sweep's question gets the same target.
  • Fail open: agentModelTarget recovers a panic and gives the defaults. The log names the types only.
  • No operator key on an agent's own target. When the agent names a target, the host does not fall back to the operator's OpenAI key. Before, a Bob request with no caller key sent that key to Bob's server.
  • A bad target is ignored, field by field, with a Warn log (the agent type and the field name, never the value): a path that is not absolute, starts with //, or holds a space, a control character, ? or #; a scheme that is not one HTTP token.

Data dependence

No component sends or stores anything new. On Bob's route, the summary call and the sweep's question now reach Bob's own server, with the caller's own key, and no other place. docs/data-dependence.md has a new row for this, under "Features outside the pipeline". Decided by: Vitaly Zabershinsky.

How it was tested

  • go test -race on ./proxy/ ./agent/... ./cheapmodel/ ./components/... ./apply/: OK (proxy 576 s). go vet ./..., gofmt, go build ./...: OK.
  • New tests, each red first (they failed to compile, because ModelTarget and Path did not exist):
    • agent: Base.ModelTarget is the zero target. agent/bob: Bob's target is its model path with Apikey.
    • cheapmodel: Complete and CompletePrefixedChat post to Path, and to /v1/chat/completions when it is empty.
    • proxy, end to end with a fake upstream:
      • on Bob's route, the summary call goes to Bob's model path, with Apikey <caller key> and the request's own model;
      • on the OpenAI route, it keeps /v1/chat/completions and Bearer;
      • an agent whose ModelTarget panics: the request succeeds, the call keeps the defaults, and the panic text is not in the log;
      • 7 bad targets (relative path, //host path, ?, #, a space in the path, a scheme with a space, a scheme with a line break) keep the defaults, and each is logged;
      • on Bob's route with no caller key and an operator OpenAI key: no summary call, and no request to Bob carries that key (this test was red first: the key reached Bob);
      • the OpenAI route still falls back to the operator's key.
  • Mutant checks. Each change below made its test fail; the code was then restored:
    • Bob without its override;
    • no validation of the target;
    • no recover;
    • no ? and # check.

Technical notes

  • Not tested end to end: the sweep's question on Bob's route. It uses the same incoming client (models.Incoming) as the summary call, and CompletePrefixedChat is tested on Path.
  • Not in this PR, and found on main: a Context Guru token of the wrong length in an auth header can become the key of a summary call on any route. CallerKey skips only a token of the exact shape. The forwarded request removes the token, but the summary call does not. The fix is a small, separate PR, because it changes an edge case on every route.
  • Bob code still in the shared proxy: the route setup, BobUpstream, and the backend label (feat(proxy): label each Bob reply with the IBM backend that served it #975, not merged yet).

vz-ibm and others added 8 commits November 10, 2026 11:34
Per-agent behavior (IBM Bob today) sits in if-branches on the route
inside the shared proxy.go, and each new feature adds one. The agent
package is the one extension point: an Agent interface, a neutral Base
that gives today's behavior, and a registry by route path. A new agent
is one package that embeds Base and overrides only what differs.

This adds the package only. No existing file changes, and nothing in
the running proxy behaves differently. A test enforces that agent never
imports a host package (proxy, proxyapp, cmd).

The interface holds what the next step wires: Name, Paths, SessionID
and ReadUsage. A method is added when its first caller is; Base keeps
that safe for every agent.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Vitaly Zabershinsky <[email protected]>
The package doc said the guard enforces "a host (the proxy, the bifrost
adapter) never" imports agent, but it checked only proxy, proxyapp and
cmd. It now checks adapters too; a probe that imports adapters/bifrost
fails it.

Register calls the agent's Name and Paths before it takes the lock, so
an agent method that calls back into the registry cannot deadlock it.
Paths() documents the exact match. docs/design.md lists agent/.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Vitaly Zabershinsky <[email protected]>
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]>
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]>
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]>
The agent interface gets ModelTarget: the chat path and the auth
scheme of the host's own calls to the route's model (a summary, the
sweep's question). Base returns the zero target, so every other route
keeps /v1/chat/completions and Bearer. Bob returns its model path and
Apikey. The agent never sees the key; the host builds the header.

- cheapmodel.OpenAI gets a Path field. Complete and
  CompletePrefixedChat both post to it.
- The host recovers a panic in ModelTarget and drops a path or a
  scheme it cannot use safely, so that field keeps the default.
- docs: a data-dependence row and the agent/bob design row.

Behavior change, on Bob's route only: these calls used to fail there
(a path Bob does not serve), and now reach Bob's own server with the
caller's own key.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Vitaly Zabershinsky <[email protected]>

@vz-ibm vz-ibm left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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 2e69d0e175d4 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

  • Merge gates, not code defects. The PR names a behavior change on Bob's route. CLAUDE.md requires a human developer's yes before merge. The new docs/data-dependence.md row has no "Decided by" yet. Both must be closed before merge.
  • agent/bob/bob.go:53 — the scheme is always Apikey, whatever the caller sent. The forwarded chat request keeps the caller's own Authorization header unchanged. The side call replaces its scheme with Apikey. Two cases differ:
    • A Bob client that sends Bearer <key> or a bare key. tenancy.go:245 documents Apikey for BobShell only. I found no evidence in the repo for what the Bob IDE sends. If it differs, the side call gets a 401 and fails open, so no harm, but no saving.
    • A caller whose key arrives in x-api-key (CallerKey checks it second). The side call sends it as Authorization: Apikey <key>.
    • Proposal: add a line on what the Bob IDE sends (a capture, #975), or note this as known.
  • proxy/proxy.go:1095-1107 — pre-existing: the operator's OpenAI key can go to Bob's host. In single-tenant mode, a Bob request with no caller key makes key = h.serverKey(h.opts.OpenAIKey). The side call then goes to BobUpstream with that key. Before this PR it went there too, with Bearer, to /v1/chat/completions. Now it goes as Apikey to Bob's model path. This PR does not make it worse, but the key of one provider still goes to another provider's host. Proposal (separate PR): do not fall back to OpenAIKey when the route's upstream is not the OpenAI upstream.
  • proxy/agentmodel.go:24-29 — a dropped field is silent. A panic logs. A bad path or scheme is dropped with no log. A developer of a new agent then sees only a non-200 from the upstream. A Warn with the agent type and the field name (not the value) would help.
  • proxy/agentmodel_test.go:192 and :215 — the failure message can panic. strings.Fields(got.auth)[0] panics with an index error when got.auth is empty. That only happens on a failing test, but it hides the real failure message.
  • Not tested end to end: the sweep's question on Bob's route (the PR says so). The trace holds: chatPrefixAsker (prefixask.go:418-424) copies models.Incoming, which incomingModel built with Path: target.Path and the Apikey header. CompletePrefixedChat posts to o.chatPath(). So the ask gets the same target as the summary.

What I checked

  • Every changed line of the one commit (14 files, +385/-11), and the commit message and PR body.
  • agent/agent.go: the new interface method. All agents in the repo embed Base (Bob, the test agents in proxy/agent*_test.go), so the new method breaks none. The package doc tells a new agent to embed Base. No other host (bifrost adapter, proxyapp, cmd/) implements agent.Agent.
  • cheapmodel/openai.go: chatPath() keeps /v1/chat/completions for an empty Path. AsModel and WithMaxTokens copy the struct, so Path stays. CompletePrefixedResponses keeps /v1/responses, which is correct (Bob is a Chat wire). dispatcher.go:120 (the configured model) sets no Path, so it keeps the default.
  • proxy/proxy.go incomingModel:
    • h.agentFor(up.path): the OpenAI route has up.path /v1/chat/completions and gets Base; only the Bob route has bob.ModelPath.
    • Hosted mode with a key_env on the Bob upstream: key becomes "" and serverKey returns "" in hosted mode, so no client. Same as before.
    • Without key_env: the caller's key, found by headerCredential, which accepts Apikey <key>. The main request forwards that same header, so both exits agree.
    • The Anthropic branch is unchanged.
  • Dispatcher.incoming masks the whole header value and its dedup key covers the full header, so the new Apikey header is held and masked the same way as Bearer.
  • Dispatcher.Do builds the URL as TrimRight(up.base, "/") + req.Path. safeTargetPath rejects a relative path, //host, control characters, space, ? and #. So a target cannot change the host. httpToken matches the RFC 9110 token set, so a scheme cannot add a header.
  • Fail open: agentModelTarget recovers a panic and returns the zero target. It logs only the types, the same pattern as agentusage.go and the session-id recovery.
  • Tests: the helpers they use exist (bigToolOutput, captureDefaultLog, panicCanary). h.agentFor is read per request, so the test override works. The Bob test asserts path, model and the exact auth header. The OpenAI test asserts the default. The 4 bad-target cases and the panic case assert the default and that the panic text is not logged. I did not run them (live tests not approved; Go is not installed).
  • docs/data-dependence.md: the row has 6 cells, as the table needs, and sits in "Features outside the pipeline". docs/design.md: the agent/bob/ row is updated.

@vz-ibm vz-ibm left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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 2e69d0e175d4 approve

Verdict: approve

Findings

None. I found no defect in the change.

Non-blocking

  • Merge gates are still open. The PR is a behavior change on Bob's route, and the new row in docs/data-dependence.md has no "Decided by". Both need a human developer's yes before merge (CLAUDE.md). The PR says this at the top. This is a reminder, not a code defect.
  • Pre-existing: the operator's OpenAI key can reach Bob's host. In proxy/proxy.go:1094-1110, a Bob request with no caller key of its own (or only a token-shaped one) falls back to h.serverKey(h.opts.OpenAIKey). In single-tenant mode with --openai-key and BobUpstream set, the summary call then sends the operator's OpenAI key to Bob's upstream. Before this PR it went as Bearer. Now it goes as Apikey. This PR does not cause it, but it now gives that call a working path. Suggest a follow-up: no server-key fallback on a route whose agent names its own target, or no fallback on the Bob route. It is the same family as the token-length issue in the PR's Technical notes.
  • Path validation has no test for ?, #, a space or a control character. safeTargetPath (proxy/agentmodel.go:35-40) rejects them, but TestMalformedAgentModelTargetKeepsTheHostDefault covers only the relative path and //host. Two more table rows (/x?y, /x#y) would pin the rest. Without the check, a ? or # would change the URL's query or fragment, and a mutant that drops only that part of the check would pass the suite.
  • The sweep's question on Bob's route has no end-to-end test. The PR says so. The chain is short and I traced it: chatPrefixAsker copies models.Incoming (proxy/prefixask.go:417-423), and the copy keeps Path and Ref. AsModel and WithMaxTokens copy the struct too (cheapmodel/openai.go:41,45), so a remodeled client keeps the target.
  • Test failure messages can panic. In proxy/agentmodel_test.go, strings.Fields(got.auth)[0] panics when got.auth is empty. It happens only on a failing run, but it hides the real message.

What I checked

  • Read the full diff (14 files) and the one commit. DCO sign-off and Assisted-By are present.
  • agent.Agent gains ModelTarget. Every implementer embeds Base or defines it: Bob, and the test agents in agent/registry_test.go, proxy/agentsession_test.go, proxy/agentusage_test.go, proxy/agentmodel_test.go. No other implementer exists in the repo.
  • agent.ForPath returns Base{} for an unknown path, never nil (agent/registry.go:50-57). So non-Bob routes get the zero target and do not hit the recover path on every request.
  • incomingModel (proxy/proxy.go:1067-1112): the zero target keeps AuthHeader(OpenAI, key, "") = Bearer. A set scheme builds Authorization: <scheme> <key>. The Anthropic branch is unchanged.
  • Hosted mode: the Bob route gets an injecting upstream, so key becomes "", serverKey returns "", and incomingModel returns nil. No change there.
  • Dispatcher.Do (proxy/dispatcher.go:252-320) builds the URL as TrimRight(base, "/") + req.Path. safeTargetPath blocks //host and query/fragment, so the call stays on the route's own upstream. incomingDedupKey hashes the auth header, so Apikey and Bearer refs do not share an entry.
  • httpToken matches the RFC 9110 tchar set. CR, LF and space are rejected.
  • Fail open: agentModelTarget recovers a panic, returns the zero target, and logs only %T of the agent and the panic value. The test checks the canary is absent from the log.
  • cheapmodel.OpenAI: every Chat call goes through post or CompletePrefixedChat, and both now use chatPath(). CompletePrefixedResponses keeps /v1/responses. Bob uses the Chat wire, so that is correct. proxy/dispatcher.go:120 (the configured model) leaves Path empty, so it keeps /v1/chat/completions.
  • CallerKey reads Apikey <key> through headerCredential (two fields → the second), so Bob's caller key reaches the summary call.
  • Tests: Bob route → Bob path, Apikey <caller key>, the request's own model. OpenAI route → unchanged. Panic → defaults. Four bad targets → defaults. The Bob test relies on the default registry, which proxy fills through its import of agent/bob (bobModelPath = bob.ModelPath).
  • Docs: docs/design.md and docs/data-dependence.md are updated. The new row is in "Features outside the pipeline", so components/all/datadep_test.go is not affected.
  • I did not run Go builds or tests (not approved for this review).

A Bob request with no key of its own fell back to the operator's
OpenAI key for CG's own model calls, and so sent that key to Bob's
server. A route whose agent names its own target now gets the
caller's key or no model call. The OpenAI route keeps its fallback.

- A target field the host drops is logged at Warn: the agent type and
  the field name, never the value.
- Tests: the query, fragment and space path rows; failure messages
  that cannot panic on an empty auth header.
- docs: the data-dependence row says so, and names who decided.

Both round-1 reviewers of #1074 raised these points.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Vitaly Zabershinsky <[email protected]>
@vz-ibm

vz-ibm commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

Round 1 replies. Both reviewers approve. Fixed in 4af5098:

  1. Merge gates (both reviewers): closed. The repo owner (@vz-ibm) approved the behavior change on 2026-11-11, and is the "Decided by" of the new data-dependence row. The PR's top note says so.
  2. The operator's OpenAI key can reach Bob's host (both reviewers): fixed here. It was a leak before this PR, and this PR gave that call a working path. A new test was red first: with --openai-key set and no caller key, a summary call to Bob's upstream carried the operator's key. Now a route whose agent names its own target gets the caller's key or no model call. A second test shows the OpenAI route keeps its fallback. The data-dependence row says so.
  3. Path checks without tests (reviewer 2): fixed. New rows for ?, # and a space. A mutant without the ? and # check now fails 2 rows.
  4. A dropped field is silent (reviewer 1): fixed. A Warn log names the agent type and the field (path or auth_scheme), never the value. The malformed-target test checks it for each row.
  5. The failure message can panic (both reviewers): fixed. A helper prints the scheme word only, or "".
  6. The scheme is always Apikey (reviewer 1): no change. The Bob IDE sends Authorization: Apikey <key>, as Bob Shell does. We saw that in live captures of Bob IDE traffic. A Bob client that sends another scheme gets a non-200 on this call, and the request goes on unchanged (fail open).
  7. Not tested end to end: the sweep's question on Bob (both reviewers): no change. Both traces agree with the PR's note.

Checks: go test -race ./proxy/ ./agent/... ./cheapmodel/ ./components/all/ OK (proxy 565 s). go vet ./... OK.

@vz-ibm vz-ibm left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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 4af50983d0d4 approve

Verdict: approve

Findings

None. The new commit fixes the round-1 points correctly, and I found no new defect.

Round-1 points, one by one

Both reviewers approved in round 1. All points were non-blocking.

# Point Raised by Status
1 Merge gates: human yes, "Decided by" 1, 2 Fixed. The owner's reply (2026-11-11T08:09) gives the yes. The row now says "Decided by: Vitaly Zabershinsky, #1074".
2 Operator's OpenAI key can reach Bob's host 1, 2 Fixed. proxy.go falls back to OpenAIKey only when the target is zero. New test TestBobRouteNeverSendsTheOperatorsOpenAIKey checks every upstream call for the canary. TestOpenAIRouteStillFallsBackToTheOperatorsKey pins the old fallback.
3 No tests for ?, #, space in the path 2 Fixed. 3 new table rows.
4 A dropped field is silent 1 Fixed. dropTargetField logs at Warn with the agent type and the field name, not the value. The test checks field=path or field=auth_scheme for each row.
5 Failure message can panic 1, 2 Fixed. authScheme returns "" for an empty value.
6 Scheme is always Apikey 1 Rejected, and I accept the reason. The author says live captures show the Bob IDE sends Apikey <key>, as Bob Shell does. I cannot see those captures. A client with another scheme gets a non-200 and fails open, so the risk is only a lost saving.
7 Sweep's question on Bob not tested end to end 1, 2 No change, accepted. Both traces agree.

Non-blocking

  • proxy/proxy.go:1098-1101 — the key rule reads the target after the checks. agentModelTarget returns the zero target when the agent panics, or when it drops both fields. Then target == (agent.ModelTarget{}) is true, and the operator's OpenAIKey fallback comes back on that agent's route. Today no real case exists: Bob does not panic, and its target is valid. A future agent with a bad target would, in single-tenant mode, send the operator's key to its own upstream, at /v1/chat/completions. Proposal: decide on the upstream, not the target (for example up.base == h.opts.OpenAIUpstream), or on whether the route has an agent other than Base. A follow-up is enough.
  • The fix is a small behavior change of its own. On Bob's route with no caller key, the old code made a call with the operator's key (it failed at Bob). The new code makes no call. The owner approved it, and the data-dependence row says so. I note it only so the PR's top note can name it too.

What I checked

  • Last review: round 1, 2e69d0e175d49e56c95b5c0671488c6df079f2f1, 2026-11-11T07:56:08Z
  • New commits read: 1 — 4af50983 fix(agent): never send the operator's OpenAI key to an agent's target (4 files, +76/-10)
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
  • New items since my last review:
    • Reviewer 2's round-1 review (07:56:17Z): I read it. Its points are 1, 2, 3, 5, 7 in the table above. I checked each fix.
    • The author's reply (08:09:01Z): I checked each of its 7 items against the diff. See the table.
  • proxy/proxy.go incomingModel: the target is now computed before the key fallback. Hosted mode is unchanged (serverKey returns "" there). The Anthropic branch is unchanged. The OpenAI route's agent is Base, so its target is zero and the fallback stays.
  • proxy/agentmodel.go: an empty field is no longer "dropped", so Base does not log a Warn on every request. Only a non-empty bad field logs. The log has the type and field name only.
  • proxy/agentmodel_test.go:
    • postSummarizable sets no Authorization header when auth is "". The new tests use that.
    • captureDefaultLog uses a text handler, so field=path is the real output form. Subtests do not run in parallel, so swapping the default logger is safe.
    • The Bob canary test checks both the header and the body of every call, and also expects 0 summary calls.
  • docs/data-dependence.md: the row keeps 6 cells and adds the key rule and "Decided by".
  • I did not run Go builds or tests (not approved for this review). The author reports go test -race and go vet OK.

@vz-ibm vz-ibm left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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 4af50983d0d4 approve

Verdict: approve

Findings

None. The new commit fixes the round-1 points, and I found no new defect.

Status of round-1 points

Neither reviewer had a blocking finding in round 1. These are the non-blocking points:

  • Merge gates (both reviewers): closed. The PR's top note and the author's comment say the repo owner approved the behavior change on 2026-11-11. The data-dependence row now has Decided by: Vitaly Zabershinsky, #1074. I cannot check the approval myself. The PR author's account posted it, and only a human can confirm it.
  • Operator's OpenAI key to Bob's host (both): fixed. proxy/proxy.go:1101 uses the operator's key only when the target is zero. TestBobRouteNeverSendsTheOperatorsOpenAIKey sends a canary key and checks that no upstream request carries it, in a header or in the body. TestOpenAIRouteStillFallsBackToTheOperatorsKey shows that the OpenAI route keeps its fallback.
  • No tests for the ? and # path checks (mine): fixed. There are new rows for ?, # and a space.
  • No log when a field is dropped (reviewer 1): fixed. dropTargetField logs at Warn with the agent type and the field name only. Each malformed-target row checks for the log and its field= value.
  • Failure message can panic (both): fixed. The authScheme helper returns "" for an empty header.
  • The scheme is always Apikey (reviewer 1): the author rejected it. The reason is live captures of Bob IDE traffic. I accept it: a wrong scheme only gives a non-200, and the request goes on unchanged (fail open).
  • No end-to-end test of the sweep's question on Bob (both): no change, accepted. Both traces agree.

Non-blocking

  • The key rule uses the target after it is cleaned, not the route. At proxy/proxy.go:1098-1101, the target is zero in two more cases: the agent's ModelTarget panics, or the host drops every field. Then a route that an agent owns falls back to the operator's OpenAI key again, with Bearer, on that route's upstream. No agent in the repo does this today: Bob returns a fixed, valid target. But the data-dependence row says "Such a route never uses the operator's OpenAI key", and it is true only while the agent behaves. A stronger rule: use the operator's key only when h.agentFor(up.path) is the neutral agent, or when the upstream is the OpenAI upstream. A follow-up is enough.
  • The doc comment of incomingModel (proxy/proxy.go:1043-1066) does not yet say that an agent route gets no server-key fallback. A one-line note there would keep that comment correct.

What I checked

  • Last review: round 1, 2e69d0e, 2026-11-11T07:56:17Z
  • New commits read: 1 (4af50983 fix(agent): never send the operator's OpenAI key to an agent's target)
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
  • New items since my last review:
    • Commit 4af50983: I read all 4 files and the code around each change (see below).
    • The author's comment at 08:09:01Z, with replies 1-7: I checked each reply against the code above.
    • The changed PR body top note (approval and the key fix): I noted that I cannot check the approval.
    • Reviewer 1's round-1 review (07:56:08Z, posted before mine, read now): I checked its points above. I do not repeat them.
  • incomingModel: the code now calls agentModelTarget before the key check, so it runs once for every OpenAI-wire request. It is cheap and cannot fail the request. The Anthropic branch and hosted mode do not change: serverKey still returns "" when tenants are set.
  • agentModelTarget: an empty field now skips the check, so the zero target does not log a Warn on every request. This is correct, because before the fix safeTargetPath("") and httpToken("") were false, and that is why the new != "" guards are needed for the log.
  • Tests: in postSummarizable, auth == "" sends no Authorization header, so CallerKey returns "". That is the no-key case the new tests need. The malformed-target subtests run one after the other, so captureDefaultLog swaps the default logger safely.
  • docs/data-dependence.md: the row text agrees with the code, with the gap that the first non-blocking point describes.
  • I did not run Go builds or tests (not approved for this review).

The key rule read the target after the host cleaned it. An agent whose
ModelTarget panicked, or whose fields were all dropped, gave the zero
target, and its route fell back to the operator's OpenAI key again.
agentModelTarget now also reports whether the agent owns its route's
auth: it named a target, or it panicked. An owned route gets the
caller's key or no model call.

Both round-2 reviewers of #1074 raised this point.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Vitaly Zabershinsky <[email protected]>
@vz-ibm

vz-ibm commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

Round 2 replies. Both reviewers approve. Fixed in b94582a:

  1. The key rule reads the cleaned target (both reviewers): fixed. A new test was red first, in 2 cases: an agent whose ModelTarget panics, and an agent whose fields are all dropped. In both, a summary call on the agent's route carried the operator's OpenAI key. agentModelTarget now also returns owned: the agent named a target (even one the host drops), or it panicked. An owned route gets the caller's key or no model call. So the data-dependence row's "never" holds when the agent misbehaves too.
  2. The incomingModel doc comment (reviewer 2): fixed. It now says that a route whose agent owns its auth never gets the server-held OpenAI key.
  3. The fix is a small behavior change (reviewer 1): named. The PR's top note already names it ("Also new, a security fix on the same route"). The owner approved it.

The repo owner granted 1 more review round (round 3) for this fix.

Checks: go test -race ./proxy/ ./agent/... ./cheapmodel/ ./components/all/ OK (proxy 567 s). go vet ./... OK.

@vz-ibm vz-ibm left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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 3 of 3 b94582ab2001 approve

Verdict: approve

Findings

None. The new commit closes the round-2 gap, and I found no new defect.

Round-2 points, one by one

Both reviewers approved in round 2. All points were non-blocking.

# Point Raised by Status
1 The key rule reads the cleaned target, so a panicking agent or an agent with only bad fields gets the operator's key again 1, 2 Fixed. agentModelTarget returns owned. It is true when the raw target is not zero, and the recover sets it true on a panic. incomingModel uses the operator's key only when !owned.
2 The incomingModel doc comment does not state the rule 2 Fixed. proxy.go:1065-1066 states it.
3 The fix is a small behavior change of its own 1 Named. The author says the PR's top note names it, and the owner approved it.

Non-blocking

  • owned means "the agent named a target", not "this is not the OpenAI upstream". A future agent on a non-OpenAI upstream that keeps the zero target (it needs only Base's path and Bearer) still gets the operator's OpenAI key. No such agent exists today: Bob names a target. The doc comment at agentmodel.go:15-17 says what owned means, so the rule is clear to the next agent author. A follow-up can add a check on the upstream if one comes.

What I checked

  • Last review: round 2, 4af50983d0d470d6758b7a2006c7a3fca10445df, 2026-11-11T08:10:18Z
  • New commits read: 1 — b94582ab fix(agent): a misbehaving agent's route gets no operator key either (3 files, +47/-7)
  • Read in full: 4 reviews, 2 comments, 0 inline comments (from the three files)
  • New items since my last review:
    • Reviewer 2's round-2 review (08:10:29Z): I read it. Its two points are 1 and 2 in the table. I checked both fixes in the code.
    • The author's round-2 reply (08:39:05Z), items 1-3: I checked each against the diff. It also says the owner granted round 3. I cannot check that grant; the author's account posted it.
    • Commit b94582ab: see below.
  • proxy/agentmodel.go:
    • owned is set from the raw target before the field checks, so a target with only bad fields still counts as owned.
    • On a panic, the deferred recover sets t, owned = zero, true. The named results carry it out. So a panic fails closed for the key and fails open for the call target.
    • Base returns the zero target, so owned is false and the OpenAI route keeps its fallback.
  • proxy/proxy.go incomingModel: the rule is key == "" && !owned. Hosted mode is unchanged (serverKey returns ""). The Anthropic branch is unchanged.
  • proxy/agentmodel_test.go TestAMisbehavingAgentRouteNeverSendsTheOperatorsOpenAIKey:
    • On the OpenAI route with OpenAIKey set, bearerKey gives a non-nil setKey (proxy.go:994-998). So key becomes "" and the test reaches the fallback branch. That is the case under test.
    • The main chat request legitimately carries the operator's key to this upstream. The test checks only the summary calls (got), so it does not fail on that request. It checks both that no summary call carries the key and that there are 0 summary calls.
    • The two cases (a panic, and both fields bad) cover both ways owned is true while the target is zero.
  • I did not run Go builds or tests (not approved for this review). The author reports go test -race and go vet OK.

@vz-ibm vz-ibm left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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 3 of 3 b94582ab2001 approve

Verdict: approve

Findings

None. The new commit fixes the round-2 points, and I found no new defect.

Status of round-2 points

Both reviewers approved in round 2. All points were non-blocking.

  • The key rule reads the target after it is cleaned (both reviewers): fixed. agentModelTarget now also returns owned.
    • owned is true when the agent named a target. A target that the host then drops still counts (proxy/agentmodel.go:28).
    • owned is also true when ModelTarget panics. The deferred recover sets it (proxy/agentmodel.go:24).
    • incomingModel uses the operator's key only when !owned (proxy/proxy.go:1104).
    • TestAMisbehavingAgentRouteNeverSendsTheOperatorsOpenAIKey covers both cases. It checks for the canary key, and it checks that 0 summary calls go out.
  • The incomingModel doc comment (mine): fixed. It now says that a route whose agent owns its auth never gets the server-held OpenAI key (proxy/proxy.go:1065-1066).
  • The key fix is a small behavior change (reviewer 1): named. The PR's top note names it, and the author's reply says the owner approved it. Only a human can confirm that approval. I cannot check it from the PR.

Non-blocking

  • The new test checks for the canary key only in the summary calls (got), not in every upstream call. TestBobRouteNeverSendsTheOperatorsOpenAIKey checks every call. This is enough here, because the test also needs len(got) == 0. A summary call that leaked the key would also fail that check.

What I checked

  • Last review: round 2, 4af5098, 2026-11-11T08:10:29Z
  • New commits read: 1 (b94582ab fix(agent): a misbehaving agent's route gets no operator key either)
  • Read in full: 4 reviews, 2 comments, 0 inline comments (from the three files)
  • New items since my last review:
    • Commit b94582ab: I read all 3 files and the code around each change (see below).
    • Reviewer 1's round-2 review (08:10:18Z): its key-rule point is the same as mine, and the new commit fixes it. I checked its behavior-change point above.
    • The author's reply at 08:39:05Z (items 1-3, and the extra round 3 that the owner granted): I checked each item against the diff.
  • agentModelTarget:
    • owned is computed from the raw target, before the checks, so a dropped field still counts as owned.
    • On a panic, owned = t != ... never runs, and the deferred function sets owned to true and t to the zero target.
    • Base returns the zero target, so the neutral agent is not owned. The OpenAI route keeps its fallback, and TestOpenAIRouteStillFallsBackToTheOperatorsKey still covers that.
  • incomingModel:
    • owned is used only for the server-key fallback.
    • A caller's own key still works on an owned route. TestPanickingAgentModelTargetFailsOpenToTheHostDefault sends a caller key, and it still expects one summary call with the default path and auth.
    • Hosted mode and the Anthropic branch do not change.
  • Fail open: a misbehaving agent's route without a caller key now gets no model client. The component falls back to its rule-based path, and the request still goes out. It fails closed for the key only, which is the right direction.
  • I did not run Go builds or tests (not approved for this review). The author reports that go test -race and go vet pass.

Hand resolutions: agent/ files keep the branch side (identical to main
plus #1074's change); docs/design.md keeps the agent/bob row with ModelTarget.

Assisted-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid
amiddavid changed the base branch from feat/agent-extension-point to main November 11, 2026 13:28
@amiddavid

Copy link
Copy Markdown
Collaborator

Integrator note: the integrator merged origin/main into this PR (423936e) and retargeted it to main, because #1029 is merged. The owner asked for this on 2026-11-11.

  • The merge resolved 5 files by hand: 4 add/add conflicts in agent/ (main holds feat(agent): an extension point for client agents #1029 squashed) and the agent/bob/ row in docs/design.md. Each one keeps the branch side.
  • The PR's own change is unchanged. The added and removed lines of git diff origin/main...423936e4 are identical to git diff 3ee169ef b94582ab, the change round 3 approved: 14 files, +492/-12. approval-still-valid.sh prints CHANGED only because the base moved under the hunks' context lines.
  • On the box: go build and go vet are clean. -race passes for ./agent/..., ./internal/providerusage/..., ./cheapmodel/... and both halves of ./proxy/....

@amiddavid
amiddavid merged commit 202087d into main Nov 11, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 11, 2026
amiddavid added a commit that referenced this pull request Nov 11, 2026
#1074 and #1068 added rows to docs/data-dependence.md after this branch.
They are now files under docs/data-dependence/features/, and the page is
rebuilt by the generator. Both tables equal main's tables.

Assisted-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
amiddavid added a commit that referenced this pull request Nov 11, 2026
…ce.md (#1090)

docs/data-dependence.md is now built from one file per row, so two
PRs that change different rows never edit the same source file.

- Row files: docs/data-dependence/components/<name>.md (24, the file
  name is the component name) and docs/data-dependence/features/
  <slug>.md (28 + 2 new from #1068 and #1074). key: value lines between
  two --- lines, then the reason as the body. An optional order number
  keeps the page order.
- The page text lives in docs/data-dependence/page.md.tmpl.
- cmd/gen-datadep (parser in internal/datadep) writes the page; make
  datadep runs it. The page stays checked in (owner's choice).
- A drift test fails when the page is out of date, and names the
  command. components/all/datadep_test.go keeps every guard on the row
  files: a registered component without a file, a file for an unknown
  or misspelt component, a missing reason.
- On a conflict in the generated page: take either side and re-run the
  generator. RELEASING.md says this is not a hand resolution.
- CLAUDE.md, RELEASING.md, the PR template and the offload-review
  reviewer prompt describe the new process.

Behavior change: none (docs, tests, a generator). Data dependence:
none; the rows' content is unchanged.

Closes #1088.

Reviews: 2 offload reviews (GLM), round 2, both approve at 98d6383,
which is the PR head.

Signed-off-by: DAVID AMID <[email protected]>
Assisted-By: Claude Opus 5.5 <[email protected]>
amiddavid pushed a commit that referenced this pull request Nov 11, 2026
…fault (#973)

The Bob plugin replaces its lossless-defer preset with bob-ultrahigh,
and bob-ultrahigh becomes the default Bob preset. bob-ultrahigh is
context-guru's ultrahigh preset with 4 Bob changes; a test pins that it
cannot drift from ultrahigh. It keeps the tool deferral (-17.7% input
per turn on real Bob tasks). Since #1074, its summary calls reach Bob's
/inference/v1/chat/completions with the user's own key and quota.

setup --plan names what the default does before the user agrees: it
stores content on the Mac (originals, summaries and held answers), sends
summary calls to Bob with the user's own key and quota, and uses Bob's
flat prices on the dashboard. It says how to choose lossless.

Behavior change: every new Bob install. Old: the default preset was
lossless. New: bob-ultrahigh. Turn it off: configure --preset lossless.
Owner's yes, 2026-11-11, in the integrator session: "there are no bob
users and bob-ultrahigh is the new default", then "bob-ultrahigh".

Data dependence changes: the default Bob install now keeps stored
content on the user's Mac. Owner's confirmation, 2026-11-11: "1 okey.
this happens on ultrahigh as well afaik". Rows:
docs/data-dependence/features/bob-plugin.md and components/toolfilter.md.

Reviews: 6 offload review rounds (Claude backend; round 6 after the
default change). Round 5: both approve at 81dba55. Round 6 blocked on
two points: a setup release check for a proxy older than v0.7.2, which
the owner ruled moot on 2026-11-12 ("there is no older proxy for bob
this is moot point"), and a missing human yes on the PR, answered by
the integrator's comment with the owner's quotes. 1dbbe6a has the
same tree as 1bdf248 (a clean merge of main into 971deb1).

Signed-off-by: Vitaly Zabershinsky <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
Assisted-By: Claude Opus 5.5 <[email protected]>
amiddavid pushed a commit that referenced this pull request Nov 12, 2026
…ts (#1112)

The agentmodel tests (from #1074) now wait for the detached summary
call before they count the upstream's calls, with a time limit. Since
#1073 the summary call runs off the request path, so a fixed check
raced it and failed now and then in CI
(TestOpenAISummaryCallTargetIsUnchanged,
TestMalformedAgentModelTargetKeepsTheHostDefault). Test only.

Behavior change: none. Data dependence: none.

Fixes #1110.

Reviews: 2 offload review rounds (Claude backend). Round 2: both
approve at 0b3a6a0, which is the PR head.

Signed-off-by: Vitaly Zabershinsky <[email protected]>
Assisted-By: Claude Opus 5.5 <[email protected]>
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