Skip to content

Stop the stall-window comparison being decided by one noisy sample - #10246

Merged
danielhanchen merged 2 commits into
mainfrom
ci-windows-stall-window-flake
Sep 3, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
ci-windows-stall-window-flake

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Frontend unit tests (Windows) is red on main at 01262664e, on one subtest out of 6821:

not ok 423 - a healthy read resets the stall window
  location: 'D:\a\unsloth\unsloth\studio\frontend\tests\background-load-notice.test.ts:351:1'
  error: 'a healthy read did not restart the stall window: 56 reads with one,
          47 without. A run of unreadable polls is inheriting the elapsed time of
          the run before it, so a slow download that keeps reporting progress can
          still be abandoned.'

The source is fine. withBackgroundLoadNotice still sets lastHealthy = Date.now() on every readable phase, and the whole suite passes on Linux.

What the test measures

It cannot assert a read count against a millisecond budget, because the source reads Date.now() and arms setTimeout itself, so it runs on the wall clock and one poll costs about 1 ms locally against about 15 ms on a Windows runner. The comment at the top of the test says so, and records that the previous version asserted reads > 4 against a 30 ms window and was both flaky on Windows and vacuous on Linux.

So it measures the reset against the same loop without one, and requires the reset to carry the loop at least 1.25x further. Dividing the platform out like that is the right idea and I have kept it.

What it does not account for is that the two halves are separate wall-clock runs, taken one after the other. Anything that slows a shared windows-latest runner between them skews the ratio, and only ever downwards for whichever half got unlucky. A half-way restart should score about 1.5; this run scored 56/47 = 1.19 against a 1.25 bar. It missed by three reads.

The change

Sample the pair up to three times and pass on the first round that clears the bar.

That costs nothing in strength, because the property under test is deterministic in the source. With the reset removed the two loops are the same loop, so every round scores about 1.0 and no amount of resampling gets one over 1.25. Only an unlucky measurement is retried, never a wrong answer. The failure message now reports every round rather than just the last, so a real regression reads as three consistent ~1.0 ratios instead of one borderline number.

Verified both directions:

  • unchanged source, the test passes, and npm test is 6821 pass / 0 fail
  • with lastHealthy = Date.now() deleted from model-lifecycle-events.ts, the test still fails, through all three rounds

The second one is the check that matters. A retry loop that cannot fail is worse than the flake it replaces, so I removed the reset in the source and confirmed the test goes red before proposing this.

Scope

Nothing else in the file or the suite changes, and no source changes. STALL_MS and the 1.25 bar are untouched, so the assertion is the same assertion, just not decided by a single sample.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 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-03T12:25:36.665197Z 8cc9e16 Manual request
🔒 Security Review ✅ Completed 2026-09-03T12:28:22.209190Z 8cc9e16 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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c033c6bdf7

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

);

const withReset = await readsBeforeSettling(Math.floor(withoutReset / 2));
if (withReset >= withoutReset * 1.25) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not accept the most favorable noisy sample

When the baseline run is scheduled more slowly than the following run, this condition can pass even if the lastHealthy reset is removed: the two otherwise identical loops then produce withReset / withoutReset >= 1.25 solely because the second loop completed more polls in the same wall-clock window. The observed runner variance can occur in either direction, and returning on the first success across three rounds increases the chance that a real regression is hidden; use a deterministic clock or a comparison that does not select the maximum favorable ratio.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, and best-of-three was the wrong shape. The noise runs in both directions, so a round that happened to schedule the second run faster could clear 1.25 on its own with the reset removed, and taking the most favourable round gave three chances at that instead of one. That is weaker than the single sample it replaced, which is the opposite of what I wanted.

Changed in 8cc9e16 to the majority of three rounds, always run, no early return. That is strictly stronger than the original single sample in both directions: it takes two unlucky rounds to fail a healthy reset, and two lucky ones to pass a missing one.

Re-verified both directions, three times each. Unchanged source passes every time. With lastHealthy = Date.now() deleted from model-lifecycle-events.ts:

0 of 3 rounds: 356 with a reset against 354 without; 365 against 361; 358 against 333
0 of 3 rounds: 359 against 355; 357 against 361; 358 against 359
0 of 3 rounds: 358 against 355; 360 against 360; 360 against 359

Which also puts a number on the noise you are describing: with the two loops identical, the widest excursion in nine paired samples was 358/333 = 1.075, against a 1.25 bar. Not proof it cannot go further on a windows-latest runner, but it is the margin the majority now has to beat twice rather than once.

On the deterministic clock: that is the right end state and I agree it beats any amount of sampling. It needs withBackgroundLoadNotice to take an injectable clock and timer, so it is a source change in src/lib/model-lifecycle-events.ts rather than a test one, and I did not want to put it in a PR whose job is unblocking a red main. Worth doing separately.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 8cc9e1669d

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 8cc9e1669d

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@danielhanchen
danielhanchen merged commit 2ed0da0 into main Sep 3, 2026
39 checks passed
@danielhanchen
danielhanchen deleted the ci-windows-stall-window-flake branch September 3, 2026 12:54
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