Repository navigation
refactor(proxyapp): run the proxy's startup as proxyapp.Main with host hooks - #1109
Conversation
Move every file of cmd/context-guru-proxy into proxyapp, with no change other than the package clause and three relative paths in tests. The next commit turns main() into proxyapp.Main and adds the hooks. This commit alone leaves cmd/context-guru-proxy without a main package, so `make build` needs the next commit. It is split out so that git and the review see every file as a rename. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
cmd/context-guru-proxy/main.go is now one call: proxyapp.Main(Hooks{}).
A host with its own parts calls Main with its Hooks and keeps only those
parts, instead of copying the whole startup.
Why: Go cannot extend a package main, so the IBM deployment copied this
startup and copied each later step by hand. Two steps were missed: ping
rows were not recorded from v0.5.2, and from v0.7.2 no ping saving was
booked, because the copy never called proxy.PingSavings.
The hooks run at fixed points: Flags, Defaults, UIPath, BeforeControlDB,
TenantOptions, Hosted, ProxyOptions, DashAuth, Mount and Handler. The zero
Hooks runs the same code as before.
Also move two cachePolicy tests from the IBM deployment, which pinned
its copy against this one.
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: DAVID BOAZ <[email protected]>
TestStartupBannerUsesTheSharedRegisterResolver read cmd/context-guru-proxy/main.go, which is now one call. Read the moved startup instead, and fix two comments that named the old path. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | fresh | 2 of 2 | 1 of 2 | a565c81ee37e |
approve |
Verdict: approve
Findings
None.
Non-blocking
- proxyapp/main_run.go:561-565 — a
Hooks.Hostederror callslog.Fatalfafter the control database and the dashboard recorder are open.log.Fatalfrunsos.Exit, so the deferredreg.Close()andrec.Close()never run, and WAL/-shm files stay behind. This is the failure shape thecheckIdleExitcomment (main_run.go:323-331) says it moved specifically to avoid. It fires only on a host-programmer error, so it stays non-blocking. Fix: run the hook beforetenant.Open, or closeregexplicitly before theFatalf. - proxyapp/main_run.go:881-885 — a malformed
Hooks.UIPathpanics after the port is bound and the "listening" line is logged.dash.SetUIPathpanics on a path that is not rooted and slash-terminated (dash/mountpath.go:34-40), andMaincalls it afterlistenAndAnnounce. The failure is loud, so it stays non-blocking. Fix: validatehooks.UIPathnext tocheckIdleExit, before anything opens. - proxyapp/hooks_test.go:96 — the UIPath test does not fetch the moved mount. The test asserts the
"/hookdash/"string, which comes fromMain's own "dashboard enabled" log line (main_run.go:464), not from the route table. A regression that callsSetUIPathafterh.Mux()would still pass. Fix:GET /hookdash/inbootAndGetand assert it is not 404. - docs/design.md package map — no
proxyapprow. The map still ends atcmd/context-guru-proxy/as the composition root. The startup now lives inproxyapp, and CLAUDE.md already names it. The PR changes no docs. Fix: add one row.
What I checked
- Read CLAUDE.md and docs/design.md.
- Read the full diff
9966adf0..HEADand the code around each change. - Verified the move is behavior-preserving: I diffed every renamed file against its base version (
cmd/context-guru-proxy/*.goat9966adf0). Each differs only bypackage main→package proxyapp, two../-depth fixes in preflight_test.go, and theTestMainhook dispatch in hostedenv_test.go.main_run.godiffers from the oldmain.goonly by the hook insertions, theuiPathhelp-text interpolation, andtopts.ManagerEmailin one log line. Both are value-identical for the shipped binary, which passesHooks{}(the zero value). - Verified the shipped binary has no behavior change:
cmd/context-guru-proxy/main.gois now a 17-line stub that callsproxyapp.Main(proxyapp.Hooks{}). No edge case changes behavior, so no human-permission rule is triggered. - Verified the hook ordering in
Mainagainst the documented contract in hooks.go:Flagsbeforeflag.Parse,BeforeControlDBandTenantOptionsbeforetenant.Open,Hostedafter it withRegistry/Upstreamsset andHandler/Muxunset,ProxyOptionsbeforeproxy.New,DashAuthin hosted mode only,MountafterMux()with everyAppfield set,HandlerafterMount, and the idle-exit stamp outermost. All match. - Verified
Hooks.UIPathis applied beforeh.Mux(), which is the orderdash.SetUIPathrequires (the route table is read at mount time, dash/mountpath.go:22-32). - Verified
stampActivityThroughis identical to the oldstampActivitywhen no host wrapper exists (next == mux), so the idle-exit clock is unchanged for the binary. - Verified no stale references: no Go file reads
cmd/context-guru-proxy/main.goanymore; the source-inspection test now readsproxyapp/main_run.go(proxy/adversarial_test.go:65). The Makefile still builds./cmd/context-guru-proxy, which exists.agent/imports_test.goalready listsproxyappas a host package, so the library-never-imports-host guard covers the new code. - Verified no import cycle and no library package imports
proxyapp; onlycmd/context-guru-proxyandcmd/cg-cache-campaignimport it. - Checked the data-dependence rule: the PR adds no component and no feature that stores data.
Hooks.Defaults.DashboardContentchanges only what a downstream host may default to; this repo's shipped default stays off. No row file is needed. - Read the new tests: hooks_test.go (hook order, effect of each hook, zero-hooks defaults, real HTTP through the mounted route and the wrapper), cachepolicy_test.go (two
cachePolicyfield tests, consistent withconfig.CacheConfig.Resolved, config/config.go:302). - Did not run builds or tests: live tests are not approved for this review.
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | fresh | 1 of 2 | 1 of 2 | a565c81ee37e |
blocking |
Verdict: blocking
Findings
-
.github/workflows/ci.yaml:155 — the CI depguard step now runs no test, and passes
- What fails: The PR moved
TestDefaultBuildLinksNoOpenTelemetryGRPCOrProtobuffromcmd/context-guru-proxytoproxyapp/depguard_test.go. The step still saysgo test -run TestDefaultBuildLinksNoOpenTelemetryGRPCOrProtobuf ./cmd/context-guru-proxy/. That directory now holds only the 17-linemain.go.go teston a package with no test files prints "no test files" and exits 0. The gate that keeps OpenTelemetry, gRPC and protobuf (11.5 MB) out of the default build silently checks nothing in therecordjob.scripts/release/part-a.sh:57has the same stale path, so the release pipeline's copy of the gate is a no-op too. - Proof:
ls cmd/context-guru-proxy/shows onlymain.go. The test lives atproxyapp/depguard_test.go:14. The depguard test's own comment says "a guard that skips proves nothing" — this is now a skipping guard in two pipelines. - Fix: Change both invocations from
./cmd/context-guru-proxy/to./proxyapp/.
- What fails: The PR moved
-
.github/workflows/ci.yaml:165 — the startup tests no longer run under
-tags cg_record+ race- What fails: The
race-recordstep covers./proxy/... ./internal/record/... ./tenant/... ./cmd/context-guru-proxy/.... The moved startup tests (hosted boot, hooks, listen, shutdown, idle-exit, recordflags) are now in./proxyapp/..., which this list does not name../cmd/context-guru-proxy/...matches no test files, so the step passes while covering less. The startup tests previously ran with the session recorder compiled in and under the race detector; now they run only in the untaggedmake coverrun.scripts/release/part-a.sh:63is the same list, so the release pipeline loses the same coverage. - Proof:
go list ./cmd/context-guru-proxy/...resolves to one package with no_test.gofiles; every moved test file (proxyapp/*_test.go) sits under./proxyapp/. - Fix: Replace
./cmd/context-guru-proxy/...with./proxyapp/...in both places.
- What fails: The
Non-blocking
docs/design.mdpackage map has no row forproxyapp, and itscmd/context-guru-proxy/row ("the proxy binary / eval-containers gateway") no longer says where the startup lives. The PR moves 1600 lines of startup intoproxyappand adds theHooksAPI; the layout doc should name it.- Stale path comments:
config/config.go:632andcontext-guru-plugin/scripts/start-proxy.sh:796still citecmd/context-guru-proxy/main.go. The code they describe is nowproxyapp/main_run.go. proxyapp/hooks.go:44— theHostedhook doc says "app.Registry and app.Upstreams are set; app.Handler and app.Mux are not yet".app.Tenantsis also not yet set at that point (it is assigned afterproxy.NewTenantSource, main_run.go:566). Say so, so a host does not read the hosted trio as complete.proxyapp/main_run.go:538— an error fromhooks.BeforeControlDBis reported ascontrol database: %v. The hook may fail for reasons unrelated to the database. Give it its own message.proxyapp/hooks_test.go:141—bootAndGetpicks a port, closes the listener, then expects the child to bind the same port. Another process can take the port in between, and the test then fails on the 20 s deadline. A flake risk, not a correctness bug.cmd/cg-cache-campaignimportsproxyappfor the Pricer facade. The facade is now the whole composition root, so that tool links the proxy server, the dashboard and every component (components/allblank import). No behavior defect; a size and dependency cost worth knowing.proxyapp/cachepolicy_test.go:22— test name saysCarriesCoresFields; "Core" was probably meant.
What I checked
- Read
CLAUDE.mdanddocs/design.mdfor the rules. - Read the full diff (3 commits) and every changed file.
- Diffed
proxyapp/main_run.goagainst the basecmd/context-guru-proxy/main.goline by line. The startup body is byte-identical except: the package clause, theHooksinsertions (Flags,Defaults,UIPath,BeforeControlDB,TenantOptions,Hosted,ProxyOptions,DashAuth,Mount,Handler),topts.ManagerEmailreplacing*managerEmailin two log lines, andstampActivityThrough. With zeroHooksall of these resolve to the old values, so the shipped binary's startup behavior is unchanged. No behavior-change permission is needed for the binary itself. - Diffed every moved file (
idleexit.go,recordflags.go,claudecompact.go, all 18 moved test files) against its base copy. All are pure package renames plus the../../deploy→../deploypath fixes inhostedenv_test.goandpreflight_test.go, which are correct for the shallower directory. - Verified the hook ordering in
Mainmatches the orderTestHooksRunInOrderAndTakeEffectasserts, and thatappfields are set before each hook reads them. - Verified
stampActivityThroughkeeps the mux as the route authority whenHooks.Handlerwraps it, so the idle-exit semantics are unchanged. - Verified
proxy/adversarial_test.gostill passes against the moved source:main_run.gocontainsproxy.RegisterMode(), and neither banned string (Getenv("CG_REGISTER"),envOr("CG_REGISTER") appears;Getenv("CG_REGISTER_CODE")does not match the banned substring. - Verified the new
cachepolicy_test.goexpectations againstconfig.CacheConfig.Resolved()andWaitPlanOn(): all defaults it asserts are filled unconditionally, andWaitPlanOnis true for an absent setting. - Verified no test or script still reads a file under
cmd/context-guru-proxy/other than building the binary path itself. - Checked the boundary rules:
proxyappis listed as a host package ininternal/boundary/boundary_test.goand inagent/imports_test.go; no library package importsproxyorproxyappthrough this change. - Data dependence: the PR adds no component and no feature, and changes nothing about what is stored. No row file under
docs/data-dependence/is needed, anddocs/data-dependence.mdis untouched, consistent with that. - Live tests were not run; Go is not approved on this machine.
…ything opens Review round 1 on #1109: - CI and scripts/release/part-a.sh ran the depguard test and the cg_record race tests on ./cmd/context-guru-proxy, which now has no tests, so both gates passed while checking nothing. They run on ./proxyapp now. - A bad Hooks.UIPath is refused next to checkIdleExit, before anything opens. dash.SetUIPath used to panic after the port was bound. - A Hooks.BeforeControlDB or Hooks.Hosted error closes the open databases before it stops the start, and names the hook. - The hook test fetches the moved dashboard, so it fails when SetUIPath runs after Mux(). bootAndGet retries when another process takes the port first. - docs/design.md gets a proxyapp row; two comments name the moved file. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
Replies to review round 1All fixed in Reviewer 1Blocking 1: the depguard step ran no test. Fixed. Blocking 2: the startup tests left the race and Non-blocking:
Reviewer 2
Failing tests that are not from this change
|
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | resumed | 2 of 2 | 2 of 2 | 38d0a8f11e1c |
approve |
Verdict: approve
Findings
None.
Status of round-1 findings
Reviewer 1, blocking 1 (CI depguard ran no test): fixed. ci.yaml:155 and scripts/release/part-a.sh:57 now run the test on ./proxyapp/, where proxyapp/depguard_test.go lives. I read both steps in context. The test exists and carries //go:build !cg_record, which matches the untagged step.
Reviewer 1, blocking 2 (startup tests left the race + cg_record run): fixed. ci.yaml:165 and part-a.sh:63 now name ./proxyapp/.... I also checked race-rest in part-a.sh: its $rest list (go list ./... minus proxy, dash, plugin) includes proxyapp, so the untagged race run covers the moved tests too.
Reviewer 2 (mine), Hosted error left the databases open: fixed. hookFailed (main_run.go:502-511) closes reg and rec, then calls log.Fatalf, and names the hook. I checked both call sites: BeforeControlDB (main_run.go:555) runs while reg is nil and only rec needs the close; Hosted (main_run.go:579) runs after tenant.Open, so reg is set. The var reg declaration moved up so the closure sees the assignment. The deferred closes never run after the explicit ones, so there is no double close.
Reviewer 2 (mine), bad UIPath panicked after the bind: fixed. checkUIPath (main_run.go:993-1000) applies the same rule as dash.SetUIPath (dash/mountpath.go:36-38), and Main calls it next to checkIdleExit (main_run.go:336-339), before the recorder, the databases or the port open. TestCheckUIPath covers four valid and four invalid paths.
Reviewer 2 (mine), the test did not fetch the moved mount: fixed. TestHooksRunInOrderAndTakeEffect now GETs both /hookdash/ and /dashboard/ and requires the page at the moved path only (hooks_test.go:109-116). The author also verified the test fails when SetUIPath runs after Mux().
Reviewer 2 (mine) and reviewer 1, design.md has no proxyapp row: fixed. docs/design.md:34 adds the row, and the cmd/context-guru-proxy/ row now says it is one call.
Reviewer 1, non-blocking: stale comments (config.go:632, start-proxy.sh:796) fixed; Hosted doc now names app.Tenants as unset; BeforeControlDB errors now read context-guru: Hooks.BeforeControlDB: ...; bootAndGet retries on "address already in use" up to 3 times; the test is renamed TestCachePolicyActivePathCarriesItsResolvedFields. All verified in the diff.
Reviewer 1, cg-cache-campaign binary size: rejected by the author, and I accept the reason. The author measured CGO_ENABLED=0 go build ./cmd/cg-cache-campaign: 21,815,298 bytes on main, 21,832,098 on this branch, +0.08%. The tool already links proxy and dash, so the startup adds almost nothing. The reason is right.
Non-blocking
- proxyapp/main_run.go:993-1000 —
checkUIPathcopiesdash.SetUIPath's rule by hand. If dash changes its rule, the copy drifts and the post-bind panic returns.TestCheckUIPathpins the copy, not the sync. Fix: export the validation fromdashand use it in both places. - proxyapp/main_run.go:502-511 —
hookFaileddoes not closetraceRec. With--record, the session recorder is open when a hosted hook fails. Nothing was recorded at that point, so nothing is lost. Fix: add the same nil-guarded close, for symmetry.
What I checked
- Last review: round 1, a565c81, 2026-11-11T19:36:04Z.
- New commits read: 1 —
38d0a8f1"fix(proxyapp): Run the CI gates on proxyapp and check hooks before anything opens". - Read in full: 2 reviews, 1 comment, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review: reviewer 1's round-1 review (posted 19:36:43Z), the author's reply comment (19:43:01Z), and commit
38d0a8f1. I read all three in full and checked every fix and every rejection against the code. - Read the full diff
a565c81e..38d0a8f1and the code around each change:main_run.go(checkUIPath placement, hookFailed, the movedvar reg),hooks.go(doc updates),hooks_test.go(the new mount assertions,TestCheckUIPath, the bootAndGet retry),ci.yaml,scripts/release/part-a.sh(including the$restlist),docs/design.md,config/config.go,context-guru-plugin/scripts/start-proxy.sh,cachepolicy_test.go. - Checked the
bootAndGetretry logic for races: theexitedchannel is checked before each poll, the deferredKillwaits on<-exited, and a child that dies between the check and the GET is caught on the next loop pass. - Checked the data-dependence rule again for the new commit: it changes no component and no storage. No row file is needed.
- Checked the behavior-change rule:
checkUIPathadds a startup refusal for a malformed host hook value only. The shipped binary passesHooks{}and is unaffected. - Did not run builds or tests: live tests are not approved. The author reports
go test -race -tags cg_record -p 1 ./proxyapp/...passes except two preflight tests that fail the same way on main (a localinstall.shenvironment issue, not from this change).
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | resumed | 1 of 2 | 2 of 2 | 38d0a8f11e1c |
approve |
Verdict: approve
Findings
None.
Round-1 findings, checked against 38d0a8f1
- CI depguard step ran no test — fixed.
ci.yaml:155andpart-a.sh:57now say./proxyapp/. I grepped.github/,scripts/andMakefileforgo test.*cmd/context-guru-proxy; no match remains. - Startup tests left the
cg_recordrace run — fixed.ci.yaml:165andpart-a.sh:63now name./proxyapp/....
Non-blocking items: design.md has a proxyapp/ row and a corrected cmd/context-guru-proxy/ row; the two stale comments (config/config.go, start-proxy.sh) now name proxyapp/main_run.go; the Hosted doc says app.Tenants is not set yet; the hook error message names the hook; bootAndGet retries on "address already in use"; the test name is TestCachePolicyActivePathCarriesItsResolvedFields.
The cg-cache-campaign note was rejected with a measurement: +16,800 bytes (0.08%), because the tool already links proxy and dash. The reason is right. I accept it.
Reviewer 2's round-1 items, checked myself
Hostederror left the databases open — fixed.hookFailed(main_run.go:503) closesregandrecbeforelog.Fatalf. The closure readsregat call time, so it is nil atBeforeControlDBand set atHosted; both nil-guards are right. The deferred closes never double-run, becauselog.Fatalfexits without running defers.- Bad
UIPathpanicked after the bind — fixed.checkUIPath(main_run.go:991) applies exactlydash.SetUIPath's condition (!HasPrefix(p, "/") || !HasSuffix(p, "/") || p == "/", dash/mountpath.go:35), andMaincalls it at main_run.go:336, next tocheckIdleExitand before the recorder, the registry and the port open.TestCheckUIPathcovers valid and invalid shapes. - The test did not fetch the moved mount — fixed.
TestHooksRunInOrderAndTakeEffectnow requiresGET /hookdash/to answer 200 with the page andGET /dashboard/not to answer 200. This is the assertion that pinsSetUIPathbeforeMux(). - design.md — fixed, same as mine.
New code reviewed in 38d0a8f1
checkUIPathand its call site: rule matchesdash.SetUIPathexactly; placement is before anything opens.hookFailed: closure capture, nil-guards, and close order read correct.traceRecis the one open resource it does not close; nothing is recorded before serving starts, so nothing is lost. Consistency only.bootAndGet/bootAndGetOnce: the retry detects the child's exit by channel, distinguishes "address already in use" from other exits, and bounds itself to 3 attempts. The wait/kill defer cannot double-wait. The first-path poll keeps the 20 s deadline.TestHooksRunInOrderAndTakeEffect's map-shapedbootAndGet: nil-map indexing on an exhausted retry returns a zero probe, so the failure mode is a clear test error with the log, not a panic.
Non-blocking
hookFailedhas no test. It is a startup-fatal path, and the repo's own standard for those is that they are tested (checkIdleExit's comment). TherunMainsubprocess harness could drive it with a failingHostedhook.checkUIPathgot a test; this path did not.checkUIPathrestatesdash.SetUIPath's rule by hand. Ifdashever widens its rule,checkUIPathover-refuses or the panic returns. A test that assertscheckUIPathaccepts whateverdashaccepts would pin the two together.
What I checked
- Last review: round 1,
a565c81ee37e72c8b4a6e3c8e5c62e684b1eea16, 2026-11-11T19:36:43Z. - New commits read: 1 (
38d0a8f1"fix(proxyapp): Run the CI gates on proxyapp and check hooks before anything opens"). - Read in full: 2 reviews, 1 comment, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review: the fix commit (read in full, reviewed above); the author's reply comment (read in full; every claimed fix verified in code; the two preflight-test failures on this Mac are environmental and pre-date this PR, since those test files are unchanged moves); reviewer 2's round-1 review (read now for the first time; its four items checked myself, all fixed).
- Verified the four CI/release invocations now target
./proxyapp/, and nogo testinvocation namescmd/context-guru-proxyanywhere in.github/,scripts/orMakefile. - Verified
checkUIPathagainstdash/mountpath.go:35condition by condition. - Verified
hookFailed's scope:recopens before the hosted block,regafterBeforeControlDBand beforeHosted; the disk state store opens after the hosted block, so no failable hook runs while it is open;ProxyOptions,MountandHandlercannot return errors. - Verified
bootAndGet's retry loop and exit-channel handling for lost-child and dead-child races. - No live tests were run; Go is not approved on this machine.
Failing tests:
|
Apply #1102's cachePolicy change (MaxBodyBytes on the parked and the enabled policy) to proxyapp/main_run.go, where commit 1 moved the code. cmd/context-guru-proxy/main.go stays the single proxyapp.Main call. The #1102 test moved to proxyapp/terminal_tools_test.go through the rename. 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 2 (bob, user of @amiddavid) | IBM Bob Shell 1.0.3 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 3 of 3 | 3715e43caf61 |
approve |
Verdict: approve
Findings
None.
Status of earlier findings
All round-1 and round-2 findings from both reviewers were fixed in commit 38d0a8f1. No new findings in this round.
What I checked
- Last review: round 2, 38d0a8f, 2026-11-11T19:45:54Z
- New commits read: 1 —
3715e43c"Merge origin/main into refactor/proxyapp-main" - Read in full: 4 reviews, 2 comments, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt) - New items since my last review: The merge commit
3715e43conly. No new reviews, comments, or inline comments after 19:46:28Z.
Merge commit analysis
The merge brings 4 PRs from main into this branch:
- #1106 (docs): Release lessons only, no code changes to review
- #1102 (keepalive): MaxBodyBytes limit change from 8 MiB to 32 MiB
- #1099 (proxy): Keep-alive credit tracking counters
- #1101 (proxy): Keep marks survive config rebuild and restart
Critical verification: #1102's MaxBodyBytes change was correctly applied to the moved code.
I verified the merge applied #1102's change correctly:
proxyapp/main_run.go:1301: The parked-block policy path now setsMaxBodyBytes: r.KeepAliveMaxBodyBytes(line matches the merge commit message)proxyapp/main_run.go:1323: The enabled policy path also setsMaxBodyBytes: r.KeepAliveMaxBodyBytesproxyapp/terminal_tools_test.go:54-64: New testTestCachePolicyCarriesTheBodyLimitverifies both paths carry the field, matching #1102's test incmd/context-guru-proxy/terminal_tools_test.go
The merge is clean. No conflicts. The #1102 change that would have conflicted with this PR's move was manually resolved correctly: the field reaches both the parked and enabled policy, as #1102 intended.
Verification of merged changes
All four merged PRs had their own offload reviews (stated in their commit messages). I spot-checked their integration:
- #1102 body limit:
keepalive/types.goupdated constants and addedBodyLimit()method.keepalive/bodylimit_test.goadded. Config default inconfig/config.go:328. All consistent with the proxyapp changes. - #1099 credit counters:
proxy/pingunpriced_test.gois a new 156-line test file covering wired/unwired hosts, rejected pings, and /stats + /metrics export.proxy/accountant_ping.goandproxy/accountant_savings.gotrack the counters.proxy/dashcapture.goincrements on missing facts. All changes are additive (new counters, new tests). No behavior change to existing paths. - #1101 keep marks:
proxy/tenancy.go:656addedcarryKeepMarks().store/store.go:1283addedPrefixCopierinterface andCarryPrefix().proxy/tenancy_test.goadded 3 tests. The session-state row file was updated. All changes preserve the fail-open rule: a store that cannot carry leaves the new store empty (line 1322). - #1106 docs:
RELEASING.mdonly. No code to review.
Data dependence check
The merge adds no new component. The keep-marks feature (#1101) updated its row file docs/data-dependence/features/session-state-table.md, which now says the cg:keep: prefix (session id + content hash, one byte value) is metadata and is written to the session-state table. This is consistent with the code: store/disk.go:84 added KeptPrefix to metadataPrefixes. No content is stored in the mark itself.
Behavior changes
The merge brings three behavior changes, all approved in their own PRs:
- #1102: Bodies of 8-32 MiB on priced models are now judged by the cost cap, not refused. Owner approved 2026-11-11.
- #1099: New /stats keys and /metrics series only (read-only counters). No request/response change.
- #1101: Keep marks survive config rebuild and restart. Owner approved 2026-11-11.
None of these changes affect the proxyapp refactor itself. The merge only integrates them into the moved code.
Boundary and fail-open rules
- No library package imports
proxyorproxyappthrough this merge. The changes are inproxy/,keepalive/,store/,config/, andproxyapp/. - Fail-open:
carryKeepMarks(proxy/tenancy.go:667) has a defer-recover that returns 0 on panic, so a store that cannot carry leaves the new store empty.store.CarryPrefix(store/store.go:1286) also has defer-recover. Both fail open. - The keep-alive changes (#1099, #1102) are in the keeper, which already fails open: a refused hold does not block the request.
Test coverage
The merge adds:
keepalive/bodylimit_test.go: 116 lines, covers the new body limit logicproxy/pingunpriced_test.go: 156 lines, covers the credit-tracking countersproxy/tenancy_test.go: 3 new tests (133 lines) for keep-marks survivalproxyapp/terminal_tools_test.go: 1 new test (11 lines) for the body limit in cache policy
All new tests are consistent with the features they test. No test was removed or weakened.
Commit message and DCO
The merge commit message is clear: it names the #1102 change, where it was applied, and which test moved. It has Assisted-By: Claude Opus 5.5 and Signed-off-by: DAVID AMID. DCO is present.
No regressions
The merge does not revert any fix from rounds 1 or 2:
- CI paths still target
./proxyapp/(not reverted) checkUIPathstill runs before anything opens (not reverted)hookFailedstill closes the databases (not reverted)- All docs updates from round 2 are still present
The merge is correct, clean, and complete.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (bob, user of @amiddavid) | IBM Bob Shell 1.0.3 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 3 of 3 | 3715e43caf61 |
approve |
Verdict: approve
Findings
None.
Status of earlier findings
All round-1 and round-2 findings were fixed in commit 38d0a8f1. The merge commit 3715e43c brings in 4 commits from main (d877ba5d, ea509595, b68d0741, 55d8b497) and correctly applies their changes to the refactored code. No new defects introduced.
Non-blocking
- keepalive/types.go:243 — the comment says "4 bodies at the per-body limit". At 32 MiB per body, 4 bodies is 128 MiB, which equals MaxBytes exactly. The comment is correct but could be clearer: "4 bodies at the 32 MiB limit exactly fill the 128 MiB budget".
What I checked
- Last review: round 2, 38d0a8f, 2026-11-11T19:46:28Z.
- New commits read: 5 (3715e43 merge + 4 from main: d877ba5, ea50959, b68d074, 55d8b49).
- Read in full: 4 reviews, 2 comments, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review: none. The last item in the conversation is reviewer 1's round-2 review at 19:46:28Z. The merge happened after all reviews.
Commit d877ba5 (docs: RELEASING.md)
- Adds release lessons from v0.7.2 to RELEASING.md: Part B traps, known flakes, stacked PR workflow, merge-of-main test failures.
- Behavior change: none (docs only). Data dependence: none.
- No code changes. Documentation is clear and follows ASD-STE100 style.
Commit ea50959 (#1102: keepalive body limit)
- Raises the per-body limit from 8 MiB to 32 MiB (keepalive.MaxBodyBytes). The cost cap (Policy.Ceiling) decides whether a large body is worth pinging.
- For unpriced models (no cost cap), keeps the old 8 MiB limit (LegacyMaxBodyBytes).
- New config key
cache.keepalive_max_body_bytes(default 33554432). Setting 8388608 restores the old limit. - Behavior change: approved by owner 2026-11-11. Bodies of 8-32 MiB on priced models are now judged by the cost cap instead of refused. How to turn off: set
cache.keepalive_max_body_bytes: 8388608. - Data dependence: none changed (metadata only).
- Verified the implementation:
Policy.BodyLimit()returns MaxBodyBytes (32 MiB) when unset, clamps to MaxBytes (128 MiB), and respects the configured value.keeper.gousespol.BodyLimit()for the per-body check andLegacyMaxBodyBytesfor unpriced models.cachePolicy()inproxyapp/main_run.gocarriesMaxBodyBytesto both the parked and enabled policy (lines 1301, 1323).config.Resolved()defaultsKeepAliveMaxBodyBytestoDefaultKeepAliveMaxBodyBytes(32 MiB).- Test coverage:
keepalive/bodylimit_test.gocovers the 9 MiB body under the cap, over the cap, the memory guard, the legacy switch, unpriced models, and the config default. proxyapp/terminal_tools_test.go:53-65verifies the limit reaches both the parked and enabled policy.
Commit b68d074 (#1099: count missing ping facts)
- Adds two counters:
keepalive_pings_priced(pings the host priced) andkeepalive_rescue_facts_missing(warm returns that found no ping facts, so credit was lost). - Behavior change: none to requests or responses. New /stats keys and 2 new /metrics series only (read-only counters).
- Data dependence: metadata only (counts).
- Verified the implementation:
PingStore.notePriced()increments the counter whenPingSavingsreturns ok (proxy/accountant_ping.go:133).savingsTracker.noteRescueFactsMissing()increments when a priced request followed pings but found no facts (proxy/dashcapture.go:850).- Both counters are exported in
/stats(proxy/proxy.go:3101-3102) and/metrics(proxy/promexport.go:697-705). - Test coverage:
proxy/pingunpriced_test.gocovers wired hosts (facts found), unwired hosts (no store, PingSavings never called, key mismatch), rejected pings, no pings in the gap, manual pings, and the /stats + /metrics export. proxy/promexport_coverage_test.goupdated to document the two new fields as exported from the handler's savings tracker and ping store, not from the aggregator snapshot.
Commit 55d8b49 (#1101: keep dedup marks across rebuild)
- dedup's "keep in full" marks (cg:keep:) now survive a tenant config rebuild and a restart when the component set is the same.
- Rebuild:
carryKeepMarks(proxy/tenancy.go:656-676) copies marks from the old Store to the new one when both pipelines have the same component names in the same order. - Restart:
store.KeptPrefixis a metadata session-state key, so the #770 session state saves and reloads the marks. - Behavior change: approved by owner 2026-11-11. Hosted tenants whose config changes, and local hosts after a restart, on a thread with an earlier expand. Old: dedup compacted those outputs again and the warm cache was rewritten. New: they stay in full and the cache is read. How to turn off: no dedicated switch;
store.enabled: falseremoves all marks,--session-state=falsestops the restart half. - Data dependence: metadata only. A mark key holds a session id and a content hash; the value is one byte. Row: docs/data-dependence/features/session-state-table.md.
- Verified the implementation:
carryKeepMarkschecks that both pipelines have the same component names in the same order (slices.Equal(prev.Pipe.Names(), next.Pipe.Names())), then callsstore.CarryPrefix.store.CarryPrefixcopies every entry under the prefix from one store to another usingEntriesWithPrefix(a newPrefixCopierinterface). It never fails: a store that cannot carry leaves the new store empty (fail open).Memory.EntriesWithPrefixreturns a copy of every live entry under the prefix, without changing any lifetime or order.store.KeptPrefixis added tometadataPrefixesinstore/disk.go:84, so it is saved and reloaded as session state.- The carry runs at two points: when a config change rebuilds the tenancy (proxy/tenancy.go:635), and when a second request publishes the rebuild first (proxy/tenancy.go:660).
- Test coverage:
proxy/tenancy_test.go:1131-1261covers marks surviving a rebuild with the same components, not surviving a rebuild with different components, and surviving two concurrent rebuilds where the second request publishes first. components/offload/dedup_test.go:64adds a test for the mark surviving a rebuild.
Merge commit 3715e43
- Merges origin/main into refactor/proxyapp-main.
- Applies #1102's
MaxBodyByteschange toproxyapp/main_run.go(the code moved fromcmd/context-guru-proxy/main.goin commit 1 of this PR). - Moves #1102's test from
cmd/context-guru-proxy/terminal_tools_test.gotoproxyapp/terminal_tools_test.go(the file moved in commit 1). - Verified the merge resolution:
proxyapp/main_run.go:1301and1323both setMaxBodyBytes: r.KeepAliveMaxBodyBytes, matching the pattern in the basecmd/context-guru-proxy/main.goat ea50959.proxyapp/terminal_tools_test.go:53-65is the exact test fromcmd/context-guru-proxy/terminal_tools_test.goat ea50959, with no changes.- The merge commit message documents the resolution and names the files.
- No conflicts in the other 3 commits: they touch files this PR does not change.
Verification across all 5 commits
- Checked the data-dependence rule: #1102, #1099 and #1101 each state their data dependence at the top of the commit message. #1102 and #1099 change no data dependence. #1101 adds one metadata key (
cg:keep:) and updates its row file (docs/data-dependence/features/session-state-table.md). - Checked the behavior-change rule: #1102 and #1101 each state the behavior change, who it affects, the old and new behavior, how to turn it off, and the owner's approval. #1099 changes no behavior (counters only). #1106 is docs only.
- Checked the fail-open rule: #1102's body limit is a memory guard, not a correctness gate; the cost cap decides. #1101's
CarryPrefixfails open (a store that cannot carry leaves the new store empty). #1099 adds counters only. - Checked the boundary rules: no library package imports
proxyorproxyappthrough any of these changes. The merge applies the changes toproxyapp/, which is already listed as a host package. - Checked the review process: #1102, #1099 and #1101 each went through 2-3 offload review rounds (GLM), and all reviewers approved at the PR head. #1106 went through 2 rounds, both approved.
- No stale references: the merge correctly moves the test to
proxyapp/terminal_tools_test.go, and no other file reads the old path. - Did not run builds or tests: live tests are not approved for this review.
Bump the plugin versions for v0.7.3. - Claude Code plugin 0.7.2 -> 0.7.3: it follows the proxy release (#1109 changed two plugin tests and scripts/start-proxy.sh). - Bob plugin 0.1.0 -> 0.1.1: #973 (bob-ultrahigh becomes the default). - OpenCode plugin: no version file. Its first start now downloads proxy v0.7.3 (was v0.7.2). Nothing compares against PINNED_VERSION; the floor stays "v0.7.1 or later". The READMEs, the install guide and 3 tests follow. - Codex 0.2.12 and Pi 0.1.1: no change since v0.7.2. Behavior change: the OpenCode plugin's first download is proxy v0.7.3. Owner's yes, 2026-11-11, in the integrator session: "1107 approved". Data dependence: none. Reviews: 3 offload review rounds (GLM, then Bob while GLM was down). Round 3: both approve at 5d11267, which is the PR head. Signed-off-by: DAVID AMID <[email protected]> Assisted-By: Claude Opus 5.5 <[email protected]>
The proxy's startup moved from cmd/context-guru-proxy/main.go to proxyapp.Main (#1109), so the push wiring moves with it: the four --metrics-push flags, the start of the push before proxy.New, the two proxy.Options fields, and the keep-alive ping hook on dashEmitter. The push files metricspush.go and metricspush_test.go move into package proxyapp. The earlier commits in this branch keep cmd/context-guru-proxy/main.go as upstream has it; this commit is where the proxy starts to use them, so those commits do not build the wiring on their own. The data-dependence row is now a row file, docs/data-dependence/features/metrics-push.md, as #1090 requires, and docs/data-dependence.md is rebuilt from it. The text of the row is unchanged except that the token sentence says the central asks for none today (#1130). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
Summary
The proxy's startup moves from
cmd/context-guru-proxyintoproxyapp.Main. A host can now run the standard proxy and add its own parts throughproxyapp.Hooks. It does not have to copy the startup any more.cmd/context-guru-proxy/main.gobecomes one call:proxyapp.Main(proxyapp.Hooks{}).No behavior change. With no hooks,
Mainruns the same code as the oldmain(). Each hook is a nil check around an addition.Why
main. So the IBM deployment (MLT/cg,ibm/cmd/cg-proxy) copied ourmain.goand edited the copy to add its IBM-only parts: the W3ID login, the per-token key store, the key injection, its own routes.main.gothen had to be copied by hand, and nothing warned when a copy was missed. Two were missed:proxy.PingSavingsand never setOptions.Pings(MLT/cg#75).AccountantState,ToolDeferPath,dash.Options.Prices(Dashboard: the first request of a session books cost $0 (token_accounting=partial), so total cost under-counts the bill #920), the ping-row panic guard (Accountant integration: the keep-alive ping pricing has no recover, so a panic would end the process #918),SeedGraceSessions.What changed
cmd/context-guru-proxymoves toproxyapp/. The only edits are the package clause and three relative paths in tests. Git shows all 23 files as renames.main()becomesfunc Main(hooks Hooks).proxyapp/hooks.goaddsHooks,DefaultsandApp.cmd/context-guru-proxy/main.gois the one call.stampActivityThroughlets the idle-exit stamp wrap a host's handler. It still asks the mux which requests count as use.TestStartupBannerUsesTheSharedRegisterResolverreadsproxyapp/main_run.go, the new place of the startup.The hooks, in the order they run:
Flags(fs)flag.ParseDefaults.DashboardContent--dashboard-content; the flag andDASHBOARD_CONTENTstill winUIPathdash.API.SetUIPathbeforeMux(), and in the dashboard's log lineBeforeControlDB(path)tenant.OpenTenantOptions(*opts)tenant.OpenHosted(app)tenant.OpenProxyOptions(*opts, app)proxy.NewDashAuth(core)Mount(mux, app)Mux()Handler(next, app)These are the points where the IBM copy changes our startup today. Each one maps to one IBM part.
How it was tested
go build ./...,go vet ./proxyapp ./cmd/..., and the same with-tags cg_record.go test ./proxyapp ./proxy ./dashpass, with the exceptions below.TestHooksRunInOrderAndTakeEffect: boots the realMainin a subprocess in hosted mode, with every hook set. It checks the order, what each hook sees, and that each one takes effect. I checked that it fails when theMountcall is removed.TestNoHooksKeepsTheBinaryDefaults: with no hooks, the dashboard stays at/dashboard/and content capture stays off.cachePolicytests move here from the IBM repo, where they pinned its copy against ours.ibm/cmd/cg-proxy/main.gowith a caller ofMainand its hooks, about 290 lines in place of 1,582. With a localreplaceto this branch,go build ./...,go vet ./...and thecg-proxytests pass. That PR waits for a release with this change.Failures that are not from this change. They fail the same way on
main, on this Mac:TestPreflightReadsKeyEnvFromConfigNotCommentsandTestPreflightResolvesToolsOnTheServicePATH:install.shfunctions are not found under the system bash.bob-pluginand others: the local Python has noPath.is_relative_to.mainagainst this branch is still running. I will post the result as a comment.Data dependence
None. No feature reads or stores anything new.
Open questions
Hooks,Defaults,AppandMainbecome public API ofproxyapp. Is that the surface you want to keep stable?Appfields.AppexposesConfig,Recorder,Registry,Tenants,Upstreams,Windows,Prices,HandlerandMux. The IBM hooks use all of them.Assisted-By: Claude (Anthropic AI) [email protected]