Skip to content

test(server): measure the hidden filter's allocations in a clean child process - #1099

Merged
dborup merged 2 commits into
masterfrom
fix/hidden-filter-allocs-flake
Dec 2, 2026
Merged

dborup merged 2 commits into
masterfrom
fix/hidden-filter-allocs-flake

Conversation

@dborup

@dborup dborup commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Relates to #1088 (where the failure was first seen on CI; the test is TestHiddenFilterPacketsNoExtraAllocs)

Status: ready for review — the failure is measurement noise from goroutines earlier tests leave running, not a regression in the hidden filter; the test now measures in a clean child process and is green 50/50 under -race and inside the full catch-all shard where master fails. Product code unchanged.

Evidence tags: [T] run here (linux/amd64, Go 1.27.1, 4 vCPU), [A] read from code, git or logs, [K] reported elsewhere and not reproduced here.

Plan

  1. Reproduce: run the test alone under -race -count=20 on origin/master and on 6e49b0d1; then in the real CI context (the catch-all shard 3/3 under -race).
  2. Bisect only if the isolated test fails on master.
  3. Decide regression vs unstable measurement from the evidence; fix accordingly with a red test first, then mutants.

Investigation

Step Result
Isolated, origin/master ebfa4ff5, -race -count=20 pass 20/20 (603 s) [T]
Isolated, 6e49b0d1, -race -count=20 pass 20/20 (483 s) [T]
Isolated alloc figures under -race (both commits) off 23, prefix-none-hidden 23, prefix-50-hidden 24 — same in all 3 trials [T]
git diff --stat 6e49b0d1..origin/master -- cmd/server only dagi_api.go, dagi_area_stats.go, dagi_area_comparison_test.go, openapi.go, routes.go; nothing on the filter / hidden-identity path [A]
Bisect not run: the isolated test does not fail on master, and in shard 3 it fails on 6e49b0d1 as well (below), so the range has no good/bad boundary to bisect. It also touches no code the test measures [T][A]
Full catch-all shard 3 on origin/master, -race (same -skip selection CI uses) fails: 50 hidden: 33 allocs, no config: 29 — same shape as CI's 28 vs 24 [T]
A debug test run right after it in that shard (per-trial figures) off [31 30 34], prefix-none-hidden [34 29 29], prefix-50-hidden [29 28 29]; isolated values are 23 / 23 / 24, so each call carries +5…+11 foreign allocations that vary run to run [T]
Goroutine dump at that point 774 goroutines: 677 database/sql.(*DB).connectionOpener (unclosed DBs, idle) and 95 (*DB).healSchemaFlags (db.go:291), each a 2 s ticker that runs detectSchema (SQL queries, allocates) on a DB an earlier test never closed [T]
6e49b0d1's CI shard 3 was green one lucky sample [K]. The same shard 3 run here on 6e49b0d1 fails too: 50 hidden: 32 allocs, no config: 26, with the same 774 goroutines (677 + 95 healers) and per-trial figures off [27 27 27], prefix-none-hidden [31 28 35], prefix-50-hidden [28 28 29] [T]. The flake predates this range; nothing in 6e49b0d1..origin/master added it.

Decision: an unstable measurement, not a regression. testing.AllocsPerRun reads the process-wide runtime.MemStats.Mallocs. Leaked healers in the same test binary allocate while it counts. Under -race one filter call over 30K packets takes ~70 ms, so several healer ticks land inside each measured call; without -race (or on a fast arm64 Mac) a call takes ~1 ms and the noise stays under the slack of 3. That is why it fails on linux -race in the catch-all shard and passes on macOS and in isolation. The filter itself allocates the same with and without hiding (+1, the predicate) on both commits.

Fix

