Skip to content

test(proxy): make the dashboard latency guard robust on a loaded runner - #576

Merged
amiddavid merged 3 commits into
mainfrom
fix/dash-latency-test-flake
Oct 20, 2026
Merged

amiddavid merged 3 commits into
mainfrom
fix/dash-latency-test-flake

Conversation

@OsherElhadad

Copy link
Copy Markdown
Collaborator

TestDashboardAddsNoRequestLatencyWithContentCapture failed on CI for #565 (57.69 ms vs a 57.10 ms budget on a 571 ms baseline) although #565 does not touch the request path. The guard already had a relative budget; the remaining fragility was comparing two independent medians. It now takes the median of the paired (on minus off, back to back) differences, which cancels load that hits both sides of a pair, and widens the relative part from 10% to 20% of the dashboard-off median. The 5 ms floor is unchanged, so the regression the test exists for (content redaction on the request goroutine, about 53 ms at a baseline of 1 to 2 ms) is still caught. Ran it 3 times locally: ok.

…and allows 20% of the baseline

A shared CI runner whose own request median was 571 ms read +57.69 ms against a 57.10 ms budget with
nothing wrong. The cost is now the median of the back-to-back pair differences (a stall that hits a pair
cancels in it) and the relative budget is 20% of the dashboard-off median; the 5 ms floor and the ~53 ms
regression it exists to catch are unchanged.

Signed-off-by: Osher-Elhadad <[email protected]>

@OsherElhadad OsherElhadad 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.

Review: REQUEST CHANGES at a3d91e1. It is small, and test-only (proxy/dash_test.go). (Posted as a comment: GitHub does not let the author account request changes.)

The paired-difference median is a real improvement.

  • Unmodified. 5 runs locally under nice 10 (dashboard-off median about 50 ms) measured added costs of -0.8 to 2.1 ms against a 10 ms budget. Noise in the paired metric is about ±2 ms.
  • Injected delay. A time.Sleep right after finish's nil check, so it runs only with the dashboard on:
    • with 15 ms, the test failed 5 of 5 (added 13.9–17.0 ms);
    • with 53 ms, it failed 5 of 5 (added 53.5–54.8 ms).
      The paired difference measures the injected cost to within about 2 ms.

The blocker is the budget, not the metric. budget = max(5 ms, off/5) grows with the baseline. On the CI runner whose baseline was 571 ms, the budget is about 114 ms, so the ~53 ms regression this test exists to catch passes there. (The old 10% budget, about 57 ms, already let it through on that runner.) The comment's claim that the regression "is caught at any baseline" is false once off exceeds about 265 ms.

Since paired differences now cancel shared load, the relative widening isn't needed for noise any more. Please add an absolute ceiling, for example:

budget := min(max(5*time.Millisecond, off/5), 30*time.Millisecond)

and fix the comment to say what the cap guarantees: any added cost over 30 ms fails on any baseline. If CI's paired noise ever approaches 30 ms, raise the cap rather than removing it.

gofmt and go vet are clean, CI is green, and the commit is signed off.

…er cannot hide the regression

Signed-off-by: Osher-Elhadad <[email protected]>
@OsherElhadad

Copy link
Copy Markdown
Collaborator Author

Pushed 9f4d5d3: the budget is min(max(5 ms, 20% of the dashboard-off median), 30 ms), comment updated, so the ~53 ms regression is caught on a slow runner too. 3 local runs ok.

…3 ms regression exceeds it at every baseline

Signed-off-by: Osher-Elhadad <[email protected]>
@OsherElhadad

Copy link
Copy Markdown
Collaborator Author

Pushed 4f3a3e4: the budget is now latencyBudget(off) = min(max(5 ms, off/5), 30 ms), with a unit test that a 53 ms regression exceeds it at baselines of 1 ms, 2 ms, 50 ms, 100 ms, 331 ms, 571 ms and 5 s (it fails with the earlier 20%-only formula at 571 ms), plus the floor (5 ms at a 2 ms baseline) and the relative part (20 ms at 100 ms). Please re-check.

@OsherElhadad OsherElhadad 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.

Re-review: APPROVE at 4f3a3e4. The budget is now latencyBudget(off) = min(max(5 ms, off/5), 30 ms). With the cap in place, the ~53 ms redaction regression exceeds it at every baseline, including CI's slow 571 ms runner, and the comment now says why. TestLatencyBudgetStillCatchesTheRedactionRegression pins that across baselines from 1 ms to 5 s, plus the floor and the relative part. With the cap raised to 300 ms it fails. The paired-difference measurement is unchanged, and the latency tests pass -count=3 locally. CI is green, and both commits are test-only and signed off. This approval covers 4f3a3e4.

@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 1 of 2 4f3a3e455d82 approve

Verdict: approve

Findings

None.

Non-blocking

None.

What I checked

  • Read CLAUDE.md and docs/design.md for repo rules
  • Read full diff: only proxy/dash_test.go changed, 79 lines added
  • Verified the change is test-only, no production code modified
  • Analyzed the latencyBudget function logic:
    • Formula: max(5ms, baseline/5) capped at 30ms
    • This is 20% of baseline (was 10%), with 5ms floor and 30ms ceiling
    • At 571ms baseline: budget = 30ms (capped from 114.2ms)
    • The 53ms regression > 30ms, so it is caught
    • Verified with TestLatencyBudgetStillCatchesTheRedactionRegression
  • Verified the measurement change:
    • Old: difference of two independent medians (on - off)
    • New: median of paired differences (median of [on[i] - off[i]])
    • Paired differences cancel shared load that hits both handlers
  • Ran the two affected tests on the eval box with -race: both pass
    • TestLatencyBudgetStillCatchesTheRedactionRegression: 0.00s
    • TestDashboardAddsNoRequestLatencyWithContentCapture: 70.82s
    • Test output shows median added latency of 9.6ms vs 30ms budget
  • Verified the fix addresses the flake described in PR body:
    • Old approach: 57.69ms measured vs 57.10ms budget (10% of 571ms) = false positive
    • New approach: paired differences + 20% budget capped at 30ms
    • The cap ensures the 53ms regression is still caught at all baselines
  • No security issues: test-only change
  • No fail-open violations: test-only change
  • Follows repo conventions: test function names, comments, DCO will be on commit

@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 1 of 2 4f3a3e455d82 approve

Verdict: approve

Findings

None. The PR fixes a flaky test without weakening its guard.

Non-blocking

None.

What I checked

  • Read CLAUDE.md and docs/design.md for repo rules
  • Read the full diff: only proxy/dash_test.go changed
  • Analyzed the changes:
    • New maxAddedLatency constant (30ms cap)
    • New latencyBudget function: 20% of baseline (was 10%), floor 5ms, cap 30ms
    • New test TestLatencyBudgetStillCatchesTheRedactionRegression: validates the budget catches the 53ms regression at all baselines including the problematic 571ms
    • Modified test loop: now captures paired differences (on-off) for each back-to-back pair
    • Changed metric: uses median(diffs) instead of difference of medians
    • Updated comments explaining the paired approach and why 20% tolerance
  • Ran the changed tests on the eval box with -race: both tests passed
  • Verified the logic:
    • off / 5 correctly computes 20%
    • Paired differences cancel shared load that hits both handlers
    • The 30ms cap prevents a slow runner from hiding the 53ms regression
    • Test at line 440 validates 100ms baseline yields 20ms budget (100/5=20)
    • Test validates the regression exceeds the budget at all tested baselines
  • Confirmed this is test-only: no production code changed
  • The fix addresses the root cause: a loaded CI runner with 571ms baseline crossed the old 10% budget (57.1ms) by 0.6ms with nothing wrong. The new approach uses paired differences to cancel shared load and increases tolerance to 20% with a 30ms cap.

@amiddavid

Copy link
Copy Markdown
Collaborator

Integrator (session integrator-053): test results on the eval box. Head 4f3a3e455d.

The eval box SSH link works again. For runs over about 2 minutes, start the run detached with a done marker, as the rules file says.

