Skip to content

Node agent tests: drive the failed-handoff hold test from the rig clock, so a slow host cannot settle the sample early - #545

Merged
teddashh merged 4 commits into
mainfrom
w5-r22-clock
Nov 15, 2026
Merged

teddashh merged 4 commits into
mainfrom
w5-r22-clock

Conversation

@teddashh

Copy link
Copy Markdown
Contributor

TestR22_H1B_FailedHandoffSettlementAndSampling (node/agent/followup39_test.go) checks that a usage sample which fails at a serving handoff stays pending and is settled later, with and without an agent restart. Its two hold subtests made the sample fail by clock. The test's meter read time.Now plus 1.5 s for the first sample and time.Now for the handoff, so the handoff reading was behind the checkpoint and the meter held it. That works only while less than 1.5 s of real time passes between the two readings. On a loaded host more time passed, the handoff sample was not held, and both hold subtests failed with failed final sample was not left pending. A later wait in the test also slept on real time, and the poll for the sample taken by Run gave up after one second.

What changes (one test file; no production code):

  • The test's meter reads the rig's manual clock. That clock moves only when the test advances it, so the handoff reading is 1.5 s behind the checkpoint whatever the host does.
  • Aligning the rig clock first. The production meter that ran before the test's meter has already written a checkpoint from time.Now. A reading behind that checkpoint would be held, and one more than a full sample interval behind it would be a clock gap. So before the first sample the test waits until real time is past that checkpoint and then moves the rig clock so that the first reading equals real time. The step can go forward or backward. A backward step is never larger than the time anchor's backward tolerance less 250 ms (timeanchor.DefaultBackwardSkew): the test waits up to ten seconds for real time to come within that limit, and fails with catch-up still behind the anchor tolerance if it does not.
  • Restart subtests. The restarted agent's meter is the production one and reads time.Now, so a clock offset in the test cannot keep its sample pending. The test's existing read-failure switch now does that: it is set before the restart and cleared where the test settles the sample.
  • Meters that read real time. Before the restarted agent starts, and before the successor at the end of the test boots, the new helper r22WaitPastCheckpoint sleeps until real time is 10 ms past the newest checkpoint. Without it, such a meter could find a checkpoint that the rig clock wrote ahead of real time and hold its own first sample.
  • Other waits. Where the test slept until real time passed a checkpoint, the subtests without a restart now advance the rig clock. The poll for the sample taken by Run waits up to 30 seconds and still leaves as soon as the ledger shows the delta.

No existing assertion changes.

One case is not handled, and the helper's comment says so: if the host's wall clock steps back while r22WaitPastCheckpoint sleeps, real time can still be behind the checkpoint afterwards and a sample taken then can be held.

Checks made with temporary edits, three runs each, each reverted afterwards. On the base commit:

  • a two-second sleep before the handoff: both hold subtests failed with failed final sample was not left pending, and both read_error subtests passed. This is the failure the change removes.

On the last commit that changes code (the final commit corrects three comments):

  • a twelve-second sleep before the handoff, and a two-second sleep before the restart: all four subtests passed;
  • a hold offset of -1.5 s, so that the handoff reads after the checkpoint: both hold subtests failed with failed final sample was not left pending;
  • the read-failure switch not set before the restart: hold_restart_true failed with pending final sample allowed Apply or serving;
  • the rig clock moved three seconds ahead of real time before the alignment, as a host clock step back would leave it: all four passed, the hold subtests about 2.5 s slower;
  • the same, with the alignment made in one step without the limit, or with the limit widened past the anchor's tolerance: all four failed with generation 3 not serving;
  • the same, with the ten-second budget cut to 100 ms: all four failed with catch-up still behind the anchor tolerance.

Validation: on the exact source 61e77fe5:

  • the change's shape: exactly the one owned path in 4 commits, scanned, with clean whitespace;
  • TestR22_H1B_FailedHandoffSettlementAndSampling by name, five runs: the test and each of its four subtests (hold_restart_false, hold_restart_true, read_error_restart_false, read_error_restart_true) passed five times, none skipped;
  • CI's Node job: lint, unit tests (10 packages ok), integration against PostgreSQL (2 packages ok; skipped: TestD096_RealNetBird), build;
  • none of the 2 test databases the runs named was left behind;
  • CI's Go job: go-lint, go test ./... (95 packages ok; 3 of them came from Go's test cache (node/internal/controlclient, node/internal/fakecontrol/cmd/fvpn-labcontrol and node/internal/timeanchor: their tests had passed a few minutes earlier in the same tree, in the Node job's unit test step above; the changed package node/agent ran fresh)), the build of every command for amd64 and arm64, and the tidy check.

Then the same checks on a temporary merge of this source into main c001b569, which merged without conflicts:

  • TestR22_H1B_FailedHandoffSettlementAndSampling by name, five runs: the test and each of its four subtests (hold_restart_false, hold_restart_true, read_error_restart_false, read_error_restart_true) passed five times, none skipped;
  • CI's Node job: lint, unit tests (10 packages ok), integration against PostgreSQL (2 packages ok; skipped: TestD096_RealNetBird), build;
  • none of the 2 test databases the runs named was left behind;
  • CI's Go job: go-lint, go test ./... (96 packages ok; 3 of them came from Go's test cache (node/internal/controlclient, node/internal/fakecontrol/cmd/fvpn-labcontrol and node/internal/timeanchor: their tests had passed a few minutes earlier in the same tree, in the Node job's unit test step above; the changed package node/agent ran fresh)), the build of every command for amd64 and arm64, and the tidy check.

These are local runs; no CI result is claimed here.

Review: four independent review rounds, each on an exact source. The first found that the first version still depended on real time in two places: the restarted meter reads time.Now, so the sample stayed pending only while real time was behind a checkpoint written nine seconds ahead, and the successor at the end booted while that checkpoint was still ahead of real time. The second commit removes the lead and keeps the sample pending across the restart with the read-failure switch. The second review found that this commit had dropped two error checks from hold_restart_true, and that a single alignment step could exceed the anchor's backward tolerance if the host clock stepped back during setup; the third commit restores the checks and bounds the step. The third review confirmed those fixes and raised two more points about host clock steps and late wake-ups. The project lead did not accept them as defects of this change: a host clock step back makes the test fail at setup, not pass for a wrong reason, and the loop reads real time again before it accepts a step, so a late wake-up cannot pass a step outside the limit. The helper's comment now names the unhandled case, and the final commit also corrects two other comments. The fourth review, of that commit, approved it with no findings.

Agent: grok/grok-4.7

🤖 Generated with Claude Code

Open and head checks run for both hold subtests. Only the rig-clock advance stays on the meter that reads that clock. The catch-up aligns the first reading with real time and will not step the wall further back than the anchor tolerance minus 250ms.

Agent: grok/grok-4.7
@teddashh
teddashh merged commit 3a21b91 into main Nov 15, 2026
41 checks passed
@teddashh
teddashh deleted the w5-r22-clock branch November 15, 2026 05:17
teddashh added a commit that referenced this pull request Nov 15, 2026
Co-Authored-By: Claude Fable 5.2 <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