Skip to content

Drive the clock by hand in the Hub backoff-window tests - #18289

Merged
danielhanchen merged 1 commit into
mainfrom
ci/hub-network-test-fake-clock
Nov 18, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci/hub-network-test-fake-clock

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Drive the clock by hand in the Hub backoff-window tests

Frontend unit tests (Windows) failed on #18248, a backend-only change:

not ok 6571 - a lapsed backoff window means probing, never proven-available
  location: 'studio\frontend\tests\hub-network-availability.test.ts:58:1'
  expected: 'unavailable'
  actual: 'probing'

Cause

The test calls markRemoteNetworkOffline(HF, 10, ...) and immediately asserts the Hub is unavailable. It then sleeps 30 ms and asserts probing.

network.ts measures the window with Date.now(), so the first assert only holds if it runs within 10 ms of the mark. On a loaded runner, especially Windows, where timers tick about every 15 ms and the frontend suite runs on 8 workers, that window had already lapsed. The code under test behaved correctly; only the test raced the wall clock.

only a success clears the recorded failure sleeps the same way. It does not fail today, but it depends on real time for no reason.

Fix

Both tests now drive Date.now() through a small manualClock() helper instead of sleeping. The helper restores the real clock in finally.

  • First test: the clock moves 9 ms, still inside the 10 ms window, and must read unavailable. It then moves past the window and must read probing.
  • Second test: the clock moves past the window before checking the recorded failure.

The assertions are unchanged, and the file no longer sleeps.

Verification

  • node --test tests/hub-network-availability.test.ts: 16 passed.
  • Sabotage checks in network.ts:
    • Treating an expired window as available instead of probing fails a lapsed backoff window means probing.
    • Ignoring the TTL, so the window ends immediately, fails it as well, along with three other tests.
  • eslint on the file reports two unused imports, getBrowserOfflineRetryDelayMs and isHuggingFaceOffline, on lines this change does not touch.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T08:57:54.220998Z 795d73c Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 795d73c082

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit f839f9d into main Nov 18, 2026
@danielhanchen
danielhanchen deleted the ci/hub-network-test-fake-clock branch November 18, 2026 08:58
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