Skip to content

feat(agent): an extension point for client agents - #1029

Merged
amiddavid merged 7 commits into
mainfrom
feat/agent-extension-point
Nov 11, 2026
Merged

amiddavid merged 7 commits into
mainfrom
feat/agent-extension-point

Conversation

@vz-ibm

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

Copy link
Copy Markdown
Collaborator

No behavior change. This PR adds the agent/ extension point (A1). It also holds the first two moves of step A2: Bob's session id (#1045) and Bob's usage reading (#1052). #1045 and #1052 are folded in and closed as merged.

What keeps it true:

  • proxy/bobsession_test.go (9 tests) is unchanged and green.
  • proxy/bobusage_test.go is byte-identical and green. Five of its tests go through a test-only shim, proxy/bobusage_shim_test.go.
  • A route with no agent override keeps today's session and usage. agent.Base returns its input unchanged; a test checks every field.
  • Both moves fail open. A panic in an agent gives the shared session and the shared usage reading.
  • Merging main (26 commits) needed no hand resolution. main made no non-test change to Bob code. Its proxy/ edits (usage: a streamed litellm Anthropic response double-counts cache_read in billed input #745 usage tiers, feat: run the sweep and the LLM parts of ultrahigh on IBM Bob (bob-ultrahigh) #1030 chat prefix ask, savings cap, compaction point) touch lines the stack did not.
  • Box run on the merged head: go vet ./..., CGO_ENABLED=0 go build, -tags cg_record build, and -race on ./agent/... ./internal/providerusage/... ./bob-plugin/... and on ./proxy/... (both halves) all pass.

Data dependence: metadata only, as before. The session id is a header value used as a label. Usage is token counts. At each storage level (off, metadata only, everything) the code behaves the same. docs/data-dependence.md needs no change.

Folded-in PRs

Bob code still in proxy.go, for the next A2 moves: the route setup, the profile and model-info handling, the backend label (#975), the summary-call route, and BobUpstream.


Original text by the author:

Summary

This PR adds agent/, one extension point for client agents such as IBM Bob. Today, per-agent behavior sits in if up.path == bobModelPath branches inside the shared proxy/proxy.go, and each new feature adds another. With agent/, a new agent is one package that embeds Base, overrides only what differs, and registers its routes. The shared code never names an agent.

This is step A1. The next step (A2) moves Bob's existing branches out of proxy.go and behind this interface, one at a time.

What we found

Bob-specific branches inside the shared proxy/proxy.go on main:

  • the route setup in Mux;
  • explicitSessionOf, which reads X-Task-Id;
  • bob := up.path == bobModelPath in serve;
  • bobResponseUsage on 2 reply paths;
  • forwardBobProfile.

More agents like Bob are expected. Each would add a branch in each of these places, so the shared code would change for every new agent.

What changed

  • agent/agent.go: the Agent interface, and Base, the neutral agent.

    Method What it gives the shared code Base (today's behavior)
    Name() The dashboard label ""
    Paths() The model routes the agent owns nil
    SessionID(h) A session id from an agent-only header, tried last ""
    ReadUsage(ct, reply, base) The agent's own usage fields base, unchanged
    • Usage is a neutral copy of the token counts: a library must not import proxy, so the host maps its own type to it and back.
  • agent/registry.go: a Registry found by route path, safe for concurrent use. It refuses a nil agent, an empty path, and a path that another agent already claims. A package-level Register, for an agent's init(), panics on a refusal, as components.Register does.

The interface holds only what A2 wires. A method is added when its first caller is. Base makes that safe: an agent that embeds it does not break when the interface grows. A summary-call target and a reply label will be added when the code that uses them moves in.

Data dependence

None. The package reads nothing and stores nothing.

How it was tested

  • go test -race ./agent/: OK. go vet, gofmt, and go build ./...: OK.
  • Each Base method returns today's neutral value. An agent that overrides only SessionID keeps every other method neutral.
  • The registry: a claimed path, an unclaimed path (Base), and the refusals. A concurrent Register and ForPath test fails without the lock (DATA RACE).
  • resetDefault is safe while lookups run. The old version, which swapped the package variable, failed with DATA RACE.
  • The library rule is enforced, not only stated: TestAgentDoesNotImportAHost fails if agent imports proxy, proxyapp or cmd/, directly or not. I checked it with a probe file that imports proxy: the test failed.
  • Base.SessionID's "" is a no-op in session.Explicit ("" is "no candidate"), so A2 can pass it on every route without a change.

Open questions

  • Bob's control-plane calls (the profile region strip, the model info) are not model routes. A second, optional interface for them is proposed for A2.

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]>

@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 84b883e8d0a4 blocking

Verdict: blocking

The package is small, correct, and has no effect on the running proxy. I found one small defect: the import guard does not cover a host that the package doc names.

Findings

  1. agent/imports_test.go:52 — the guard misses the bifrost adapter, but the package doc says it enforces the rule for it
    • What fails: a later change makes agent import github.com/rossoctl/context-guru/adapters/bifrost (directly or through another package). TestAgentDoesNotImportAHost still passes.
    • Proof:
      • agent/agent.go:6-7 says: "A host (the proxy, the bifrost adapter) imports it; it never imports a host. imports_test.go enforces that."
      • agent/imports_test.go:11 says the same: "a host (the proxy, the bifrost adapter) imports it, never the reverse. This test enforces that rule."
      • isHost (line 52) checks only /proxy, /proxyapp and /cmd. adapters/bifrost is in the same module (one go.mod at the root), so go list -deps . lists it, but isHost returns false for it.
      • TestIsHostMatchesEveryHostPackage (line 37) is named "every host package" and also leaves out adapters/.
      • The PR body is accurate ("fails if agent imports proxy, proxyapp or cmd/"). The code comments are not.
    • Fix: add "/adapters" to the list in isHost, and add module + "/adapters/bifrost" to the true cases in TestIsHostMatchesEveryHostPackage. (Or change both comments to name only proxy, proxyapp and cmd. I prefer the guard fix: the adapter is a host per CLAUDE.md.)

Non-blocking

  • docs/design.md package map has no agent/ row. CLAUDE.md points to that table for the layout. Other new packages (tenant/, tooldefer/, kvcache/) are also missing, so this is not new drift. One row ("per-client-agent extension point: Agent, Base, registry by route path") helps the A2 reader.
  • Fail open for ReadUsage and SessionID is a host duty, and only a comment states it. agent.go:23-25 says a reply the agent cannot read "must return base unchanged". Nothing recovers a panic in an agent's method. When A2 wires these calls in proxy.go, wrap each call with a recover that keeps base / "", and add a test with a panicking agent. Today bobResponseUsage is in-tree and trusted, so this is not a defect yet.
  • Embedding Base hides a typo in an override. An agent that writes SessionId (not SessionID) still compiles and silently gets "". This is the cost of the Base design. A compile check such as var _ agent.Agent = bob{} does not catch it. A per-agent test that calls each overridden method does. Worth a sentence in the package doc for A2 authors.
  • Paths match only by exact string. The proxy mux registers "POST " + bobModelPath, and serve compares the bare up.path. A2 must pass the bare path (no method, no query) to ForPath. A doc line on Paths() ("exact path, no method prefix") prevents a silent miss that returns Base.
  • Error messages with an empty Name(). Register prints "" for an agent with no name, so path /x is claimed by "" and "" is hard to trace. %T of the agent would help. Cosmetic.
  • go list in the guard uses exec.LookPath("go"). cmd/context-guru-proxy/depguard_test.go uses runtime.GOROOT(). The new choice is better (the comment says why). The old test can move to it later; not in this PR.

What I checked

  • Read the full diff (5 new files, 396 lines) and the commit message. No existing file changes.
  • agent.go: interface, Usage, Base. Compared Usage with proxy/usage.go:18-45: the 5 count fields match names and meaning (CacheWrite1h is part of CacheWrite). The proxy-only fields (Searches, Live, …) stay out, which is right for a library type.
  • Compared the interface with the Bob branches it will replace: explicitSessionOf / X-Task-Id (proxy/proxy.go:739-747), bobResponseUsage(contentType, body, base) (proxy/bobusage.go:67). The ReadUsage signature matches. SessionID "tried last" matches apply.ExplicitSession(sess, body, host...) (apply/apply.go:353), where host ids come after the header and body ids.
  • registry.go: Register checks all paths before it writes any, under one lock, so a refused agent claims nothing (test at registry_test.go:50). Nil agent, empty path, repeated path and a claimed path are refused. ForPath returns Base{} for an unclaimed path. Package Register panics like components.Register (components/registry.go:27).
  • resetDefault clears the map under the lock and does not swap the variable. It is used only in tests. No init() in this package registers anything, so the reset wipes nothing real.
  • Tests: each assertion checks a specific value. The concurrency tests only prove something under -race; make test runs go test -race.
  • Library rule: agent imports only net/http, errors, fmt, sync. No host import.
  • Data dependence: none. The package reads and stores no customer data. components/all/datadep_test.go covers registered components only, so no row is needed.
  • No behavior change: nothing imports agent yet.
  • I did not run any build or test (live tests not approved; Go is not installed here).

@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 84b883e8d0a4 blocking

Verdict: blocking

Findings

  1. agent/imports_test.go:52 — the import guard does not cover the bifrost adapter, which the package doc names as a host
    • What fails: agent/agent.go:6-7 says "A host (the proxy, the bifrost adapter) imports it; it never imports a host. imports_test.go enforces that." But isHost checks only /proxy, /proxyapp and /cmd. If agent imports github.com/rossoctl/context-guru/adapters/bifrost (directly or through another package), TestAgentDoesNotImportAHost still passes. The rule the doc states is not the rule the test enforces.
    • Proof: imports_test.go:52 lists []string{"/proxy", "/proxyapp", "/cmd"}. adapters/ is absent. TestIsHostMatchesEveryHostPackage (imports_test.go:37-49) has no adapters/... case, so the gap is not visible in the tests. The PR body also says the test checks only proxy, proxyapp and cmd/, so the doc comment claims more than the code does.
    • Fix: add "/adapters" to the host list and an module + "/adapters/bifrost" case to TestIsHostMatchesEveryHostPackage. Or, if the adapter is out of scope on purpose, change the doc comment so it does not claim the test enforces it.

Non-blocking

  • agent/registry.go:21-24: Register checks only an untyped nil. A typed nil pointer ((*myAgent)(nil)) passes the check, and a.Paths() then panics if the method reads a field. In an init() the result is a panic either way, so the effect is only a less clear message.
  • agent/registry.go:25-37: Register calls a.Name() while it holds the write lock (in the error paths). An agent whose Name calls ForPath deadlocks. This is unlikely; calling Paths() before the lock (as the code does) and Name() before the lock too would remove the case.
  • agent/agent.go:24-25: ReadUsage says "must return base unchanged" on a reply it cannot read, but the library gives no recover. A2 must wrap the call in a recover in the host so that a panic in one agent's parser reverts only that correction (fail open). Worth a line in the A2 plan.
  • docs/design.md "Package map" does not list agent/. The map already misses other packages (tooldefer/, predictive/, kvcache/, tenant/), so this is not new, but A2 is a good time to add the row.
  • agent/registry.go:46: ForPath is an exact string match. A2 must pass the same path form the proxy routes on (no query string, same trailing slash), or a claimed route falls back to Base.

What I checked

  • Read the full diff (5 new files, 396 lines) and the commit message. No existing file changes.
  • CLAUDE.md rules: the package is a library and imports only net/http, errors, fmt, sync. It imports no host. Data dependence: none; no component is registered, so components/all/datadep_test.go is not affected.
  • No behavior change: nothing in the repo imports agent/ yet (grep for the import path finds only the new package).
  • Base methods return neutral values; the embed test proves an agent that overrides one method keeps the others neutral.
  • Registry.Register is all-or-nothing: it checks every path before it writes any. TestRegisterRefusesAPathAnotherAgentClaims proves a refused agent claims nothing.
  • Locking: Register takes the write lock, ForPath the read lock; resetDefault clears the map under the lock and does not swap the package variable.
  • imports_test.go uses exec.LookPath("go"). Since Go 1.19, go test puts $GOROOT/bin first on the test's PATH, so this finds the toolchain that runs the test. The contains(deps, module+"/agent") check stops a vacuous pass.
  • Compared agent.Usage with proxy.Usage (proxy/usage.go:18): the 5 count fields match by name. The host must keep its non-count fields (Searches, Live, ...) when it maps back; that is A2 work.
  • I did not run Go tests (not approved, Go is not installed).

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]>
@vz-ibm

vz-ibm commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

Round 1: replies

Both reviewers found the same gap. Fixed in bf80677f.

R1-1 and R2-1: the import guard does not cover the bifrost adapter. Correct: the doc said the guard enforces the rule for "the bifrost adapter", but isHost checked only proxy, proxyapp and cmd.

  • isHost now checks /adapters too.
  • TestIsHostMatchesEveryHostPackage has adapters and adapters/bifrost as true cases. It also has adaptersish as a false case, so the prefix cannot match a lookalike. Before the fix: isHost(".../adapters/bifrost") = false, want true.
  • The real guard catches it: a probe file that imports adapters/bifrost makes TestAgentDoesNotImportAHost fail with "depends on host package .../adapters/bifrost". The probe is removed.

Non-blocking, fixed:

  • Name() under the write lock (R2). Register now calls Name() and Paths() before it takes the lock, so an agent method that calls back into the registry cannot deadlock it. The error text uses %T, so an agent with an empty Name is still named (R1).
  • Exact path match (R1, R2). Paths() now documents it: the exact path, no method, no query, the same trailing slash.
  • docs/design.md package map (R1, R2). It has an agent/ row.

Non-blocking, for A2 (the wiring step):

  • Fail open in the host (R1, R2). Correct: the library cannot recover a panic in an agent method. A2 wraps each call to the agent in a recover in the host, so a panic reverts only that one correction. I will add a test there.
  • A typed nil agent (R2). In an init() it panics either way. Left as is.
  • An override typo hidden by Base (R1). That is the cost of Base. A2's Bob agent will carry a compile-time check (var _ agent.Agent = bob{}) and a test that its override is called.

Checks

  • go test -race ./agent/: OK. go vet, gofmt, go build ./...: 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 bf80677f9c25 approve

Verdict: approve

Findings

None.

Earlier findings:

  • R1-1 and R2-1 (the import guard misses the bifrost adapter): fixed. isHost (agent/imports_test.go:53) now lists /adapters. TestIsHostMatchesEveryHostPackage has adapters and adapters/bifrost as true cases and adaptersish as a false case. The root+"/" prefix rule keeps the lookalike out. The doc comments at agent/agent.go:6-7 and imports_test.go:11 now match the code.

Earlier non-blocking points:

  • Name() under the write lock (R2): fixed. registry.go:25 calls Paths() and Name() before r.mu.Lock(). The duplicate-claim error uses %T for the old agent, so no agent method runs under the lock.
  • Empty Name() in errors (R1): fixed with %T.
  • Exact path match (R1, R2): fixed in the Paths() doc (agent.go:16-17).
  • docs/design.md package map (R1, R2): fixed, agent/ row added.
  • Fail open in the host (R1, R2), typed nil (R2), override typo (R1): the author defers them to A2 or leaves them. I accept this: nothing calls the package yet, and a typed nil in an init() panics either way.

Non-blocking

  • No test proves the deadlock fix. A test agent whose Name() calls reg.ForPath would fail (hang) on the old code and pass on the new. Small; fine to add in A2.
  • The A2 wiring must carry the recover and its test that the author promised in the round-1 reply.

What I checked

  • Last review: round 1, 84b883e, 2026-11-10T09:37:48Z
  • New commits read: 1 (bf80677f fix(agent): the import guard covers the bifrost adapter)
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
  • New items since my last review:
    • Author comment "Round 1: replies" (2026-11-10T09:40:48Z): checked each claim against the diff. All claimed fixes are in bf80677f. Deferred items are accepted above.
    • Reviewer 1 round-1 review (09:37:39Z, posted before mine, read now): its one finding is the same as mine and is fixed. Its non-blocking points are covered above.
  • Read the full diff 84b883e8..bf80677f (4 files, +17/-10) and the whole of agent/registry.go Register and agent/imports_test.go around the changes.
  • Register stays all-or-nothing: it checks the empty and repeated paths before the lock, then checks claimed paths and writes all of them under one lock. The existing refusal tests still cover each path.
  • No behavior change: nothing outside agent/ imports the package. The docs/design.md change is one table row.
  • I did not run Go tests (live tests not approved, Go is not installed).

@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 bf80677f9c25 approve

Verdict: approve

The one finding (both reviewers) is fixed. The new commit adds no defect.

Findings

None.

Earlier findings

  • R1-1 and R2-1 (guard misses the bifrost adapter): fixed. isHost (agent/imports_test.go:53) now lists /adapters. TestIsHostMatchesEveryHostPackage has adapters and adapters/bifrost as true cases and adaptersish as a false case. The root+"/" prefix check makes adaptersish return false. The package doc (agent/agent.go:6-7) now matches the guard.
  • R2 non-blocking, Name() under the write lock: fixed. Register calls Paths() and Name() before r.mu.Lock() (agent/registry.go:25).
  • R1 non-blocking, empty Name() in errors: fixed. Messages use %q (%T) for the new agent and %T for the old one.
  • R1 and R2 non-blocking, exact path match: fixed. Paths() doc (agent/agent.go:16-17) says: exact path, no method, no query, same trailing slash.
  • R1 and R2 non-blocking, docs/design.md row: fixed. docs/design.md:23 adds agent/.
  • R1 and R2 non-blocking, recover in the host: deferred to A2. I accept this. Nothing calls an agent yet, so no fail-open path exists to break.
  • R2 non-blocking, typed nil agent: left as is. I accept the reason: in an init() it panics either way.
  • R1 non-blocking, typo hidden by Base: deferred to A2. I accept the plan. Note: the var _ agent.Agent = bob{} check does not catch a typo. The planned test that calls the override does.

Non-blocking

  • None new.

What I checked

  • Last review: round 1, 84b883e, 2026-11-10T09:37:39Z
  • New commits read: 1 — bf80677f fix(agent): the import guard covers the bifrost adapter
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
  • New items since my last review:
    • Reviewer 2 round-1 review (09:37:48Z). Its finding 1 is the same as mine. I checked each of its non-blocking points against the new commit (see "Earlier findings").
    • Author comment "Round 1: replies" (09:40:48Z). I checked each claim against the diff. All claimed code changes are present.
  • Register after the change: it validates empty and repeated paths before the lock. Under the lock it checks every path for a claim, then writes all. A refused agent still claims nothing, so TestRegisterRefusesAPathAnotherAgentClaims still holds. Paths() is called once, so the checked list and the written list are the same.
  • adapters/ holds only bifrost/. It is in the root module, so go list -deps lists it.
  • No existing behavior changes: only agent/ and one doc row change. Nothing imports agent yet.
  • I did not run any build or test (live tests not approved; Go is not installed here).

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]>
@vz-ibm
vz-ibm added this pull request to stack #1050 November 10, 2026 13:06
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]>
amiddavid added a commit that referenced this pull request Nov 10, 2026
A shared prefix asker for OpenAI Chat Completions, so the sweep can
ask on Chat routes (#1030 item 1). chatPrefixAsker has Ask,
AskCovered and CoversSpan, the same contract as the Anthropic and
Responses askers.

Behavior change, 2 parts:
1. On Chat Completions, a preset with extract_llm_sweep (xhigh,
   ultrahigh, housellm) now declares context_guru_adjudicate (about
   945 bytes) on every request, and the cold sweep can ask at the
   keep-alive ping. Anthropic and Responses already do this. The warm
   sweep stays off unless a config sets warm: true.
2. cache_aware_summarizer on Chat with model.source: config and no
   static cheap model now uses the caller's model through the asker,
   as on Anthropic and Responses. Shipped presets use incoming and are
   not affected.
On IBM Bob the ask fails open for now (wrong path and auth), until
#1030 item 4 / #1029.
Owner's yes, 2026-11-10, in the integrator session: "approve both".

Data dependence: no change.

Reviews: 2 offload reviews (GLM, --no-fallback), round 2, both approve
at 93342d9. After it: 3 merges of main with no hand resolution
(remerge-diff 0 each), each tested on the merged tree (cheapmodel,
components, keepalive, proxy).

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator

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 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 offload-review skill, @amiddavid's session fresh 2 of 2 3 of 3 3ee169eff49a approve

Verdict: approve

Findings

None.

Earlier findings

  • R1/R2 round 1 (the import guard misses the bifrost adapter): still fixed. After the new commits I re-read agent/imports_test.go and agent/registry.go. isHost still refuses /adapters; Register still calls Paths() and Name() before the lock. The guard now reads go list -deps ./..., so it covers agent/bob too, and it still proves it listed both packages before it checks anything.

Non-blocking

  • The round-2 note "a test agent whose Name() calls reg.ForPath would pin the deadlock fix" was not added. The fix itself is in the code and I verified it by reading (agent/registry.go:23-25). Fine to leave.
  • agentSessionHandler (proxy/agentsession_test.go) is a copy of bobSessionHandler plus the registry override. Small test duplication; the override is the point of the copy.
  • readAgentUsage now runs, with a deferred recover, on every response, also on routes no agent owns (the neutral agent). One defer per response; negligible.

What I checked

  • Last review: round 2, bf80677, 2026-11-10T09:41:50Z
  • New commits read: 5 on the branch (21ebb929 refactor(agent): move Bob's session id into agent/bob; 4519eeea test(agent): the agent is asked, and its panic text is not logged; 98d50cd8 refactor(agent): move Bob's usage reading into agent/bob; 562bb9fc refactor(usage): share the usage-present rule in providerusage; 3ee169ef merge of origin/main). The commits the merge brought in are main's own, each reviewed in its own PR; I checked the merge itself.
  • Read in full: 4 reviews, 1 comment, 0 inline comments (from the three files)
  • New items since my last review: none in the conversation. The newest item is reviewer 1's round 2 (09:41:56Z, 6 s after mine); it raises nothing new. So the new material is the 5 commits above.
  • Read the full diff bf80677f..562bb9fc (15 files, +677/-75) and each changed file around the changes: agent/agent.go, agent/bob/{bob,usage}.go, agent/imports_test.go, internal/providerusage, proxy/{proxy,agentusage,usage}.go, proxy/agentsession_test.go, proxy/agentusage_test.go, proxy/bobusage_shim_test.go, docs/design.md.
  • The merge 3ee169ef has no hand resolution. git merge-tree --write-tree 562bb9fc a067848b exits clean and returns tree 4d635c2c, which equals the merge commit's tree. So the merge cannot have changed either side by hand.
  • Session behavior is unchanged. Old: Bob's route alone read X-Task-Id, other routes returned the session header. New: agent.ForPath returns Bob only on bob.ModelPath (the proxy imports agent/bob, so its init() registers it), Bob.SessionID reads the same header, and every other route gets the neutral Base, whose SessionID is "" → the session header. Same inputs, same ids.
  • The empty-agent-id branch keeps the body ids. When no agent id is present, explicitSessionOf now returns the bare header instead of apply.ExplicitSession(sess, body, ""). The pipeline re-reads the body ids downstream (sessionIDFrom → session.Scoped → ExplicitSession), and newRecCtx re-reads them through apply.SessionIDFor, so the final session and the wire-record trace id are the same. TestBobShellTaskIDWithoutTheHeaderIsStillTheSession and TestBobModelCallTakesSessionFromXTaskID pin both.
  • The usage move is field-equivalent. readAgentUsage copies back only the 5 token counts; Bob's parser (agent/bob/usage.go) changes only FreshInput, CacheWrite and CacheWrite1h, and passes CacheRead and Output through base. The old bobResponseUsage returned the same fields off the same base. The stream-chunk rule is the same function (providerusage.Present), now shared instead of copied.
  • The A2 promises from round 1 are kept. The host wraps SessionID and ReadUsage in a recover that reverts only that correction, and logs the panic's type, never its message. TestPanickingAgentSessionIDFailsOpenToTheSessionWithoutTheAgent and TestPanickingAgentReadUsageFailsOpenToTheSharedReading prove the agent was asked (call counters), that the request still returns 200 with the no-agent result, and that a canary in the panic text stays out of the log. bob_test.go calls each override, so a typo in one cannot fall through to Base in silence.
  • No nil agentFor outside New. Production builds Handler only in New (proxy/proxy.go:444), which sets agentFor: agent.ForPath. The many &Handler{} test constructions call methods that never reach agentFor (newRecCtx, compactionPointFor, threadFor, and the like); the end-to-end tests use New.
  • Library rules: agent/bob imports only agent, internal/providerusage and gjson — no host. The import guard covers it. Data dependence: none; the parser reads the same usage metadata as before, only from a library package. No behavior change without permission: the commits claim none, and the traces above agree.
  • I did not run Go tests (live tests not approved; Go is not installed).

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator

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 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 offload-review skill, @amiddavid's session fresh 1 of 2 3 of 3 3ee169eff49a approve

Verdict: approve

The PR grew from the A1 package to the first two A2 moves. I checked each move against the old
code path it replaces. I found no defect.

Findings

None.

Earlier findings

  • R1-1 and R2-1 (guard missed the bifrost adapter): still fixed. isHost
    (agent/imports_test.go:53) lists /proxy, /proxyapp, /cmd, /adapters. The new commits
    kept it, and the guard now also proves agent/bob is listed (imports_test.go:26).
  • R2 non-blocking, Name() under the write lock: still fixed. Register calls Paths() and
    Name() before r.mu.Lock() (agent/registry.go:55).
  • R1 and R2 non-blocking, recover in the host: delivered in this round, as promised.
    agentSessionID (proxy/proxy.go:760) and readAgentUsage (proxy/agentusage.go:16) each
    recover a panic and fail open. Tests prove the agent was asked (a call counter) and that the
    panic's message stays out of the log (a canary). Both call sites are covered: the streamed path
    (streamRecOn, plain body) and the buffered path (a tools body gets the expand tool).
  • R1 non-blocking, override typo hidden by Base: delivered. var _ agent.Agent = Bob{}
    plus a test per overridden method: Name, Paths, SessionID (agent/bob/bob_test.go),
    ReadUsage (agent/bob/usage_test.go).
  • R2 non-blocking, typed nil agent: left as is, as accepted in round 2.

Non-blocking

  • Agent.Name() has no host caller yet. Base's doc (agent/agent.go:51-52) says the
    interface holds "only what a host wires today". The dashboard still labels Bob from its own
    strings (dash/event.go, proxy/compactioncfg.go), not from Name(). One doc sentence, or
    the A2 wiring, settles it.
  • Reviewer 2's round-2 note stands: no test proves the Register deadlock fix (an agent whose
    Name() calls ForPath). Accepted then; still fine.

