Skip to content

Make the keybindings menu's Lua bind scan safe against load-time config reads - #7564

Merged
dhh merged 9 commits into
omacom:quattrofrom
tobi:fix/menu-keybindings-stub-scan
Oct 22, 2026
Merged

dhh merged 9 commits into
omacom:quattrofrom
tobi:fix/menu-keybindings-stub-scan

Conversation

@tobi

@tobi tobi commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

omarchy-menu-keybindings learns about Lua-only binds by dofile-ing the user's hyprland.lua under a stub hl whose every lookup returns a truthy noop table. Real configs read compositor state at load time, and the stub cannot survive that:

  1. Runaway lua at 100 % CPU. for _, m in ipairs(hl.get_monitors()) never terminates, because noop[1], noop[2], … are all non-nil. The menu exits, but the lua child keeps spinning under systemd --user until reboot. Found one on my laptop that had run for 27 hours after a single SUPER+K (PIDs omarchy-menu-keybindings → lua, 60 % of a core, dofile(hyprland.lua) never returned).

    local noop = setmetatable({}, { __index = function() return noop end, __call = function() return noop end })
    for _, m in ipairs(noop) do end   -- never returns
  2. Silently dropped binds. On current quattro, default/hypr/qconsole.lua:64 does monitor.scale <= 0, which under the stub raises attempt to compare table with number. The scan is pcall'd, so it just stops there — every Lua bind declared after that require is missing from the menu (DEBUG=1 shows lua bind scan failed: …qconsole.lua:64).

Fix

  • noop.__index answers nil for numeric keys (so ipairs/numeric loops end), __len is 0, and __lt/__le, arithmetic, __concat, __tostring degrade to harmless values instead of raising. String-key lookups behave as before.
  • The scan is wrapped in timeout 10 so a config the stub still cannot satisfy can never outlive the menu.

Test

test/shell.d/menu-keybindings-lua-scan-test.sh extracts the embedded scan and runs it against a fixture hyprland.lua that iterates monitors, compares monitor.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 no scan failed and lists the Lua binds that were previously lost after qconsole.lua.

Fixes #7025

Fixes #12052

Fixes #12124

…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.
Copilot AI balanced review requested due to automatic review settings August 20, 2026 01:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@agush22

agush22 commented Aug 30, 2026

Copy link
Copy Markdown

Ran into this exact issue after upgrading to Quattro 4.0
Pressing SUPER + K pegged a background lua process at 100% CPU because my monitors.lua iterates over hl.get_monitors() with ipairs.

Tested this fix locally; it resolves the infinite loop cleanly and makes the keybindings scan instantaneous. Hope to see this merged soon!

@shwig1

shwig1 commented Sep 14, 2026

Copy link
Copy Markdown

Confirming on omarchy 4.0.3-1 (Hyprland 0.56.2, Lua 5.5.1): a personal module that
iterated hl.get_windows() at require time hung the scan, and repeated Super+K presses
left eight orphaned lua processes at 100% CPU each for over six hours. The timeout in
this PR is the part that would have contained that; the stub fix removes the trigger.

@alinuxfan

Copy link
Copy Markdown

Confirming another real-world manifestation of this on 4.0.0.r2147.g2fbac0c-1 — this one doesn't just drop a bind from the menu, it makes the menu launch the wrong app.

I have flea set as my default file manager. Its installer (flea --default) correctly unbinds and rewrites SUPER+SHIFT+F in ~/.config/hypr/bindings.lua:

o.bind("SUPER + SHIFT + F", "File manager", { launch = 'flea --gui' })

Pressing SUPER+SHIFT+F directly opens flea correctly (hyprctl binds shows the live dispatcher resolving as expected). But selecting the same "File manager" row from the SUPER+K search menu opens Nautilus instead.

Root cause is this PR's diagnosis exactly: hyprland.lua loads default.hypr.omarchy (which pulls in default/hypr/qconsole.lua) before hypr.bindings (the user's own overrides). The scan crashes inside qconsole.lua — same attempt to compare number with table on a monitor.scale > 0 check, now at line 123 rather than 64, so the line's moved but the bug hasn't:

$ DEBUG=1 omarchy-menu-keybindings
[DEBUG] lua bind scan failed: /usr/share/omarchy/default/hypr/qconsole.lua:123: attempt to compare number with table

Because the crash happens before hypr.bindings is ever reached, the scan's cache keeps the stale default from default/hypr/bindings/applications.lua:

$ lua <extracted scan snippet>
65      File manager    F       exec    omarchy-launch-nautilus
73      File manager (cwd)      F       exec    omarchy-launch-nautilus-cwd

...instead of the user's actual flea --gui override. So it's not just that entries silently go missing — for anyone who has overridden a default Omarchy keybind, the search menu can confidently dispatch the old action while the real key combo does the right thing. Would be good to land this fix; the noop stub degrading harmlessly under comparison (not just under ipairs/length) directly fixes this case too.

omarchybot and others added 2 commits September 28, 2026 12:37
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]>
@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review and removed verified Omarchy Triage has verified that this issue is ready for final review labels Sep 28, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed and reproduced on a worker built from the Omarchy ISO, with the stock config plus a user o.rebind("SUPER + SHIFT + F", "File manager", { launch = "flea" }) and, separately, an ipairs(hl.get_monitors()) loop:

  • On quattro the scan aborts at default/hypr/qconsole.lua:123 and the menu's File manager row dispatches omarchy-launch-nautilus; the loop hangs the menu until killed.
  • On this branch the row dispatches flea and the loop returns at once. With the stub changes reverted, both failures come back. A config stuck in while true do end now ends at the 10 s timeout and leaves no lua behind.
  • test/shell.d/menu-keybindings-lua-scan-test.sh passes 3/3 here and fails on quattro; test/shell.d/keybindings-menu-test.sh passes 16/16. ./test/cli stops at "vscode generated theme references current theme file" on this branch and on quattro alike, so that failure is not this change's, but it does mean the rest of that suite did not run.

I pushed two commits to the branch. The first merges quattro, which had moved the cache version to v14. The second bumps the version to v15. The records cache is keyed only on that version, the keymap and hyprctl binds, so without the bump anyone already holding a cache from the broken scan keeps getting the stale default after this lands. I confirmed that on the worker: a v14 cache written by quattro kept dispatching nautilus until the bump.

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:

  • A scan cut off by the timeout is cached like a finished one, so its partial records stay until the binds change. A scan that errors partway is already cached the same way.
  • Because comparisons, arithmetic and concatenation on stub values now return made-up results, a config that guards a comparison with pcall, or builds a command from a monitor field, can take a different branch or record a truncated command where the scan used to stop.

This links #7025, #12052 and #12124, which it fixes. The next step is the maintainer's.

@linyiru

linyiru commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Merged this with #12557 locally and measured it, because the two edit the same scan and are textually compatible while being behaviourally incompatible. git merge-tree reports no conflict, and the merged tree fails one test from each side.

#12557 adds an id column to the scan's output, inserted as field 3, so a row that read modmask description key kind arg reads modmask description id key kind arg. That breaks the two fixed-string assertions in menu-keybindings-lua-scan-test.sh:52-53, which pin the five-field layout:

expected: 64	Keybindings menu	K	exec	omarchy-menu keybindings
actual:   64	Keybindings menu	Keybindings menu	K	exec	omarchy-menu keybindings

In the other direction, this PR rewrites the heredoc to timeout 10 lua <<'LUA', and #12557's hyprland-bind-id-test.sh extracts the scan by matching that line exactly, so on the merge the extraction returns nothing and the five assertions that read scan output go with it.

On the merge: menu-keybindings-lua-scan-test.sh 1 ok and 1 not ok, hyprland-bind-id-test.sh 4 ok and 1 not ok, keybindings-menu-test.sh unaffected at 16/16. Both breakages are a one-line fix in whichever PR lands second, and I will make them on my side if this one lands first. Writing it down because the repo has no CI, so nothing would surface it before a 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 quattro and passes on the branch, which is the property that makes a fix here checkable later. The timeout matters for a reason the other candidates cannot cover either, since a stub that degrades comparisons can still be sent into a loop by a config that iterates on a condition.

linyiru added a commit to linyiru/omarchy that referenced this pull request Sep 30, 2026
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]>
@omarchybot

Copy link
Copy Markdown
Collaborator

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:

  • From Fix Super+K hang when config iterates hl.get_workspaces() #14128 (@AnPod): the scan now runs under an instruction-count hook, so a config that loops in a way the stub cannot end stops after 50M instructions instead of holding the menu for the full 10 s. On a worker, a while true do end config returns in 0.29 s instead of 10.0 s, and the bind declared before the loop is still reported. The stock config needs about 69k instructions, and it scans to the same 234 binds with or without the hook. timeout 10 stays as the backstop for what the hook cannot reach: a loop inside a coroutine, or a config that catches the error and keeps going. A scan the hook stops is cached like one that errors part way. That is the one part of Fix Super+K hang when config iterates hl.get_workspaces() #14128 I left out, for the reason in my last comment: the same config would just stop again on the next SUPER+K.
  • From End the bind scan's stub window list instead of looping on it #15308 (@nekomario28): an end-to-end test in keybindings-menu-test.sh. It puts an ipairs(hl.get_windows()) walk ahead of the stock config, runs the whole menu under a timeout and checks that the Lua-only Terminal bind still resolves.
  • menu-keybindings-lua-scan-test.sh now runs the scan with lua -E, as the menu does, which Greptile pointed out. Without it, a LUA_INIT or LUA_PATH in the tester's environment could fail the test. A new test there checks that the runaway config above stops early and keeps its binds.

What ran, on a worker built from the Omarchy ISO: the scan test and the window-walk test both fail on quattro (cce8b1c) and with the stub change reverted, and the runaway test fails without the hook. On this head, menu-keybindings-lua-scan-test.sh passes 4/4, keybindings-menu-test.sh 21/21, menu-keybindings-key-names-test.sh 3/3, and ./test/cli passes.

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 verified at the new head. It still waits on the maintainer, because #12712 carries ready for the same bug and only one of the two should land.

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]>
@omarchybot omarchybot added ready Good to merge and removed ready Good to merge labels Oct 18, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

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, menu-keybindings-lua-scan-test.sh failed any scan that took 5 s or more, which a slow or busy machine can hit with nothing wrong. A scan that never ends is still caught, by its exit status instead of the clock. Run directly, a hung scan is killed by the test's timeout 60 and the test fails. Run through the menu, the menu's own timeout 10 stops it before the Terminal bind that keybindings-menu-test.sh looks for. The outer timeouts went from 10 s to 60 s, so only a real hang reaches them. The code in bin/ did not change.

What ran, on a worker built from the Omarchy ISO, against current quattro (4e059ac):

  • With this pull request's tests, the scan test and the window-walk test both fail on quattro, and both fail with the bin/ change reverted.
  • With only the instruction-count hook removed, the runaway test still fails. It waits out the 60 s timeout and fails on the exit status, so the hook stays covered without a clock.
  • On this head, menu-keybindings-lua-scan-test.sh passes 4/4, keybindings-menu-test.sh 21/21 and menu-keybindings-key-names-test.sh 3/3, and ./test/cli passes. All of that holds again with the head merged with current quattro, which merges cleanly.

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 verified at the new head. It is not marked ready, because #12712 carries ready for the same bug, and only one of the two should land. On current quattro, #12712 still stops the scan at qconsole.lua:123, and this pull request does not. Choosing between them is the maintainer's call, and that is what this waits on.

@c4software

Copy link
Copy Markdown
Contributor

Another real-world hit, still present in the packaged 4.0.5-1, and not from a plugin this time: my own ~/.config/hypr/customisation.lua re-floats windows of saved floating workspaces at load time:

for id in pairs(floating) do
  float_windows(hl.get_workspace_windows(tostring(id)))  -- ipairs() inside
end

Under the scan's stub, hl.get_workspace_windows(...) returns the self-referential noop, so the ipairs never ends. Each SUPER + K left a lua child pinning a core (two of them ran for 37 min before I noticed, laptop at 12 W instead of ~7 W on battery).

The numeric-index → nil change in this PR covers it, since it applies to every getter. Locally I worked around it with for i = 1, #windows do in the config. +1 for getting this merged.

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]>
@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 22, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Re-reviewed against current quattro (7075b61), which has moved 192 commits since the last review, and pushed one fix (now 63f99b2).

Still needed on quattro. On a worker built from the Omarchy ISO, with its stock config and a user o.rebind("SUPER + SHIFT + F", "File manager", { launch = "flea" }), quattro's scan still aborts at default/hypr/qconsole.lua:123 and the menu's File manager row runs omarchy-launch-nautilus. With this branch merged onto quattro, the scan finishes and the row runs uwsm-app -- flea. quattro has also gained ipairs(hl.get_monitors()) and hl.get_workspaces() walks in default/hypr/monitor-workspaces.lua, which the qconsole abort hides today, so ending those loops matters more than when this was opened. @c4software's hl.get_workspace_windows case above is the same hang.

Fixed: indexing a stub collection aborted the scan. Codex Medium found that answering nil for every numeric index, which is how ipairs was made to end, also made local name = hl.get_monitors()[1].name raise. quattro scans that line fine, but here the scan stopped there and every bind declared after it was lost. I reproduced that on the worker. 63f99b2 makes the stub answer every index again and gives the scan an ipairs that sees a stub collection as empty, so the loops still end without running their bodies against stand-in values. A new case in menu-keybindings-lua-scan-test.sh covers it, and it fails with the bin/ change reverted.

What ran on 63f99b2 merged with quattro, on the worker: menu-keybindings-lua-scan-test.sh 5/5, keybindings-menu-test.sh 21/21, menu-keybindings-key-names-test.sh 3/3, ./test/cli 125 ok. The stock config scans to 237 rows with no failure, the flea rebind above resolves to flea, and no lua is left running.

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 if hl.get_active_monitor().scale > 1 then command = "flea" else command = "nautilus" end, records the other branch, and the menu runs that command where quattro would have dropped the bind. Codex found it and I reproduced it on the worker. Any stand-in value can choose the wrong branch this way, so I have not tried to patch it. The way out is to stop re-running the config under a stub at all: hyprctl eval on Hyprland 0.56.2 runs Lua inside the compositor with the real o and hl, so bind metadata recorded as the real config loads could replace the scan. That is a bigger change and a separate pull request.

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.

@omarchybot omarchybot removed the bug Something isn't working label Oct 22, 2026
@dhh
dhh merged commit b12539b into omacom:quattro Oct 22, 2026
2 checks passed
omarchybot added a commit to seshna/omarchy that referenced this pull request Oct 22, 2026
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]>
dhh pushed a commit that referenced this pull request Oct 22, 2026
)

#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]>
omarchybot added a commit to seletz/omarchy that referenced this pull request Oct 22, 2026
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]>
@emirb emirb added this to the 4.5 milestone Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet