fix(os): consume a timer holder's period in WaitAny #2141
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2141
Loading…
Reference in a new issue
No description provided.
Delete branch "dazemc/Longshot:fix/os-timer-holder-period"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
A periodic
TimerEventlinked into a multi-wait is reported ready forever.wait_anyasksholder_ready, which answers "due" wheneverdue_nshas passed, but nothing on that path advancesdue_ns— while both single-timer paths do (WaitTimerEvent,TryWaitTimerEvent:while (t->due_ns <= now) t->due_ns += t->period_ns). So the first expiry makesWaitAny/TimedWaitAny/TryWaitAnyreturn that holder on every call, the period is ignored, and a guest wait-any loop spins.What changed:
timer_consumed_locked(new): advances a periodic timer'sdue_nsby whole periods, skipping any that passed meanwhile, as a hardware timer would.holder_readychecks readiness, consumes a ready timer and reads its next deadline under the timer lock;wait_any's scan takes the next deadline from there.WaitTimerEventuses the helper;TryWaitTimerEventuses the same calculation under one lock acquisition.TryWaitTimerEvent's check-and-consume are under the timer'st->lk, soWaitAny's scan and a single-timer wait cannot both consume the same periodic expiry.Five commits.
refactor(os): keep the timer fix without the multi-wait holder-array changeremoves the multi-wait holder-array fixes that had been in this branch, as the review asked. They are split into open, ready #2445; its current rebased head is recorded there. This PR remains only the timer-period topic. The last,test(os): run the multi-wait test on a tree without the extracted helper, extractstimer_consumed_lockedonly when the tree has it, so the same committed test runs againstmainand fails there (below).This head is
c11cd1356:host/nn_os_sync.c+29/−11,tests/test_multiwait_wake.py+118/−6, the same content these files carry at10bea861/7da472869. The last commit istests/only (+12/−5 over91add521).Read
host/nn_os_sync.c'stimer_consumed_locked,holder_ready,wait_any,WaitTimerEventandTryWaitTimerEventfirst; the test istests/test_multiwait_wake.py.Rebase status (2026-11-25, current):
66e327e62→c11cd1356ontomain @ 8f7300756701b7c9a278e576bb075ac20e622a32. Stable patch-id723a5721c725645fe6bec09bb0fbc558a1bd1a4fis unchanged and main's old-base→new-main file intersection with this PR is empty. The evidence already named below (suite, platform, in-game and measurement, as applicable) therefore still stands at the historical heads that produced it. Earlier rebase notes are history; where they say "this head", they mean the evidence commit named beside that run, notc11cd1356.Testing
Rebase (2026-11-25). Rebased onto
origin/mainbe663a08a30fa953420104d3cef6877bed6674a2. Old head7da4728698bc2b3350540247cfe7cc5550337450→ new head66e327e62865b5a44e9c6a6c887f7f2051168e63.git diff -U0 8aa5ab87..7da472869andgit diff -U0 be663a08a3..66e327e6hold the identical changed-line set (154 added/removed lines, 0 differing), so the rebase changed nothing this PR writes. Main's new commits since8aa5ab87touch neitherhost/nn_os_sync.cnortests/test_multiwait_wake.py— the intersection is empty — so the suite, windowed run and Windows whole-pack run below still describe this PR's code; they were taken at10bea861/7da472869, message-only apart, and this rebase is the only change since. No suite re-run is owed.Tested: Linux on this PC, kernel 7.3.5-zen1, RTX 4070 Ti (NVIDIA 620.73.04).
python -I -B tests/run_all.py --strict test_multiwait_wakethrough the PC's job queue at91add521: 1 check, 0 skipped, 1 passed, 0 failed, exit 0 (queue rowpr2141-mw-91add521, whosecwdis a worktree whoseHEADis91add521; evidence log/home/daze/.local/share/longshot-dev/suite-evidence/pr2141-mw-91add521.log, sha25642ec61511e346bc1e6544d8ebf665f13483e70e3e7938fd6b220c6f463873f00, read 2026-11-24T00:54:44-08:00). It is superseded at this head by the full suite below. An earlier row,w3-a-final, prints the same output but ran in/home/daze/GitHub/Longshot-2141-12ed3a32, i.e. at12ed3a32, and is not evidence for this head.Suite at this head.
mise run test -- --jobs 5at10bea861c685648d39e85764322f82f7644a9af0, in a scope capped at 12 GiB (systemd-run --user --scope -p MemoryMax=12G -p MemorySwapMax=0), wroteprrefresh-logs/suite-2141-10bea861.log(sha2565dcaeb9da1673119f0dbfe68a6672eb93a6efb2359a0b1d98675f64406f81234):961 checks, 18 skipped, 5 at once (linux),942 passed, 19 failed, 18 skipped in 406 s (linux, 5 at once); JUnittests="979" failures="19" skipped="18" time="406.032"; peak 8,084,963,328 B, no guard fired. The 19 failing ids are exactly the CORE set ofSUITE-COMPARISON-RULE.mdAmendment 1 with the same exception classes; no id outside CORE∪FLAKY failed and no FLAKY id failed, so the head passes under Amendment 1.tests/test_multiwait_wake.pyis apassrow (0.7 s).Tested in the game: Windowed run at
10bea861c685648d39e85764322f82f7644a9af0(versionv3.2.0-17-g10bea861c, queue job2141-windowed-10bea861-b, modeshared): Kokiri Forest (child), 948x512 logical window on workspace 2 of HDMI-A-2 (Hyprland, output 3840x2160), ~17.0 s of measured play after the 10 s warm-up ((play-end present 3201 − play-start present 1583 − 600)/60 = 16.97 s), 60.1 fps at the end, age child, life 12/12, no crash, clean quit (state: finished,exit_code: 0,stop_method: quit).hyprctl clients -jduring play shows the game window classdev.magicbean.Longshot, pid 266854, mapped, 948x512; two externalgrimshots were taken during play (3840x2160 each); the log has novk: no window. Linux/Hyprland (Wayland), RTX 4070 Ti, driver 620.73.04. Run folder~/.local/share/longshot-dev/runs/control/2141-10bea861-windowed-20261124.On
main, the same committed test fails for the bug's reason.tests/test_multiwait_wake.pyat10bea861extractstimer_consumed_lockedonly when the tree has it (maybe_block), sopython -I -B tests/test_multiwait_wake.py --source /home/daze/GitHub/Longshot-main-8aa5ab87/host/nn_os_sync.ccompiles againstmain8aa5ab87and exits 1 withFAIL: TryWaitAny left the timer holder due at 9999999 (want 10999999: the next period on),FAIL: TryWaitAny reported the periodic timer holder again without a period passing,FAIL: a timer 3.5 periods overdue moved on to 6500000 (want 10500000: four periods on)andFAIL: TryWaitAny reported the long-overdue timer holder again. No assertion changed: the only difference onmainis that the helper it does not have is not extracted. At10bea861the same file passes (targeted: ok,all: ok,PASS, exit 0).A game smoke and a host build exist at earlier trees (
a3dae742/805361a2, before the final timer synchronization commit and before the split): Kokiri Forest (child), 20 s measured after warm-up, the game boots and plays, 1862 frames, 93.1 fps, median 10.66 ms, p99 14.48 ms (base: 1805 frames, 90.3 fps, median 11.08 ms); Linux pack overa2dc5385compileshost/nn_os_sync.cand links (37 s); Windows compileshost/nn_os_sync.cas an x86-64 COFF object with llvm-mingw 20261104's clang 23.1.5 — a compile, not a link. They are not runs of this head.Tested on Windows (llvm-mingw). At
10bea861on a Windows 11 x86-64 box (Acer Nitro AN515-57, i5-11400H, llvm-mingw 20261104 UCRT),nx2\build.py --standalonewithRX_VK_ONLY=1compiled 268 renderer objects of this head and linked them:compiled in 149 s, 0 failed, link 1 s, 6 jobs,lifted code … (0 files)in the log, so no game data was read. Result:C:\Users\daze\longshot-2141\work\sa\build\longshot_vk.dll, 17,704,960 bytes, sha256aabd61c392275b57e6b2074dc2bbd3c753a5fc44f79fd0a3df882614bac39a9d, PE32+ (0x20B)IMAGE_FILE_MACHINE_AMD64/IMAGE_SUBSYSTEM_WINDOWS_GUI, exportingmkwvk_init,mkwvk_close_asked,mkwvk_crash_closeandmkwvk_crash_page;llvm-stringsfinds10bea861 (source 3f45af4d)in it. The checkout'sgit rev-parse HEADwas10bea861c685648d39e85764322f82f7644a9af0(.headbeside the log); build logbuild-10bea861-clean.log, sha256feaf8b63863ec67262bf43fda9c03bf70fa1da404b0f64164773c638cdc18632. The file this PR changes compiles as well:host/nn_os_sync.c→host_nn_os_sync.obj, 136,205 bytes, sha2568cc7d3a5dda6fefecec33e9409e2160b4a312f1ce97ec03b560695ced718b6c8, COFF machine0x8664, withnx2/build.py's own host flags and the generated headers the tree writes itself (a64_suyu.hthere is byte-identical to the one the build wrote: sha256a5b462d01483576cf34f8925d21c3365ae661a5077054a33fa6080a321583bed). This is a link, not the single-object compile the earlier tree had; it is the renderer DLL alone, so that build could not startlongshot.exe— the whole pack was built and started separately at this head (next paragraph).Tested on Windows, the whole pack — a whole-pack start, not the DLL-only build above. The same box then built the pack at
10bea861c685648d39e85764322f82f7644a9af0and started it.python -I nx2\lift.py --standalone --writewrote 88 code files intowork\sa\genfrom the game copy on that box (244 s,EXITCODE=0);python -I nx2\build.py --standalone --jobs 4reportedcompiled in 1326s, 0 failed,linked …\work\sa\build\longshot.exe: 539 MB (4s)andEXITCODE=0, and left thelongshot_vk.dllbeside it as the last link left it (the DLL above, not relinked).C:\Users\daze\longshot-2141\work\sa\build\longshot.exeis 566,189,568 bytes, sha256DFF74F4061100FBF4FFBD6317E71D370F7CB66DB9345F2A0BCE26D292305AC21, and the run's own replies readversion: 10bea861 (source 3f45af4d). Started windowed at thekokiri-startsave, it reachedplayat frame 2776 onKokiriForest_Childand was still on that map at the last play sample (frame 4664): 1,888 frames in play over 64.5 s, 30.3 fps at the end, age child, life 12/12, no crash, clean quit (control: quit asked by a client,control: exiting). The GPU is the box's ownNVIDIA GeForce GTX 1650and the log saysvk: driver: NVIDIA 610.62(Turing, driver id 4, VRAM 3,935 MB, RAM 7,971 MB; the low-memory notice that box shows was dismissed before play). The window is real:C:\Users\daze\smoke.logrecordswindow[in-play],window[mid-play]andwindow[end-play]forhandle=1311358 title='Longshot' … visible=True;C:\Users\daze\runs\win1\log.txthas novk: no windowand ends by writing frame 4689's present toC:\Users\daze\runs\shots\bridge.png(2,765,798 bytes), the game's own picture of the run. The evidence stays on that box: run logC:\Users\daze\runs\win1\log.txt(686,918 bytes),C:\Users\daze\smoke.log(24,979 bytes), build logC:\Users\daze\build-full.log(30,712 bytes, sha256c63b5839ffe21cf2ee020dd183488f722284620556967faea8447928f095e1f7). The head has since moved to7da472869by a message-only rewrite;git diff 10bea861..7da472869is empty and the tree is unchanged (4d9cc08e), so this run describes the current tree.Still to test:
10bea861(job2141-windowed-10bea861-b), Kokiri Forest (child), ~17.0 s measured play after warm-up, exit 0, no crash.10bea861the same box lifted the pack, builtlongshot.exe(compiled in 1326s, 0 failed) and playedKokiriForest_Childwindowed — 1,888 frames in play over 64.5 s, 30.3 fps at the end, visible window, clean quit (Tested).mise run testat this head, by hand:942 passed, 19 failed, 18 skipped in 406 s (linux, 5 at once), all 19 CORE, 0 outside (above).Measurements
Nothing to measure for frame time: the fix is latent on the shipped game — no path we can observe links a periodic timer into
WaitAny. This head has now been run in the game windowed (10bea861, job2141-windowed-10bea861-b, Kokiri Forest (child), ~17.0 s measured play after warm-up, exit 0, no crash); the earlier game smoke ata3dae742/805361a2is not a run of this head.Risks
Could break: a guest that links a periodic timer into a multi-wait now sees the period honoured instead of an always-ready holder (the intended behaviour); one-shot timers are unchanged on purpose. The consume and the check happen under the timer lock, so a long-overdue timer is advanced in one step rather than in a catch-up loop while
mw_lockis held. No switch; a revert is enough. Nothing changes for saves,longshot_options.inior the caches.Checklist
Ready for review
main; the title is a Conventional Commit. — Rebased headc11cd1356is directly onmain @ 8f7300756701b7c9a278e576bb075ac20e622a32; the preserved diff is the single topic described in Summary.10bea861(job2141-windowed-10bea861-b, Kokiri Forest (child), ~17.0 s measured play, exit 0, no crash,hyprctlwindow and externalgrimshots during play); details in Tested.mise run testpasses (any failure that also fails onmainis named). Suite at10bea861(prrefresh-logs/suite-2141-10bea861.log, sha2565dcaeb9d…):961 checks, 18 skipped, 5 at once (linux),942 passed, 19 failed, 18 skipped in 406 s (linux, 5 at once); the 19 failing ids are exactly Amendment 1's CORE set with the same exception classes, no id outside CORE∪FLAKY (details in Tested).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here.tests/test_multiwait_wake.pyat10bea861extractstimer_consumed_lockedonly when the tree has it (maybe_block), so the committed file runs againstmain8aa5ab87and exits 1:FAIL: TryWaitAny left the timer holder due at 9999999 (want 10999999: the next period on),FAIL: TryWaitAny reported the periodic timer holder again without a period passing,FAIL: a timer 3.5 periods overdue moved on to 6500000 (want 10500000: four periods on),FAIL: TryWaitAny reported the long-overdue timer holder again(python -I -B tests/test_multiwait_wake.py --source /home/daze/GitHub/Longshot-main-8aa5ab87/host/nn_os_sync.c). The same file passes at10bea861(targeted: ok,all: ok,PASS, exit 0), including the two-thread case. No assertion was removed: the last commit istests/test_multiwait_wake.py+12/−5.tests/that reads changed source is updated, not weakened.tests/test_multiwait_wake.pygains the periodic-timer and concurrent-waiter cases; the allocation-failure and self-move cases moved tofix/os-multiwait-holder-allocwith their fix, and no timer assertion was removed.nx2\build.py --standalonewithRX_VK_ONLY=1compiled 268 renderer objects of10bea861and linkedlongshot_vk.dll(compiled in 149 s, 0 failed, link 1 s) from a checkout whosegit rev-parse HEADis10bea861c685…:C:\Users\daze\longshot-2141\work\sa\build\longshot_vk.dll, 17,704,960 bytes, sha256aabd61c392275b57e6b2074dc2bbd3c753a5fc44f79fd0a3df882614bac39a9d, PE32+IMAGE_FILE_MACHINE_AMD64/IMAGE_SUBSYSTEM_WINDOWS_GUI, exportsmkwvk_init,mkwvk_close_asked,mkwvk_crash_close,mkwvk_crash_page, and the DLL carries10bea861 (source 3f45af4d). The changed file compiles too:host/nn_os_sync.c→ 136,205-byte COFF objecthost_nn_os_sync.obj(machine0x8664, sha2568cc7d3a5…). Linux: the pack overa2dc5385compiledhost/nn_os_sync.cand linked (37 s, earlier tree). Run as well at this head:longshot.exewith the whole pack — built over the game-derivedwork/sa/genon that box — started and played (KokiriForest_Childwindowed, 1,888 frames in play over 64.5 s, 30.3 fps at the end, clean quit; Tested).Assisted-by:/Co-Authored-By:trailers. All five commits carry one — assisted by DeepSeek V4.1 Flash throughout; the earlier commits gained the trailer in this rewrite, so it states the author's mapping rather than a per-commit log:022f2f576(was601a1ecbd)Assisted-by: DeepSeek V4.1 Flash 1017 (opencode-go)4159dc5f7(wasd08b30823)Assisted-by: DeepSeek V4.1 Flash 1017 (opencode-go)39555b33c(was31ff8d8a4)Assisted-by: DeepSeek V4.1 Flash 1017 (opencode-go)e93cc8eaa(wasbdabdbff2)Assisted-by: opencode (DeepSeek V4.1 Flash)66e327e62(was7da472869)Assisted-by: opencode (DeepSeek V4.1 Flash)Message-only:
git diff --stat 10bea861..7da472869andgit diff 10bea861..7da472869are both empty and the tree is the same object, so the tests, suite and windowed run quoted above at10bea861describe this head's tree.Ready to merge
10bea861c685:longshot.exe, 566,189,568 bytes, sha256DFF74F4061100FBF4FFBD6317E71D370F7CB66DB9345F2A0BCE26D292305AC21— a whole-pack start, not the DLL-only build — onNVIDIA GeForce GTX 1650,vk: driver: NVIDIA 610.62,KokiriForest_Childat the first and last play sample, 30.3 fps at the end, 1,888 frames in play over 64.5 s,visible=Trueonhandle=1311358with novk: no window(C:\Users\daze\runs\win1\log.txt,C:\Users\daze\smoke.log,C:\Users\daze\runs\shots\bridge.png); the in-game item ran at this head too (windowed at10bea861).BigBeansmember.main, measured again or a comment says why the numbers still hold. Every build and test job on this head is stillBlocked by required conditions; the description check is the only one that has passed.Tested in game: Kokiri Forest (child) under a pack over
8aa74983: 20 s after warm-up, 93.1 fps median 10.66 ms, 0 cold frames; game boots and plays. Arch Linux/Hyprland, RTX 4070 Ti, NVIDIA 620.70.06.Checklist: ticked the 'tests read changed source' box (test_multiwait_wake.py extended, not weakened); left the Windows build box unticked and named in Still to test.
Checklist: the Windows build/start stays named in Still to test; the duplicate 'When it applies' box is removed, as the checker asks for a box it cannot tick.
a3dae742abc459701137Rebased onto
1101b612. The commits since the run (input, renderer, tests) do not touch host/nn_os_sync.c, so the in-game run still holds; head isc4597011.c4597011375b9642d7adRebased onto
344deb6c(head5b9642d7). Commits since the run touch input/renderer/tests, not host/nn_os_sync.c; the run still holds.Note for whoever is sequencing this: siantm's WIP #2090 (
perf/mutex-guest-id) edits the sametests/test_multiwait_wake.pyallowlist —safe_external, ~line 241 on main — that this PR rewrites (~233–265), so the two touch the same hunk. Whichever lands second resolves that hunk.No action needed from reviewers today; this is just so it isn't a surprise at merge time.
@Beanstalk Windows: build and start this branch, then verify
WaitAnyon a periodic timer holder still behaves — the holder should come back once per period, not on every call, and the guest's wait-any loop must not spin. The fixture here is Linux-friendly and the change is in shared host code (host/nn_os_sync.c), so the Windows build and start are what's left.Ready otherwise.
@dazemc only members of
BigBeanscan start the farm.One of them can approve this request by reacting 👍 to it or to this comment.This request was for5b9642d, and the PR has changed since (805361a), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.fix(os): consume a timer holder's period in WaitAny, and refuse a link that cannot allocateto WIP: fix(os): consume a timer holder's period in WaitAny, and refuse a link that cannot allocateBack to WIP for one box: this head's merge base is
344deb6c, andmainhas since moved toa2dc5385with #2171 (9e10f6f7) fixing the game-free checks (~199 test files). The suite numbers here were measured against the oldmain(811/109/18 there, now 911/22/18), so 'mise run test' is unticked until a rebase ontoa2dc5385and a re-run oftests/run_all.py --strict.The in-game smoke stands: I checked its record (
a3dae742, 1862 frames, 93.1 fps, 0 cold frames) andgit diffofhost/nn_os_sync.c's changed lines is identical to the head's.The Ready to merge boxes stay unticked and now say why beside them: Windows is with the Test Farm, waiting for a BigBean's approval; no review yet; CI's build/test jobs are still pending.
5b9642d7ad805361a2d7Rebased onto
a2dc5385: head is now805361a2. The rebase was clean — both branch commits replayed with no conflicts.Full game-free suite, run in the same shape as a clean
a2dc5385baseline (tests/run_all.py --strict --jobs 3,systemd-run --user --scope -p MemoryMax=8G -p MemorySwapMax=0, the pinned headers):a2dc5385: 911 passed / 23 failed / 18 skipped in 635 s805361a2: 911 / 23 / 18 in 629 sFailing names identical, compared name by name (23). The one name new on
a2dc5385since9e10f6f7istests/test_sim_turf_pools.py: #2174 changed the simulated-turf floor while that old check still asserts a zero floor, so it is stale onmainand red identically here. This branch'stest_multiwait_wakeand the 13 checks that cuthost/nn_os_sync.cpass.In-game evidence (Jev: 0.71, likely valid): the smoked
a3dae742record matches the branch, the changed lines inhost/nn_os_sync.care identical to this head, and no commit in344deb6c..a2dc5385touches that file. No new in-game run was made.WIP: fix(os): consume a timer holder's period in WaitAny, and refuse a link that cannot allocateto fix(os): consume a timer holder's period in WaitAny, and refuse a link that cannot allocate@Beanstalk Windows: build and start this branch, then verify
WaitAnyon a periodic timer holder still behaves — the holder should come back once per period, not on every call, and the guest's wait-any loop must not spin. The fixture here is Linux-friendly and the change is in shared host code (host/nn_os_sync.c), so the Windows build and start are what's left.Head:
805361a2(rebased ontoa2dc5385).@dazemc only members of
BigBeanscan start the farm.One of them can approve this request by reacting 👍 to it or to this comment.This request was for805361a, and the PR has changed since (8cc083e), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.Testing now names the run commit and what separates it from the head:
a3dae742and805361a2are the same branch diff (git diff 8aa74983 a3dae742andgit diff a2dc5385 805361a2produce the same diff) andhost/nn_os_sync.cis byte-identical, so the in-game run covers this change's game code. No code change; stays ready.The status hint is right: this changes
host/nn_os_sync.c, which is host code, so the template's "Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths" belongs under When it applies — keep it unticked with the Windows Still-to-test item, rather than deleting it. Everything else in Ready for review verifies at805361a2(thea3dae742Testing run is the pre-rebase head; the body names it and the branch diff/file are identical; the suite's 23 failures are the same names onmain, withtest_sim_turf_poolsthe new #2174 stale check; Windows is honestly still to test).Host-build row added and ticked with real evidence: Windows —
host/nn_os_sync.cat805361a2as an x86-64 COFF object, llvm-mingw 20261104's clang 23.1.5, 490 symbols (runs/pr2141-win/nn_os_sync.obj), a compile only, not the full Windows link; Linux — the packLongshot-pr2141overa2dc5385at805361a2compileshost/nn_os_sync.cand links (37 s, 618088312 bytes). Both are named in Testing as well. No code change; stays ready.dazemc referenced this pull request2026-11-22 11:08:27 +00:00
Head
805361a2is still ready and waits only on fork CI: itspull_requestjobs are "Blocked by required conditions" and the PR has noci: approvedlabel. No earlier fork-CI ask names this head.@HumanBean: please approve this head's fork CI runs (the Actions jobs, and the
ci: approvedlabel for the fork project) and review #2141 — WaitAny consuming a timer holder's period and refusing a link that cannot allocate.Evidence is in the thread: the suite at
805361a2(911/23/18, the baseline's names), the in-game recorda3dae742on the same branch diff, and the COFF host build at805361a2.fix(os): consume a timer holder's period in WaitAny, and refuse a link that cannot allocateto WIP: fix(os): consume a timer holder's period in WaitAny, and refuse a link that cannot allocate@review
Recommendation: Request changes. The timer readiness check and consumption are not synchronized, so concurrent waits can report the same expiry twice and access the deadline with a data race. The pull request also combines two unrelated fixes despite the repository’s one-topic rule.
Periodic timer holders advance after WaitAny selects them, and holder-array allocation failures no longer immediately dereference a null pointer. The change adds a shared timer-consumption path, but its readiness check remains separate from the lock that protects consumption.
Blocking (2): must change before merging.
host/nn_os_sync.c:1519: The timer is checked without its lock and consumed only afterward under that lock. (more on the line) Do: Check readiness and advance the periodic deadline together under t->lk, and synchronize the scan’s deadline read with timer writers. Add a concurrent wait regression test.host/nn_os_sync.c:1478: The holder-array allocation and self-move fixes are independent of periodic timer consumption, contrary to the repository’s one-topic rule. (more on the line) Do: Split the holder-array fixes into a separate pull request, retaining the timer fix and its relevant test here.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
@fixcan do L1 and L2.Checks: Still running: 10 checks.
More: does it help, other systems, switches, what was read
Does it help: Yes for the tested sequential case: the author reports that the game-free fixture fails on the base and passes on this head. The in-game smoke does not exercise a known periodic timer holder; its single-run FPS comparison does not establish a performance gain.
Other systems: The timer code is shared by Windows and Linux and by single-timer and multi-wait paths. Linux fixture and game smoke results are reported; a Windows build and start remain outstanding. The fixture uses stub locks and does not cover concurrent timer waits.
Switches: None added, changed, or removed.
Reviewed:
805361a2d7againsta2dc538590: Read the repository rules, pull request template, commits, both changed-file diffs, the changed test and relevant timer, holder, allocation and locking paths in host/nn_os_sync.c. Skimmed the remainder of the host file and standards; docs/review-checklist.md and the adjacent Tooling checkout were absent. No generated files or translations changed.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no build, test, or project script was run. CI is still pending, and the PR remains WIP and behind current main.
Overlaps and merge order: #2090 also edits the test’s allowlist hunk; whichever pull request lands second must resolve the overlap.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -1457,3 +1477,2 @@if (mw->nlinks == mw->caplinks) {mw->caplinks = mw->caplinks ? mw->caplinks * 2 : 8;mw->links = (Obj **)realloc(mw->links, mw->caplinks * sizeof *mw->links);const int cap = mw->caplinks ? mw->caplinks * 2 : 8;L2 (blocking): The holder-array allocation and self-move fixes are independent of periodic timer consumption, contrary to the repository’s one-topic rule.
When: The allocation failure and self-move defects occur with event holders and no timer; neither change is needed to make a periodic timer advance.
Do: Split the holder-array fixes into a separate pull request, retaining the timer fix and its relevant test here.
@ -1495,1 +1517,3 @@else if (mw->links[i]->sem_max == H_TIMER) {if (holder_ready(mw->links[i])) {found = mw->links[i]->key, found_watch = holder_watch(mw->links[i]);if (mw->links[i]->sem_max == H_TIMER) timer_consumed(obj_nockpt(mw->links[i]->event, K_TIMER));L1 (blocking): The timer is checked without its lock and consumed only afterward under that lock. The new write to due_ns also races with the unlocked reads in holder_ready and the deadline calculation.
When: A WaitAny scan sees a periodic timer due, then a concurrent TryWaitTimerEvent consumes that expiry before timer_consumed acquires t->lk. WaitAny still returns the holder even though that expiry was already consumed; the plain concurrent deadline accesses also constitute a data race.
Do: Check readiness and advance the periodic deadline together under t->lk, and synchronize the scan’s deadline read with timer writers. Add a concurrent wait regression test.
@fix
805361a2d78cc083e717Recommendation: Request changes. The independent holder-array fixes still sit alongside the periodic-timer fix, contrary to the repository’s one-topic rule. The final synchronization change also awaits testing on Linux and Windows.
What
@fixchangedI changed this pull request: the new head is
8cc083e717. I rebased it ontomain(6acae6aa87). I edited its description to match the change.Changed
Left for the author
Nothing was built or run: the checks run again on the new head.
Periodic timers selected by multi-wait advance to their next period, avoiding a spinning guest loop. The pull request also refuses failed holder-array allocations and makes self-moves a no-op, at the cost of combining independent fixes.
Blocking (1): must change before merging.
host/nn_os_sync.c:1478: The holder-array allocation and self-move fixes are independent of periodic timer consumption, contrary to the repository’s one-topic rule. When: The allocation failure and self-move defects occur with event holders and no timer; neither change is needed to make a periodic timer advance. Do: Split the holder-array fixes into a separate pull request, retaining the timer fix and its relevant test here. (for the author:@fixcouldn't: LinkMultiWaitHolder and MoveAllMultiWaitHolder still contain the independent allocation and self-move fixes alongside periodic timer consumption; they need to be split into a separate pull request.)Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
Checks: they run again on this head; a failure shows on the pull request.
Also noticed (4; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Unproven for the final synchronization change: the reported game-free test and game smoke predate it. The earlier Linux run reported 93.1 fps versus 90.3 fps on the base in one run per side, which is not evidence of a performance gain.
Other systems: The timer and multi-wait code is shared by Windows and Linux. The final locking change has no reported host builds or game smoke; the Windows build and start remain outstanding. Saves, audio, input and GPU-specific paths are not directly changed by the timer fix.
Switches: None added, changed or removed by the reviewed fix.
Reviewed:
8cc083e717against6acae6aa87: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the fix diff, the multi-wait and timer code and its test fixture; inspected the surrounding lock and timer-start paths. The stated base-to-head diff contains many additional files, which were not read in full. Tooling’s AGENTS.md and docs/review-checklist.md were not present.; nothing run (a code review).Checked and fine:
Testing: No commands that build or run project code were executed. The supplied report says tests, host builds and the game smoke for the final synchronization change are pending; CI has not run on this head.
Overlaps and merge order: The author reports that #2090 edits the same test allowlist hunk; whichever pull request lands second will need to resolve it.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
8cc083e71712ed3a32ae@HumanBean — fork CI for head
12ed3a32, please.What it is:
WaitAnyconsumes a periodic timer holder's period instead of reporting it ready forever, and a link or self-move that cannot allocate is refused instead of writing NULL.Asked: approve this head's fork CI runs, and a review when you have the time.
Evidence: the fail-on-main output in Testing (
SIGSEGVatmw->links[mw->nlinks++]) againsttests/test_multiwait_wake.py, which passes here; the in-game smoke is ata3dae742.Still WIP — suites land one at a time, so this is not a merge request.
dazemc referenced this pull request2026-11-24 06:41:08 +00:00
Evidence at head
12ed3a32: the changed game-free test, run through the queue at this head.python -I scripts/dev.py queue run pr2141-mwtest --mode build --desc "PR 2141: WaitAny timer consumption and holder fixes at 12ed3a32" -- python -I -B tests/run_all.py --strict test_multiwait_wakepr2141-mwtest, ticket PID 759064; log/home/daze/.local/share/longshot-dev/suite-evidence/pr2141-mwtest-12ed3a32.log, sha256846447d6d8e55b194551191f9399205936808570aa5e83444bc9692031b4e5e4, read 2026-11-24 00:15.That test is the concurrent-wait regression the review asked for with L1 (
tests/test_multiwait_wake.py, theCONCURRENTharness with two threads on real host locks), run at this head rather than reported.Unchanged by this comment: L2 (the holder-array allocation and self-move fixes still sit in this PR beside the timer fix and need splitting into their own) and L3 (the Windows build and start). Both need a new push, which re-runs the checks, or the Test Farm — not a comment. Nothing was pushed here.
@Beanstalk Windows: build and start this branch at head
12ed3a32— a link and a start of the whole pack, not a single-object compile. The review on this PR already said that compilinghost/nn_os_sync.calone does not show the Windows build links and starts with the change.The earlier request was for
5b9642d/805361aand is void (the branch was force-pushed since), so this is a request for aBigBeansmember's approval, not an approval.What to look for: the periodic-timer path a
WaitAnyscan takes (host/nn_os_sync.c:1519area). With a periodicTimerEventlinked into a multi-wait, the holder should come back once per period rather than on every call, and the guest's wait-any loop must not spin. New at this head: readiness, consumption and the next-deadline read all happen under the timer lock, andtests/test_multiwait_wake.pycarries a two-thread regression that passes on Linux at this head (queue rowpr2141-mwtest, 1 passed, exit 0). The fixture is Linux-friendly; the Windows build and start are what is left.@dazemc only members of
BigBeanscan start the farm.One of them can approve this request by reacting 👍 to it or to this comment.This request was for12ed3a3, and the PR has changed since (91add52), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.Split per the review: the multi-wait holder-array allocation and self-move fixes are now on branch
fix/os-multiwait-holder-alloc, offmain8aa5ab87, head0132411. That branch is not a pull request yet becausehost/nn_os_sync.cis game-run code and it has not been in the game. A new commit on this branch,91add52, removes those fixes from here.The description now covers only the timer fix at
91add52(host/nn_os_sync.c+29/−11,tests/test_multiwait_wake.py+111/−6, four commits). The previous description's allocation paragraph, itsLinkMultiWaitHolder/MoveAllMultiWaitHolderbullets, its+89/−14figures and its holder fail-on-mainSIGSEGVall described code that is no longer in this pull request.Timer evidence at this head:
test_multiwait_wakethrough the PC's job queue, queue roww3-a-final, 1 check, 0 skipped, 1 passed, 0 failed, exit 0. Againstmainthe committed test cannot compile, because it extracts the newtimer_consumed_locked; with only the harness adjusted to compile there, the timer assertions fail for the bug's reason (due_nsstays 9999999 and the holder is reported again). No in-game run exists at this head, so the game and Windows items remain unticked.pr updatehas no title option, so the title still names the removed holder fix.@Beanstalk Windows: build and start this branch at head
91add52— a link and a start of the whole pack, not a single-object compile. The review on this PR already said that compilinghost/nn_os_sync.calone does not show the Windows build links and starts with the change.The earlier requests (for
5b9642d/805361a, and again at12ed3a32) are void: the branch moved since, because the holder-array fixes were split out of this pull request intofix/os-multiwait-holder-alloc. This is a request for aBigBeansmember's approval, not an approval.What to look for: the periodic-timer path a
WaitAnyscan takes (host/nn_os_sync.c:1519area). With a periodicTimerEventlinked into a multi-wait, the holder should come back once per period rather than on every call, and the guest's wait-any loop must not spin. Readiness, consumption and the next-deadline read all happen under the timer lock, andtests/test_multiwait_wake.pycarries a two-thread regression that passes on Linux at this head (queue roww3-a-final, 1 passed, exit 0). The fixture is Linux-friendly; the Windows build and start are what is left.@dazemc only members of
BigBeanscan start the farm.One of them can approve this request by reacting 👍 to it or to this comment.This request was for91add52, and the PR has changed since (10bea86), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.WIP: fix(os): consume a timer holder's period in WaitAny, and refuse a link that cannot allocateto WIP: fix(os): consume a timer holder's period in WaitAnyWindows testing dropped by the human 2026-11-24: the Host-code-builds-on-Windows box stays unticked, so this PR stays WIP. No link and no Test Farm request are planned.
10bea861c67da4728698WIP: fix(os): consume a timer holder's period in WaitAnyto fix(os): consume a timer holder's period in WaitAnyReview 2448's two items, against head
7da4728698(tree4d9cc08e, the same tree as10bea861, which the runs below name):git diff 8aa5ab876d7c..7da4728698 -- host/nn_os_sync.cis 29+/11− and timer-only —timer_consumed_lockedat:1156,holder_readyat:1435,wait_any, and the two single-timer waits; it has noLinkMultiWaitHolder/MoveAllMultiWaitHolder/reallochunk (0 matches), and the holder-array refusal and self-move cases are not in the test at this head (the fourfail_next_reallocuses that remain are the pre-existing watched-address case, as onmain). They live onfix/os-multiwait-holder-alloc=01324116(onforge-forktoo;host/nn_os_sync.c24+/6−,tests/test_multiwait_wake.py30+/3−). That branch has no pull request yet becausehost/is game-run code and has not been in the game; that is the one item still owed, outside this PR.DESKTOP-CDD8SQ2at10bea861: the whole pack built withnx2\build.py --standalone --jobs 4→compiled in 1326s, 0 failed,linked …\longshot.exe: 539 MB (4s),EXITCODE=0; started windowed fromkokiri-start,version: 10bea861 (source 3f45af4d),KokiriForest_Childat frame 2776 and again at 4664, 1,888 frames over 64.5 s, 30.3 fps at the end,window[in-play|mid-play|end-play] … visible=True, novk: no window, clean quit — the body's "Tested on Windows, the whole pack"; those logs stay on that box. The game-free fixture was not run on Windows: the review asked for that only if a suitable fixture is available, and the harness is Linux-shaped (-pthread).No code was changed for this comment.
Correction to the L2 line above: that split branch has been a pull request since 2026-11-24T08:50:03Z — #2445,
fix(os): refuse a multi-wait link or move whose holder array cannot grow, head01324116f6ce26be10bd196fa7958e85744bc33donfix/os-multiwait-holder-alloc,draft=false,mergeable=true(read from the API after this comment was posted; the 08:38Z comment above predates it by 12 minutes). So L2 is fully addressed: the holder-array fixes and theirfail_next_realloccases are in #2445 with their own suite, measurements and runs, and #2141 at7da4728698is the timer fix alone.7da472869866e327e628Description: Testing names the machine instead of a distribution; no other change.
66e327e628c11cd13568Rebased
66e327e62toc11cd1356on main8f7300756; patch-id unchanged and intersection empty. Existing suite, Linux and Windows evidence stands; split PR reference corrected.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.