Skip to content

Time the stall window test instead of counting polls - #10987

Merged
danielhanchen merged 4 commits into
mainfrom
fix-stall-window-test-measures-time
Sep 15, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
fix-stall-window-test-measures-time

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Frontend unit tests (Windows) fails on PRs that touch nothing near it. Most recently #10950, which changes GGUF export token fallback:

a healthy read did not restart the stall window, in 1 of 3 rounds:
  65 with a reset against 55 without;
  64 with a reset against 43 without;
  62 with a reset against 50 without.

Those are ratios of 1.18, 1.49 and 1.24 against a 1.25 bar. The same healthy code both passed and failed inside a single run, and round three missed by half a read.

The measurement is what is wrong, not the threshold

The stall window is defined in time. settleWhenLoadEnds keeps a lastHealthy stamp and gives up at Date.now() - lastHealthy >= stallMs.

The test counted reads. A read count is that same quantity divided by the cost of one poll, and poll cost is the noisiest thing within reach on a shared runner: about 1ms here, about 15ms on windows-latest, and varying run to run on both. Worse, the reset point was a read index derived from the previous run's count, so drift between the two runs moved the thing being measured as well as the measurement. The baselines in the failure above range from 43 to 55 reads, a 28 percent spread, within one test.

The file's own history shows two attempts to average that away: one sample became best-of-three, which became majority-of-three. Neither shrank the spread, because the spread is the measurement.

Timing it instead

Measure how long the loop survives, and fire the healthy read on a clock rather than at a read index. The reset then lands halfway through the window whatever a poll costs, and the signal becomes a difference rather than a ratio: a loop whose window restarted halfway should outlast the plain one by about half a window.

Jitter is bounded by one poll interval, so about 15ms at worst against a 200ms signal. One sample of each now does what six rounds could not, which also makes the test 2.5x faster, 3285ms to 1282ms.

Not vacuous

The version this replaces said in its own comment that it was vacuous on Linux, where 30ms of 1ms polls cleared the old bar whether or not the window was ever reset. This one is not. Dropping the lastHealthy refresh from model-lifecycle-events.ts fails it here:

a healthy read did not restart the stall window: it bought -1ms
(400ms with a reset against 401ms without), where restarting halfway
through a 400ms window should buy about 200ms.

Healthy code buys about 200ms against a 100ms bar; the broken source buys 0. The old test decided the same question on 1.18 against 1.25.

Verification

tests/background-load-notice.test.ts: 11 passed, five runs in a row.

Whole frontend suite, with and without this change: 5645 tests, 5405 passed, 240 failed, identical both ways. Those 240 are a local node_modules gap, not this branch.

Tests only, no production code.

'a healthy read resets the stall window' fails on windows-latest on PRs that
touch nothing near it. Seen on #10950 at 65/55, 64/43 and 62/50 reads, ratios
of 1.18, 1.49 and 1.24 against a 1.25 bar, so the same healthy code both
passed and failed inside one run.

The measurement is the problem. The window is defined in time: the source
keeps a lastHealthy stamp and gives up at Date.now() - lastHealthy >= stallMs.
The test counted READS, which is that quantity divided by the cost of one
poll, and poll cost is the noisiest thing in reach on a shared runner, about
1ms on Linux against about 15ms on Windows. The reset point was derived from a
previous run's read count too, so any drift between the two runs moved the
thing being measured as well as the measurement.

Best-of-three and then majority-of-three were both attempts to average that
away. Neither shrank the spread, because the spread is the measurement.

So time the loop, and fire the healthy read on a clock rather than at a read
index. The reset lands halfway through the window whatever a poll costs, and
the signal becomes a difference rather than a ratio: the loop should outlast
the plain one by about half a window. Jitter is bounded by one poll interval,
~15ms at worst against a 200ms signal.

One sample of each now does what six could not, so the test is also 2.5x
faster: 3285ms to 1282ms.

Not vacuous, which the version it replaces admitted it was on Linux. Dropping
the lastHealthy refresh from the source makes it fail here with 'it bought
-1ms (400ms with a reset against 401ms without)'.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-15T07:55:25.077752Z bea5cb6 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 214424e0f1

ℹ️ 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 added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 34de7f889c

ℹ️ 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".

