.claude/skills/review-race-conditions/SKILL.md
Audit for race conditions in timers, hotkeys, callbacks, and shared state
npx skillsauth add cwilliams5/Alt-Tabby review-race-conditionsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Enter planning mode. Systematically audit the codebase for race conditions. Use maximum parallelism — spawn explore agents for independent areas.
AHK v2 is single-threaded but not atomic — timers, hotkeys, and callbacks CAN interrupt each other mid-execution. Critical "On" prevents interruption for the current thread. This is the only synchronization primitive available. See .claude/rules/ahk-patterns.md (Race Conditions section) and .claude/rules/keyboard-hooks.md for established patterns.
Globals modified inside timer callbacks, hotkey handlers, or event callbacks without Critical "On":
gRev += 1if (!map.Has(k)) { map[k] := v }gGUI_State or similar)Critical "On" present but:
Critical "Off" missing on an early return or continue pathkeyboard-hooks.md "Do NOT Release Critical Before Rendering")A SetTimer callback modifying state that a hotkey handler also reads/writes. Both can fire in the same thread context. Use query_timers.ps1 to inventory all timers and their callbacks, then cross-reference with hotkey handlers.
Named pipe reads processed via timer while the state machine is mid-transition. Check that IPC handlers either defer during transitions or are properly guarded.
Producers (WinEventHook, Komorebi subscription) firing callbacks that modify gGUI_LiveItems, window store data, or MRU order while the GUI is painting or the state machine is processing input.
These have been deliberately designed and tested — flagging them wastes time:
Critical "On" held through the entire GUI_OnInterceptorEvent handler including rendering (~16ms). This is intentional — releasing early causes corruption.SendMode("Event") instead of SendInput — prevents hook uninstall during sends.gGUI_EventBuffer — events buffered while gGUI_Pending.phase != "".ALT_DN + ALT_UP without TAB).FR_Record() — pre-allocated ring buffer, writes are inherently safe._GUI_LogError() — always-on by design.Split by concurrency boundary, not just file location:
gui_input.ahk, gui_interceptor.ahk: all INT_* functionsquery_timers.ps1 to find all SetTimer targets, then read each callbackquery_messages.ps1 to map WM_ handlers and senders (interrupt sources)winevent_hook.ahk: _WEH_* callback functionskomorebi_sub.ahk, komorebi_lite.ahk: subscription event handlersipc_pipe.ahk, pump files: pipe read/write pathsquery_state.ps1 to extract specific branches from GUI_OnInterceptorEvent without loading the full functionquery_function_visibility.ps1 to map which interrupt sources can reach vulnerable code (e.g., "is this function called from both timer callbacks and hotkey handlers?")query_mutations.ps1 <globalName> to see per-function mutation sites with assignment operators and assigned values — reveals unguarded writes without reading full filesAfter explore agents report back, validate every finding yourself. Race conditions are easy to hypothesize and hard to confirm. Many "races" identified by exploration are actually guarded by Critical sections or by AHK's threading model (only one pseudo-thread runs at a time; interruption only happens at specific yield points).
For each candidate:
file.ahk lines X–Y" with actual code quoted. Vague line references are not sufficient.Group by severity (data corruption > logic error > cosmetic):
| File | Lines | Race Description | Interrupt Source | Severity | Fix |
|------|-------|-----------------|-----------------|----------|-----|
| file.ahk | 42–58 | gFoo read-then-write without Critical | Timer _HeartbeatTick | Data corruption | Wrap in Critical "On" / Critical "Off" |
For each fix, note:
Ignore any existing plans — create a fresh one.
tools
Create a new git worktree and switch the session into it
tools
Spawn agent to trace code flow via query tools — answer only, no context cost
tools
Commit, push, and create a PR for the current branch
tools
Retire a shader by moving its files to legacy/shaders_retired