Skip to content

refactor(proxyapp): run the proxy's startup as proxyapp.Main with host hooks - #1109

Merged
amiddavid merged 5 commits into
mainfrom
refactor/proxyapp-main
Nov 11, 2026
Merged

amiddavid merged 5 commits into
mainfrom
refactor/proxyapp-main

Conversation

@boazdavid

Copy link
Copy Markdown
Collaborator

Summary

The proxy's startup moves from cmd/context-guru-proxy into proxyapp.Main. A host can now run the standard proxy and add its own parts through proxyapp.Hooks. It does not have to copy the startup any more. cmd/context-guru-proxy/main.go becomes one call: proxyapp.Main(proxyapp.Hooks{}).

No behavior change. With no hooks, Main runs the same code as the old main(). Each hook is a nil check around an addition.

Why

What changed

  1. Commit 1, a pure move. Every file of cmd/context-guru-proxy moves to proxyapp/. The only edits are the package clause and three relative paths in tests. Git shows all 23 files as renames.
  2. Commit 2, the hooks.
    • main() becomes func Main(hooks Hooks).
    • proxyapp/hooks.go adds Hooks, Defaults and App.
    • cmd/context-guru-proxy/main.go is the one call.
    • stampActivityThrough lets the idle-exit stamp wrap a host's handler. It still asks the mux which requests count as use.
  3. Commit 3. TestStartupBannerUsesTheSharedRegisterResolver reads proxyapp/main_run.go, the new place of the startup.

The hooks, in the order they run:

Hook When it runs
Flags(fs) before flag.Parse
Defaults.DashboardContent as the default of --dashboard-content; the flag and DASHBOARD_CONTENT still win
UIPath dash.API.SetUIPath before Mux(), and in the dashboard's log line
BeforeControlDB(path) hosted mode, before tenant.Open
TenantOptions(*opts) just before tenant.Open
Hosted(app) just after tenant.Open
ProxyOptions(*opts, app) just before proxy.New
DashAuth(core) wraps the hosted dashboard authenticator
Mount(mux, app) after Mux()
Handler(next, app) wraps the mux; the idle-exit stamp wraps the result

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 ./dash pass, with the exceptions below.
  • New TestHooksRunInOrderAndTakeEffect: boots the real Main in 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 the Mount call is removed.
  • New TestNoHooksKeepsTheBinaryDefaults: with no hooks, the dashboard stays at /dashboard/ and content capture stays off.
  • Two cachePolicy tests move here from the IBM repo, where they pinned its copy against ours.
  • The IBM side builds on this branch. I replaced ibm/cmd/cg-proxy/main.go with a caller of Main and its hooks, about 290 lines in place of 1,582. With a local replace to this branch, go build ./..., go vet ./... and the cg-proxy tests 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:

  • TestPreflightReadsKeyEnvFromConfigNotComments and TestPreflightResolvesToolsOnTheServicePATH: install.sh functions are not found under the system bash.
  • The Python suites of bob-plugin and others: the local Python has no Path.is_relative_to.
  • A comparison of the failing test names on main against 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

  • API promise. Hooks, Defaults, App and Main become public API of proxyapp. Is that the surface you want to keep stable?
  • App fields. App exposes Config, Recorder, Registry, Tenants, Upstreams, Windows, Prices, Handler and Mux. The IBM hooks use all of them.

