Repository navigation
refactor(campaign): move the adapt recommendation choice out of the proxy (3/3, #1302) - #1334
Conversation
…the proxy Add the library package `campaign`. It holds the calibrated constants, the closed-form replay, the fidelity model, the ship gate, the auto builder and the decision math that proxy/predictive.go, campaignauto.go, adaptreplay.go and adaptcache.go used to hold. The proxy reads history and files and calls it. No behaviour change. The rowFloor wait-cause gap stays as it is (#1298). Refs #1309 Closes #1302 (with the next PR in the stack) Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
amiddavid
left a comment
There was a problem hiding this comment.
| 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.331 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | c3b15632dc43 |
approve |
Verdict: approve
Findings
None.
Non-blocking
Pick.GateDiffandPick.GateCIread as zero whenGateID == "". The proxy reads them only underRecommends(), so no wrong output. A caller could misread them; not worth a change now.campaign.Option.Diffis unused for the"never"baseline (the tests set it). Harmless.
What I checked
- Read the full diff (
campaign/recommend.gonew,campaign/recommend_test.gonew,proxy/adaptcache.gorewritten block) and the base version ofproxy/adaptcache.goatbc42e0f0. - Behavior equality, line by line. I compared the old inline block against
Picker.AddandPicker.Result:- Best tracking: same
"never"exclusion, same start at-Inf, same strict>(first option wins a tie). - Gate and fail tracking: same
gateID == ""/failID == ""guards, same strict>, samestrings.Join(why, "; "). - Disagreement: same
realBeats != GatePasstest, same reset-then-append, same leader-by-net choice. - Summary switch: same case order (
BestID == ""first,GateID != ""second, thenbeats && failID == bestID,beats,defaultid, else). The recommendation map is built underRecommends(), which is set only in the same case that built it before.
- Best tracking: same
- Wire format. I extracted every format string from the old file and the new file and diffed them. All five moved strings (three summaries, two disagreement lines, plus the gate summary) are byte-identical. The strings that stayed in the proxy are unchanged.
- Compile-level checks by reading (no builds, per the review rules):
math,strings,fmtare all still used inproxy/adaptcache.go(lines 471-518,strings.Join(disagree, ""),fmtthroughout).recommend.goimports onlyfmt,math,strings, all used. No name collisions:Option,Pick,Picker,NewPickerdo not exist elsewhere incampaign; the test identifierspick,never,defcollide with nothing in the package's other test files. - Hard boundaries. The move follows the library/proxy rule: the choice logic now lives in
campaign, which imports no host package. The proxy keeps only the report assembly. No data-dependence change: the code reads the same inputs it read before, so nodocs/data-dependence/row change is needed. No behavior change for users, so no human sign-off is required. - Tests. The new tests cover all six summary branches (no option, gate pass, adapted leader fails the gate, fixed leader, default leads, interval includes zero) and both disagreement directions. I traced each assertion against
Add/Resultby hand; each expectation matches the code. The proxy'srecommendation,gainand warning assembly still read the same fields they read before.
amiddavid
left a comment
There was a problem hiding this comment.
| 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.331 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | c3b15632dc43 |
approve |
Verdict: approve
Findings
None. The change moves the adapt report's recommendation choice out of the proxy, and I found no behavior difference.
Non-blocking
proxy/adaptcache.go:345— the K3 baseline (campaign.ScoreRows(facts, test, fixed(3, se), &fp)) is recomputed inside the loop, once per adapted option. Pre-existing, unchanged by this PR.K3is also scored as its own arm earlier, so the same numbers are computed twice per adapted arm.campaign/recommend.go:44— theAdddoc comment spans three lines and mixes the "never" rule with the Disagreement rule. A short second sentence onDisagreementwould read easier. Style only.
What I checked
- Read
CLAUDE.mdanddocs/design.md. - Read the full diff (3 files, +199/−45) and the code around each change.
- Compared the moved logic line by line against
bc42e0f0:proxy/adaptcache.go:- Best pick: same rule (
id != "never", best net,-Infstart, strict>so the first of a tie wins), same fields (Net,CI,Diff = SumOf(d)). - Gate pick, fail pick, disagreement pick: same conditions, same tie-breaks, same reset-to-nil of
disagree. - All six summary strings and both disagreement strings: byte-identical to the old ones.
beats(BestID != "default" && BestCI[0] > 0), the recommendation condition (GateID != ""↔Recommends()), and the switch order: identical.- Unavailable strategies still
continuebeforepicker.Add, so they enter neither the best nor the gate pick, as before.
- Best pick: same rule (
- Checked the boundaries the repo sets: logic moved from
proxyinto the library packagecampaign(the direction the rules ask for);campaignimports nothing fromproxy; no new data dependence (the picker works on computed numbers only), so nodocs/data-dependence/row is needed; no behavior change, so no human sign-off is needed. - Checked for symbol collisions:
Option,Picker,Pick,NewPickerare new incampaign; the test helperpickand varsnever,defcollide with nothing at package scope (defincampaign/replay.gois a parameter). - Checked the new tests: they cover the recommend path, the leader-fails-gate path, the fixed-plan leader, the interval-includes-zero case, the default leading, no option at all, and both disagreement directions. The proxy's own
adaptcache_test.gostill exercises the report end to end. - Did not run builds or tests (live tests not approved).
- Document that Eval and BuildSpec need facts when segBy is set. - Drop the dead `if ss := ...; true` wrapper in Rows. - Drop the idle loop in the Apply test: Apply takes no idle. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Move the mapping of a suggest arm to a live keep-alive strategy, the cell resolution, the overlap and duplicate checks, the weekday and hour tiling and the grouping of cells into strategies into the `campaign` library package. - The mirror constants of config.Default* are gone. The library reads config.DefaultKeepAliveIdle, DefaultKeepAliveMaxPings, DefaultKeepAliveMinPrefix and DefaultHeadTTLMinTokens. The values do not change. - `campaign.HonorsHeadTTL1h` replaces two copies of the "every model honors the 1h tier" rule: the proxy's and cmd/cg-cache-campaign's. - The proxy keeps the HTTP routes, the views and validateGroupStrategy. No behaviour change. Refs #1309 Closes #1302 Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
- DefaultWeekdays is a function that returns a copy; a test pins it. - Explain the 50,000-token head-TTL gate and why the deprecated config constant is the right value there. - Fix stale comments that named the old proxy functions. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
c3b1563 to
cee61e6
Compare
bc42e0f to
f27cf87
Compare
|
Round-1 notes, fixed in cee61e6 (macOS, Go 1.27.4). At this head: build, vet, gofmt clean;
Kept as is:
|
amiddavid
left a comment
There was a problem hiding this comment.
| 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.331 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | cee61e68bad1 |
approve |
Verdict: approve
Findings
None.
Earlier findings, status
- Mine, round 1 (non-blocking):
Pick.GateDiff/Pick.GateCIread as zero whenGateID == "". Fixed.cee61e68documents both fields as "zero when GateID is""". - Mine, round 1 (non-blocking):
Option.Diffunused for the"never"baseline. Kept as is, with a correct reason: the picker never picks"never"as best, and nothing reads itsDiff. I verified this again in round 1; the reason is right. Accepted. - Reviewer 2, round 1 (non-blocking): the
Adddoc comment mixed two rules in three lines. Fixed. It is now two short sentences. - Reviewer 2, round 1 (non-blocking): the K3 baseline recomputed once per adapted option. Kept as is. The reason is right: the line is old code moved unchanged, and a cache is a separate change. It is also outside this PR's diff (the base moved to
f27cf87fin the rebase).
Non-blocking
campaign/recommend.go:46— the newAdddoc says the option "is named in Disagree".Disagreeis a field ofPick, the result ofResult(), not ofPicker. A reader still finds it. Doc precision only.
What I checked
- Last review: round 1,
c3b15632dc43838cac99da24012421f903485be9, 2026-11-24T09:14:14Z. - New commits read: 2.
ad25a17b"refactor(campaign): move the adapt report's recommendation choice out of the proxy" — the reviewed commit, rebased onto the new basef27cf87f. I diffed its tree againstc3b15632for the three PR files: identical. No code change to re-review.cee61e68"docs(campaign): address round-1 notes on the picker, add the package map rows" — read in full. Two doc-comment edits incampaign/recommend.go, two new rows indocs/design.md. No code change.
- Read in full: 2 reviews, 1 comment, 0 inline comments (from the three saved files; the inline file is empty).
- New items since my last review, and what I did about each:
- Reviewer 2's round-1 review (09:14:49Z): two non-blocking notes. Both checked above.
- Author's comment (09:30:40Z): states the fixes and three kept-as-is items. Each checked above. The comment also reports build, vet, gofmt and tests green at this head (macOS, Go 1.27.4). I did not run them; live tests are not approved.
- Commit
cee61e68: verified thedocs/design.mdrows against the code.BuildSpec,Choose,Apply,Pickerexist incampaign;AutoTuneexists inpredictive; the arm mapping iscampaign/arms.go. Both rows' import claims hold:campaignandpredictiveimport only library packages (config,internal/*,keepalive,kvcache,predictive,tenant), neverproxyorproxyapp.
- The PR diff at this head is the same three-file change I approved in round 1, plus the two doc edits. The rebase changed the base to
f27cf87f; that commit is not part of this PR's diff.
amiddavid
left a comment
There was a problem hiding this comment.
| 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.331 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | cee61e68bad1 |
approve |
Verdict: approve
Findings
None. The new commit changes doc comments and docs/design.md only. No code path changed.
Earlier findings, status
- Mine, round 1 (non-blocking): the
Adddoc comment mixed two rules in three lines. Fixed.cee61e68splits it into two short sentences. The new text matches the code: "leads in gateway dollars while the gate disagrees, or the reverse" is exactlyrealBeats != GatePass. - Mine, round 1 (non-blocking): the K3 baseline recomputed once per adapted option. Kept as is. The reason is right: the line is old code, moved unchanged, and it sits outside this PR's diff now that the base moved to
f27cf87f. A cache is a separate change. Accepted. - Reviewer 1, round 1 (non-blocking):
Pick.GateDiff/Pick.GateCIread as zero whenGateID == "". Fixed. Both fields now say "zero when GateID is""" (campaign/recommend.go:74-75). Checked myself: the fields are set only inside thegateID != ""branch, so the doc is true. - Reviewer 1, round 1 (non-blocking):
Option.Diffunused for the"never"baseline. Kept as is, with a right reason: the picker never picks"never"as best, and nothing reads itsDiff. Verified. Accepted.
Non-blocking
- Agree with reviewer 1, round 2:
campaign/recommend.go:46— theAdddoc says the option "is named in Disagree", butDisagreeis a field ofPick(the result ofResult()), not ofPicker. A reader still finds it. Doc precision only.
What I checked
- Last review: round 1,
c3b15632dc43838cac99da24012421f903485be9, 2026-11-24T09:14:49Z. - New commits read: 5 in
c3b15632..cee61e68(the rebase abandoned the old shas):ad25a17b"refactor(campaign): move the adapt report's recommendation choice out of the proxy" — this PR's commit, re-based.git diff c3b15632 ad25a17bis empty: the tree is identical to the commit I approved in round 1. No code to re-review.cee61e68"docs(campaign): address round-1 notes on the picker, add the package map rows" — read in full. Two doc edits incampaign/recommend.go, two rows indocs/design.md. No code change.beb1292d,ba18d136,f27cf87f— the sibling stacked PRs' round-1 note fixes, now below this PR's basef27cf87f. Read all three diffs in full, although they are outside this PR's diff: doc and comment fixes,DefaultWeekdaysnow a function returning a copy (with a pinning test), a deadif ss := ...; truewrapper dropped incampaign/replay.go, and a dead idle loop dropped in theApplytest. Nothing that touches the picker or the adapt report.
- Read in full: 3 reviews, 1 comment, 0 inline comments (from the three saved files; the inline file is empty).
- New items since my last review, and what I did about each:
- Reviewer 1's round-1 review (09:14:14Z): two non-blocking notes. Both statused above.
- Author's comment (09:30:40Z): claims fixes in
cee61e68and three kept-as-is items. Each checked above. The comment also reports build, vet, gofmt and tests green at this head (macOS, Go 1.27.4). I did not run them; live tests are not approved. Its item "the bounds-test floor inproxy/campaign_test.go:32" maps to no finding in either round-1 review; it answers a note from outside this PR's conversation. Nothing to act on. - Reviewer 1's round-2 review (09:33:09Z): read. Its status calls match my own checks.
- Commit
cee61e68: verified thedocs/design.mdrows against the code.BuildSpec,Choose,Apply,Pickerexist incampaign;AutoTuneexists inpredictive; the arm mapping iscampaign/arms.go. The "no host code" claims hold:go list -depsshowspredictivedepends only onkvcache, andcampaignon library packages only (config,kvcache,predictive,tenant,keepalive,schema, andinternal/*) — neverproxyorproxyapp.
- The PR diff at this head (
git diff f27cf87f..cee61e68) is the three-file change I approved in round 1, plus the two doc edits. No behavior difference remains. - Did not run builds or tests (live tests not approved).
go listwas used only to read the package graph.
Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
… of the proxy Move the choice of the best option, the option that passes the builder's gate, the gate and gateway-dollar disagreement line, and the summary sentence of the adapt report into `campaign.Picker`. The proxy still builds the report rows and the JSON. No behaviour change. Refs #1309 Closes #1302 Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
…map rows Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
cee61e6 to
9854ddf
Compare
|
Output of Why CHANGED: the base moved too (#1333 got a comments-only commit), so the merge base differs, and the script only accepts comments-only with the same merge base. The range-diff shows commits 1 and 2 are equal and commit 3 (9854ddf) is one |
|
Approval check by hand: comments only. The approvals of
The only difference is one line in Secret scan by hand (vault-radar, offline) on the files changed at |
Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
|
Merged Conflict: one file,
Resolution: I kept this branch's side of the file.
The PR's changed lines are unchanged. The +/- lines of Tested on macOS, Go 1.27.4: build, vet and |
Summary
Last of 3 stacked PRs. Based on
feat/mv-1302-campaign-arms. Closes #1302. Part of #1309.What changed
campaign.Picker.adaptReportin the proxy builds the rows and JSON, and calls the picker.Behaviour
None. The sentences and the order of the checks are the same.
Left in the proxy, on purpose
adaptReportrow and JSON assembly, heatmap and display labels: display.validateGroupStrategy: waits for refactor(keepalive): move keep-alive policy resolution out of the proxy #1301.predictiveDecideInnerstill reads the response body for a few request facts when the capture gives none. That is refactor: move request and response fact parsing out of the proxy #1307's wire-format work.Data dependence
Same as before. No new reader of stored text.
How it was tested
macOS, Go 1.27.4, at this head:
go build ./... && go vet ./... && gofmt -l .: clean.CGO_ENABLED=1 go test -race -timeout 30m:./campaign,./cmd/...,./internal/...,./components/all,./predictive,./tenant,./keepalivepass../proxy(1204 s) pass.o.Net > p.bestNetto<fails 3 picker tests.o.GatePassnegated fails 2.Closes #1302. Refs #1309.