Skip to content

Stop the keybindings cache key flipping on menu keyboard focus - #8229

Open
HoneyTyagii wants to merge 9 commits into
omacom:quattrofrom
HoneyTyagii:fix/keybindings-cache-menu-focus
Open

HoneyTyagii wants to merge 9 commits into
omacom:quattrofrom
HoneyTyagii:fix/keybindings-cache-menu-focus

Conversation

@HoneyTyagii

Copy link
Copy Markdown

Fixes #8140.

The bug

keybindings_cache_key() hashed the active keymap: line from hyprctl devices alongside hyprctl binds. While an Omarchy menu holds exclusive keyboard focus, Hyprland stops reporting an active keymap altogether, so the same binds produced two different cache names depending on whether a menu was open. Each successful refresh deletes sibling caches (find ... ! -name "" -delete), so every alternating press paid a ~540ms cold rebuild and threw away the cache it had just replaced. On the reporter's machine that meant Super+K was slow on nearly every press.

The fix

Hash only what the records are built from:

  • Drop the hyprctl devices line from the hash. Nothing in the pipeline consumes the session's active keymap: keycode resolution goes through xkbcli compile-keymap, which reads the user's configured XKB defaults, not Hyprland's transiently reported keymap.
  • Bump the version marker v13 to v14 so caches written under old keys cannot be mistaken for current ones.

The sibling-cache cleanup stays as is: with a stable key there is normally exactly one live cache, and the deletion still clears stale entries after real config changes.

Verification

Added a regression test in test/shell.d/keybindings-menu-test.sh: it renders once with the stub reporting active keymap: English (US), flips the stub to report no keymap (the state while a menu has focus), renders again, and asserts both runs land on one records file and render identically.

  • Against unfixed code the test fails: identical binds hash to two names (6e9583... vs 197c92...).
  • With this change the full keybindings-menu-test.sh, bin-style-test.sh, and ./test/cli all pass.

While an Omarchy menu holds exclusive keyboard focus, Hyprland reports
no active keymap, so hashing the 'active keymap:' line from hyprctl
devices gave every other Super+K a second cache name: a cold rebuild
that deleted the cache the next press wanted. Nothing in the built
records reads that keymap (keycode resolution goes through xkbcli and
the configured XKB defaults), so hash only hyprctl binds.
Copilot AI balanced review requested due to automatic review settings August 25, 2026 16:06

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Quattro moved the cache marker to v14 while still hashing the active keymap, so this fix now bumps it to v15 to keep a key that no longer depends on the keymap distinct from every earlier one. The regression test sits after quattro's new terminal-bind test, since it rewrites the hyprctl stub for the rest of the file.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Sep 28, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed and verified on a disposable Omarchy worker running Hyprland 0.56.2. The fix holds.

Reproduction. On quattro, dropping just your new test in fails with two cache names for identical binds. On this branch the test passes. I also ran the real script against live Hyprland on the worker, with us,de layouts and a layout switch between runs. On quattro, every switch changed the cache name and rebuilt the cache from scratch, deleting the previous one. On this branch, one cache survived every switch and each run after the first was a warm read (about 8ms versus about 85ms on this VM). xkbcli compile-keymap gave byte-identical output under both layouts, and so did the rendered records. So the active keymap line never fed anything the cache holds, and dropping it loses no invalidation. The specific trigger in #8140, the line disappearing while a menu has keyboard focus, did not show up on this VM: hyprctl devices kept reporting the keymap with the root menu open. The layout switch exercises the same flaw, a volatile line in the key, through the same code path.

Pushed. This branch conflicted with quattro, which had since moved the marker to v14 and added a terminal-bind test at the end of the same test file. I merged quattro into the branch (0939ae3) and resolved the conflict. The key still leaves out the keymap line, and the marker is now v15. Your test sits after the terminal-bind test, because it rewrites the hyprctl stub for the rest of the file. No rebase or force-push; your commit is unchanged.

