Repository navigation
test(proxy): CG's token never reaches an upstream in a summary call - #1092
Conversation
A guard for the second credential exit: a component's own model call (model.source: incoming). The test sends CG's token, whole and one character short, on the OpenAI route and on Bob's route, and checks that no request the upstream gets holds it. It passes on main: the dispatcher scrubs every call it sends. With that scrub removed, the damaged-token cases fail on both routes. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Vitaly Zabershinsky <[email protected]>
vz-ibm
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 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 | b963b2274bae |
blocking |
Verdict: blocking
Findings
- proxy/summarytoken_test.go:59-76 — the test does not wait for the summary call, so it can pass without checking it
- What fails: on the proxy path, summarize calls the model in a goroutine. The forwarded request does not wait for it. The test checks
seenas soon as the forwarded response comes back. At that time the summary call may not have reached the fake upstream yet. Thenseenholds only the forwarded request. That request is scrubbed on a different path, so the test passes. This happens even when the dispatcher scrub (the guard this test exists for) is removed. - Proof:
- A proxy request always has a session.
applysetsSessionfromsession.Scoped(...). With no explicit id, that is a hash of system + first user message (session/session.go:216-221). Soc.Session != "". - With a session, summarize does not call
summarizeInline. It callsstartAsyncSummaryand returns at once (components/offload/summarize.go:637-670). startAsyncSummarysends the model call fromgo func() {...}(components/offload/summarize_async.go:267). The request goroutine does not wait for it.- The only guard is
len(seen) == 0(line 67). The forwarded request alone meets it. No line checks that a summary call arrived. - The repo already has the fix for this race:
offload.WaitForAllSummariesForTest(components/offload/summarize_testhook.go:64).proxy/cgllm_test.go:278-286uses it, and also fails when the model was never called (calls.Load() == 0).
- A proxy request always has a session.
- Second effect, across subtests: the in-flight registry is global (
inFlight,summarize_async.go:101). Its key is the session (convKey). All six subtests send the same body and no tenant, so they have the same session. If one subtest's summary goroutine is still in flight, the next subtest getssummary_already_in_flight(summarize_async.go:227-230). Then it makes no summary call at all. Map order is random, so the case that gets skipped changes from run to run. - So the commit message's claim ("with that scrub removed, the damaged-token cases fail on both routes") depends on goroutine timing. It is not a property of the test.
- Fix:
- After
resp.Body.Close(), calloffload.WaitForAllSummariesForTest(5*time.Second)and fail if it returns false. - Assert that the summary call arrived. For example, require
len(seen) >= 2, or require one request whose body is the summarize prompt. - Give each subtest its own
x-context-guru-sessionvalue. Then no subtest can block another's summary.
- After
- What fails: on the proxy path, summarize calls the model in a goroutine. The forwarded request does not wait for it. The test checks
Non-blocking
- The doc comment says "in any header or body". The fake upstream records headers and body, but not
r.URL. Addingr.URL.String()toallcosts one line and also covers a token in a query string. b, _ := io.ReadAll(r.Body)drops the error. A short read would hide part of the body from the check.t.Erroron it is safer. (It runs in the handler goroutine, sot.Erroris fine there, nott.Fatal.)
What I checked
- The full diff: one commit, one new file,
proxy/summarytoken_test.go(116 lines). I read every line. - The commit message. It has DCO sign-off and
Assisted-By:. - The token rules:
tenant.TokenPrefix,tenant.LooksLikeToken(exact length) andproxy.tokenShaped(prefix only). The "damaged" value (prefix + 25 characters) is notLooksLikeToken, soCallerKeyreturns it. That is correct, and it is the hard case the test names. - The summary call's credential path:
incomingModel(proxy/proxy.go:1067-1105) →Dispatcher.incoming→Dispatcher.Do→setUpstreamAuth→scrubToken(proxy/proxy.go:2745-2749). The scrub is there on main, so the production guard is correct. My finding is only about the test. - The other two cases. "Token beside the caller's key":
CallerKeyskips the valid token and returnsX-Api-Key. "Two Authorization values":CallerKeyreadsHeader.Get, so it returns the first value,caller-key. Both cases are correct inputs. - The helpers the test uses exist:
bobModelPath,bigToolOutput,Options.OpenAIUpstream/BobUpstream,config.LoadBytes,cfg.Build,New,h.Close,h.Mux. - Data dependence: this is a test-only PR. No feature changes, so
docs/data-dependence.mdneeds no update. - I did not run the tests. Live tests are not approved, and Go is not installed on this machine.
vz-ibm
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (claude, user of @vz-ibm) | Claude Code 2.1.316 | offload-review skill, @vz-ibm's session | fresh | 1 of 2 | 1 of 2 | b963b2274bae |
blocking |
Verdict: blocking
Findings
- proxy/summarytoken_test.go:68 — the test does not prove that the summary call reached the upstream, so it can pass without checking the exit it is named for
- What fails: the summary call runs in a detached goroutine. The test reads
seenas soon as the client gets its response. At that timeseencan hold only the forwarded request. The guardlen(seen) == 0passes on the forwarded request alone. So a token leak in the summary call (the "second credential exit") can go unseen, and the test stays green. - Proof:
apply/apply.go:1472-1474:sessionIDFromalways gives a session id. With no header, it is the content hash of the head. Soc.Session != ""on this proxy request.components/offload/summarize.go:641-647: with a session, summarize does not callsummarizeInline. It callsstartAsyncSummaryand returns at once.components/offload/summarize_async.go:265-268:go func() { ... }withcontext.WithoutCancel. Nothing on the request path waits for it.proxy/proxy.go:550-561:Handler.Closedoes not wait for detached summaries either.- Second effect: all 6 subtests send the same body, so they share one conversation key.
inFlight(summarize_async.go:101) is a package global. If one subtest's goroutine has not calledinFlight.finishwhen the next subtest starts,startAsyncSummaryreturns "already in flight", and that subtest makes no summary call at all. - The commit message says the damaged-token cases fail with "that scrub" removed.
setUpstreamAuth(proxy/proxy.go:2745) is shared by the forwarded request (proxy/proxy.go:709) and byDispatcher.Do(proxy/dispatcher.go:312). If the mutation removed the scrub insetUpstreamAuth, the forwarded request alone makes the test fail. That does not show that the summary call was checked. I could not run the test to see which case it was (live tests are not approved).
- Fix: wait for the summary call with a timeout before the check, and fail when it does not come. For example, poll until the upstream has seen 2 requests, or until it has seen a request whose body holds the summarizer prompt. Then check every request. Also give each subtest a different body (or a different first user message), so the global
inFlightslot of one subtest cannot block the next.
- What fails: the summary call runs in a detached goroutine. The test reads
Non-blocking
proxy/summarytoken_test.go:40-45: the upstream records headers and body, but notr.URL(path and query). The doc comment says "in any header or body", so this matches the claim. A query-string check costs one line and closes the last place a key can travel.proxy/summarytoken_test.go:28-30: the innermapmakes the subtest order random. This is fine for correctness. If finding 1 is fixed with distinct bodies, a slice of cases makes failures easier to read again in the same order.
What I checked
- The full diff: one new file,
proxy/summarytoken_test.go, 116 lines. I read every line. - The commit message of b963b22.
tenant.LooksLikeTokenandTokenPrefix(tenant/tenant.go:1112-1131): the test'svalidtoken has the exact length;damagedis one character short. Correct.CallerKey,CallerAuthScheme,scrubToken,tokenShaped(proxy/tenancy.go:290-345): a damaged token is not skipped byCallerKey, so it becomes the summary call's key, andtokenShaped(prefix only) removes it later. The test's three header cases match this logic.incomingModel(proxy/proxy.go:1067-1106),Dispatcher.incomingandDispatcher.Do(proxy/dispatcher.go),setUpstreamAuth(proxy/proxy.go:2745):DocallssetUpstreamAuth, which callsscrubTokenwhen there is no server-held key. So the production code does remove the token from the summary call. I found no leak in the code. The finding is only about what the test proves.- The summarize config in
tokenCanaryHandler:min_request_frac: 0,start_from_message: 0,min_tokens: 1,keep_last: 1. These let the summary start on the first turn. - Repo rules: test-only change, no behavior change, no data-dependence change, no new component.
docs/data-dependence.mdneeds no update. - I did not run the test. Go is not installed, and live tests are not approved.
The summary call runs in a detached goroutine, and the test read the upstream's requests as soon as the client got its reply. So it could pass on the forwarded request alone. It now waits with offload.WaitForAllSummariesForTest, and fails when no summary call came. Each case has its own session, so one case's summary in flight cannot block the next. The upstream also records the URL, the cases run in a fixed order, and a body read error fails the test. Both round-1 reviewers of #1092 raised this. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Vitaly Zabershinsky <[email protected]>
|
Round 1 replies. Fixed in a30c0fa:
Checks: |
vz-ibm
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (claude, user of @vz-ibm) | Claude Code 2.1.316 | offload-review skill, @vz-ibm's session | resumed | 2 of 2 | 2 of 2 | a30c0fa0c540 |
approve |
Verdict: approve
Findings
None.
Earlier findings
- Reviewer 2, finding 1 (the test does not wait for the summary call): fixed.
- The test now calls
offload.WaitForAllSummariesForTest(5 * time.Second)after the response, and fails on a timeout. - The test fails when no request holds
"max_tokens". I checked this marker.cheapmodel.OpenAI.postalways setsmax_tokens(cheapmodel/openai.go:239-246).tokenCanaryRequestdoes not set it. So the marker finds exactly the summary call. - The author's mutant removes only the
setUpstreamAuthcall inDispatcher.Do. The forwarded request keeps its scrub. So a failure under that mutant comes from the summary call. This answers my round-1 doubt about the commit message.
- The test now calls
- Reviewer 1, finding 1 (same defect): fixed, for the same reasons.
- Non-blocking points (
r.URL, theio.ReadAllerror, random case order): fixed. The URL is in the checked text. A read error callst.Errorf. Routes and cases are slices now.
Non-blocking
- proxy/summarytoken_test.go:72 — the per-case session id does nothing. The value is
"token-canary-"+route.name+"-"+tc.name, for exampletoken-canary-openai-a token beside the caller's key.session.safeExplicitallows only[A-Za-z0-9._:-](session/session.go:56-63). The space and the'fail that check. SoScopedfalls back to the content hash (session/session.go:216-221), and all six cases share one session again.- The test is still correct. Each case waits for every summary to finish before it returns, so no flight is left to block the next case. Also, a skipped summary call now makes the test fail.
- But the comment at lines 25-26 ("Each case has its own session, so one case's summary in flight cannot block the next") is not true. The guard is the wait, not the session.
- Fix, either one: use a safe id (for example, an index:
fmt.Sprintf("token-canary-%s-%d", route.name, i)), or change the comment to name the wait as the guard.
What I checked
- Last review: round 1, b963b22, 2026-11-11T15:30:42Z
- New commits read: 1.
a30c0fa0test(proxy): wait for the summary call before the token check - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
- New items since my last review:
- Reviewer 1's round-1 review (15:32:11Z). I checked its finding 1. It is the same defect as my finding 1, and it is fixed. I checked its two non-blocking points. Both are fixed.
- The author's reply comment (15:35:02Z). I checked each claim against the new diff: the wait, the
"max_tokens"marker, the per-case session header,r.URL, the read error and the slices. All are true in the code except "its own session" (see Non-blocking). I accept the mutant result as the author's report. I could not run it.
- The full new diff of
proxy/summarytoken_test.go(+42/-18), and the whole file around it. offload.WaitForAllSummariesForTest(components/offload/summarize_testhook.go:64-76). It polls the globalinFlightmap until it is empty, with a deadline. That is the correct wait for a detached summary.- The
x-context-guru-sessionpath:session.Scoped→safeExplicit(session/session.go:43-65, 206-226). - This is a test-only PR. No behavior change and no data-dependence change, so
docs/data-dependence.mdneeds no update. - I did not run the tests. Live tests are not approved, and Go is not installed on this machine.
vz-ibm
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (claude, user of @vz-ibm) | Claude Code 2.1.316 | offload-review skill, @vz-ibm's session | resumed | 1 of 2 | 2 of 2 | a30c0fa0c540 |
approve |
Verdict: approve
Findings
None.
Earlier findings
- Reviewer 1, finding 1 (the test does not wait for the summary call): fixed.
proxy/summarytoken_test.go:79callsoffload.WaitForAllSummariesForTest(5 * time.Second)and fails on a timeout.- The helper (
components/offload/summarize_testhook.go:64-76) polls the same globalinFlightregistry thatstartAsyncSummaryfills.inFlight.beginruns on the request goroutine, before the forwarded request goes out. So the job is in the registry before the client gets its response, and the wait cannot return early. - The helper does not wait for deferred commissions (
coldDeferred,warmDeferred). OnlyCacheAwareSummarizer.deferSummary(components/offload/cache_aware_cold.go:103) makes those. This test uses plainsummarize, so no deferral applies. - Lines 84-94 fail when no request carries
"max_tokens". The OpenAI cheap-model client sets it (cheapmodel/openai.go:245). The client's chat body has none, and no proxy code adds one (I searchedproxy/andapply/). So the check needs a real summary call. A missing summary call now makes the test fail. It cannot pass without the check. - Each case sends its own
x-context-guru-session(line 72). So the cases have different conversation keys, and one case's flight cannot block the next. - The author says the mutant now removes only the
setUpstreamAuthcall inDispatcher.Do, and the 2 damaged-token cases failed 5 of 5. That mutant isolates the summary exit. I accept the report. I could not run it myself.
- Reviewer 2, finding 1 (same defect): fixed. The same proof applies. The fix uses the helper and the per-case session that reviewer 2 proposed.
- Non-blocking points (
r.URL, theio.ReadAllerror, the case order): all fixed. Line 53 recordsr.URL.String(). Lines 47-50 report a read error witht.Errorf, which is correct in a handler goroutine. Routes and cases are slices now.
Non-blocking
proxy/summarytoken_test.go:87:"max_tokens"is an indirect sign of a summary call. It holds today. If the proxy ever addsmax_tokensto a forwarded body, the count can come from the forwarded request. A match on part of the summarize prompt is a direct sign. This is not needed for merge.
What I checked
- Last review: round 1, b963b22, 2026-11-11T15:32:11Z
- New commits read: 1 (a30c0fa test(proxy): wait for the summary call before the token check)
- Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
- New items since my last review:
- Commit a30c0fa: read the full diff and the whole changed file. Reviewed above.
- Comment by vz-ibm at 2026-11-11T15:35:02Z (round-1 replies): I checked each of its 4 points against the code. All 4 are true for the code I can read. The mutant runs and
go test -raceare the author's report. I did not run them. - Reviewer 2's round-1 review (15:30:42Z, posted before mine): read in full. Its finding and non-blocking points are covered above.
- The helper
WaitForAllSummariesForTestis in a non-_test.gofile, so packageproxycan import it.proxy/cgllm_test.goalready uses it. - The wait is global. Go runs top-level
t.Paralleltests only after the sequential ones finish, and this test is sequential. So other tests cannot keep the registry busy during this wait. x-context-guru-sessiondoes not go upstream:copyHeadersdropsx-context-guru-*.- Repo rules: test-only change, no behavior change, no data-dependence change. The commit has DCO sign-off and
Assisted-By:. - I did not run the test. Go is not installed, and live tests are not approved.
The case name held a space and a quote, which the session check refuses, so all cases fell back to one content-hash session. The id is now the route and the case index. Raised by reviewer 2 of #1092. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Vitaly Zabershinsky <[email protected]>
|
Round 2 replies. Both reviewers approve.
The review budget (2 rounds) is used. The last commit changes only the session id string in the test. Checks: |
|
Integrator note: the owner added this PR to v0.7.4 (2026-11-12). Its 2 approvals are at a30c0fa, and the head has new code since then ( |
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (claude, user of @amiddavid) | Claude Code 2.1.322 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 3 of 3 | 32699e094e7b |
approve |
Verdict: approve
Findings
None.
Earlier findings
- Reviewer 1, round 1, finding 1 (the test does not wait for the summary call): fixed in a30c0fa. The fix is unchanged at this head (
proxy/summarytoken_test.go:80-95). - Reviewer 2, round 1, finding 1 (same defect): fixed, for the same reason.
- Reviewer 2, round 2, non-blocking (the per-case session id does nothing): fixed in 32699e0.
- The id is now
token-canary-<route>-<index>, for exampletoken-canary-openai-0andtoken-canary-bob-2(line 73). safeExplicitallows[A-Za-z0-9._:-](session/session.go:43-65). Both route names (openai,bob) and the digits are in that set. The id is not all dots and is short. SoScopeduses the id, not the content hash. The 6 cases now have 6 different sessions.- So the comment at lines 26-27 ("Each case has its own session") is now true.
- The id is now
- Reviewer 1, round 2, non-blocking (
"max_tokens"is an indirect sign): rejected by the author. The reason: a match on prompt text ties the test to text that changes more often. I accept it. Both round-2 reviews confirmed the marker holds today, and the check fails loudly (summaries == 0) if it ever stops finding a summary call.
Non-blocking
proxy/summarytoken_test.go:96:for i, s := range seenshadows the outer case indexifrom line 44. It is correct: line 73 reads the outeribefore the shadow starts. A different name (for examplen) would make the two clearer. Not needed for merge.
What I checked
- Last review: round 2, a30c0fa, 2026-11-11T15:37:26Z
- New commits read: 1 (
32699e09test(proxy): give each token-canary case a valid session id) - Read in full: 4 reviews, 3 comments, 0 inline comments (from the three files)
- New items since my last review:
- Commit 32699e0 (+3/-2): read the diff and the whole file (141 lines). Reviewed above. It changes only the session id string and adds the
fmtimport. The commit has DCO sign-off andAssisted-By:. - Comment by vz-ibm at 2026-11-11T15:38:59Z (round-2 replies): point 1 checked against
safeExplicitand line 73, true. Point 2 is the rejection above, accepted. - Comment by amiddavid at 2026-11-12T07:13:11Z (integrator note: approvals are at a30c0fa, head changed): this review is the round on the final head that the note asks for.
- Reviewer 2's round-2 review (2026-11-11T15:36:55Z): read in full. Its one point is the session id, now fixed.
- Commit 32699e0 (+3/-2): read the diff and the whole file (141 lines). Reviewed above. It changes only the session id string and adds the
- Go 1.22+ loop-variable semantics (module is Go 1.26): each subtest closure gets its own
i,routeandtc. - Full PR diff against base
f123d528: one new file,proxy/summarytoken_test.go. Test-only. No behavior change, no data-dependence change, no binary. - I did not run the test. Go is not installed, and live tests are not approved.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (claude, user of @amiddavid) | Claude Code 2.1.322 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 3 of 3 | 32699e094e7b |
approve |
Verdict: approve
Findings
None.
Earlier findings
- Reviewer 2, round 1, finding 1 (no wait for the summary call): fixed in a30c0fa. It stays fixed at this head. Lines 79-81 wait with
WaitForAllSummariesForTest. Lines 85-95 fail when no summary call came. - Reviewer 1, round 1, finding 1 (same defect): fixed, for the same reason.
- Reviewer 2, round 2, non-blocking (the per-case session id does nothing): fixed in 32699e0.
- The id is now
fmt.Sprintf("token-canary-%s-%d", route.name, i)(line 73). Example:token-canary-openai-0. - Every character is in the
safeExplicitallow-list (session/session.go:43-65): letters, digits,-. The length is far belowMaxExplicitLen. SoScopeduses the id and does not fall back to the content hash. - The 6 ids are distinct: 2 routes × index 0-2.
- So the comment at lines 26-27 ("Each case has its own session") is now true.
- The id is now
- Reviewer 1, round 2, non-blocking (
"max_tokens"is an indirect sign): rejected by the author. The reason: a match on the summarize prompt ties the test to prompt text that changes more often. I accept it. It is non-blocking, and the marker holds today, as both round-2 reviews checked.
Non-blocking
proxy/summarytoken_test.go:96:for i, s := range seenshadows the outer case indexi(line 44). It is correct: the outeriis used only at line 73, before the loop. A different name (for examplen) would read more clearly. Not needed for merge.
What I checked
- Last review: round 2, a30c0fa, 2026-11-11T15:36:55Z
- New commits read: 1
32699e09test(proxy): give each token-canary case a valid session id (+3/-2,proxy/summarytoken_test.go)
- Read in full: 4 reviews, 3 comments, 0 inline comments (from the three files)
- New items since my last review:
- Reviewer 1's round-2 review (15:37:26Z). Approve. Its one non-blocking point is covered above.
- The author's round-2 reply (15:38:59Z). I checked point 1 against the code: true. I accept point 2 (see above).
- The integrator note by amiddavid (2026-11-12T07:13:11Z). It asks for a review round on the final head. This review is that round, at
32699e09.
- The whole file at this head (141 lines), not only the diff lines.
session.ScopedandsafeExplicit(session/session.go), for the new id.- The whole PR is still 1 file,
proxy/summarytoken_test.go. No binary, no behavior change, no data-dependence change.docs/data-dependence.mdneeds no update. - All 3 commits have
Signed-off-by:andAssisted-By:. None hasCo-Authored-By. - I did not run the tests. Live tests are not approved, and Go is not installed on this machine.
Summary
A guard test for one security rule: Context Guru's own token never reaches an upstream. It covers the second way a credential leaves the proxy: a component's own model call (
model.source: incoming), such as the summary call.What we found
CallerKeyskips only a token of the exact shape (tenant.LooksLikeToken: prefix and length). So a damaged token (one character short) can become the key of a summary call.DocallssetUpstreamAuth, which runsscrubTokenon every call (proxy/dispatcher.go).scrubTokenmatches the prefix alone, at any length.scrubTokenitself and the forwarded request.What changed
New
proxy/summarytoken_test.go,TestSummaryCallNeverSendsContextGurusToken:Authorizationvalues with the token second.offload.WaitForAllSummariesForTest, and fails when no summary call came.How it was tested
main.go test -raceon it and the existing token tests: OK.go vet: OK.setUpstreamAuthcall inDispatcher.Doremoved (the forwarded request keeps its own scrub), the 2 damaged-token cases fail, 5 runs of 5 (OpenAI and Bob). The code was then restored.-count=3 -race: OK.Data dependence
None changed. Test only.