Skip to content

test: give a test's timing judgement one home and bound flaky timing - #1982

Open
REPPL wants to merge 13 commits into
mainfrom
cutfix-c-1202
Open

REPPL wants to merge 13 commits into
mainfrom
cutfix-c-1202

Conversation

@REPPL

@REPPL REPPL commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

What

Flaky tests were one cause of the v0.18.0 cut's delay. A census of 60 days of CI found that about half of the failing runs were time or budget failures: wall-clock upper bounds and fixed waits that a loaded runner overshoots. This change resolves iss-2612022218392055.

  • One home for a test's timing judgement. internal/testtiming holds:
    • a bound with a ratio and a floor;
    • a check that judges a call against the stall it must cut short;
    • the process CPU clock;
    • waits for a sign rather than a fixed time.
      gittest.AnswerPipeAfter stalls a fake git answer on purpose.
  • The census's flaky tests wait for a sign. Each now waits for the event it depends on, not a fixed budget. A kept fixture world ages from its build, and Live.Since is bounded by its read. Five of the seven had been fixed by earlier changes. Of the two left, one was reproduced by delaying the pid file's write and the other by slowing its renewals: each failed before its change and passed after.
  • The ten worst timing bounds are judged by what they cut short, not by the wall clock alone. Where a ratio alone would have been tighter than the old limit, the old limit stays as a floor.
  • No new wall-clock bound. An audit refuses a wall-clock upper bound in a test outside internal/testtiming. It holds the existing 56, in 55 functions, in a list that can only shrink.
    • It counts a bound held to a literal, a function-local constant, a package constant or variable, or a field the function itself sets. It reads the package's variables to a fixed point, so its result does not depend on the order of the file names.
    • A field set elsewhere (a helper, a fixture's constructor) is not read, and the audit's header says so.

dcn-2612022337510454 records what waits for a later change: a starved CI lane that runs the suite under load, and an audit for fake clocks.

Checks

  • make preflight passed on this head.
  • Every changed test passed by name through the load gate.
  • Four review rounds, each with a security review and a correctness review; each later round checked the points the one before raised.
  • The audit's own test was watched fail before each widening and pass after it.

Resolves: iss-2612022218392055
Refs: dcn-2612022337510454

Assisted-by: Claude:claude-opus-5-5

REPPL added 11 commits December 2, 2026 22:57
No shared way to judge how long something took existed. The ratio of a
reference with a floor lived inside lint's scalesLinearly, and the process
CPU clock was copied three times, in core/reading, surface/cli and
implement/loop. A fix for each slow-runner flake would otherwise add a
fourth copy, which one-canonical-primitive forbids.

internal/testtiming is a standard-library leaf imported only by tests:
Bound holds a measured run to Ratio times a reference measured in the
same run and never under Floor; CutShort is the Bound for a run that a
context or a kill ends, judged against the work it ended; CPU is the
process's CPU clock. scalesLinearly takes its bound from Bound.Limit, and
the three clock copies are now testtiming.CPU. The reading package's test
of the clock moves to testtiming with it. The package map names the
package, and the choice is recorded as a decision.

Refs: iss-2612022218392055
Assisted-by: Claude:claude-opus-5-5
…y its read

The loop flake fixed on loopflake-1202 (4dd8a7e) was a stand-in clock
that moved with the real one. The census of iss-2612022218392055 names
two sibling sites of that shape, and each is fixed here.

fixtureworld_test.go:254 set a kept world's clock in keep(), after its
build had run, and line 97 reuses the world while time.Since of that
clock is under keptWorldAge. Every time a world's files hold is written
during the build, on the real clock, so a build a slow runner took
minutes over was aged from its end and reused for those minutes past
keptWorldAge, its run's clock that much older than the age read. The
clock now starts before the world's first walk, the earliest moment any
of its files can hold; line 97 needs nothing more once the clock is
right. TestAKeptWorldIsAgedFromWhenItsBuildBegan holds it.

livework_test.go:129 held Live.Since within three seconds of the
process's start. The reader dates the table from just before it asks and
the table ages the process to the moment it is read, so the start it
gives is early by up to the reading's own length: a table read that a
loaded runner kept for over three seconds failed. The bound is now that
reading's measured length (testtiming.Bound, ratio 1, floor 1s), and a
late start still fails. Line 88 (Age: time.Since(p.start)) cannot
misfire: p.start is fixed, and the age is taken at the read, inside the
window the bound already allows for.

Red before green, through the narrow load gate, with throwaway copies of
the new test bodies on a copy of the tree before this change: the kept
world test failed on the old fixture ("the world is aged from ...,
21.549167ms after its build began"); with a process table a loaded
runner kept for 3.5s, the old Live.Since bound failed ("Live.Since =
23:25:58.497966, want about 23:26:02") and the new one passed.

Green, through the narrow load gate: TestAKeptWorldIsAgedFromWhenItsBuildBegan,
TestASecondWorldInOneTestIsBuiltApart and TestLiveWholeRunMarksTheItem
pass, and so does the new Live.Since bound against the 3.5s table read.

Refs: iss-2612022218392055
Assisted-by: Claude:claude-opus-5-5
The census of iss-2612022218392055 confirms seven flaky tests. Their
causes, read from each failing run's log and the commits since:

- TestHostAndGuestOverTheWire: the guest joined before the host's update
  was logged, a race in the test; fixed by 632b07f, after the failing
  336cb67.
- TestARejoinDuringASlowReplayStaysBounded: a closed connection lived
  about 5s past its close grace, a production defect; fixed by 556a7c9,
  after the failing 49dd579.
- TestAFourthRemovalAtOneHeadIsHandedBackAfterThreeArmings: a check for
  "1111" matched inside a commit hash (31111f...); fixed by 926eeb2.
- TestVulncheckInterruptedLeavesNoCopyBehind: the signal raced the stub's
  fork (fixed by 2eab9c2), then a second HUP during cleanup, a
  production defect (fixed by 157741d and 758cd72); no failure since.
- TestAGarbledClockNeverCostsTheReceipt: a real-clock hourAgo mixed with
  fixture times; fixed by 28c952a.
- TestALeaderStopsItsGroupWhenTheRunnerGoes: the pid file existed before
  the pid was in it, so a stop in that gap read pid 0; bb468ed made the
  test wait for the pid. Its sibling TestTheWholeRunsVerdictEndsTheAudits
  has the same gap and was still open to it.
- TestAReservationRenewsDuringAPreflight: still open. It waited 5s of
  wall time for a renewal pass that fetches and pushes; on a loaded
  runner the pass took longer. TestAReservationRenewsDuringACall gave the
  same pass a call 1s long.

Both production defects were fixed and recorded before this change; none
of the seven needs a new capture. The five already fixed are fixed on
this head and were not rerun.

The fixes here:

- testtiming.Patience is how long a test waits for work elsewhere: three
  quarters of the time the test binary has left, not a constant, and
  testtiming.Await asks for a sign for that long. AwaitWithin is the same
  wait for at most a limit, for a sign a fault would also give later: a
  process killed with its group is gone, but so is one that escaped once
  its own minute runs out, so that wait is bounded by half that minute,
  not by a Patience that could outlast it. interview's budget(t) is now
  Patience, the copy it held.
- terminal_renew_test.go: the preflight test waits for the renewal to be
  recorded (Await) inside the preflight, and the call test's agent takes
  a new turn, untilrenewed, that stays in its call until the test marks
  the renewal recorded and says it saw it, at most 15s inside the
  runner's 20s bound, so the call lasts as long as the renewal takes
  rather than a second. The renewal is made only while a call runs, so
  the wait has to be the agent's, not the stage's before it calls.
- precheck-audits: sh writes the pid beside the file and renames it on,
  so the file exists only with the whole pid in it, which closes the gap
  for every test that uses sh; waitForFile, waitForPid and the
  interrupt's wait use Await; the leader test's last wait uses
  AwaitWithin half the run's minute.

Red before green, with each old body and its new one in throwaway tests
run through the narrow load gate on a copy of the tree before this
change: with every renewal slowed by 6s, as a fetch and a push on a
loaded runner, the old preflight test failed ("the reservation was not
renewed while the preflight ran"); the old call test's poll, about five
seconds of reads, happened to outlast that 6s here and passed, so its
change rests on the same shape, not on a reproduction. With half a
second between the pid file's creation and its pid, the old way sh
wrote it failed the whole run's verdict test (strconv.Atoi: parsing "")
and the new way passed.

Green, through the narrow load gate: both renewal tests pass (6.9s and
7.9s), and so do the same tests with every renewal slowed by 6s (12.5s
and 13.3s); testtiming's tests and interview's two budget tests pass.
cmd/precheck-audits, the leader
and verdict tests among it, passes whole under make precheck.

Refs: iss-2612022218392055
Assisted-by: Claude:claude-opus-5-5
The flake census of iss-2612022218392055 ranks the tests most likely to
fail on a slow runner. Each of its top ten is moved onto testtiming here,
so a slow or loaded runner slows the test without failing it, and a
fault still fails it:

1 testreuse run_test.go: the seven 1500ms sleeps before releasing a lock
  the second check must already be waiting on now wait for the check's
  own "waiting for another check" line (the shape clock_test.go took in
  3076812), for as long as testtiming.Patience allows.
2 runner gatewait_test.go: the gate now waits past the run's bound (4s
  against 3s), so a run charged for its wait is killed however fast the
  runner, and the work ends once the gate opens (a file a timer writes
  at the opening, since the run stops asking the gate once its credit
  is spent), with two seconds of bound and credit left, instead of
  sleeping 0.7s against a 1s bound with 0.3s to spare; the gate credit
  is judged against a reference run's kill time, by the ratio
  LongestRun allows, not against a constant.
3 loop widen_paths_test.go: the refusal of 200,000 paths is judged
  against a pass over a tenth of them, and so is the dedup,
  measured in the same run, not against 2s and 4s.
4 claim: status_test.go's origin hangs a minute and the prompt is judged
  by CutShort of that; generated_match_test.go and generated_test.go read
  their slack bounds off the process CPU clock, which load does not
  inflate.
5 github scheduled_test.go: the origin is made before the 200ms context
  starts, and the hung stub runs a minute, judged by CutShort.
6 sessionname register_test.go: naming under a held lock is judged
  against a clean start timed in the same run (ratio 2, floor 1s).
7 gitutil: every hung stub git runs a minute (gitHang) and each read a
  context ends is judged by CutShort of it, not 2 to 3s; the 300ms sleep
  before asking whether prepare-commit-msg's program survived the stop is
  a wait for it to go, for half that program's minute (AwaitWithin).
8 cli: the stuck augmenter, the stalled stdin, the git that does not
  answer and the stuck renewal each end after a minute, and each hook or
  waiter is judged by CutShort of that, where 5 to 10s left a slow runner
  a few seconds to start and end the command in.
9 gitleaks augmenter_context_test.go: the context ends once the run has
  started (the runner closes a channel on entry), not on a 100ms timer a
  slow runner could spend before the run began; 9a5bfd4's fix for the
  scanner's own test.
10 matrix: the 4s bound under a 5s deadline is CutShort of a 20s
  deadline; the leader and FIFO runs are judged by CutShort of their
  deadlines; the compliance checks' FIFO is answered after a minute and
  judged by CutShort of that, not 20 and 30s.

gittest.AnswerPipeAfter gives a FIFO git configuration that finite
alternative: it opens the pipe for writing, without blocking, after the
given time, so a git still reading it goes on, and a git the bound
stopped leaves nothing to answer.

Every change turns a bound a slow runner could fail into one only a
fault fails. No reproduction was possible: none of the old bounds fails
on demand, and a starved run long enough to try each would have added
to a machine already at three to five times its cores' load, so none
was run. The audit in the next commit, run on a copy of the tree before
the census's fixes (3436e16), names exactly the 22 bounds this commit
and the two before it moved.

Green, through the narrow load gate, each changed test by name: cli (5),
testreuse (5), runner (3), matrix (5), gitutil (7), claim (3), github
(2), gitleaks (1), sessionname (1), gittest (1) and loop's widening (1)
pass. The gate wait test's first version
failed there at 6s: it opened the gate only when next asked, which a
run whose credit was spent no longer does, so a timer now opens it
(4.01s).

Refs: iss-2612022218392055
Assisted-by: Claude:claude-opus-5-5
The last part of iss-2612022218392055's remedy that fits this change: an
audit that flags a test holding a measured wall-clock time to a
constant, so the census's pattern cannot come back one test at a time.

TestNoNewWallClockBound (internal/core/lint, which precheck and both CI
legs run whole) reads every test file under internal/ and cmd/ and finds
each upper bound on an elapsed wall-clock time (time.Since, time.Now()
.Sub, or a name assigned from one) that is a constant duration (unit
literals, the package's constants, time.Duration conversions). A lower
bound is passed: a slow runner only lengthens what it measures. The 48
bounds left after the census's ten worst were moved are listed by file
and function in wallClockBaseline; one more in any function fails, and
a listed one fixed fails until the list drops it, so the list only
shrinks. internal/testtiming itself is exempt.
TestTheWallClockAuditReadsEachShape holds the scan to each shape it
flags and each it passes.

Red before green: with an empty baseline it named 50 functions on this
tree; with lower bounds still counted it named the two lower bounds it
now passes, as entries to drop; and on a copy of the tree at 3436e16,
before the previous three commits, it named exactly the 22 bounds those
commits moved onto testtiming, in 21 functions.

It sees neither a constant passed through a helper (claim's slack(d)),
nor a fixed sleep used as a hand-off, nor a fake clock that reads
time.Now; those stay a reviewer's. The last and the remedy's starved
lane are deferred by dcn-2612022337510454, with their grounds.

The issue is resolved here: the timing helper (3436e16), the census's
two sibling stand-in clocks, the seven confirmed flaky tests' causes and
the one still open, the census's ten worst bounds, and this audit.

make precheck passes on this tree (exit 0), internal/core/lint and
cmd/precheck-audits whole among it.

Resolves: iss-2612022218392055
Assisted-by: Claude:claude-opus-5-5
…ck audit

The correctness review of 58c84da found the audit blind to a bound held
to a constant the test function declares itself: consts was filled only
from file-level declarations, so `const budget = time.Second` inside a
test and `took >= budget` passed, and moving a listed constant into its
function took the bound off the list with the bound still there. Three
such bounds were in the tree and unlisted.

boundsIn now reads the function's own constants as it reads the
package's (withLocalConsts): each name a const declaration in the body
declares, and each variable whose every assignment, `:=`, `=` or `var`,
is a constant duration, in the order written, so one built from another
counts; a variable also given anything else, stepped or ranged over is
not constant. TestTheWallClockAuditReadsEachShape gains a function with
each of the three shapes and a passed variable also given a measured
value.

The baseline grows once, here, from 48 bounds to 52 in 51 functions:
landing's TestTheReceiptReadEndsAtItsDeadlineWhileGitHangs (10s) and a
second bound in cli's TestThePromptHookReturnsInsideItsSecond (5s),
which the review named, and two it did not: claim's
TestPushHonoursCallerContext (a second and 6s of grace and margin) and
spotcheck's writeCutOff (a local sum of package constants).

promptlog_reap_test.go held the record to its own one-second deadline,
which left a loaded runner the half second after the scan's stop to
clean up, write and return in. The scan now keeps the deadline it was
given, and the test reads it, not times it: it must be before the
record's. The scan ends on its own after a minute, and the record is
judged by CutShort of that minute, so a record that stops nothing still
fails. No reproduction was possible: the old bound does not fail on
demand, and a starved run was not made on a machine already at three to
five times its cores' load.

The audit's blind spot for a fixed budget waited out, a select on
time.After(<constant>) or a time.Now().Add(<constant>) poll loop, which
the security review named, is recorded in dcn-2612022337510454 rather
than taught here: 378 such calls in 191 test files, most fixture dates
or deadlines far past the work, which syntax does not tell from a
budget. The audit's header names it.

Red before green, through the narrow load gate: the new shapes run
through a throwaway copy of the audit as 58c84da had it found
TestFlagged's 4 and none of TestFlaggedLocally's 3, and failed; the new
audit found both and passed. On the tree, the new audit named exactly
the four bounds above, and nothing else, until they were listed.
TestPermissionPromptRecordWaitsForAStoppedScan passes (0.62s).

Refs: iss-2612022218392055
Assisted-by: Claude:claude-opus-5-5
The correctness review of 58c84da found three rewrites that judged a
run by a ratio of a reference with a floor under the bound they
replaced, so a stall a loaded runner puts in one call could fail
correct code the old bound passed:

- runner gatewait_test.go, TestTheGateCreditIsBounded: the held run at
  2.5 times a no-wait run allowed about 1.3s where LongestRun and 2s
  allowed 3s, and one start or kill held up 0.3s longer than the other
  failed it. The floor is now LongestRun(bound) + 2s; a credit never
  ended still runs the sleep's minute.
- sessionname register_test.go: naming under each failure keeps the
  1.5s it was allowed before as its floor, in place of 1s.
- loop widen_paths_test.go: the refusal keeps 2s and the dedup 4s as
  floors, in place of 1s each.

Each regression these tests exist for is still far over its floor: a
gate credit never ended (a minute), a held lock waited out at its two
second default, a refusal or dedup that compares every path with every
other (ten thousand passes).

dcn-2612022252475157 names the cost the security review left as
designed: an "ends at its deadline" test judged by CutShort of a minute
no longer catches a slip of up to about 29s.

No reproduction was possible: a stall in one call does not come on
demand, and a starved run was not made on a machine already at two to
four times its cores' load. Through the narrow load gate,
TestTheGateCreditIsBounded passes (1.52s).

Refs: iss-2612022218392055
Assisted-by: Claude:claude-opus-5-5
…ck audit, however read

Both reviews of 6fefbcf found the audit's header claiming constants
without limit where isConstDuration read only the package's own,
bare: `took >= gitutil.StopGrace` in an external test package
(bounded_unix_test.go, 5s, as long as the delay it detects) and
`took > spotcheckNetTimeout+grace+margin` (claim remote_test.go), a
package variable the test sets and puts back, were neither counted nor
named.

The audit now counts:

- the package's constants and its variables declared with a constant
  duration, read bare or, from an external test package, through the
  package's name, its export_test files included;
- a variable, the function's or the package's, whose every assignment
  in the function keeps it constant: a constant duration, a `var` with
  no value, a step by a constant (`limit *= 5`, `n++`), or a value put
  back from a copy taken while it was constant;
- an elapsed time given by `var took = time.Since(...)`.

A variable also given anything else, a value put back through a
function's parameter included, is not constant. What the audit still
does not read is listed in its header and in dcn-2612022337510454,
shape by shape: another package's constant or variable (none in the
tree is held as a bound), a struct field, parameter or call's result,
a variable given anything but a constant, an elapsed time taken any
other way (end.Sub(start) of two readings, which syntax does not tell
from a fake clock's), the CPU clock by design, a fixed sleep as a
hand-off, and a budget waited out on time.After or time.Now().Add.

The fixture is now a package with an external test package beside it
(wallclock_shapes_test.go), so a scratch copy can run it through an
older audit.

The baseline grows once, here, from 52 bounds to 55 in 54 functions:
claim's TestTheSpotcheckFetchEndsAtItsBound (a package variable set and
put back), loop's TestTheWaiterPassesOverARunWhoseLockIsHeld (ten times
the package variable lockTimeout and 5s) and gitutil's
TestAStoppedCommitLeavesNoChildGitStartsAfterTheSnapshot (gitutil.StopGrace
from the external test package). No other selector form is held as a
bound in the tree: a grep of every test file that takes time.Since or
time.Now().Sub for a comparison with a package-qualified name found only
gitutil.StopGrace.

Red before green, through the narrow load gate: on a scratch copy at
6fefbcf, the new fixture through the audit as that head has it found
TestFlagged's 4 and TestFlaggedLocally's 3, none of TestFlaggedStepped's
3 or TestFlaggedOutside's 2, and failed; on this tree it found all four
and passed, and the scan of the tree named exactly the three functions
above until they were listed.

The resolved issue's resolution is brought in line: the count left and
the three deferrals.

Refs: iss-2612022218392055
Assisted-by: Claude:claude-opus-5-5
The security review of 6fefbcf found that no test held the record to
its context's end: both fake scans honour their context, so deleting
redactWithin's `case <-ctx.Done()` (promptlog.go) left every test green,
at this head and at the branch's base alike. Pre-existing, and fixed
here.

TestPermissionPromptRecordEndsWithItsContext gives the record a scan
that ignores its context and returns only after a minute (or when the
test ends). The record must return, the command recorded by its
length, within CutShort of that minute; a record that waits for the
scan takes the whole minute. Its context is five seconds, so the
scanner has time to start the scan before it is told to stop, and the
test fails on the premise if the scan never started.

TestPermissionPromptRecordWaitsForAStoppedScan no longer holds the
record inside its own second, and that is kept so: the deadline is now
held in two halves, that test's read of the scan's deadline (told to
stop before the record's) and this test's (the record does not wait
past its context). A record that stopped the scan late and waited for
it past its deadline fails both. What neither holds is a slow write
after the scan, which is the flake the second-long bound was, or a
slip of under half a minute, the cost dcn-2612022252475157 records.

Red before green, through the narrow load gate: on a scratch copy at
6fefbcf with that case deleted, the new test failed ("took
1m0.0116605s, over its bound of 30s"); on this tree it passes (5.05s),
and so does TestPermissionPromptRecordWaitsForAStoppedScan (0.64s).

Refs: iss-2612022218392055
Assisted-by: Claude:claude-opus-5-5
The correctness review of d7b3a98 found that the audit read the
package's variables in one pass, in file-name order, so a variable
declared from one a later file declares was never constant to it: in
package loop, gitenvs.go's `var heldReadTimeout = originAskTimeout`
comes before lane.go's `var originAskTimeout = time.Minute`, and
`took >= heldReadTimeout/2` in remoteid_bounded_test.go's
TestAComparisonSlowOnEveryReadEndsAtItsOverallBound (five minutes once
the test sets the variable to ten) was off the list. Renaming lane.go to
sort first would have failed the audit on a change that adds no bound.

The variable pass now repeats until it declares nothing new, so what
the audit finds does not hang on the order of the file names. The
function is listed; the baseline is 56 bounds in 55 functions, and
dcn-2612022337510454 and the resolved issue say so.

The security review of the same head noted the header said a bound
held to a struct field is not read, where a field the function itself
sets only to constant durations (`cfg.Timeout = 2 * time.Second`) is
counted. The header, the decision and the doc comments now say exactly
that: a field the function sets is read, one set elsewhere (a helper,
a fixture's constructor) is not.

The fixture gains a variable declared from one in a file that sorts
after it (TestFlaggedLater), a field set in the function
(TestFlaggedLocally) and one set by a constructor (TestPassed).

Refs: iss-2612022218392055
Assisted-by: Claude:claude-opus-5-5
@REPPL
REPPL enabled auto-merge December 3, 2026 13:46
REPPL added 2 commits December 3, 2026 15:05
Assisted-by: Claude:claude-opus-5-5
The release-hold test that reached main beside this branch held the
judgement a deadline ends to half the hung git's stall with its own
comparison. The wall-clock audit refuses a bound written that way; the
check is now testtiming.CutShort against the same stall, the bound it
already meant.

Refs: iss-2612022218392055
Assisted-by: Claude:claude-opus-5-5
@REPPL
REPPL disabled auto-merge December 3, 2026 21:57
@REPPL
REPPL enabled auto-merge December 3, 2026 21:58

This branch has not been deployed

No deployments
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