Repository navigation
test(proxy): wait on the writer's counters in seedStopReasonHistory - #1034
Merged
Merged
Conversation
amiddavid
commented
Nov 10, 2026
amiddavid
left a comment
Collaborator
Author
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.322 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 70ba5463a120 |
approve |
Verdict: approve
Test-only change. seedStopReasonHistory now waits on the recorder's own counters instead of a fixed 10 s poll. No product code changed. I found no real defect.
Findings
None.
Non-blocking
proxy/adaptcache_test.go:694-697— the fast fatal cannot tell a query error from a missing row.Requestsreturns a nil page on a transient read error, and the message then says "the tenant has fewer than 160". Risk is low: the query runs only afterWritten >= Captured, when the writer has no DB work left, so a lock conflict is unlikely. Fix if you touch this again: print the query error andp.Totaltoo.proxy/adaptcache_test.go:690—DroppedandErrorsare lifetime counters. A drop or an error from rows captured before the seed would fail the seed wait. In these three tests the recorder sees no earlier rows, and the queue holds 4096 against 160, so this cannot fire today.proxy/adaptcache_test.go:688— a genuine failure now costs up to 2 minutes per test, 6 minutes across the three users of the helper. The PR names this a safety net, so it is a choice, not a defect.
What I checked
- The full diff (one file, +14/−4) and the code around it.
- The counter semantics the wait relies on:
Recordcountscapturedbefore the queue send, anddroppedonly on a full queue (dash/capture.go:370-375). The queue holds 4096 (defaultQueueSize,dash/capture.go:121), the seed sends 160, so drops cannot happen in this fixture.run/writecountwrittenonly afterinsertBatchcommits, anderrorscovers a failed batch (dash/capture.go:529-533). SoWritten >= Capturedimplies every captured row is committed.insertBatchinserts every event with no filtering (dash/store.go:552), so written rows are visible rows.
- The fixture claim in the new comment:
newCampaignFixturesetsBatchSize: 1,FlushInterval: 1 ms,DBPath: ":memory:"(proxy/campaignbuild_test.go:39). All three callers ofseedStopReasonHistory(lines 250, 551, 633) use this fixture. - The DB check:
RequestswithFilter{Tenant: tid}counts every row of the tenant (dash/query.go:271-313,whereatdash/query.go:96), keep-alive rows included. The seeded 160 rows carry that tenant id and distinct timestamps. - Background jobs that could delete rows during the 2-minute wait: the janitor runs every 5 minutes and the archiver every 15 (
dash/capture.go:132,:135), both outside the wait window. - No concurrent
Recordcalls during the wait: all three tests seed before any further HTTP request. - The PR description matches the diff, including the reproduction and the negative check.
amiddavid
commented
Nov 10, 2026
amiddavid
left a comment
Collaborator
Author
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.322 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 70ba5463a120 |
approve |
Verdict: approve
Findings
None.
Non-blocking
- proxy/adaptcache_test.go:697 — the
Requestsread error is discarded, so a failed read is reported as lost rows.
The loop readsp, _ := f.rec.DB().Requests(...). If the query fails,pis nil and the fatal says "the writer stored every captured row but the tenant has fewer than 160" — a wrong claim about the cause. The sibling helperf.record(proxy/manager_test.go:103-105) treats a read error as its own failure. I could not construct a live trigger (see What I checked), so this is hardening, not a defect. Fix: keep the error and print it, or treatp == nilas "not ready, retry". - proxy/adaptcache_test.go:690 — the bound grew from 10 s to 2 min per caller. A truly stuck writer now costs up to 2 min in each of the 3 tests that use this helper, against the old 10 s. The Makefile runs
-timeout 20mand./proxy/...takes about 7.5 min under-race, so it fits. The comment says the bound is a safety net only. Acceptable.
What I checked
- The full diff: one commit, one function (
seedStopReasonHistory), test code only. No production behavior, no data-dependence change. - The counter semantics the new wait rests on (
dash/capture.go:370-374,530-533):Recordcounts a row as captured before the enqueue; the single writer goroutine adds each row towrittenafterinsertBatchcommits, toerrorson failure, or the full queue counts itdropped. So every captured row ends written, dropped or errored — the comment's claim is true. - The wait predicate
Written >= Captured: all 160 rows are recorded before the loop starts, the channel is FIFO, and the writer is the only consumer. SoWritten >= Captured(withCaptured >= 160) forces all 160 seeded rows to be committed. The fatal in that branch cannot fire while a seeded row is still in flight. - The drop/error fatal cannot fire spuriously: the queue cap is 4096 (
dash/capture.go:121) against 160 rows, and both fixtures setBatchSize: 1, so the "one transaction per row" claim in the comment is true. - The tenant count (
dash/query.go:271,Filter.whereatdash/query.go:96):Filter{Tenant: tid}matchesr.tenant_id = ?only — no time window, andRequestsforces keep-alive rows in. Once the rows are committed,Total >= 160holds. - Concurrent DB access during the wait: the in-memory DSN uses
cache=shared(dash/store.go:96). The read runs only when the writer is quiescent. Other DB writers do not overlap it: the count worker needsBypassCount(absent on the seeded events,dash/capture.go:1066), the janitor first fires at 5 min (pruneInterval,dash/capture.go:135), and the startup migrations finish during sign-up. The existing helperf.recordpollsRequestsevery 5 ms during active writes and fatals on a read error, and the suite is stable — so a read at quiescence does not fail in practice. - The
Stats()fields used in the messages (Captured,Written,Dropped,Errors,Queued) all exist (dash/capture.go:447-476), andStats()is safe to poll: atomics,len(ch), and mutex-guarded reads. - The three callers of the helper (proxy/adaptcache_test.go:250, 551, 685) record no other dash events before or during the wait, so the per-test recorder's counters describe only the seeded rows.
The helper polled for 160 rows for a fixed 10 s. The fixture writes one row per transaction, so under -race on a loaded runner the writer needs more than 10 s. Nothing is lost: the queue holds 4096 events and the drop counter stays 0. The helper now waits until Written reaches Captured. A drop or an error fails at once with the counts. A 2 minute bound stays as a safety net. Test-only. No behavior change. Closes #1028 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Collaborator
Author
|
Rebased onto main and hardened. New head:
|
amiddavid
force-pushed
the
fix/flake-adapt
branch
from
November 10, 2026 11:01
70ba546 to
12fa344
Compare
amiddavid
commented
Nov 10, 2026
amiddavid
left a comment
Collaborator
Author
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.322 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 12fa34410e9a |
approve |
Verdict: approve
The PR is one test-only commit, rebased onto main and hardened. Both round-1 reviews approved. The new head fixes the one shared non-blocking point. I found no defect, old or new.
Findings
None.
Status of earlier findings
- Mine, non-blocking,
adaptcache_test.go:694-697(a read error reported as lost rows): fixed. The helper now keeps theRequestserror and fails with its own message (adaptcache_test.go:694-697). The missing-row message prints the tenant's actual count (adaptcache_test.go:701-705). - Mine, non-blocking, lifetime
Dropped/Errorscounters: rejected by the author, reason accepted. The author says they cannot fire in these 3 tests. I verified this in round 1: the queue holds 4096 against 160 rows, and no earlier rows are captured before the seed. - Mine, non-blocking, the 2-minute bound: kept as a safety net, accepted. Reviewer 2 checked it fits: the Makefile allows 20 m and
./proxy/...takes about 7.5 m under-race. - Reviewer 2's two non-blocking points match mine. I checked both myself. The read-error point is the same fix; the bound point is the same acceptance.
Non-blocking
proxy/adaptcache_test.go:701-704— thep != nilguards are dead code.Requestsreturns a non-nil page on everyerr == nilpath (dash/query.go:293). Harmless defensive handling; no action needed.
What I checked
- Last review: round 1,
70ba5463a1204831740ac6774fd9b9a15ef820c6, 2026-11-10T10:12:44Z. - New commits read: 3 in the range
70ba5463..12fa3441.12fa3441— the PR's own commit, rewritten. Reviewed in full below.a3495863and77a910b0— main commits pulled in by the rebase (#1011,#1035). Both are onorigin/main; neither is this PR's change. The PR diff vs the base77a910b0is one file,proxy/adaptcache_test.go(+22 −4).
- 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:
- Reviewer 2's round-1 review (10:15:11Z): read in full. Two non-blocking points, both overlapping mine. Checked each against the code myself; agree with both dispositions.
- Author's comment (11:01:34Z): read in full. Claims the rebase reason (main was red on two plugin tests, fixed by #1035), the fix for the read-error point, the two kept points, and green tests on the box at the new head. The code matches every claim I can check by reading.
- The new head
12fa3441: reviewed the full diff against both the base and the old head.
- The hardening in
12fa3441: the error branch fails with the error and the counters; the success path is unchanged from round 1. The wait predicate and the counter semantics are unchanged, so my round-1 verification stands:Written >= Capturedimplies every seeded row is committed, the writer is quiescent when the read runs, and the janitor (5 m) and archiver (15 m) stay outside the 2-minute window. - Commit message: conventional title, DCO sign-off,
Assisted-By:attribution per repo convention,Closes #1028for the flake it fixes.
amiddavid
commented
Nov 10, 2026
amiddavid
left a comment
Collaborator
Author
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.322 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 12fa3441 |
approve |
Verdict: approve
Findings
None.
Earlier findings
- My round-1 non-blocking (the discarded
Requestserror shows as lost rows): fixed. The helper now keeps the error and fails with it (proxy/adaptcache_test.go:697-699). When rows are missing, the message prints the tenant's actual total (proxy/adaptcache_test.go:708). This is the fix I proposed. - Reviewer 1's non-blocking (same read-error point): fixed by the same change. I checked it myself; the fix covers both wordings.
- Reviewer 1's non-blocking (lifetime counters) and the 2-minute bound: rejected by the author, with reasons. The author's comment says the counters cannot fire in these 3 tests and the bound is a safety net. I verified the same facts in round 1: the queue holds 4096 against 160 rows, the three tests record no earlier rows, and the Makefile allows
-timeout 20m. The reasons are right. Nothing to keep.
Non-blocking
- proxy/adaptcache_test.go:702,706 — the
p != nilguards are dead code.Requestsreturns a non-nil page whenever the error is nil, so after theerr != nilfatal the twop != nilchecks always pass. Harmless. Leave them or drop them.
What I checked
- Last review: round 1, 70ba546, 2026-11-10T10:15:11Z.
- New commits read: 3 (
a3495863feat(pi) #1011,77a910b0fix(plugin) #1035,12fa3441test(proxy) — the amended PR commit). - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review:
- The rebase onto
77a910b0: verified withgit range-diffthata3495863and77a910b0in this branch are identical (=) toorigin/main. They are main's own commits, reviewed in their own PRs, not re-authored here. - The PR's own diff vs main: 1 file,
proxy/adaptcache_test.go(+22 −4). Read in full. - The amended error handling:
erris now checked before the total, and the missing-rows fatal prints the real total.Requestsreturns(nil, err)or(page, nil), so the logic is correct. - The author's comment (2026-11-10T11:01:34Z): each claim checked — rebase verified, fix verified, the two kept non-blocking points verified in round 1, and the box test run (
go test -race ./proxy/...passes, 540 s) is the author's report; live tests are not approved for me, so I did not run them.
- The rebase onto
- The rest of the helper is unchanged from the head I approved in round 1; my round-1 checks (counter semantics, FIFO writer, queue capacity, tenant filter, no overlapping DB writers) still hold at this head.
This was referenced Nov 10, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the flaky
TestAdaptReportGateMatchesTheBuilder. Test-only, no behavior change.What we found
BatchSize: 1, so each row is its own transaction. Under-raceand CPU load, 160 rows need more than 10 s.What changed
seedStopReasonHistory(proxy/adaptcache_test.go) waits untilStats().Written >= Stats().Captured. It no longer polls for 10 s.How to reproduce and test
Load:
taskset -c 0-3 sh -c 'while :; do :; done' &x16, killed by pid after.CGO_ENABLED=1 GOMAXPROCS=4 taskset -c 0-3 go test -race -count=15 -run '^TestAdaptReportGateMatchesTheBuilder$' ./proxy/go test -race ./proxy/...: ok (538 s).go vet ./proxy/andgofmt -l proxy: clean.