Skip to content

test: assert bearings snapshot local-read overlap from peak reads in flight - #73

Merged
doitdigital0495 merged 2 commits into
mainfrom
fm/firstmate-bearings-snapshot-timing-flake
Oct 13, 2026
Merged

doitdigital0495 merged 2 commits into
mainfrom
fm/firstmate-bearings-snapshot-timing-flake

Conversation

@doitdigital0495

Copy link
Copy Markdown
Owner

Intent

tests/fm-bearings-snapshot.test.sh around line 3132 compares serial against concurrent wall-clock time at one-second resolution. It flaked on a loaded CI runner (serial 6s against concurrent 5s) in PR 45 run 36748883535. Make the assertion robust.

What Changed

  • tests/fm-bearings-snapshot.test.sh: the large local snapshot test no longer compares serial and concurrent runs by whole-second wall clock. That check flaked on a loaded runner. The fake no-mistakes now writes a start/end line with a millisecond timestamp around each delayed one-second axi status read into FAKE_NM_READ_LOG. It gets milliseconds from EPOCHREALTIME first, then date +%s%N, then whole seconds.
  • New fake_read_log_overlap helper: it replays the log in timestamp order (on a tied timestamp, an end sorts before a start) and prints the start count, end count and peak number of reads in flight. A missing log counts as zero reads.
  • The test now requires all five reads to start and finish in both runs, the serialized run to peak at 1 read in flight, and the concurrent run to peak at 2 or more. The existing check that the fm-bearings.v1 projection matches between the two runs is unchanged.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The change only touches a test. It replaces the whole-second wall-clock comparison with a peak-in-flight overlap metric taken from millisecond start/end stamps, which host load cannot fake. It also requires exactly 5 starts and 5 ends in both runs, closing the round-1 findings (review-1 load stagger, review-2 missing end stamps, review-3 redundant saved_ms bound). The end-before-start tie sort keeps the serial peak at 1 even if the stamp falls back to whole seconds.

Testing

Each run used a temporary single-test copy of the suite, so only the changed test ran; the full suite was not run. The test passed 3 of 3 times idle and 3 of 3 times under heavy CPU load (load average about 48 on 10 cpus). A mutant that serializes the concurrent reads fails with "concurrent local reads did not overlap (peak 1 in flight)". The overlap helper also gives the right summaries for a missing log, serial reads that touch at the same stamp, and a read cut short; these cases fail the 5-start/5-end check or count touching reads as no overlap. The original CI flake did not reproduce locally: the base-commit test also passed 3 of 3 times under the same load, so the evidence shows the new assertion is robust and still catches regressions, but there is no local before/after flake. There is no UI surface, so no screenshots were taken. All temporary files were removed.

  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Concurrent local snapshot overlaps reads and gives the same projection as serial: the target test passes on an idle host ✅ pass live 01-idle-runs.txt (3/3 ok)
Adversarial load: the target test stays green with the host heavily CPU-loaded (the flake condition from CI) ✅ pass live 03-under-load.txt (new test 3/3 ok at load average about 48)
Regression guard: if the concurrent run's reads are serialized again, the test fails ✅ pass live 02-serialized-mutant.txt: 'concurrent local reads did not overlap (peak 1 in flight)', EXIT=1
A cut-short or missing read log cannot fake a pass (start and end counts are checked, touching reads are not counted as overlap) ✅ pass live 04-helper-edge-cases.txt: missing log gives 0 0 0, killed read gives 2 starts and 1 end (fails the 5/5 check), touching serial reads give peak 1
Evidence: Idle runs of the target test (3x pass)

Source: Idle runs of the target test (3x pass)

ok - large local snapshot overlaps local reads with byte-identical serial and concurrent projections

real	0m13.478s
user	0m6.329s
sys	0m1.513s
ok - large local snapshot overlaps local reads with byte-identical serial and concurrent projections

real	0m13.217s
user	0m6.189s
sys	0m1.503s
ok - large local snapshot overlaps local reads with byte-identical serial and concurrent projections

real	0m14.072s
user	0m6.276s
sys	0m1.457s
Evidence: Serialized-reads mutant is caught

Source: Serialized-reads mutant is caught

not ok - concurrent local reads did not overlap (peak 1 in flight) EXIT=1

not ok - concurrent local reads did not overlap (peak 1 in flight)
EXIT=1
Evidence: New and base test under heavy CPU load

Source: New and base test under heavy CPU load

== load: 30 busy loops on 10 cpus
-- new test run 1
ok - large local snapshot overlaps local reads with byte-identical serial and concurrent projections
EXIT=0
-- new test run 2
ok - large local snapshot overlaps local reads with byte-identical serial and concurrent projections
EXIT=0
-- new test run 3
ok - large local snapshot overlaps local reads with byte-identical serial and concurrent projections
EXIT=0
-- base test run 1
ok - large local snapshot overlaps local reads with byte-identical serial and concurrent projections
EXIT=0
-- base test run 2
ok - large local snapshot overlaps local reads with byte-identical serial and concurrent projections
EXIT=0
-- base test run 3
ok - large local snapshot overlaps local reads with byte-identical serial and concurrent projections
EXIT=0
 15:16:54 up 2 days,  5:27, 16 users,  load average: 47.80, 32.16, 23.75