Assisted-By: Claude (Anthropic AI) [email protected]

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 boazdavid 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 (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.Hosted error calls log.Fatalf after the control database and the dashboard recorder are open. log.Fatalf runs os.Exit, so the deferred reg.Close() and rec.Close() never run, and WAL/-shm files stay behind. This is the failure shape the checkIdleExit comment (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 before tenant.Open, or close reg explicitly before the Fatalf.
  • proxyapp/main_run.go:881-885 — a malformed Hooks.UIPath panics after the port is bound and the "listening" line is logged. dash.SetUIPath panics on a path that is not rooted and slash-terminated (dash/mountpath.go:34-40), and Main calls it after listenAndAnnounce. The failure is loud, so it stays non-blocking. Fix: validate hooks.UIPath next to checkIdleExit, 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 from Main's own "dashboard enabled" log line (main_run.go:464), not from the route table. A regression that calls SetUIPath after h.Mux() would still pass. Fix: GET /hookdash/ in bootAndGet and assert it is not 404.
  • docs/design.md package map — no proxyapp row. The map still ends at cmd/context-guru-proxy/ as the composition root. The startup now lives in proxyapp, 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..HEAD and the code around each change.
  • Verified the move is behavior-preserving: I diffed every renamed file against its base version (cmd/context-guru-proxy/*.go at 9966adf0). Each differs only by package main → package proxyapp, two ../-depth fixes in preflight_test.go, and the TestMain hook dispatch in hostedenv_test.go. main_run.go differs from the old main.go only by the hook insertions, the uiPath help-text interpolation, and topts.ManagerEmail in one log line. Both are value-identical for the shipped binary, which passes Hooks{} (the zero value).
  • Verified the shipped binary has no behavior change: cmd/context-guru-proxy/main.go is now a 17-line stub that calls proxyapp.Main(proxyapp.Hooks{}). No edge case changes behavior, so no human-permission rule is triggered.
  • Verified the hook ordering in Main against the documented contract in hooks.go: Flags before flag.Parse, BeforeControlDB and TenantOptions before tenant.Open, Hosted after it with Registry/Upstreams set and Handler/Mux unset, ProxyOptions before proxy.New, DashAuth in hosted mode only, Mount after Mux() with every App field set, Handler after Mount, and the idle-exit stamp outermost. All match.
  • Verified Hooks.UIPath is applied before h.Mux(), which is the order dash.SetUIPath requires (the route table is read at mount time, dash/mountpath.go:22-32).
  • Verified stampActivityThrough is identical to the old stampActivity when 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.go anymore; the source-inspection test now reads proxyapp/main_run.go (proxy/adversarial_test.go:65). The Makefile still builds ./cmd/context-guru-proxy, which exists. agent/imports_test.go already lists proxyapp as a host package, so the library-never-imports-host guard covers the new code.
  • Verified no import cycle and no library package imports proxyapp; only cmd/context-guru-proxy and cmd/cg-cache-campaign import it.
  • Checked the data-dependence rule: the PR adds no component and no feature that stores data. Hooks.Defaults.DashboardContent changes 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 cachePolicy field tests, consistent with config.CacheConfig.Resolved, config/config.go:302).
  • Did not run builds or tests: live tests are not approved for this review.

@boazdavid boazdavid 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 (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

  1. .github/workflows/ci.yaml:155 — the CI depguard step now runs no test, and passes

    • What fails: The PR moved TestDefaultBuildLinksNoOpenTelemetryGRPCOrProtobuf from cmd/context-guru-proxy to proxyapp/depguard_test.go. The step still says go test -run TestDefaultBuildLinksNoOpenTelemetryGRPCOrProtobuf ./cmd/context-guru-proxy/. That directory now holds only the 17-line main.go. go test on 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 the record job. scripts/release/part-a.sh:57 has 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 only main.go. The test lives at proxyapp/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/.
  2. .github/workflows/ci.yaml:165 — the startup tests no longer run under -tags cg_record + race

    • What fails: The race-record step 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 untagged make cover run. scripts/release/part-a.sh:63 is 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.go files; every moved test file (proxyapp/*_test.go) sits under ./proxyapp/.
    • Fix: Replace ./cmd/context-guru-proxy/... with ./proxyapp/... in both places.

Non-blocking

  • docs/design.md package map has no row for proxyapp, and its cmd/context-guru-proxy/ row ("the proxy binary / eval-containers gateway") no longer says where the startup lives. The PR moves 1600 lines of startup into proxyapp and adds the Hooks API; the layout doc should name it.
  • Stale path comments: config/config.go:632 and context-guru-plugin/scripts/start-proxy.sh:796 still cite cmd/context-guru-proxy/main.go. The code they describe is now proxyapp/main_run.go.
  • proxyapp/hooks.go:44 — the Hosted hook doc says "app.Registry and app.Upstreams are set; app.Handler and app.Mux are not yet". app.Tenants is also not yet set at that point (it is assigned after proxy.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 from hooks.BeforeControlDB is reported as control database: %v. The hook may fail for reasons unrelated to the database. Give it its own message.
  • proxyapp/hooks_test.go:141 — bootAndGet picks 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-campaign imports proxyapp for the Pricer facade. The facade is now the whole composition root, so that tool links the proxy server, the dashboard and every component (components/all blank import). No behavior defect; a size and dependency cost worth knowing.
  • proxyapp/cachepolicy_test.go:22 — test name says CarriesCoresFields; "Core" was probably meant.

What I checked

  • Read CLAUDE.md and docs/design.md for the rules.
  • Read the full diff (3 commits) and every changed file.
  • Diffed proxyapp/main_run.go against the base cmd/context-guru-proxy/main.go line by line. The startup body is byte-identical except: the package clause, the Hooks insertions (Flags, Defaults, UIPath, BeforeControlDB, TenantOptions, Hosted, ProxyOptions, DashAuth, Mount, Handler), topts.ManagerEmail replacing *managerEmail in two log lines, and stampActivityThrough. With zero Hooks all 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 → ../deploy path fixes in hostedenv_test.go and preflight_test.go, which are correct for the shallower directory.
  • Verified the hook ordering in Main matches the order TestHooksRunInOrderAndTakeEffect asserts, and that app fields are set before each hook reads them.
  • Verified stampActivityThrough keeps the mux as the route authority when Hooks.Handler wraps it, so the idle-exit semantics are unchanged.
  • Verified proxy/adversarial_test.go still passes against the moved source: main_run.go contains proxy.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.go expectations against config.CacheConfig.Resolved() and WaitPlanOn(): all defaults it asserts are filled unconditionally, and WaitPlanOn is 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: proxyapp is listed as a host package in internal/boundary/boundary_test.go and in agent/imports_test.go; no library package imports proxy or proxyapp through 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, and docs/data-dependence.md is 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]>
@boazdavid

Copy link
Copy Markdown
Collaborator Author

Replies to review round 1

All fixed in 38d0a8f1, except one note, which I answer with a measurement.

Reviewer 1

Blocking 1: the depguard step ran no test. Fixed. ci.yaml:155 and scripts/release/part-a.sh:57 run it on ./proxyapp/. Checked: go test -run TestDefaultBuildLinksNoOpenTelemetryGRPCOrProtobuf ./proxyapp/ reports --- PASS, not "no test files".

Blocking 2: the startup tests left the race and cg_record run. Fixed. ci.yaml:165 and part-a.sh:63 name ./proxyapp/.... Checked: go test -race -tags cg_record -p 1 ./proxyapp/... passes, except the two preflight tests below.

Non-blocking:

  • docs/design.md: fixed. It has a proxyapp/ row, and the cmd/context-guru-proxy/ row says it is one call.
  • Stale comments in config/config.go and start-proxy.sh: fixed.
  • Hosted doc: fixed. It says app.Tenants is not set yet.
  • BeforeControlDB message: fixed. A hook error now reads context-guru: Hooks.BeforeControlDB: ....
  • Port race in bootAndGet: fixed. When the child exits on address already in use, the boot retries on a new port, up to 3 times.
  • cachepolicy_test.go name: renamed to TestCachePolicyActivePathCarriesItsResolvedFields.
  • cg-cache-campaign links the whole startup: no change. I measured it. CGO_ENABLED=0 go build ./cmd/cg-cache-campaign is 21,815,298 bytes on main and 21,832,098 bytes on this branch, +16,800 bytes (0.08%). The tool already links proxy and dash, so the startup adds almost nothing.

Reviewer 2

  • A Hosted error left the databases open: fixed. hookFailed closes the registry and the recorder, then calls log.Fatalf. It covers BeforeControlDB too, where the recorder is already open.
  • A bad UIPath panicked after the bind: fixed. checkUIPath applies dash.SetUIPath's rule next to checkIdleExit, before anything opens. New TestCheckUIPath covers it.
  • The test did not fetch the moved mount: fixed. It now requires GET /hookdash/ to answer 200 with the page, and GET /dashboard/ not to answer 200. In hosted mode the old path gets the auth layer's 401, not a 404. I checked that the test fails when SetUIPath runs after Mux(): /hookdash/ then answers 401 and /dashboard/ 200.
  • docs/design.md: fixed, as above.

Failing tests that are not from this change

TestPreflightReadsKeyEnvFromConfigNotComments and TestPreflightResolvesToolsOnTheServicePATH fail on this Mac with install.sh: ... command not found. They fail the same way on main at 9966adf0.

@boazdavid boazdavid 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 (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 — checkUIPath copies dash.SetUIPath's rule by hand. If dash changes its rule, the copy drifts and the post-bind panic returns. TestCheckUIPath pins the copy, not the sync. Fix: export the validation from dash and use it in both places.
  • proxyapp/main_run.go:502-511 — hookFailed does not close traceRec. 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..38d0a8f1 and the code around each change: main_run.go (checkUIPath placement, hookFailed, the moved var 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 $rest list), docs/design.md, config/config.go, context-guru-plugin/scripts/start-proxy.sh, cachepolicy_test.go.
  • Checked the bootAndGet retry logic for races: the exited channel is checked before each poll, the deferred Kill waits 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: checkUIPath adds a startup refusal for a malformed host hook value only. The shipped binary passes Hooks{} 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 local install.sh environment issue, not from this change).

@boazdavid boazdavid 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 (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

  1. CI depguard step ran no test — fixed. ci.yaml:155 and part-a.sh:57 now say ./proxyapp/. I grepped .github/, scripts/ and Makefile for go test.*cmd/context-guru-proxy; no match remains.
  2. Startup tests left the cg_record race run — fixed. ci.yaml:165 and part-a.sh:63 now 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

  • Hosted error left the databases open — fixed. hookFailed (main_run.go:503) closes reg and rec before log.Fatalf. The closure reads reg at call time, so it is nil at BeforeControlDB and set at Hosted; both nil-guards are right. The deferred closes never double-run, because log.Fatalf exits without running defers.
  • Bad UIPath panicked after the bind — fixed. checkUIPath (main_run.go:991) applies exactly dash.SetUIPath's condition (!HasPrefix(p, "/") || !HasSuffix(p, "/") || p == "/", dash/mountpath.go:35), and Main calls it at main_run.go:336, next to checkIdleExit and before the recorder, the registry and the port open. TestCheckUIPath covers valid and invalid shapes.
  • The test did not fetch the moved mount — fixed. TestHooksRunInOrderAndTakeEffect now requires GET /hookdash/ to answer 200 with the page and GET /dashboard/ not to answer 200. This is the assertion that pins SetUIPath before Mux().
  • design.md — fixed, same as mine.

New code reviewed in 38d0a8f1

  • checkUIPath and its call site: rule matches dash.SetUIPath exactly; placement is before anything opens.
  • hookFailed: closure capture, nil-guards, and close order read correct. traceRec is 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-shaped bootAndGet: 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

  • hookFailed has no test. It is a startup-fatal path, and the repo's own standard for those is that they are tested (checkIdleExit's comment). The runMain subprocess harness could drive it with a failing Hosted hook. checkUIPath got a test; this path did not.
  • checkUIPath restates dash.SetUIPath's rule by hand. If dash ever widens its rule, checkUIPath over-refuses or the panic returns. A test that asserts checkUIPath accepts whatever dash accepts 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 no go test invocation names cmd/context-guru-proxy anywhere in .github/, scripts/ or Makefile.
  • Verified checkUIPath against dash/mountpath.go:35 condition by condition.
  • Verified hookFailed's scope: rec opens before the hosted block, reg after BeforeControlDB and before Hosted; the disk state store opens after the hosted block, so no failable hook runs while it is open; ProxyOptions, Mount and Handler cannot 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.

@boazdavid

Copy link
Copy Markdown
Collaborator Author

Failing tests: main against this branch

The PR description promised this comparison. No test fails because of this change.

I ran the same packages on main (9966adf0) and on this branch (a565c81e), on this Mac: bob-plugin, context-guru-plugin, internal/modelinfo, pi-package, proxy, and the startup tests (cmd/context-guru-proxy on main, proxyapp here).

  • 21 tests fail on both sides, with the same names. Examples: the two TestPreflight* tests, the bob-plugin and pi-package Python suites, and the context-guru-plugin install and golden tests. They are environment failures on this Mac: old system bash and Python.
  • proxy passes on both sides.
  • One test failed on this branch only: TestStatuslineGoldenLive (context-guru-plugin).
    • context-guru-plugin does not depend on proxyapp: go list -deps ./context-guru-plugin names no proxyapp.
    • Run alone, it passes 3 times out of 3 on each side (-count=3).
    • So it is a flake in the long parallel run, not a result of this change.

Assisted-By: Claude (Anthropic AI) [email protected]

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 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 (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 3715e43c only. 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 sets MaxBodyBytes: r.KeepAliveMaxBodyBytes (line matches the merge commit message)
  • proxyapp/main_run.go:1323: The enabled policy path also sets MaxBodyBytes: r.KeepAliveMaxBodyBytes
  • proxyapp/terminal_tools_test.go:54-64: New test TestCachePolicyCarriesTheBodyLimit verifies both paths carry the field, matching #1102's test in cmd/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.go updated constants and added BodyLimit() method. keepalive/bodylimit_test.go added. Config default in config/config.go:328. All consistent with the proxyapp changes.
  • #1099 credit counters: proxy/pingunpriced_test.go is a new 156-line test file covering wired/unwired hosts, rejected pings, and /stats + /metrics export. proxy/accountant_ping.go and proxy/accountant_savings.go track the counters. proxy/dashcapture.go increments on missing facts. All changes are additive (new counters, new tests). No behavior change to existing paths.
  • #1101 keep marks: proxy/tenancy.go:656 added carryKeepMarks(). store/store.go:1283 added PrefixCopier interface and CarryPrefix(). proxy/tenancy_test.go added 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.md only. 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:

  1. #1102: Bodies of 8-32 MiB on priced models are now judged by the cost cap, not refused. Owner approved 2026-11-11.
  2. #1099: New /stats keys and /metrics series only (read-only counters). No request/response change.
  3. #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 proxy or proxyapp through this merge. The changes are in proxy/, keepalive/, store/, config/, and proxyapp/.
  • 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 logic
  • proxy/pingunpriced_test.go: 156 lines, covers the credit-tracking counters
  • proxy/tenancy_test.go: 3 new tests (133 lines) for keep-marks survival
  • proxyapp/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)
  • checkUIPath still runs before anything opens (not reverted)
  • hookFailed still closes the databases (not reverted)
  • All docs updates from round 2 are still present

The merge is correct, clean, and complete.

@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 (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.go uses pol.BodyLimit() for the per-body check and LegacyMaxBodyBytes for unpriced models.
    • cachePolicy() in proxyapp/main_run.go carries MaxBodyBytes to both the parked and enabled policy (lines 1301, 1323).
    • config.Resolved() defaults KeepAliveMaxBodyBytes to DefaultKeepAliveMaxBodyBytes (32 MiB).
    • Test coverage: keepalive/bodylimit_test.go covers 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-65 verifies 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) and keepalive_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 when PingSavings returns 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.go covers 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.go updated 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.KeptPrefix is 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: false removes all marks, --session-state=false stops 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:
    • carryKeepMarks checks that both pipelines have the same component names in the same order (slices.Equal(prev.Pipe.Names(), next.Pipe.Names())), then calls store.CarryPrefix.
    • store.CarryPrefix copies every entry under the prefix from one store to another using EntriesWithPrefix (a new PrefixCopier interface). It never fails: a store that cannot carry leaves the new store empty (fail open).
    • Memory.EntriesWithPrefix returns a copy of every live entry under the prefix, without changing any lifetime or order.
    • store.KeptPrefix is added to metadataPrefixes in store/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-1261 covers 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:64 adds a test for the mark surviving a rebuild.

Merge commit 3715e43

  • Merges origin/main into refactor/proxyapp-main.
  • Applies #1102's MaxBodyBytes change to proxyapp/main_run.go (the code moved from cmd/context-guru-proxy/main.go in commit 1 of this PR).
  • Moves #1102's test from cmd/context-guru-proxy/terminal_tools_test.go to proxyapp/terminal_tools_test.go (the file moved in commit 1).
  • Verified the merge resolution:
    • proxyapp/main_run.go:1301 and 1323 both set MaxBodyBytes: r.KeepAliveMaxBodyBytes, matching the pattern in the base cmd/context-guru-proxy/main.go at ea50959.
    • proxyapp/terminal_tools_test.go:53-65 is the exact test from cmd/context-guru-proxy/terminal_tools_test.go at 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 CarryPrefix fails open (a store that cannot carry leaves the new store empty). #1099 adds counters only.
  • Checked the boundary rules: no library package imports proxy or proxyapp through any of these changes. The merge applies the changes to proxyapp/, 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.

@amiddavid amiddavid closed this Nov 11, 2026
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 11, 2026
@amiddavid amiddavid reopened this Nov 11, 2026
@amiddavid
amiddavid merged commit 3048e12 into main Nov 11, 2026
9 checks passed
amiddavid added a commit that referenced this pull request Nov 12, 2026
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]>
boazdavid added a commit that referenced this pull request Nov 12, 2026
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]>
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