Run Result
TestLatencyBudgetStillCatchesTheRedactionRegression and TestDashboardAddsNoRequestLatencyWithContentCapture, -race -count=3 pass
Mutation: maxAddedLatency 30 ms to 60 ms fails: TestLatencyBudgetStillCatchesTheRedactionRegression

@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 resumed 1 of 2 2 of 2 4f3a3e455d82 approve

Verdict: approve

Findings

None. All earlier findings were fixed before my round 1 review.

Non-blocking

None.

What I checked

  • Last review: round 1, 4f3a3e4, 2026-10-20T12:57:11Z
  • New commits read: 0 (git log 4f3a3e4..HEAD showed empty output)
  • Read in full: 4 reviews, 3 comments, 0 inline comments
  • New items since my last review (2026-10-20T12:57:11Z):
    • Comment by amiddavid at 2026-10-20T13:35:46Z: Integrator test results on eval box
      • Tests pass with -race -count=3
      • Mutation test: changing maxAddedLatency from 30ms to 60ms correctly fails TestLatencyBudgetStillCatchesTheRedactionRegression
      • This validates the guard works as intended
  • Earlier conversation review:
    • OsherElhadad's initial review (2026-10-15T13:58:11Z): requested changes, identified that budget without cap would let 53ms regression pass on slow runners
    • Author fixed in commits 9f4d5d3 and 4f3a3e4
    • OsherElhadad's re-review (2026-10-15T14:14:21Z): approved after fix
    • Reviewer 2's review (2026-10-20T12:56:45Z): approved
    • My round 1 review (2026-10-20T12:57:11Z): approved
  • All findings from OsherElhadad's first review were fixed before my round 1 review
  • The integrator's mutation test confirms the 30ms cap is necessary and working
  • No new code changes, no new findings

@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 resumed 2 of 2 2 of 2 4f3a3e455d82 approve

Verdict: approve

Findings

None.

Non-blocking

None.

What I checked

  • Last review: round 1, 4f3a3e4, 2026-10-20T12:56:45Z
  • New commits read: 0 (verified with git log 4f3a3e455d823f0a39ebe1657ec845fde8d2b368..HEAD - empty output)
  • Read in full: 4 reviews, 3 comments, 0 inline comments (from the three files)
  • New items since my last review:
    • Reviewer 1's round 1 review at 2026-10-20T12:57:11Z: also approved, no findings. Checked their analysis - agrees with mine on the budget formula, paired differences, and test validation.
    • Integrator comment at 2026-10-20T13:35:46Z: test results on eval box. Tests pass with -race -count=3. Mutation test: changing maxAddedLatency from 30ms to 60ms causes TestLatencyBudgetStillCatchesTheRedactionRegression to fail, proving the test correctly guards the cap.
  • Earlier round 1 reviews (before my review):
    • OsherElhadad's initial review at 2026-10-15T13:58:11Z requested the 30ms cap (at commit a3d91e1)
    • Author pushed 4f3a3e4 with the cap and validation test
    • OsherElhadad approved at 2026-10-15T14:14:21Z
  • No new code changes since round 1
  • No new findings from other reviewers to verify
  • Integrator's mutation test confirms the test works as designed
  • My round 1 approval stands: test-only change, fixes the flake, maintains the regression guard

@amiddavid
amiddavid merged commit ef17c9a into main Oct 20, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 20, 2026
amiddavid added a commit that referenced this pull request Oct 27, 2026
)

fix(proxy): join feedback mail before a test's sink goes away (#213)

The feedback POST commits the row and hands the mail to a goroutine. The
dev sink path (CG_MAIL_DEV_SINK) is read at SEND time, so a send still in
flight when its test ends reads whatever the NEXT test has set, and lands
in that test's sink. TestFeedbackMailCannotInjectHeaders then counts more
than one real subject line and fails.

The handler now tracks those goroutines in a WaitGroup. The hosted test
fixture joins them in t.Cleanup, registered after the sink's t.Setenv so
it runs before it (cleanups are LIFO): by the time the env points
anywhere else, no send is about to read it. Production behaviour is
unchanged — the wait exists only on the test teardown path.

Written by GLM through Claude Code.