Evidence: Overlap helper edge cases

Source: Overlap helper edge cases

missing log -> 0 0 0 touching serial reads -> 2 2 1 read killed mid-sleep -> 2 1 2

missing log -> 0 0 0
touching serial reads -> 2 2 1
read killed mid-sleep -> 2 1 2
- Outcome: ⚠️ 1 info across 1 run (5m39s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 3 issues found → auto-fixed ✅
  • ⚠️ tests/fm-bearings-snapshot.test.sh:3217 - Residual load flake in the new parallel_span_ms -le 2500 bound. The span runs from the first read's start to the last read's end, so it still includes the start stagger between the five jobs. snapshot_tasks_parallel (bin/fm-fleet-snapshot.sh:660-689) forks each job as a subshell, and each job does its own pre-read work before it calls no-mistakes axi status. On the runner that flaked, composition overhead was about 4s (concurrent wall clock 5s against about 1s of reads), so a start stagger above 1.5s is plausible and the test fails again. The comment at 3178-3180 ('leaving host load nothing to hide in') overclaims for the same reason. Suggested fix: use a load-independent overlap metric from the same log. For example, have awk report the peak number of reads in flight (sort the start/end events by timestamp and track the count), then assert peak >= 2 for the concurrent run and peak == 1 for the serial run. This still fails when the reads are serialized, and it makes the 2500ms and 2000ms wall-time bounds unnecessary. Same-invariant sites: line 3215 (serial >= 4000, safe because the sleeps are sequential) and line 3220 (saved_ms >= 2000, which inherits the stagger sensitivity of the 2500ms bound).
  • ℹ️ tests/fm-bearings-snapshot.test.sh:3099 - fake_read_log_span validates only the count of 'start' lines; 'end' lines are never counted. If a read is killed mid-sleep (a snapshot bound or timeout), its end stamp is missing, so max can fall below min. That gives a short or negative span that passes the -le 2500 and saved_ms checks. Suggested fix: count end lines too and require 5 starts and 5 ends (or print both counts and assert each is 5 at line 3213).
  • ℹ️ tests/fm-bearings-snapshot.test.sh:3219 - The saved_ms &gt;= 2000 check at line 3220 is redundant with the other bounds when timing is at millisecond resolution: five sequential 1s sleeps give a serial span of at least 5000ms, so passing parallel <= 2500 already implies saved_ms >= 2500. The check adds a third assertion and failure message without adding coverage. Suggested fix: drop it, or drop it as part of switching to the peak-in-flight metric.

🔧 Fix applied.
✅ Re-checked - no issues remain.

⚠️ **Test** - 1 info
  • ℹ️ tests/fm-bearings-snapshot.test.sh - The original CI flake (serial 6s against concurrent 5s) did not reproduce locally. The base-commit test also passed 3 of 3 times under the same heavy load. The robustness claim therefore rests on the load-independent overlap metric, not on a local fail-before, pass-after reproduction.
  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Concurrent local snapshot overlaps reads and gives the same projection as serial: the target test passes on an idle host ✅ pass live 01-idle-runs.txt (3/3 ok)
Adversarial load: the target test stays green with the host heavily CPU-loaded (the flake condition from CI) ✅ pass live 03-under-load.txt (new test 3/3 ok at load average about 48)
Regression guard: if the concurrent run's reads are serialized again, the test fails ✅ pass live 02-serialized-mutant.txt: 'concurrent local reads did not overlap (peak 1 in flight)', EXIT=1
A cut-short or missing read log cannot fake a pass (start and end counts are checked, touching reads are not counted as overlap) ✅ pass live 04-helper-edge-cases.txt: missing log gives 0 0 0, killed read gives 2 starts and 1 end (fails the 5/5 check), touching serial reads give peak 1
  • bash tests/zz-tmp-overlap-only.test.sh (temporary copy that runs only test_large_local_snapshot_overlaps_local_reads_without_projection_drift) x3 on an idle host
  • bash tests/zz-tmp-overlap-serialized.test.sh: mutant that sets FM_SNAPSHOT_LOCAL_READ_CONCURRENCY=8 to 1 for the concurrent run, so the reads are serialized again
  • New target test x3 and base-commit (3f115f3) target test x3, all under 30 busy-loop CPU hogs on 10 cpus (load average about 48)
  • Ran fake_read_log_overlap on crafted logs: missing log, serial reads that touch at the same stamp, and a read killed mid-sleep
  • Removed the temporary tests/zz-tmp-* files; the worktree is clean
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…all clock

The large-local snapshot test compared whole seconds of wall clock between
a serialized and a concurrent run, and a loaded CI runner flaked it
(serial 6s vs concurrent 5s) because second-granularity rounding plus
composition noise ate the whole margin. The fake no-mistakes now stamps
each one-second read's start and end in milliseconds, and the assertions
bound the read spans themselves: the serialized baseline must span at
least four of its five seconds, the concurrent reads must all fit inside
two and a half, and at least two saved seconds must show up between them.
The spans exclude the snapshot's composition overhead by construction and
the delayed reads carry no CPU work, so host load has nothing left to
hide in, while reads serialized again span the same five seconds as the
baseline and fail.
@doitdigital0495
doitdigital0495 merged commit 5e1dfbd into main Oct 13, 2026
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.

2 participants