Subtracting two separately scheduled runs re-imports the noise the previous
commit set out to escape. An unrelated stall of 100ms or more is well within
what a shared runner does, and it breaks the comparison in both directions: a
stall during the baseline fails healthy code, and a stall during the other run
passes code that never refreshes lastHealthy. The claim that jitter is bounded
by one poll interval covered poll scheduling, not OS or event-loop stalls.

So use one run and assert what the source actually promises: the window
restarts at the healthy read, so the loop must survive a further full window
from THAT moment. Both sides of the bound come from the same run, and a stall
can only make the total larger, so the bound is one-sided and delay cannot
fail healthy code.

A stall can still hide a missing reset by inflating the total, so the run
records the longest gap between two reads and skips when that gap gets close
to the signal. A run that cannot tell the two apart reports no evidence rather
than a verdict.

One run rather than two also makes it 600ms, against 1282ms for the previous
version and 3285ms for the one before that.

Failure output is now exact rather than statistical: 'the loop ended 400ms in,
having reported progress at 200ms, so it should have run to at least 600ms'.
Verified by dropping the lastHealthy refresh, and passing 5 of 5 under 240
busy processes on a 192-core box.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: bea5cb69c7

ℹ️ 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 added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
@danielhanchen
danielhanchen merged commit e60f48c into main Sep 15, 2026
34 of 37 checks passed
@danielhanchen
danielhanchen deleted the fix-stall-window-test-measures-time branch September 15, 2026 09:31
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
* Time the stall window test instead of counting polls

'a healthy read resets the stall window' fails on windows-latest on PRs that
touch nothing near it. Seen on unslothai#10950 at 65/55, 64/43 and 62/50 reads, ratios
of 1.18, 1.49 and 1.24 against a 1.25 bar, so the same healthy code both
passed and failed inside one run.

The measurement is the problem. The window is defined in time: the source
keeps a lastHealthy stamp and gives up at Date.now() - lastHealthy >= stallMs.
The test counted READS, which is that quantity divided by the cost of one
poll, and poll cost is the noisiest thing in reach on a shared runner, about
1ms on Linux against about 15ms on Windows. The reset point was derived from a
previous run's read count too, so any drift between the two runs moved the
thing being measured as well as the measurement.

Best-of-three and then majority-of-three were both attempts to average that
away. Neither shrank the spread, because the spread is the measurement.

So time the loop, and fire the healthy read on a clock rather than at a read
index. The reset lands halfway through the window whatever a poll costs, and
the signal becomes a difference rather than a ratio: the loop should outlast
the plain one by about half a window. Jitter is bounded by one poll interval,
~15ms at worst against a 200ms signal.

One sample of each now does what six could not, so the test is also 2.5x
faster: 3285ms to 1282ms.

Not vacuous, which the version it replaces admitted it was on Linux. Dropping
the lastHealthy refresh from the source makes it fail here with 'it bought
-1ms (400ms with a reset against 401ms without)'.

* Tighten the comments added by this PR

* Assert the stall window against the mechanism, not a second run

Subtracting two separately scheduled runs re-imports the noise the previous
commit set out to escape. An unrelated stall of 100ms or more is well within
what a shared runner does, and it breaks the comparison in both directions: a
stall during the baseline fails healthy code, and a stall during the other run
passes code that never refreshes lastHealthy. The claim that jitter is bounded
by one poll interval covered poll scheduling, not OS or event-loop stalls.

So use one run and assert what the source actually promises: the window
restarts at the healthy read, so the loop must survive a further full window
from THAT moment. Both sides of the bound come from the same run, and a stall
can only make the total larger, so the bound is one-sided and delay cannot
fail healthy code.

A stall can still hide a missing reset by inflating the total, so the run
records the longest gap between two reads and skips when that gap gets close
to the signal. A run that cannot tell the two apart reports no evidence rather
than a verdict.

One run rather than two also makes it 600ms, against 1282ms for the previous
version and 3285ms for the one before that.

Failure output is now exact rather than statistical: 'the loop ended 400ms in,
having reported progress at 200ms, so it should have run to at least 600ms'.
Verified by dropping the lastHealthy refresh, and passing 5 of 5 under 240
busy processes on a 192-core box.

* Tighten the comments this PR added
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