From b33d50e2ada68472637ac7dd76f462cd260565a6 Mon Sep 17 00:00:00 2001 From: PytechNo <63828779+PytechNo@users.noreply.github.com> Date: Fri, 16 Oct 2026 14:13:33 -0400 Subject: [PATCH] Sleep until a task timer is due before waking it The Luau task scheduler slept once with setTimeout and then resumed the earliest timer without checking the clock. Host timers can fire about a millisecond early, so task.wait(0.03) could return 0.0299, which failed the task library test on main's first CI run. The scheduler now sleeps again until the timer's wake time has passed, so task.wait always returns at least the time requested, as on Roblox. Co-Authored-By: Claude Opus 5.5 --- src/workers/projectRuntime.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/workers/projectRuntime.ts b/src/workers/projectRuntime.ts index 3c57a48..a88d9d5 100644 --- a/src/workers/projectRuntime.ts +++ b/src/workers/projectRuntime.ts @@ -964,8 +964,12 @@ export const LUAU_TASK_BOOTSTRAP = ` end if #timers == 0 then return end + -- Host timers can fire a little early, so sleep again until the timer is due. local remaining = timers[1].wake - clock() - if remaining > 0 then sleep(remaining) end + while remaining > 0 do + sleep(remaining) + remaining = timers[1].wake - clock() + end local due = popTimer() resume(due.thread, due.args) end