The repo already handles exactly this for heap figures: TestNodeTxSetsRetainedHeap_534 (cmd/server/bynode_txid_534_test.go) re-runs itself in a child process because "goroutines earlier tests leave running … allocate while it is read and make an in-process figure meaningless". This PR does the same:

  • TestHiddenFilterPacketsNoExtraAllocs re-executes the test binary with -test.run=^TestHiddenFilterPacketsNoExtraAllocs$ -test.count=1 and CORESCOPE_1088_ALLOCS_CHILD=1. The child measures (hidFilterAllocs, the unchanged measurement: least of 3 × AllocsPerRun(5) per mode) and prints one HID1088 … line; the parent parses it and asserts. The child has no other tests' goroutines.
  • The original assertions are unchanged (slack 3, nNone == nOff, nHid < nOff). One assertion is added: with no hiding configured, fewer than one allocation per 500 packets (20 at 30K, 23 under -race). The relative checks alone pass if every mode allocated once per packet (mutant M4 below).
  • hidAllocNoise runs in the parent for the test's lifetime, a background allocator (1000 small allocations per ms) that stands in for the leaked healers. It keeps the test honest: an in-process measurement fails with it every time.

Why not the alternatives:

  • Skip under -race (raceBuild, already in cmd/server): every Go server shard in CI runs under -race, so the per-packet claim would no longer be enforced in CI without a new non-race workflow step.
  • Larger slack / more trials: the noise scales with the number of leaked goroutines and the runner's speed, so it would only move the threshold.
  • Close the 95 leaked DBs: worth doing (see Remaining), but it touches dozens of unrelated tests, and the next leak would bring the flake back.

Perf: test only, no product code touched. The child rebuilds the same 30K store the test built before, and the parent does no store work, so the test takes about the same time (53 s in the -race shard, ~4 s without -race).

Requirement — TestHiddenFilterPacketsNoExtraAllocs stable on linux -race

Item Before (448655c2, red test) After (7d4937bb)
Test with background allocator, no -race, -count=5 red 5/5, e.g. no config: 420 allocs for 30000 packets, 50 hidden: 449 allocs, no config: 420 [T] green 5/5, HID1088 off=20/30000 none=20/30000 hid=21/29700 [T]
Same, -race -count=2 red 2/2, no config: 7823 allocs / 3823 allocs [T] green 50/50 (-race -count=50, 2461 s), all 50 off=23 none=23 hid=24 [T]
Full catch-all shard 3, -race master: fail 33 vs 29; 6e49b0d1: fail 32 vs 26 [T] pass, HID1088 off=23/30000 none=23/30000 hid=24/29700 [T]
Mutant Where Result
M1: measure in process (call hidFilterAllocs in the parent, no child) test killed 3/3: no config: 220 / 420 allocs for 30000 packets [T]
M2: one allocation per packet in the hidden branch (strings.ToUpper(tx.Hash) when hidden != nil) store.go filterPacketsPrepared killed: 50 hidden: 22491 allocs, no config: 20 [T]
M3: child prints no HID1088 line test killed: no measurement in the child's output (no silent pass) [T]
M4: one allocation per packet in every mode store.go filterPacketsPrepared killed only by the new absolute bound: no config: 22490 allocs for 30000 packets [T]
(M0: snapshot always stale, hiddenFrom = math.MinInt) store.go survived, and should: the uncovered check allocates nothing, so it is equivalent for allocations (20/20/21) [T]

Invariants

Check Result
cmd/server read-only test file only, no DB writes [A]
New map[string]interface{} 0 added lines (git diff origin/master..HEAD) [T]
Hardcoded colours / scripts/check-xss-sinks.sh --diff origin/master no frontend change; script: no public/**/*.{js,html} changes to scan, exit 0 [T]
Fork guards .github/ untouched (0 diff lines); == 'Kpa-clawbot/CoreScope' count 9 in deploy.yml, 1 in release-fast-path.yml [T]
node scripts/run-go-server-shard.js --validate 4104 runnable entries, each in exactly one shard (15 / 15 / 4074) [T]

Test runs

