Repository navigation
test(proxyapp): boot helpers read the child's output, not the clock or the shell env - #1371
Conversation
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 | 7025dac56a6d |
approve |
Verdict: approve
Test-only change. The subprocess boot helpers now wait on the child's own
"listening" line, and the child gets an allow-listed env with a private HOME.
I found no defect I can prove.
Findings
None.
Non-blocking
proxyapp/hostedenv_helpers_test.go:120— the goroutine checks theattr
match only once, at the moment the generic watch fires. If the pipe ever
splits the line between "context-guru-proxy listening" and "addr=...", the
goroutine returns without closingready, andwaitListeningreports a
falsechildTimedOutafter 90 s. Probability is very low: slog writes one
record perWrite, and both parts sit in that record. The exit branch
re-checks the buffer; the split-write case has no such backstop. A loop that
re-checks on every later write would close it.proxyapp/hostedenv_test.go:44—runMainreturns a made-up exit code0
in the listening case. No caller readscodewhenexitedis false today.
A comment or a named constant would stop a future caller from trusting it.scripts/release/known-laptop-failures.txt— the removal of
TestNoHooksKeepsTheBinaryDefaultsis sound by reading: the shell's
DASHBOARD_CONTENTcan no longer reach the child, and that var was the
documented cause. The local-tests run at this head is the live proof; I could
not run it (live tests not approved).
What I checked
- The full diff, and every file it touches, in full.
- All call sites of
runMain,bootAndGetandbootAndGetOnce
(hostedenv_test.go,hooks_test.go,importhistory_test.go,
lifecycleflag_test.go). All updated to the new signature. No stale caller. TestMain(hostedenv_test.go:16): the child path needs only
CG_TEST_RUN_MAIN,CG_TEST_MAIN_ARGS,CG_TEST_HOOKSandLISTEN_ADDR.
childEnvsets the first,startChildthe last, and each test passes the
rest. Nothing the child needs is missing from the allow list.- Env duplicate order: Go's
Getenvscans the env list in reverse, so the last
entry wins.childEnvappends the test'sextralast, so a test var such as
DASHBOARD=trueoverrides an earlierDASHBOARD=falsefromhostedEnv.
Same semantics as the oldappend(os.Environ(), ...). - The waited-on line exists and is unique:
listenAndAnnounce
(proxyapp/main_run.go:61) is the only non-test caller, it logs after the
bind succeeds, and the text and JSON handlers both put the msg andaddr=
on one line.attr=""matches any line, which is whatrunMainwants. - The exit races: a listening line written just before an exit is re-checked in
the<-c.exitedbranch ofwaitListening, so it still counts as listening. - Refusal tests keep their meaning: the hosted refusal runs before the listen,
soexited=truewith a non-zero code, as before.-handimport-history
children never print the listening line, so they take the exit path. TestSingleTenantKeepsTheBinaryDefaults→TestSingleTenantKeepsCaptureEnv:
the new rule ("reached the listening line") is stricter than the old one
("still alive at 4 s"), and the verdict no longer depends on a clock.timingguard: the new helper usestime.NewTimer+select, which the
guard does not flag, so no new baseline entry is needed. The two removed
entries match the removedtime.Sleepand deadline loop; the baseline only
shrinks, which is the required direction.testutil.WaitForfatals on timeout (internal/testutil/testutil.go:38),
so the shutdown test still fails loudly if the SSE client never registers.local-tests.shhandles an empty known-failures list: thecommfilter
then treats every failing test as unknown, which is the intent.- Compile shape: the moved
syncBufferhas one definition, the removed imports
(bytes,context,os,os/exec,sync,timeinhooks_test.go) match
the remaining usage in each edited file, and no symbol in the new file
collides with one elsewhere in packageproxyapp. - Commit message: DCO sign-off present,
Assisted-By:used, no behavior
change claimed, and the claim matches the 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 | fresh | 2 of 2 | 1 of 2 | 7025dac56a6d |
approve |
Verdict: approve
The PR is test-only. It replaces clock-based waits and os.Environ() inheritance in the
proxyapp boot helpers with output-driven waits and a scrubbed child environment. I found no
real defect. Three robustness notes are below, none blocking.
Findings
None.
Non-blocking
-
proxyapp/hostedenv_helpers_test.go:120-133 — the watcher checks the
addr=part only once.- What could fail: the goroutine scans the lines when the message substring first appears. If that
one pipe write ever lands split betweencontext-guru-proxy listeningandaddr=…, the goroutine
returns without closingready, and the wait falls to the 90 s bound or the exit. - Why I do not believe it today:
listenAndAnnouncewrites the whole line in one slog record
(main_run.go:66), far below the pipe buffer, so both substrings arrive in the sameWrite. I could
not construct a failing input. - Fix if wanted: when the scan finds no matching line, re-arm the watch instead of returning.
- What could fail: the goroutine scans the lines when the message substring first appears. If that
-
proxyapp/hooks_test.go:151-159 — the third port collision returns
got=nil.- Callers then read a zero-value probe (status 0) and the failure names the route, not the lost
port. Pre-existing: the old code returnednilin the same place. Worth aportTakenmessage one
day, not in this PR.
- Callers then read a zero-value probe (status 0) and the failure names the route, not the lost
-
proxyapp/hooks_test.go:184-191 —
http.Gethas no bound.- A child that binds, logs the listening line and then hangs before
Servewould hang the test
until the binary's-timeout. The old poll failed within 20 s. Everything between the log line and
Serveis synchronous (main_run.go:933-1026), so I see no path to it.
- A child that binds, logs the listening line and then hangs before
What I checked
- The full diff, all 8 files, and the code around each change.
- Boot order in
main_run.go. The hosted capture refusal (line 553) runs before
listenAndAnnounce(line 933), sorunMain's "exit before the listening line" is a correct refusal
signal.hooks.Mount(line 950) runs beforesrv.Serve(line 1026), so any HTTP response implies
the hook routes are mounted — the removed retry ingetis safe. - Log format. The child env is scrubbed, so
logging.Setupdefaults to the text handler
(internal/logging/logging.go:71), which printsaddr=127.0.0.1:portunquoted. ThewaitListening
attr match works. The scrub also removes theCG_LOG_FILE/CG_LOG_FORMATdrift that JSON mode would
cause — the plausible cause of the oldTestNoHooksKeepsTheBinaryDefaultslaptop failure. - Env allow list. Every variable the boot path reads (
UPSTREAMS,CONTROL_DB,DASHBOARD_*,
CG_LOG_*, keys) is either scrubbed or set per test.GOCOVERDIRis kept, so coverage still works.
HOMEis a private temp dir, soclaudeCompactAtStartis deterministic. AllrunMain/bootAndGet
callers were checked against the new signature and the scrubbed env. - Races in the helpers.
syncBuffer.watch/firerun under one mutex.c.exitedcloses only after
cmd.Waitreturns, so pipe output is complete before the exit branch scans it, and
ProcessState.ExitCode()is read only after<-c.exited. A listening line written just before an
exit is still counted (the exit branch re-scans). Notmethod is called from a non-test goroutine. - timingguard. The new helper uses
time.NewTimeras a safety bound, which no rule flags
(sleep, poll,time.After). The two removed baseline lines match the now-zero counts in
hooks_test.goandshutdown_test.go. - Cleanup order.
startChildregisters the kill beforet.TempDir's removal (LIFO), so the child
dies before itsHOMEdir disappears. - I did not run builds or tests (live tests not approved for this review). The removal of
TestNoHooksKeepsTheBinaryDefaultsfromscripts/release/known-laptop-failures.txtrests on the
env scrub making the child deterministic; the PR's own local-tests run is the proof to check before
merge.
…r the shell env Test-only, no behavior change. - The child of bootAndGet and runMain gets an allow-listed env and a private HOME. A DASHBOARD_CONTENT=1 in the shell no longer breaks TestNoHooksKeepsTheBinaryDefaults. - Both helpers wait for the child's "context-guru-proxy listening" line or its exit, with a 90 s safety bound. "Booted" now means only that the line appeared. - TestGracefulShutdownWithSSEClient waits with testutil.WaitFor. - TestNoHooksKeepsTheBinaryDefaults leaves known-laptop-failures.txt. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
… probe Test-only, no behavior change. - The output watch runs its match func after every write. A listening line split across 2 writes now ends in ready. A unit test feeds it in 2 writes. - bootAndGet probes with a 60 s client timeout. - runMain says its code is not an exit code when the child still runs. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
7025dac to
e6bba04
Compare
|
Fixed in the new head. Thanks to both reviewers.
Rebased on origin/main. The 5 target tests and the 2 new tests pass at |
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 | e6bba04ab1e1 |
approve |
Verdict: approve
The fix commit e6bba04 answers every round-1 note, and the rebase onto the
new main (#1366) is clean. No new defect.
Findings
None.
Earlier findings, round 1
Mine (all non-blocking):
- Split-write race in
waitListening— fixed.watchnow takes a match
func andfireruns it after every write (hostedenv_helpers_test.go:62),
so a line split across 2 writes still fires. The one-shot goroutine is gone.
TestWaitListeningSeesALineSplitAcrossWritesfeeds the line in 2 writes and
proves both halves: not fired after the first, fired after the second. - Fabricated exit code
0inrunMain— fixed with the comment at
hostedenv_test.go:44("code is not an exit code here"). known-laptop-failures.txtremoval — the author reports the 5 target tests
and the 2 new tests pass at-race -count=10. The local-tests run at this
head stays the live proof before merge, as in round 1.
Reviewer 2's:
- Same split-write race — fixed as above. Agree; no new proof to add.
- Third port collision returns
got=nil— rejected by the author: it is
older than this PR and belongs in its own change. I checked the reason: the
oldbootAndGetOncereturnednilin the same place before this PR, and
the repo rule keeps a main defect off a feature branch. The reason is right. - Unbounded
http.Get— fixed.probeClientbounds each probe at 60 s
(hooks_test.go:143), so a child that logs "listening" and hangs fails with
the child's output, not at the binary's-timeout.
Non-blocking
hostedenv_helpers_test.go:62—firenow runs the match func over the whole
buffer on every write, andhasListeningLinesplits the buffer into lines
each time. That is O(writes × output size). The children in these tests print
at most a few hundred lines, so it cannot matter here. Worth a note only if
the watch ever moves to a child with large output.
What I checked
- Last review: round 1, 7025dac, 2026-11-24T17:57:02Z.
- New commits read: 2 (d83ae3f "boot helpers read the child's output, not the
clock or the shell env" — the round-1 change rebased; e6bba04 "re-check the
listening line on every write, bound the probe" — the fixes). The new base
commit e54d499 (#1366) sits under them. - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files).
- New items since my last review, and what I did:
- Reviewer 2's round-1 review (17:57:39Z): read in full. Checked each of its
three notes against the new head (fixed, rejected-with-reason, fixed). - Author comment (18:17:33Z): read in full. Each claim checked against
e6bba04; all four answers match the code. - Rebase onto e54d499: diffed the PR's own files across the rebase
(7025dac → d83ae3f). The only PR-file changes the rebase brings are
#1366's own edits now under the PR:RequireTimingin two metricspush
tests andtestutil.TimingEnabled() &&on the shutdown-time assertion
(shutdown_test.go:75), which merges cleanly with this PR's
testutil.WaitForon the line above. No PR content was lost or changed. - Fix commit e6bba04: read the full diff.
watch's new match-func shape has
exactly three callers (waitListening, the two new tests), all on the new
signature.waitListeningkeeps the exit-branch re-check through
hasListeningLine. The new test file has no timing pattern, so no
timingguard baseline entry is needed.hooks_test.gore-addstimefor
the 60 s client timeout, which the guard does not flag.
- Reviewer 2's round-1 review (17:57:39Z): read in full. Checked each of its
- Commit messages: DCO sign-off and
Assisted-By:present on both commits.
Both say "Test-only, no behavior change", and the diffs match the claim.
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 | e6bba04ab1e1 |
approve |
Verdict: approve
The new head fixes all three of my round-1 notes, two with a new unit test. The rebase onto
origin/main (#1366) changed none of the PR's own content except the intended merge in
shutdown_test.go. I found no defect in the new code.
Findings
None.
Earlier findings, now resolved
-
Watcher checked the
addr=part only once (mine, round 1; also reviewer 1).- Fixed.
watchnow takes a match func and runs it after every write
(hostedenv_helpers_test.go:58-76), so a listening line split across two writes fires on the
second.waitListeningshrank to one watch plus the exit re-check (:128-145). TestWaitListeningSeesALineSplitAcrossWrites(hostedenv_watch_test.go) feeds the line in two
writes and proves both halves: no fire after the first, fire after the second. The
no-early-fire check is deterministic — both writes and bothfirecalls happen under the buffer
mutex before the select.TestWaitListeningIgnoresAnotherAddrcovers the wrong-addr case.
- Fixed.
-
http.Gethad no bound (mine, round 1).- Fixed.
probeClientbounds each probe at 60 s (hooks_test.go:141-143), under the 90 s
childBound, so a hung child fails with the buffer in the message.
- Fixed.
-
runMain's made-up exit code 0 (reviewer 1's note; I raised it as a doc gap too).- Fixed. The comment at
hostedenv_test.go:44says the code is not an exit code when the child
still runs.
- Fixed. The comment at
-
Third port collision returns
got=nil(mine, round 1).- Rejected by the author: it is older than this PR and belongs in its own change. The reason is
right — the same content was in the pre-PR code, and the repo rule gives a main defect its own
issue and PR. I keep nothing.
- Rejected by the author: it is older than this PR and belongs in its own change. The reason is
Non-blocking
hostedenv_helpers_test.go:35-36,57— two comments still describe the old substring watch:
"when the output first contains a string" and "each watch whose string is now in the output". The
code now runs a match func. Words only; no behavior.
What I checked
- Last review: round 1,
7025dac56a6d3beae84d01c6412f19f7cee0f591, 2026-11-24T17:57:39Z. - New commits read: 3 in
7025dac5..HEAD—e54d499a(new base, #1366 from main, message and stat
read),d83ae3fb(the round-1 change re-applied on the new base),e6bba04a(the fix commit,
full diff read). - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three saved files).
- New items since my last review, and what I did about each:
- Author comment 2026-11-24T18:17:33Z: lists the four dispositions above and the test note
(-race -count=10on the 5 target and 2 new tests, timingguard, gofmt, vet). I checked each
claim against the diff; the code matches it. I ran nothing myself (live tests not approved). - Rebase onto #1366: I diffed
7025dac5vsd83ae3fbon the PR's own paths. Only
proxyapp/shutdown_test.godiffers, by the intended merge — the PR'stestutil.WaitForplus
#1366'stestutil.TimingEnabled()guard on the 2 s assertion.proxyapp/metricspushpicks up
#1366'sRequireTimingcalls unchanged. No PR content was lost or altered. - Fix commit
e6bba04a: reviewed line by line (below).
- Author comment 2026-11-24T18:17:33Z: lists the four dispositions above and the test note
- The new watch design:
matchruns under the buffer mutex fromfire, the closure captures only
the immutableattr, and the exited branch re-checks the same predicate throughString(), so a
line written just before an exit still counts.watchfires at registration, so a line printed
beforewaitListeningis called is still seen. - timingguard at the new head:
probeClient'sTimeout: 60 * time.Secondand thetime.NewTimer
bound match no flagged pattern; the new test file uses notimeat all; the baseline needs no
change and got none. - The PR diff against the new base (
e54d499a..HEAD) is the round-1 content plus the fix commit;
nothing else entered.
|
Local tests at
Skipped: TestBobReleasePythonSuite (Bob plugin on hold, #1221).
Log tail of race-dash: |
test(release): give race-dash the same 40 m limit as race-record Part A runs the dash race tests with a 25 m limit. On the shared laptop (10 CPUs, load 190-400) the run took 1507 s and the rerun 1514 s. Both hit "panic: test timed out after 25m0s" on PR #1371. That PR did not touch dash. Raise the limit to 40 m, as race-record has. Add a comment that says why. docs(release): say dash has a 40 m limit in the Part A docs The header of part-a.sh and RELEASING.md still said "dash 25m". Change both to "dash 40m" to match the script. Test script only, no behavior change. Round 2 approved. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
#1371, #1372, #1373, #1376 and #1377 fixed them. Add 2 tests found since: keepalive TestTheManualHoldTimerReleasesAndZeroisesWithoutASweep and tooldefer TestHistorySetLoadedTwice. 118 tests remain. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
#1378) test: gate the tests where time is the behavior behind CG_TIMING_TESTS Gate 32 tests that assert a wall-clock limit, a rate, a watchdog or a kill-at-the-limit. They run only with CG_TIMING_TESTS=1, so the integrator's heavy checks run them and a loaded laptop does not. - Go: testutil.RequireTiming(t) in 19 tests. - OpenCode: the timingOnly option in 4 tests. - pi-package and bob-plugin statusbar: a small timingOnly option in 6 tests. - bob-plugin scripts: a small timing_only skip in 3 tests. Test-only. No behavior change. No data dependence. test: run the checks that do not depend on time in every run A gated test that also checks something other than time hid that check without the variable. Fix that. - dash: move the query-plan check into TestSessionTokens_UsesTheIndexOnALargeWindow. It runs always. The time ratio stays gated. - 13 tests assert their time bound only with CG_TIMING_TESTS=1. The rest of each test runs always: strategies read, testdb open, waitAll, OpenCode versions, pi (3), bob statusbar (3), bob scripts (3). Test-only. No behavior change. test: ungate 3 tests and teach the timing detector the new switches - Ungate 3 silence tests whose result does not depend on time or load. - WaitFor test: guard only the elapsed bound. The message checks run always. - central rules test: RequireTiming after the CENTRAL_SLOW check, with a comment. - OpenCode: export timingEnabled from helpers.mjs. Use it in versions and in the failopen missing-binary bound. - timing-tests-needed.sh: match CG_TIMING_TESTS and timingEnabled, and look in *.py and *.test.ts files. Add cases to local-tests_test.sh. Test-only. No behavior change. test(bob): name CG_TIMING_TESTS in test_bob_control.py Review round 2 (#1378): the file reads TIMING from test_bob_plugin but never named the switch, so scripts/dev/timing-tests-needed.sh could not see its timing gate. One comment line names it. fix(dev): stop the timing detector losing to SIGPIPE Review round 3 (#1378): with pipefail on, `grep -q` exits at the first match, the writer (`git show` or `git diff`) then dies of SIGPIPE, and the pipeline status becomes 141, so the `if` failed and the script printed "skip" at random. On a large test file it said skip in 9 of 40 runs. Plain grep to /dev/null reads to the end. Two new self-tests, a 20,000-line file and a 20,000-line diff, each run 20 times: with `grep -q` both say run 0 of 20, with this change 20 of 20. docs(release): drop the 89 pending timing tests that merged PRs fixed #1371, #1372, #1373, #1376 and #1377 fixed them. Add 2 tests found since: keepalive TestTheManualHoldTimerReleasesAndZeroisesWithoutASweep and tooldefer TestHistorySetLoadedTwice. 118 tests remain. No behavior change (tests and test scripts only). Round 4 approved (owner granted rounds 3 and 4). Local tests waived (owner rule). Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
Summary
Batch 1 of the owner's timing task: "tests that are based on time will go into the pool that runs on integrator, and tests that can be fixed since time is a by product of poor design are fixed."
Test-only, no behavior change. Data dependence: none.
What we found
TestNoHooksKeepsTheBinaryDefaultsis not a timing test. The child process copied the shell env.DASHBOARD_CONTENT=1turnedcontent_captureon, and the test rejects that.TestHooksRunInOrderAndTakeEffectprobed a port it had freed. Another process could take the port, and the test read a foreign server. It also had a 20 s probe limit and a 30 s context.TestHostedModeRefusesCaptureEnvcounted a 15 s timeout as "booted". Under load, a late refusal looked like a boot.TestSingleTenantKeepsCaptureEnvpassed at its 4 s deadline, even if the proxy never booted.TestGracefulShutdownWithSSEClientpolled 200 x 10 ms for the SSE client.What changed
proxyapp/hostedenv_helpers_test.gowithchildEnv,startChildandwaitListening.childEnvis an allow list (PATH, TMPDIR, TZ, LANG, LC_*, SYSTEMROOT, GOCOVERDIR) plus a privateHOME. The proxy reads dozens of env vars (DASHBOARD_*,CG_*,CONTEXT_GURU_*,UPSTREAMS,CONTROL_DB, API keys). A block list goes stale. An allow list does not.bootAndGetandrunMainwait for the child'scontext-guru-proxy listeningline or its exit. The safety bound is 90 s. No clock decides the verdict.bootAndGetwaits foraddr=<its addr>in that line, then probes. It keeps the retry on "address already in use".TestGracefulShutdownWithSSEClientusestestutil.WaitFor. Its 2 s shutdown check is a real deadline, so it stays.runMainlost its unusedwaitargument.TestNoHooksKeepsTheBinaryDefaultsleftknown-laptop-failures.txt.baseline.txtdropped 2 entries.How it was tested
macOS, Go 1.27.4, laptop under heavy load.
DASHBOARD_CONTENT=1 go test -run '^TestNoHooksKeepsTheBinaryDefaults$' ./proxyapp/fails (content_capture=true) on the base.DASHBOARD_CONTENT=1,DASHBOARD_DB,DASHBOARD_QUEUE,UPSTREAMS,CONTROL_DBexported.CGO_ENABLED=1 go test -race -count=10 -run '^(TestNoHooksKeepsTheBinaryDefaults|TestHooksRunInOrderAndTakeEffect|TestHostedModeRefusesCaptureEnv|TestSingleTenantKeepsCaptureEnv|TestGracefulShutdownWithSSEClient)$' ./proxyapp/passes (515 s).os.Environ()back inchildEnv.TestNoHooks...fails withcontent_capture=true.go test -race ./proxyapp/...passes in 3 parts.gofmt,go vetandgo test ./internal/timingguard/pass.Open questions
addr, not the bound port.LISTEN_ADDR=:0with a reported port does not work today. Product code would be needed (product=y). This PR keeps the bind, close and retry step.