What I checked

  • Last review: round 2, bf80677, 2026-11-10T09:41:56Z
  • New commits read: 5 — 21ebb929 (Bob's session id into agent/bob), 4519eeea (the agent is
    asked; the panic text is not logged), 98d50cd8 (Bob's usage reading into agent/bob),
    562bb9fc (share the usage-present rule in providerusage), 3ee169ef (merge of origin/main).
  • Read in full: 4 reviews, 1 comment, 0 inline comments (from the three files).
  • New items since my last review: the 5 commits above. No new comment or review arrived after
    2026-11-10T09:41:56Z; reviewer 2's round-2 review (09:41:50Z) I read now in full — its two
    notes are answered above.
  • Read the full PR diff against the base (a067848b..3ee169ef, 18 files, +1071/−66) and each
    changed file around the changes.
  • Session move, no behavior change. Old code on Bob's route always called
    apply.ExplicitSession(sess, body, X-Task-Id). New code returns bare sess when the agent id
    is empty. I traced every consumer of explicitSessionOf: apply.BodyOpts → sessionIDFrom
    (apply/apply.go:1473), EnforcedSessionIDFor → SessionIDFor (apply/apply.go:1504), and
    newRecCtx → SessionIDFor. Each re-reads the body ids through ExplicitSession, in the same
    order (header, user_id, taskId, agent id). The results converge in every case I traced:
    header set, body id set, both, neither. TestBobShellTaskIDWithoutTheHeaderIsStillTheSession
    pins the one case that could differ.
  • Usage move, no behavior change. agent/bob/usage.go holds the old parser byte-for-byte
    (readUsage/count = bobUsage/bobCount; the stream loop = the old bobResponseUsage).
    readAgentUsage copies back only the 5 token counts; the old bobUsage kept every other field
    from base too, so the net result is the same. providerusage.Present is the old
    usagePresent body, unchanged. bobUsage's 5 direct tests run through a test-only shim that
    wraps the block as a JSON reply; each old garbage input still returns base.
  • Route gating. Old: bob := up.path == bobModelPath. New: h.agentFor(up.path). The default
    registry holds Bob on bob.ModelPath (init in agent/bob), and bobModelPath = bob.ModelPath
    keeps the strings one. static.path and up.path are the same string by construction
    (comment at proxy/proxy.go:1305). Non-Bob routes get Base, whose methods are the identity —
    pinned by TestReadAgentUsageWithTheNeutralAgentIsTheIdentity and
    TestNonBobRoutesIgnoreBobCacheWrites.
  • Fail open. Both recovers log the panic's type only, never its message. The log tests capture
    slog.Default() before the request; the request logger derives from it
    (proxy/proxy.go:1311), so the assertions read the lines the code writes.
  • Library rule. agent and agent/bob import no host; the guard runs go list -deps ./...
    from the package and fails if either package is missing from the list.
  • Merge 3ee169ef. git show --cc shows no hand-resolved conflict. main's proxy/ edits
    touch lines the stack did not, as the PR body says.
  • The PR body states the behavior change (none) and the data dependence (metadata only, as
    before) at the top, per the repo rules.
  • I did not run any build or test (live tests not approved; Go is not installed here).

@amiddavid
amiddavid merged commit d865b25 into main Nov 11, 2026
12 of 13 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 11, 2026
amiddavid pushed a commit that referenced this pull request Nov 11, 2026
…lock (#1066)

A keep-alive ping that missed and re-wrote the cache now moves the
refresh clock. The next real request is no longer labeled ttl_expiry
when the ping had re-created a live entry. A 2xx ping that read or
wrote the cache moves the clock in five places: the scheduled ping
(record1), the manual ping (no schedule restart, no credit), the
summary substitute, the live restart-grace clock in the dash recorder,
and the clock rebuilt after a restart. A ping that billed neither read
nor write, or that failed, moves nothing.

Behavior change: keep-alive users. Old: a failed ping with
CacheRead > 0 moved refreshedAt, and a ping that only wrote the cache
did not. New: only a 2xx ping that read or wrote moves it. How to turn
it off: no switch.
Owner's yes, 2026-11-11, in the integrator session: "u have my approval
for 1064 and 1066."

Data dependence: metadata only (status codes, cache read and write
counts, times). docs/data-dependence.md has the updated row.

Fixes #580.

Reviews: 2 offload reviews (GLM), round 3, both approve at f08969d,
which is the PR head. Main's later change to docs/design.md (#1029) is
in a separate hunk; the merge is clean.

Signed-off-by: DAVID BOAZ <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]>
amiddavid pushed a commit that referenced this pull request Nov 11, 2026
On IBM Bob's route, Context Guru's own model calls (the summary call
and the sweep's question, #1036) now go to Bob's model path with Bob's
auth, behind the agent extension point (#1029). Step A2.4, #1030
item 4.

- agent: a new method, ModelTarget() (chat Path and AuthScheme). Base
  returns the zero target: 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. Complete and
  CompletePrefixedChat post to it.

Behavior change, Bob route only. Who: Bob users with a preset that
makes model calls (bob-ultrahigh); today's Bob presets (off, lossless)
make none. Old: the calls went to /v1/chat/completions with Bearer,
failed, and the request went on unchanged. New: they go to
/inference/v1/chat/completions with "Authorization: Apikey <caller's
key>". Security fix on the same route: a Bob request with no key of
its own no longer falls back to the operator's --openai-key, so that
key is not sent to Bob's server. The OpenAI route keeps its fallback.
Turn it off: use a preset without model calls.
Owner's yes, 2026-11-11, in the integrator session: "yes I approve it
since we dont have Bob users yet".

Data dependence: none changed.

Reviews: 3 offload review rounds (Claude backend). Round 3: both
approve at b94582a. After it, the integrator merged main (423936e)
and retargeted the PR from #1029's branch to main. The PR's own
added and removed lines are identical to the approved change (14
files, +492/-12); the hand resolutions in agent/ and docs/design.md
keep the branch side.

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
…975)

On IBM Bob's route, each reply is labelled with the IBM backend that
served it: A, B or other. IBM serves Bob's model route from 2 backends
that count tokens differently, so a preset comparison is valid only on
one backend.

- Behind the agent interface (#1029): agent.Usage gets a Backend
  field; the label rule, the helper-call skip (models security and
  router), the counters and the once-per-shape warning live in
  agent/bob/usage.go; Bob.ReadUsage sets Backend. proxy calls the
  agent on every reply; when the shared parser found no usage, only
  Backend comes from the agent and the token counts stay as parsed.
- A new dashboard column, backend, and a new /stats top-level key,
  bob_backend (always present).

Behavior change, Bob route only: the dashboard and /stats for Bob
traffic. Old: a Bob row had no backend. New: each Bob reply carries
the label. A strict /stats parser that rejects unknown keys must allow
bob_backend. A new backend that looks like B is labelled B, with no
alarm. The label never changes a request. Turn it off: do not set
--bob-upstream.
Owner's yes, 2026-11-12, in the integrator session: "975 approve"; the
port behind agent/bob: "your recommendation".

Data dependence: metadata only (a label per request row). Row:
docs/data-dependence/features/billed-token-and-cache-time-records.md.

Reviews: 5 offload review rounds (Claude backend). Round 5: both
approve at 37443f3, which is the PR head, after the integrator's
merge of main and the port behind the agent interface.

Signed-off-by: Vitaly Zabershinsky <[email protected]>
Signed-off-by: DAVID AMID <[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