Tests. ./test/cli on the worker: one failure, vscode generated theme references current theme file, which fails identically on quattro. keybindings-menu-test.sh passed 17/17 and bin-style-test.sh passed 2/2, both with the worker's compositor wired in.

Second opinion. None this run. The configured reviewer (Codex Medium) had reached its daily review limit, so only one model (Claude Opus 5.5) reviewed this change. It waits on that second review before it can go to the maintainer as ready. Nothing is needed from you.

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.
linyiru added a commit to linyiru/omarchy that referenced this pull request Oct 1, 2026
The scan folds a tab in a description to a space so the record it prints keeps
its fields, but the menu looked the bind up by the description `hyprctl binds`
reported, tab and all, so the two keys could never meet: the bind came back
with no id and no dispatcher. The reported description reaches the tab
delimited record too, where the menu reads the back half of a label as the
dispatcher it would run -- a bind labelled "Tabbed\tkillactive" dispatches
killactive when it is picked, on quattro as much as here.

So fold the delimiters out of the reported description the same way, and cut
the scan's copy at the first newline, which is where hyprctl's own output cuts
the description it reports. Bump the cache version, or an install that already
cached a broken record keeps serving it. The literal skips to v17 because v15
is taken by omacom#7564 and omacom#8229 and v16 by omacom#13888, all open: two branches setting
that line to the same value merge with no conflict and leave no bump at all.

A comma in a label still shifts the fields of the intermediate record, here and
on quattro alike. That one is the record format itself, not this lookup.
linyiru added a commit to linyiru/omarchy that referenced this pull request Oct 1, 2026
The records are sorted before they are cached, and the cache key hashes the
version literal, the active keymap and `hyprctl binds` -- none of which moves
when this script's sort does. So an install that already has a cache keeps
serving the order it was written with, and since en_US.UTF-8 is the default
locale that is most installs: the pinned order would arrive later, at some
unrelated moment when a bind or the keymap changed. Measured over one cache
directory and the two chords that swap, the new script printed the old
script's en_US order byte for byte.

Bump the version so that cache is retired, and plant a record under the key
the previous version would have written, so that changing the order without
a bump fails here rather than in a user's menu.

The literal skips to v18 because v15 is taken by omacom#7564 and omacom#8229, v16 by
omacom#13888 and v17 by omacom#12557, all open: two branches setting that line to the
same value merge with no conflict and leave no bump at all. omacom#13521 bumped
v13 to v14 for a records change the same way.
@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 10, 2026
omarchybot and others added 2 commits October 11, 2026 01:54
quattro added the platform key-names file to the cache key and moved the marker to v15. The key keeps the key-names file, still leaves out the active keymap line, and the marker is now v16.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The comment said keycodes resolve through the user's configured XKB defaults. xkbcli compile-keymap without --enable-environment-names compiles its built-in defaults and ignores XKB_DEFAULT_* as well as Hyprland's layout, which is the actual reason the keymap line contributes nothing to the records.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Codex Medium <[email protected]>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 10, 2026
@greptile-apps

greptile-apps Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Summary

Stops the keybindings cache from changing when a menu takes keyboard focus.

  • The keybindings menu keeps its cache when keyboard focus changes.

No actionable issues found. Tests were reviewed but not run.

Reviews (3) · Last reviewed commit: "Require a records cache before checking ..." · Reviewed by Greptile

@omarchybot omarchybot added the ready Good to merge label Oct 11, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

This branch stopped merging cleanly after quattro changed the same cache key, so I brought it across again and re-verified it on a disposable Omarchy worker. The fix holds.

Pushed. quattro (#14431, #14433) added the platform key-names file to the cache key and moved the marker to v15. I merged quattro into the branch (f3e70a3) and resolved the conflict. The key keeps the key-names file and still leaves out the active keymap line, and the marker is now v16. A second commit (c2b6df7) corrects the comment above keybindings_cache_key(). It said keycodes resolve through the user's configured XKB defaults, but xkbcli compile-keymap without --enable-environment-names compiles its built-in default keymap and ignores both XKB_DEFAULT_* and Hyprland's layout. I checked that on the worker: XKB_DEFAULT_LAYOUT=us and de gave byte-identical keymaps. That is the real reason the keymap line contributes nothing to the cached records. Your commit is unchanged, and nothing was rebased or force-pushed.

Reproduction. I ran the real script against live Hyprland on the worker, switching between us and de layouts before each run. On quattro, every switch changed the cache name and rebuilt the cache from scratch, taking about 95ms each time. With the fix reverted on this branch it did the same. On this branch, one cache survived every switch and each run after the first was a warm read of about 8ms. The rendered output was identical under both layouts. Your regression test fails on quattro and on the reverted branch, and passes here.

Tests. On the worker: ./test/cli passed 117/117, keybindings-menu-test.sh passed 19/19 and bin-style-test.sh passed 2/2, both run against the worker's compositor. CI is green.

Second opinion. Codex Medium reviewed it in two rounds. In the first it found no defect in the fix or the merge, and it spotted the inaccurate comment, which I confirmed before correcting it. In the second it reviewed the corrected head and had nothing open. Independence is not guaranteed, because the reviewer can read this session's work.

It now waits on the maintainer. Nothing is needed from you.

@omarchybot omarchybot removed ready Good to merge verified Omarchy Triage has verified that this issue is ready for final review labels Oct 14, 2026
…criptions

quattro now keys the cache on the Omarchy language and its keybindings catalog and bumped the version to v16. Keep both of those inputs, leave the active keymap out as this branch does, and bump to v17 so caches written under quattro's v16 key are not reused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review ready Good to merge labels Oct 14, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

This stopped merging cleanly after quattro started translating keybinding descriptions (#15326), which also changed the cache key. I merged quattro into the branch again (abe7994). The cache key now keeps everything quattro added (the Omarchy language and its keybindings catalog) and still leaves out the active keymap line, as this fix intends. The version moves to v17 so no cache written under quattro's v16 key is reused. The test file keeps both quattro's translation test and the cache test from this PR.

Checked on a worker built from the Omarchy ISO, against quattro at 84cfb93:

  • test/shell.d/keybindings-menu-test.sh: the cache test fails on quattro, passes on this head, and fails again with the fix reverted. Everything else in that file passes, as do menu-keybindings-key-names-test.sh and ./test/cli.
  • On the worker's live Hyprland, with layouts set to us,de and switched back and forth four times: this head kept one records file and opened in about 40ms each time. With the fix reverted, every switch produced a new cache name and a rebuild, at 350–470ms.

Second opinion: Codex Medium reviewed the merged head and found no defects. It agreed that nothing in the rendered records reads the active layout, since keycodes resolve through xkbcli's default keymap. It also agreed that the merge keeps quattro's inputs and that the test is not vacuous. It can read this review's reasoning, so its agreement is not independent.

This is ready for the maintainer to decide on. Nothing is waiting on the author.

@omarchybot omarchybot removed ready Good to merge verified Omarchy Triage has verified that this issue is ready for final review labels Oct 15, 2026
…yout

Quattro now resolves keycode names through the configured leading layout and puts that in the cache key, so the key keeps leading_keyboard and still leaves out Hyprland's active keymap line, which flips while a menu holds keyboard focus.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review ready Good to merge labels Oct 15, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

This conflicted with quattro again after #15508, which names keycode bindings by the leading layout and added leading_keyboard to the cache key. I merged quattro into the branch (2f364f3): the cache key keeps leading_keyboard, so changing the configured layout or variant still invalidates the cache, and it still leaves out Hyprland's active keymap line, which drops out while a menu holds keyboard focus and changes on every layout switch. Nothing the records depend on reads the active keymap any more, so leaving it out cannot serve stale key names. The comment above keybindings_cache_key now says that.

Checked on a worker built from the Omarchy ISO, at 2f364f3:

  • test/shell.d/keybindings-menu-test.sh: your new case fails on quattro, passes on this head, and fails again with the active keymap line put back. The rest of the file passes.
  • On the worker's live Hyprland with us,de, switching layouts between presses kept one records file (about 50ms a press once warm). With the line put back, every switch rebuilt the cache (about 300ms) and deleted the other one.
  • ./test/cli is green.

Codex Medium reviewed the merged diff as a second opinion and found nothing; it agreed with the reading above, and its independence is not guaranteed. This now waits on the maintainer.

@omarchybot omarchybot removed ready Good to merge verified Omarchy Triage has verified that this issue is ready for final review labels Oct 22, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

This conflicts with quattro again. #7564 changed the same lines: it moved the cache marker to v18 and added its Lua bind scan test where your test sits in keybindings-menu-test.sh. The resolution is mechanical. Keep quattro's v18 marker and leave out the active keymap line. Keep both tests, with yours after the Lua scan test, because yours rewrites the hyprctl stub for the rest of the file.

I didn't bring it across or re-verify it in this run. A change since the last check needs a second model to confirm what kind of change it is, and that model's daily review allowance was already used up. Only Claude Opus 5.5 looked at it this time. Nothing in the fix itself has changed since the last verified head (2f364f3). It will be picked up again once a second review can run. Nothing is needed from you.

omarchybot and others added 3 commits November 26, 2026 06:29
…focus

Keep the batched Hyprland query and Lua source invalidation from quattro, removing the device query from both batched and fallback cache keys. Preserve both sets of regression coverage. This also brings in the base fixes for the translation test failure reproduced on the previous head and its merge base.

Co-Authored-By: Codex High <[email protected]>
Make the batch stub return device state only when requested, then assert a layout switch reuses the records file and its inode. This catches devices being reintroduced into the default query while retaining the existing fallback regression.

Co-Authored-By: Codex High <[email protected]>

Co-Authored-By: Opus 5.5 High <[email protected]>
Fail if stat cannot find the initial cache, so two empty command outputs cannot satisfy the cache identity assertion.

Co-Authored-By: Codex High <[email protected]>

Co-Authored-By: Opus 5.5 High <[email protected]>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Nov 26, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

I merged current quattro into this branch and pushed the result at e82bf1872922c62a73f632f8f28197a45f65075a. The cache key keeps the configured layout/variant, language, catalog, key names, Lua contents and binds, and drops device state from both the batched and fallback queries. The marker now changes from current quattro’s v23 to v24; the PR description still names the older v13/v14 change.

Checked on a disposable Omarchy ISO worker with Hyprland 0.57.2: 143 CLI checks and 38 keybindings checks pass, along with the structural translation test and extraction check. The new batch regression fails on quattro and when only the batched device query is restored. Switching live us,de layouts kept one cache with identical inode, mtime and rendered records, at 15–18ms warm; base and reverted code rebuilt on every switch at about 60ms. This reproduces the volatile-input bug through layout switching; I did not reproduce the historical menu-focus disappearance on this Hyprland version.

Codex High reviewed the change. Opus 5.5 High reviewed the final head and found nothing left after its batch-coverage and cache-existence findings were fixed. muse-wonder via pi, thinking high also reviewed the earlier candidate. Their agreement is not guaranteed independent. #14659 remains open as an alternative for #8140. Greptile scored this head 5/5 with no findings.

This waits on the maintainer: Tests and Check translation structure both require workflow approval and have started no jobs, so GitHub CI has not passed. The old failed run’s logs are no longer available; locally, the old head and its merge base share the same locale-generation failure, while current quattro and the merged code pass. The item is verified and remains open pending the CI gate.

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

Labels

bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keybindings cache key includes volatile "active keymap" state, causing repeated 540ms cold rebuilds

3 participants