Task · TSO-0167

Make Headscale limiter timeout proof deterministic instead of a 5ms network race

Description

Loop20 local gate failed in TestClientRateLimitWaitIsOutsideAttemptTimeoutAndRequestDuration on an unchanged Python-only candidate. The existing localhost HTTP request must finish inside 5ms and compares elapsed wall-clock margins. Retrying past the scheduling flake is not proof; the limiter-wait-versus-attempt-timeout contract needs a deterministic observation.

Acceptance Criteria

Definition of Done

Implementation Plan

Use deterministic fake-time/context contract probe instead of wall-clock localhost latency; prove deliberate production ordering regressions fail then restore production bytes, run focused race and serialized full gate.

Implementation Notes

AC2 wording corrected to the behavioral contract: production already starts duration measurement before waiting and subtracts waitDuration. The observed negative mutation removes that exclusion, rather than moving a start that is already early. Timeout-before-wait and wait-charged-duration both fail; no test assertion or production behavior changed.

loop20: 1 implementation attempts; Done after acceptance, landed code and green composed gate. Earlier superseded/cancelled CI runs are not passes.

Final Summary

loop20 landed evidence 6deb98393a72bda6c030c2c982fc4b5bbf3ea9f9. Replaced flaky localhost5ms margin with real limiter/retry transport and fake network under synctest. Negative timeout-order and wait-charged-duration checks fail; production restored byte-identical. Focused race100 repetitions and full gate green; independent review PASS; completed CodeRabbit zero findings. Final composed just check on actual shipped SHA129945fb3230f1c5d8a1127ad3e3c7faa2c514f4 passed, unchanged tree. Exact CI e96e74e31e2df4c697435dd4b7a32315e0e02f41 run38003933710 ci-success succeeded; no production diff outside backlog from that tested code. Helm absent-not-required (no landed chart change). Just formatting passed. Generated-input DoD is not applicable or covered by gate; no generator drift or weakened test claimed.

References

View the source file on GitHub