Assisted-By: GLM
Signed-off-by: DAVID AMID <[email protected]>
test(keepalive): wait on the state Arrive reports, not the ping counter (#206)

TestArriveCancelsAndReports waited on the pings counter, then asserted on
what Arrive reports. The counter is bumped when the ping's round trip is
over; e.refreshed is written a moment later under k.mu. A test that waits
on the counter can therefore read the entry before the field it asserts
on is set — the original #206 race, still latent now that the keeper
tests run fire inline.

The test now uses waitRefreshed, which polls the entry's own refreshed
field. It is correct under any runner, so the waitPings doc comment no
longer claims counter-waiting is enough for state assertions.

Written by GLM through Claude Code.

Assisted-By: GLM
Signed-off-by: DAVID AMID <[email protected]>
test(proxy): stop asserting absolute values on process-global counters (#192)

Two tests asserted absolute values on counters that live for the whole
test binary: the extract registry (metrics.ExtractSnapshot) and expand's
unresolved pair. A -count=2 run of ./proxy failed on its second
iteration, because iteration 2 starts from iteration 1's counts.

TestExtractEconomicsAreExported now reads a baseline first and asserts
the delta, the same shape TestAdjudicateStraySeriesRender already uses.
TestExpandUnresolvedSeriesRender resets the two unresolved counters at
the top, so its at-zero assertions hold on every iteration.

Written by GLM through Claude Code.

Assisted-By: GLM
Signed-off-by: DAVID AMID <[email protected]>
test(proxy): wait for the campaign aggregate the assertion reads (#163)

TestCtlGetCampaignAggregatesPredictedAndRealPerTenant waited for each
recorded ROW to persist, then asserted on real_saved_usd — an aggregate
computed over several rows at read time. On a starved 2-core CI runner
(#163) it read 0 with every row persisted.

The test now polls the campaign detail route until the tenant's
real_saved_usd is non-zero (5 s deadline, loud failure), then asserts on
that response. A wrong value still fails the assertion, so the check
keeps its meaning; only the load sensitivity goes.

Could not reproduce on today's main on the eval box (50x at -cpu=1, 20x
under -race at -cpu=1, and 5 concurrent runs pinned to 2 cores all
passed), so this is the wait the issue proposed rather than a fix for an
identified remaining race.

Written by GLM through Claude Code.

Assisted-By: GLM
Signed-off-by: DAVID AMID <[email protected]>
test(dash): wait for hub publication, not just row persistence (#91)

The scope fixture drained the writer by polling the DATABASE. The writer
publishes to the SSE hub only AFTER the insert commits, so a row
/api/requests could see was not yet a row /api/events could replay, and
TestEventsDerivesItsScopeFromTheResolver could read a manager's live
feed with no events in it.

The fixture now also waits for the hub's ring to hold the same three
events, so both the positive and the negative assertions on /api/events
run against a published backlog.

The latency half of #91 is not touched: it was fixed on main by #576 and
#693, which landed after the issue and implement its addendum.

Written by GLM through Claude Code.

Assisted-By: GLM
Signed-off-by: DAVID AMID <[email protected]>
fix(dash): stop the insights tests reading the runner's own disk (#700)

The insights handler reads the machine's ~/.claude: it parses every
transcript under projects (90 MB on a measured machine) and walks the
whole plugin cache. The project API tests passed home "" — the real
machine — so their cost was a property of whatever box ran them. Under
-race in a full-package run on a loaded box, TestTheInsightsDocumentIs-
ScopedToOneProject went past the route's fixed 10 s handler timeout and
failed. Reproduced here at 10.21 s with an 81 MB transcript tree.

Two changes:

- The tests' projectAPI helper passes an empty t.TempDir, so the route's
  cost is about the store, which is its subject. The 10 s timeout stays
  meaningful: a handler that really hangs still trips it.
- The handler sources skill descriptions from a.diskHome() instead of
  the hardcoded "". Local behaviour is unchanged (diskHome is "" there);
  a hosted API now gets the empty map its own doc already promised; and
  a test home now reaches the plugin walk too.

Written by GLM through Claude Code.

Assisted-By: GLM
Signed-off-by: DAVID AMID <[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