Skip to content

Expire gateway requests exactly at their deadline - #4

Merged
Abhayrkhot merged 1 commit into
mainfrom
fix-gateway-expiry-boundary
Nov 21, 2026
Merged

Abhayrkhot merged 1 commit into
mainfrom
fix-gateway-expiry-boundary

Conversation

@Abhayrkhot

Copy link
Copy Markdown
Owner

GatewayState.expire_pending compared now - started >= timeout. When now is exactly started + timeout, the subtraction can round just below the timeout, so the request was kept for one more expiry pass:

>>> s = 252.15820775
>>> (s + 10) - s
9.999999999999972

test_lost_results_expire_and_free_capacity checks that boundary using the real perf_counter() start time, so it fails for some clock values. Over a million random start times under 1,000 s (where a freshly booted CI runner's clock sits), the old check missed the deadline 1.26% of the time. It failed the macOS TSan job on main after PR #2 (run 44932944283), even though the same code had passed on the PR.

Change

  • expire_pending now compares now >= started + timeout, so a request expires exactly at its deadline. Away from the boundary, behavior is unchanged; in production the comparison runs once a second against the real clock, so the difference was at most one extra pass.
  • New test test_request_expires_exactly_at_its_deadline pins the start time from the failing run. It fails on the old code and passes with the fix.

Testing

  • pytest python/tests in the dev image: 11 passed (the new test failed before the fix).

expire_pending compared now - started >= timeout. When now is exactly
started + timeout, the subtraction can round just below the timeout
(252.15820775 + 10 - 252.15820775 is 9.99999999999997), so a request
was kept for one more expiry pass. test_lost_results_expire_and_free_capacity
checks that boundary with the real perf_counter() start time, so it failed
for about 1.3% of start times under 1,000 s, which is where a fresh CI
runner's clock sits. It failed the macOS TSan job on main after PR #2.

Compare now against started + timeout instead, and add a test that pins
the start time from the failing run.
@Abhayrkhot
Abhayrkhot merged commit 40d43b9 into main Nov 21, 2026
5 checks passed
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