Repository navigation
Make the keybindings menu's Lua bind scan safe against load-time config reads - #7564
Conversation
…ig reads omarchy-menu-keybindings learns about Lua-only binds by running the user's hyprland.lua under a stub `hl` whose every lookup answers a truthy noop table. That stub breaks as soon as a config reads compositor state at load time, which real configs do: - `for _, m in ipairs(hl.get_monitors())` never terminates, because noop[1], noop[2], ... are all non-nil. The menu exits, the `lua` child keeps spinning at 100% CPU under systemd --user until the next reboot. One such orphan ran for 27 hours on a laptop after a single SUPER+K. - `monitor.scale <= 0` (default/hypr/qconsole.lua:64) raises "attempt to compare table with number", which aborts the pcall'd scan, so every bind declared after that file is silently missing from the menu. The stub now answers nil for numeric indexes (so ipairs/`#` terminate), reports length 0, and degrades comparisons, arithmetic, and concatenation to harmless values instead of raising. The scan is also wrapped in `timeout 10` so a config the stub still cannot satisfy can never outlive the menu. Adds a shell test that scans a fixture config doing exactly those load-time reads; without the fix it hangs for the full timeout.
There was a problem hiding this comment.
Pull request overview
Hardens Lua keybinding discovery against hangs and load-time type errors.
Changes:
- Time-boxes Lua scanning to 10 seconds.
- Adds safer proxy metamethods.
- Adds regression coverage for loops, comparisons, and arithmetic.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
bin/omarchy-menu-keybindings |
Hardens and time-boxes Lua bind scanning. |
test/shell.d/menu-keybindings-lua-scan-test.sh |
Tests load-time reads and timeout configuration. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Ran into this exact issue after upgrading to Quattro 4.0 Tested this fix locally; it resolves the infinite loop cleanly and makes the keybindings scan instantaneous. Hope to see this merged soon! |
|
Confirming on omarchy 4.0.3-1 (Hyprland 0.56.2, Lua 5.5.1): a personal module that |
|
Confirming another real-world manifestation of this on I have o.bind("SUPER + SHIFT + F", "File manager", { launch = 'flea --gui' })Pressing Root cause is this PR's diagnosis exactly: Because the crash happens before ...instead of the user's actual |
The cache key hashes only the version, the active keymap and `hyprctl binds`, so a records file written by the scan that aborted in qconsole.lua keeps being served after this fix lands, and the menu goes on dispatching the stale default in place of the user's override until their binds happen to change. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-Authored-By: Codex Medium <[email protected]>
|
Reviewed and reproduced on a worker built from the Omarchy ISO, with the stock config plus a user
I pushed two commits to the branch. The first merges Six other open pull requests fix parts of the same bug: #8876, #12712, #12916, #13276, #12155 and #11733. This one fixes both the endless loop and the qconsole abort, and it has a test that fails without the fix. #12712, #12916 and #12155 do not get past qconsole. #8876 gets past it by returning nil monitors, which still breaks a config that reads a field off one. #13276 has no test. #11733 is a redesign that would need its own review. Second opinion from Codex Medium, which agreed with that choice and with the cache bump (its independence from this review is not guaranteed). It also raised two design points that I have not changed, because they are a call about how far the stub should pretend:
This links #7025, #12052 and #12124, which it fixes. The next step is the maintainer's. |
|
Merged this with #12557 locally and measured it, because the two edit the same scan and are textually compatible while being behaviourally incompatible. #12557 adds an In the other direction, this PR rewrites the heredoc to On the merge: Separately, as the author of one of the seven PRs touching this scan: this is the only one of them whose test fails on |
Pairing and sorting happen before a record reaches the cache, and the cache key hashes only the version, the active keymap and `hyprctl binds`. So on a machine whose keymap and binds have not moved, the menu goes on serving the rows the previous version laid out and none of the sorting above reaches the user until something unrelated happens to change their binds. The version skips v15 on purpose: omacom#7564 and omacom#8229 are both open and both take it, and a merge that agrees on the same literal from both sides resolves silently into no bump at all.
Otherwise a LUA_INIT in the tester's environment runs ahead of the fixture, and a LUA_PATH changes what a config's require finds, either of which can fail a test the menu itself would pass. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
I pushed three commits to this branch (now b1ac64e). They bring in the best parts of two later fixes for the same hang, with their authors credited as co-authors:
What ran, on a worker built from the Omarchy ISO: the scan test and the window-walk test both fail on Codex Medium reviewed the three commits over two rounds. It found no defects in the code. In the first round it pointed out wording in the commits that claimed more than was shown: a general speed claim, and a test described as proving the whole scan finished. It also raised the coroutine case. All of that is corrected in what I pushed, and its second round was clean. It can read this session's notes, so where it agrees with me, that agreement isn't guaranteed to be independent. This is labelled |
The scan tests failed if a scan took five seconds or more, which a slow or loaded machine can hit with nothing wrong. A scan that never ends is already caught without a clock: run directly, the test's timeout kills it and fails on the exit status; run through the menu, the menu's own timeout stops it before the Terminal bind the test looks for. The outer timeouts are now long enough that only a hang reaches them. The approach is omacom#15704's. Co-Authored-By: Dylan Kenney <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
I pushed one commit to this branch (now 3deb771). It brings in the test approach from #15704, with @dmkenney credited as co-author: the scan tests no longer use a wall-clock budget. Before this, What ran, on a worker built from the Omarchy ISO, against current
Codex Medium reviewed the new commit and found no defects. It confirmed that both regression cases still fail when what they guard is broken. It noted that the only thing the old checks proved and these do not is finishing within 5 s on the test machine, which is the budget this change removes on purpose. It can read this session's notes, so where it agrees with me, that agreement isn't guaranteed to be independent. This is |
|
Another real-world hit, still present in the packaged 4.0.5-1, and not from a plugin this time: my own for id in pairs(floating) do
float_windows(hl.get_workspace_windows(tostring(id))) -- ipairs() inside
endUnder the scan's stub, The numeric-index → |
Answering nil for every numeric index ended `ipairs(hl.get_monitors())`, but it also made `hl.get_monitors()[1].name` raise, which the scan read before this change. The scan then aborts and every bind declared after that line is lost. Make `ipairs` see the stub as empty instead, so loops still end without running their bodies against stand-in values, and indexing reads a stub again. Co-Authored-By: Codex Medium <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Re-reviewed against current Still needed on Fixed: indexing a stub collection aborted the scan. Codex Medium found that answering nil for every numeric index, which is how What ran on 63f99b2 merged with Still open, for the maintainer: comparisons against the stub are now always false, so a config that picks a bind's command by comparing compositor state, such as Second opinion: Codex Medium reviewed 3deb771 and found the two issues above. It has not reviewed 63f99b2, because the reviewer's daily budget ran out. So that commit has been checked only by Claude Opus 5.5 and the worker runs above. Waiting on: the maintainer. |
quattro's omacom#7564 added a bind-scan test at the same spot in keybindings-menu-test.sh. Both are kept, its first: it checks the Terminal bind the stub just before it registers, so it has to run before the split toggle's stub replaces that. Co-Authored-By: Claude Opus 5.5 <[email protected]>
) #7564 made the stub answer every index so that `hl.get_monitors()[1].name` keeps reading, but that also means `while monitors[i] do i = i + 1 end` never finds a nil. The instruction limit stops it, and every bind declared after the loop is lost. Answer indexes 1 and 0 with the stub and every other number with nil: the first element and `list[#list]` (0, since the stub's length is 0) still read, a walk by index ends after a step, and `ipairs` still sees the collection as empty. The cache version moves to v19 so scans truncated by such a loop are redone. Co-authored-by: omarchybot <[email protected]> Co-authored-by: Codex Medium <[email protected]> Co-authored-by: muse-spark-1.3-contributor <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
quattro moved the cache key to v19 with the Lua bind scan hardening (omacom#7564, omacom#16276), so this branch's v18 no longer invalidates a cache quattro wrote; v20 does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem
omarchy-menu-keybindingslearns about Lua-only binds bydofile-ing the user'shyprland.luaunder a stubhlwhose every lookup returns a truthynooptable. Real configs read compositor state at load time, and the stub cannot survive that:Runaway
luaat 100 % CPU.for _, m in ipairs(hl.get_monitors())never terminates, becausenoop[1],noop[2], … are all non-nil. The menu exits, but theluachild keeps spinning undersystemd --useruntil reboot. Found one on my laptop that had run for 27 hours after a singleSUPER+K(PIDsomarchy-menu-keybindings→lua, 60 % of a core,dofile(hyprland.lua)never returned).Silently dropped binds. On current quattro,
default/hypr/qconsole.lua:64doesmonitor.scale <= 0, which under the stub raises attempt to compare table with number. The scan ispcall'd, so it just stops there — every Lua bind declared after thatrequireis missing from the menu (DEBUG=1showslua bind scan failed: …qconsole.lua:64).Fix
noop.__indexanswersnilfor numeric keys (soipairs/numeric loops end),__lenis 0, and__lt/__le, arithmetic,__concat,__tostringdegrade to harmless values instead of raising. String-key lookups behave as before.timeout 10so a config the stub still cannot satisfy can never outlive the menu.Test
test/shell.d/menu-keybindings-lua-scan-test.shextracts the embedded scan and runs it against a fixturehyprland.luathat iterates monitors, comparesmonitor.scale, does arithmetic/concatenation on stub fields, and then declares two binds. Without the fix it hangs for the full 10 s timeout and fails; with it the scan returns in milliseconds and both binds are reported. Also verified on my own config: the scan now completes with noscan failedand lists the Lua binds that were previously lost afterqconsole.lua.Fixes #7025
Fixes #12052
Fixes #12124