Skip to content

Stop the keybindings scanner spinning on hl list accessors - #10388

Closed
calledtoconstruct wants to merge 3 commits into
omacom:quattrofrom
calledtoconstruct:fix/keybindings-plugin-ipairs
Closed

calledtoconstruct wants to merge 3 commits into
omacom:quattrofrom
calledtoconstruct:fix/keybindings-plugin-ipairs

Conversation

@calledtoconstruct

@calledtoconstruct calledtoconstruct commented Sep 5, 2026 •

Copy link
Copy Markdown

User configs that ipairs(hl.get_loaded_plugins()) hang omarchy-menu-keybindings at 100% CPU. The Hyprland stub's __index returned a table for numeric keys, so ipairs never saw nil.

Return nil for numeric keys on the noop/hl metatables. Give noop comparison (__lt, __le, __eq) and arithmetic metamethods so stock qconsole.lua's monitor.scale <= 0 and the following height / scale - reserved do not raise; pcall no longer aborts the scan before require("hypr.bindings").

The regression tests load a standalone hyprland.lua that iterates hl.get_loaded_plugins() and binds a chord after the loop, and a stock user config (require("default.hypr.omarchy") then require("hypr.bindings")) with a probe bind in ~/.config/hypr/bindings.lua that must render as SUPER + Y.

Fixes #10214

Related hang/missing-binds reports that need both of these stub changes: #7025, #8819, #9052, #9395. This does not time-box the lua child, so a config that spins for some other reason can still hang the menu.

The scan swallows its own errors, so a stub that raised on a numeric index
would end the loop, kill the scan, and still exit 0. Bind a chord after the
loop and require the menu to render it: Hyprland reports a Lua bind without
its key, so the chord can only come from the scan reaching past the loop.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed by Claude Opus 5 in Claude Code with an independent second opinion from Codex GPT-5.6-sol at xhigh reasoning. The metatable change is correct and I pushed one commit to your branch strengthening the regression test. What follows is about scope rather than about the code, and it matters because your body says Fixes #10214.

The fix works. On a disposable Omarchy worker, a config that iterates hl.get_loaded_plugins() before the Omarchy defaults spun until killed at 15s on the unfixed script and returned in 35ms on yours. ./test/cli and test/shell.d/keybindings-menu-test.sh (16 assertions) pass on the worker against your head, and the new assertion fails on the unfixed script, so it does bite.

What I pushed (9abccc2): the assertion checked only that the process exits 0, and the scan swallows its own errors under pcall. I verified that a "fix" that raises on every numeric index instead of returning nil — which stops the spin by killing the scan and losing every bind after it — passed your test unchanged. The commit binds SUPER + P after the loop and requires the menu to render that chord. Hyprland reports a Lua bind without its key, so the chord can only come from the scan reaching past the loop. It now fails against both mutations. Your timeout 2 I left alone: I measured the scenario at 31-44ms across five runs, so there is ample headroom, though a loaded CI runner is the one place that could be argued.

The part that is not fixed, and why the issue links overstate what this closes. On quattro the scan does not get as far as most people's own bindings. default/hypr/qconsole.lua:64 does monitor.scale <= 0; under the stub monitor.scale is the noop table, noop has no __le, and Lua raises attempt to compare table with number. pcall(dofile, config) swallows it, so the scan stops there — I reproduced this in a live session on the worker with a stock ~/.config/hypr, and with DEBUG=1 it prints lua bind scan failed: .../default/hypr/qconsole.lua:64. Because default/hypr/omarchy.lua requires qconsole at line 18 and the user's own require("hypr.bindings") is back in config/hypr/hyprland.lua at line 21, everything a person put in their own ~/.config/hypr/bindings.lua is never scanned. I added one bind there on the worker and it rendered as SUPER + → Probe user bind, with a blank chord, both before and after your change. Adding comparison and arithmetic metamethods to noop on top of your commit made the same row render as SUPER + Y → Probe user bind.

That is the second of the two failure modes these issues are really about, and this PR does not touch it. So #7025, #8819, #9052, #9395 and #10214 each need the numeric-key change and a stub that survives the comparison in qconsole before the reporter gets a correct menu. There is also no time-box on the lua child, which is what #9052 asks for in its third suggestion; a config that spins for some other reason still hangs the menu with nothing to stop it. Codex checked the orphan claim in #9052 separately and, like me, could not reproduce a surviving lua under Lua 5.5.1 — timeout took the child with it.

Where this leaves it. Four open PRs fix this bug: yours, #10212, #8876 and #7564. Yours, #10212 and #8876 are the same one-mechanism change; yours additionally answers nil for numeric keys on hl itself, which #7564 does not, though that only matters for ipairs(hl) rather than ipairs(hl.get_something()). #7564 covers both failure modes and time-boxes the scan, so on mechanism it is the wider fix. All four merge cleanly onto quattro but conflict with each other in bin/omarchy-menu-keybindings; #10402 touches the same file without overlapping any of them, and #10457 does not touch it at all. Which one lands is the maintainer's call, not mine, and nothing here is a request for changes — but if this one is the one, Fixes #10214 would close an issue whose reporter would still open the menu and not find their own bindings in it.

Codex agreed with the qconsole analysis, and since it can read this session's files its independence is not guaranteed where it merely agrees. Three things it contributed that I had not reasoned about, and that I verified against the source: __len is redundant because # reads the raw table and an empty table already answers 0; for i = 1, hl.get_count() do still raises bad 'for' limit because returning nil for numeric indexing does not reach a numeric-for limit; and the hl.bind calls at default/hypr/bindings/utilities.lua:57-65 sit inside an hl.on("layer.opened", ...) callback, so they are never reached by any scan and are absent from the menu for a different reason entirely. I rejected its one style objection — that ... || fail leans on an exiting branch, against AGENTS.md — because that is the assertion idiom every test in this file already uses.

noop compared as a table and aborted the scan before user bindings.
@calledtoconstruct

Copy link
Copy Markdown
Author

daabd4f: noop now has comparison and arithmetic metamethods, so the stock qconsole monitor.scale <= 0 no longer aborts the scan. The test asserts a user bind from ~/.config/hypr/bindings.lua after require("default.hypr.omarchy") renders as SUPER + Y.

@bjarneo

bjarneo commented Sep 21, 2026

Copy link
Copy Markdown
Member

Automated duplication check: this pull request looks similar to #8876, which covers the same keybindings scanner ipairs termination fix. I keep that one open and close this one to consolidate review.

If you feel this is the wrong decision, please open the PR again with a note on the difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

omarchy-menu-keybindings hangs (100% CPU) when a user config iterates hl.get_loaded_plugins()

3 participants