Suite Result
cd cmd/server && go test ./... (no -race) FAIL on 6 perf budgets; the same 6 fail on origin/master on the test machine [T]: TestAdvertIntervalAnalytics_AggregatePerf (32 ms vs 25 ms budget; master 41 ms), TestAdvertIntervalBucket_Perf (26 / 29 ms vs 25 ms), TestDagiAreaStatsWithinBudget (378 / 328 ms vs 150 ms), TestProfileCard_Cost, TestCoverage941_PerfBudget and TestCoverage941M2_PerfBudget (both 504 terrain data timed out). Everything else passes.
Catch-all shard 3 under -race, up to and including the hidden-filter test (2708 tests) failing besides it, on master and on this branch alike: TestAreaCard_NoStoreLock (the area share waited for the store lock) and TestEstimatedPositionsInvalidStartup (must reject startup promptly: signal: killed) — slow-machine timing under -race [T]. The rest of the shard was not run locally (with -coverprofile it is ~4 h here).
sh test-all.sh 398 / 407 files pass; the 9 failures are perf budgets on the test machine and fail identically on origin/master [T]: test-live-heard-filter.js, test-live-scope-color.js, test-issue-724-masts-hint.js, test-issue-728-ortho-base.js, test-issue-941-predicted-reach.js, test-issue-730-buildings-ui.js, test-1055-live-dagi.js, test-1055-m3-area-rule.js, test-issue-598-hop-path-inference.js
node test-frontend-helpers.js 746 passed, 0 failed [T]
E2E none affected (one Go test file changed, no frontend or API change); not run

CI per job

Expected CI: Go Server Tests 3/3 carries the change (green locally in the same shard selection); shards 1/3, 2/3 and every other job are unaffected (test-only change in one cmd/server test file).

Remaining

  • 95 healSchemaFlags goroutines and 677 open *sql.DB leak from earlier tests in the catch-all shard (DBs opened through OpenDB and never closed). This fix makes this test immune; other AllocsPerRun tests in cmd/server that run in-process could be hit by the same noise. Tracking which tests leak and adding t.Cleanup(db.Close) is a separate follow-up.
  • Local perf budgets listed above fail on this 4 vCPU test machine on master too; not touched.

🤖 Generated with Claude Code

dborup and others added 2 commits December 2, 2026 14:42
… goroutines' allocations (#1088)

TestHiddenFilterPacketsNoExtraAllocs failed in the -race catch-all shard
("50 hidden: 28 allocs, no config: 24") while it passes on its own: by the
time it runs, earlier tests have left 95 schema healers behind
(healSchemaFlags, a 2 s re-probe on DBs never closed), and AllocsPerRun
counts their allocations too, 5-11 per filter call under -race.

The test now runs a background allocator that stands in for them, and
bounds the no-config path absolutely (under one allocation per 500
packets; 23 at 30K). Red: the in-process figure carries the noise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…#1088)

AllocsPerRun reads the process-wide malloc count. In the -race
catch-all shard, goroutines left behind by earlier tests (95 schema
healers re-probing unclosed DBs every 2 s) allocated 5-11 times per
filter call while it was measured, so "50 hidden" could exceed
"no config" by more than the slack of 3 with no change in the filter
(isolated: 23 / 23 / 24 under -race on master and on 6e49b0d).

The test now re-runs itself alone in a child process, as
TestNodeTxSetsRetainedHeap_534 does for its heap figure, and asserts on
the figures the child prints. The product code is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dborup

dborup commented Dec 2, 2026

Copy link
Copy Markdown
Owner Author

Review — CS-Minimax PR#1099 — head 7d4937b

Dom: APPROVE med nits

Evidence tags: [T] run here (darwin/arm64, Go 1.26.0, on the merged tree with origin/master 9687204e), [A] read from code/git/logs, [K] reported by the author, not reproduced.

Findings

# Severity Finding
1 nit The child is started without -test.timeout. A hung child is only bounded by the parent's global timeout. Same pattern as TestNodeTxSetsRetainedHeap_534, so acceptable. [A]
2 nit The PR body says "E2E: none affected, not run". CI E2E jobs were still pending when I looked. A one-file test-only change cannot affect them. [A]
3 nit The hidAllocNoise goroutine runs in the parent for the whole test, while the child does the measuring. It only proves that an in-process measurement is noisy (mutant M1 in the PR). It is not needed for the child's correctness. Harmless. [A]
4 info Other in-process AllocsPerRun tests can have the same exposure to leaked healers. The author lists this as a follow-up. [A]

No blocking findings.

Answers to the review points

  1. Diagnosis. Plausible and consistent with the evidence. AllocsPerRun reads the process-wide malloc count, so unclosed-DB healSchemaFlags tickers add allocations, and under -race a 30K filter call takes ~70 ms, which makes ticks land inside the measured call. Isolated, the figures are a stable 23/23/24 under -race. I reproduced the isolated figures but did not reproduce the foreign allocations inside the full catch-all shard (≈4 h under -race); for that I rely on the author's logs [K]. The repo already uses the same child-process technique in bynode_txid_534_test.go [A].
  2. Mutants. The child-process test still fails when the filter allocates per packet [T]:
    • A: fmt.Sprint(tx.ID, tx.Hash) per packet in the hidden != nil branch of filterPacketsPrepared → killed: 50 hidden: 89766 allocs, no config: 20.
    • B: one allocation per packet in every mode → killed only by the new absolute bound: no config: 59756 allocs for 30000 packets. The relative checks alone would pass here.
    • C (test-side): the child's -test.run matches nothing → killed: no measurement in the child's output, so there is no silent pass.
    • Scratch store.go and the test file were restored and compared byte for byte afterwards.
  3. Flakiness. go test -race -run '^TestHiddenFilterPacketsNoExtraAllocs$' -count=20 → 20/20 pass, every run HID1088 off=23/30000 none=23/30000 hid=24/29700 [T]. Without -race: 20/20/21.
  4. Shard manifest. node scripts/run-go-server-shard.js --validate → 4116 runnable entries, each in exactly one shard (15 / 15 / 4086) [T]. The test name is unchanged, so no assignment moves.
  5. Product code. git diff origin/master...HEAD --stat shows one file, cmd/server/hidden_identity_packets_bench_test.go (+83 −15). No store.go change; cmd/server stays read-only [T][A].

Invariants

  • New map[string]interface{} lines: 0 [T].
  • scripts/check-xss-sinks.sh --diff origin/master: clean ("no public/**/*.{js,html} changes to scan") [T].
  • No frontend change, so no hardcoded colours and no phone UI flow to walk through [A].
  • .github/ diff is 0 lines, so the fork guards (9 and 1) are untouched [T].
  • Commit author is dborup <kontakt@meshview.dk> [A]. No closing keyword: the body says "Relates to info: bring the info pages in line with what is served, add the tools page, fix two phone landings #1088" [A].
  • The red-before / green-after commit pair (448655c2 red, 7d4937bb green) is present [A].
  • Head unchanged on git ls-remote before and after the review [T].

Tests (merged tree)

Suite Result
cd cmd/server && go test -count=1 ./... ok (154 s) [T]
go vet ./cmd/server clean [T]
node test-frontend-helpers.js pass [T]
sh test-all.sh 407 pass / 2 fail: test-issue-628-vendor-gitattributes.js (git check-attr needs a .git dir) and test-issue-715-og-denmark.js (the "no raw shapefiles" check uses git). Both are artifacts of the git archive export and untouched by this PR [T].

CI per job (at review time)

Pass: Go Build & Test, Go Ingestor Tests, Go Libraries & CLI, Go Server Tests 1/3, 2/3 and 3/3, JavaScript Unit Tests & Lint, Script & Container Unit Checks, Verify Go Test Assignments, Validate Docker Image. Pending: Playwright E2E 1/3, 2/3 and 3/3. Skipping: Release Artifacts. [A] Shard 3/3 passing once is weak evidence for a flake fix; the -count=20 run plus the mutants above are the stronger evidence.

Not verified

  • The foreign allocations inside the full -race catch-all shard (≈4 h; relied on the author's logs).
  • linux/amd64 -race timing (I ran darwin/arm64, where calls are faster).
  • Playwright E2E (still pending on CI and not affected by this change).

@dborup
dborup merged commit 46d4827 into master Dec 2, 2026
18 checks passed
adminopenclaw8-sketch pushed a commit that referenced this pull request Dec 2, 2026
Brings in #1099 (the TestHiddenFilterPacketsNoExtraAllocs flake fix) and
the rest of master since the branch point.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant