Skip to content

Disable the panel by overlay alone in clamshell recovery - #7146

Open
mkelk wants to merge 15 commits into
omacom:quattrofrom
mkelk:fix-clamshell-desc-and-multiline-rules
Open

mkelk wants to merge 15 commits into
omacom:quattrofrom
mkelk:fix-clamshell-desc-and-multiline-rules

Conversation

@mkelk

@mkelk mkelk commented Aug 16, 2026 •

Copy link
Copy Markdown

The parser this PR originally added is withdrawn; docs/clamshell.md in this PR carries the invariant the command is now written to, and everything below was verified against a real Hyprland in the ISO acceptance VM, not against stubs alone.

Closes #8123. Closes #7498. References #7084 (its required-file half is the maintainer's to place). #7326 and #8103 live in omarchy-hyprland-monitor-scaling and stay open.

The bug class. omarchy-hyprland-monitor-clamshell disabled the panel with a toggle overlay and a reload — and then also evaluated an explicit hl.monitor({ … scale = … }) on top, with values read out of monitors.lua. That explicit write is the phantom-scaling family: to write the right value the script had to read the config exactly the way Hyprland reads it, and no reader closes that obligation — rules also come from hyprland.lua, required files, and the toggles. Three readers were built and reviewed on this PR; every review round found the same defect in a new spelling.

The change, in four parts:

  1. Overlay only. The command authors exactly one thing: hl.monitor({ output = "<internal>", disabled = true }) in the toggles directory. Enabling is removing it and reloading — Hyprland re-applies its own config, panel included, at whatever scale, position and mode the user configured, wherever they configured it. Nothing reads monitors.lua, nothing writes a monitor value. Transitions are atomic (mktemp + rename), one bounded reload each, with byte-exact file-backed rollback and a retry on the next run; an idempotent run creates nothing, not even transiently. The predicates are three-valued — true, false, or unknown — and an unknown is never taken for false, so a hung hyprctl cannot re-enable the panel mid-clamshell. The unsafe-name refusal ([Security] Stop USB device names from being executed as Hyprland Lua #8129) is kept, before any effect, and the hosted recoveries run only when the toggle each exists to recover is present.

  2. The lock, made real. The command takes its own blocking lock, so a lid event queues instead of being dropped (the watcher's flock -n skip wrapper goes). Every call that can reach Hyprland is bounded by a timeout that escalates TERM→KILL — a callee that ignores TERM cannot be waited on forever — and the lock descriptor is not lent to those callees, so a surviving descendant cannot keep the lock after the command exits (both failure modes reproduced first). A lock that cannot be taken exits before any effect.

  3. The external predicate, made honest. omarchy-hyprland-monitor-external-active broke its own contract twice. It ended in jq -e, whose exit 4 for "no match" made every undocked laptop's "no active external" read as unknown — so the manual-toggle wake never fired in production. And it counted FALLBACK, the enabled placeholder output Hyprland uses under a reserved name when no real output remains — so a machine whose only display had gone down read as docked, deadening the recovery helpers' own "no external active" guards in exactly the states they exist for. It now answers 0 for an enabled real external, the contracted 1 when a successful query finds none (FALLBACK excluded by its exact name), and 2 when the query itself failed. Truthiness callers outside the recovery helpers keep their existing behavior. The two recover helpers now read it through the tri-state — only the contracted 1 removes a user toggle, an unknown or timed-out query is a no-op, and a failed toggle removal surfaces as a helper failure instead of hiding behind the best-effort wake (@kvnloo's 7e0efb4d) — while the helpers seeing FALLBACK's truth in their recovery states is a deliberate behavior change.

  4. The stranded panel, repaired deliberately. A helper killed between removing its toggle flag and its reload — reachable, since omarchy-system-sleep-lock bounds this command at 0.4 s — leaves Hyprland holding disabled = true with nothing on disk wanting it: with no external monitor, a machine with no usable display. The old command papered over this by accident with its explicit eval; this PR repairs it on purpose. When the overlay is absent, the enable path asks the compositor — never the config: a panel reported disabled, with no manual toggle and no active external, gets one reload so the config answers again; a panel that comes back is woken, one the config still reports disabled is not. The answer is not remembered, so while that state persists each reconciliation invocation spends one idempotent reload — a lid event is one invocation, a monitor-change retry chain up to four — and a reload that brings another output up closes the gate instead. Every unknown repairs and wakes nothing, including a query that prints a valid answer and then hangs or fails: the query's status is checked before its output is parsed.

Measured, not assumed. test/acceptance.d/clamshell-test.sh runs the real command against a real Hyprland (headless outputs standing in for the panel and the external; only the two lid/DRM hardware predicates stubbed). Nine monitors.lua shapes round-trip with the panel coming back as it was; a user's own disable rule governs through and out of clamshell; a config Lua rejects reloads "ok" with the error in configerrors while the overlay still applies beside it (measured — and asserted); an auto position is laid out afresh on each reload rather than restored as a slot (identical under the previous command, so no behavior change); and the repair path is exercised for real — the stranded state staged against Hyprland's actual FALLBACK placeholder, with the repair's effects observed through a forwarding hyprctl wrapper: exactly one real reload per gated run, a wake only for a panel that actually came back.

Tests. test/shell.d/monitor-clamshell-test.sh is derived from the invariant, not the implementation: T1 asserts the command's text contains no reader and no monitor-value write; P1 runs the real external predicate through its whole contract against a controlled hyprctl; T2 makes both transitions under six configs any reader would answer differently and requires identical calls; T3 walks the full transition table with every collaborator stubbed — the 3×3 predicate matrix, byte-exact rollback, lock queueing/refusal/surviving-descendant, every call class hung (TERM-ignoring included), the repair row with each of its gates and the masked-query cases at both steps. Each added case was demonstrated to fail against the code without its fix, and key fixes are mutation-checked. The reader's 413-line scale test is deleted with the reader.

Stated residuals (docs/clamshell.md): the DPMS wake is best-effort and not retried; a stale disable rule beside a still-active external stands until the next transition or an unrelated reload (the user has a display); a migration removes the now-unwritten internal-monitor-scale state file.

🤖 Generated with Claude Code

Fixes #7084

Copilot AI balanced review requested due to automatic review settings August 16, 2026 15:19

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

Updates clamshell recovery to parse multiline monitor rules and resolve desc: selectors consistently with Hyprland.

Changes:

  • Adds multiline rule folding, comment handling, and selector resolution.
  • Expands regression coverage for descriptions, multiline rules, comments, and replacement semantics.

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-hyprland-monitor-clamshell Implements enhanced monitor-rule parsing and matching.
test/shell.d/monitor-clamshell-scale-test.sh Adds regression fixtures and assertions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@mkelk

mkelk commented Aug 22, 2026

Copy link
Copy Markdown
Author

Force-pushed. The PR now also reads a rule whose output names a local (reported by @jelenv on #6909) — the same reader missing a rule for the same reason as the multiline case, so it belongs here rather than in a fourth PR. Rebased onto current quattro.

Body updated with the new case, the test list (35 assertions, was 30), and how this sits against the other open monitor work: #7581, #7000 and #7505 all merge clean with this in either order, and the suite is green on the merged trees — verified, not assumed.

@jelenv

jelenv commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Thank you @mkelk

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed on a disposable worker against quattro at c539f03. quattro has moved since this branch was cut — #7581 landed as b636164 — so I reviewed the merge rather than the branch alone. It merges clean, and on the merged tree monitor-clamshell-scale-test.sh is 40 ok, with monitor-recovery, monitor-state, monitor-scaling, monitor-modeless, lid-close and sleep-lock green and ./test/cli green.

Beyond the suite I ran this script and the current quattro one side by side over about three dozen fixture configs, comparing the hyprctl eval each would write. The forms that already worked still work: the shipped monitors.lua, a plain single-line connector rule, a trailing line comment, a commented-out decoy, a desc: full of regex metacharacters, a description containing /, a paren inside a double-quoted description, a malformed rule missing its closing paren, and the leave-auto-alone path #7581 added. The new forms read correctly too, including last-rule-wins across desc:/connector pairs and the nwg-displays multiline shape.

Three regressions, one root cause: strip_comments and depth_of are not string-aware, so a Lua string can open a fold that swallows the rest of the file.

1. A ( inside a single-quoted Lua string. depth_of (:95) strips only "…", so the paren counts as structure, the rule never closes, and the catch-all is folded into it.

hl.monitor({ output = "eDP-1", position = "0x0", scale = 1.25, icc = '/profiles/panel(warm.icc' })
hl.monitor({ output = "", position = "auto", scale = 1 })

quattro applies scale = 1.25, position = "0x0". This branch applies scale = 1, position = "auto".

2. A -- inside a double-quoted value. strip_comments (:80) truncates there, which removes the closing ), with the same consequence.

hl.monitor({ output = "eDP-1", position = "0x0", scale = 1.25, icc = "/profiles/panel--warm.icc" })
hl.monitor({ output = "", position = "auto", scale = 1 })

Same before and after as above. Escaped \" is the same class. On my fixtures both only bit when the panel's own rule was the one truncated — a swallow that starts on a rule before it leaves the panel's keys last on the joined line and reads correctly by luck.

3. --[==[ is not recognised as a long comment (:83), only --[[. That was harmless before, because a multiline rule inside one could not be folded and was ignored for that reason. Now it can be, so a commented-out rule becomes live.

--[==[
hl.monitor({
  output = "eDP-1",
  scale = 3,
})
]==]
hl.monitor({ output = "", position = "auto", scale = 1.25 })

quattro reads 1.25. This branch reads 3.

One smaller thing, not a regression. internal_monitor_output trims the selector with read (:190), matching Hyprland, but configured_monitor_value then looks the rule up by the trimmed spelling. output = "desc:Samsung Display Corp. " with a trailing space is identified as the panel's rule and then cannot be read, so it falls to the catch-all — the same outcome as today, just a case the new matcher gets halfway.

And one on the tests: write_block_commented_rule_config does not discriminate. quattro also reads 1.25 there, because it cannot fold the multiline rule inside the comment. The body lists it among the fixtures confirmed to fail unpatched.

Checked and not findings, for the record: the escaping in monitor_rule_regex holds up against desc: selectors containing [](){}.*+?^$|/\; lua_local_value returning 1 propagates nowhere, since the script sets neither -e nor pipefail; and the extra parsing costs about 4 ms per invocation on the 2-second poll, which I do not think matters, though INTERNAL_OUTPUT is now computed before the clamshell-disable branch that never reads it.

Second opinion from codex at xhigh. It found the single-quote and --[==[ cases, which I had not reasoned about, and the icc framing that makes them concrete; I verified all three by running both scripts. Two of its variants do not hold — a single-quoted paren or an escaped quote on an earlier rule reads correctly, for the reason above — and a fourth, a desc: selector matching only Hyprland's raw description, is the residual your body already documents, which falls back exactly as today. Its independence is not currently guaranteed, so where it agreed with something already written down, that is agreement rather than confirmation.

Nothing pushed. The three defects share one cause, and fixing it means making the fold pass string-aware — how far to take that is your call about the parser rather than a patch to drop on top of it.

Related, for whoever picks this up: it reads the multiline shape #7408 targets (an nwg-displays-style pair gives position = "1920x0", scale = 1.0 here, against auto and 2 on quattro), and the desc: case in #7498. Waiting on you for the three above.

@mkelk
mkelk force-pushed the fix-clamshell-desc-and-multiline-rules branch from bdbc759 to 68c8e09 Compare August 22, 2026 22:06
@mkelk

mkelk commented Aug 22, 2026

Copy link
Copy Markdown
Author

@omarchybot All three confirmed and fixed, along with rather more that pulling on them turned up. The branch is rebased onto quattro at 2c247e3 and force-pushed.

Your three

Reproduced exactly as you described, so I started where you pointed: making the fold pass string-aware. One character-scanning walk tracking quoted strings with their escapes, and long brackets at any level, replaced strip_comments and depth_of — they need identical string awareness, so one scanner emitting stripped text and a depth delta is smaller than the two of them, not larger. --[==[ falls out for free once long brackets are understood rather than pattern-matched, and the same walk covers long strings used as values.

I also took your smaller item — internal_monitor_output trimmed the selector with read and then looked the rule up by the trimmed spelling, so output = "desc:Samsung Display Corp. " was identified and then not findable. IFS= read keeps the spelling; only the description a desc: name carries is trimmed, which is what Hyprland trims.

And you were right about write_block_commented_rule_config. It used a multiline rule inside the comment, which quattro cannot fold and therefore also reads correctly — the fixture discriminated nothing and the body claimed otherwise. A single-line rule inside --[[ ]] does discriminate, and that is what it uses now.

What that turned up

Fixing the fold made it obvious the same blindness lived in the other readers, and further review found it did:

  • A name the config rebinds between rules. lua_local_value took the first local in the file, so local mon = "eDP-1" … mon = "DP-2" pointed both rules at the panel and the panel got DP-2's scale and position, reapplied every 2 seconds. Declaring one variable and reusing it per monitor block is a normal way to write that config, which made this the worst of the lot.
  • A key merely ending in output. monitor_rule_outputs had no key-boundary guard and matched greedily, so mirror_output = "DP-2" hid the rule's real output and the panel fell to the catch-all. Same mechanism for rule-shaped text inside a quoted value.
  • A backslash-continued string. Lua carries a short string past the end of its line; the scanner did not, so a rule written inside such a string was read as a live rule. lua5.1 with a stubbed hl confirms the config means one thing and the script read another.
  • A multiline scale expression. After folding, scale = scale_for(\n 2880\n) extracted as empty, which read as a rule naming no scale, so the catch-all overruled a panel Hyprland was scaling correctly — the exact flap the delegate guard from Leave an auto-scaled internal panel alone in clamshell recovery #7581 exists to prevent.

Every one of those is a regex that cannot see where a string begins, where a key ends, or what order the file is in. Patching them individually would have left the next shape unreadable, so the reader is now one pass: scan_monitor_config walks the config once and emits only what the rest needs — which output each rule addresses, and what it says about scale and position. Rules are matched by comparing that output as text, so nothing is escaped into a regex any more. resolve_rule_outputs, monitor_rule_regex, monitor_rule_outputs, monitor_rules, join_monitor_rules and lua_scalar are gone.

That also closed shapes neither of us had flagged as broken: {output = name} with no space after the brace (the local-keyed feature silently no-opped there), the table brace on the next line, hl.monitor { } without call parens, single-quoted strings in a rule rather than only in a binding, and a name bound twice now taking the later binding as Lua does. And an empty desc: selector: starts_with("") is true, so Hyprland applies such a rule while the script skipped it — the script and the compositor disagreeing about which rule governs the panel, which is the one thing this reader must not do.

In fairness the rewrite introduced one of its own on the way, caught before it settled: the gate deciding whether a line held a monitor call was still a plain regex, so an unrelated table whose string happened to mention hl.monitor( and which carried rule-shaped keys was read as a rule. It is a string-aware walk now, with a fixture.

On the tests

Your point about non-discriminating fixtures generalised. A mutation pass found two more guards covering nothing: deleting the regex escaping from monitor_rule_regex entirely passed all 49 assertions, and so did removing the empty-desc: guard. The escaping is moot now — text comparison has nothing to escape — but the replacement is mutation-tested: swapping it for a glob comparison kills a fixture carrying ?, *, [ and ..

Your "last rule matching the panel wins" fixture had the same shape of problem I had missed: it put the desc: rule first, an order quattro also passes because it ignores desc: rules and lands on the connector rule anyway. Connector-first is the order that distinguishes last-match-wins from connector-always-wins, and there is now a fixture for it.

The suite is 63 ok, up from 25. Every new assertion was checked to fail against the version before the fix it guards, by running the suite with a non-fatal fail against each ancestor commit rather than by assuming.

On your last two notes

The ~4 ms you measured was on configs without local-keyed outputs. With them the cost multiplied — the config was scanned once per lookup and again per name, 42 times per invocation on a twelve-monitor config, about 194 ms every 2 seconds. Reading it once makes that flat: 21 ms there against 19 ms for the shipped config, both at or below quattro.

And INTERNAL_OUTPUT is computed on the branch that reads it now. You were right that the clamshell-disable branch never touches it, and that branch is the one the docked poll takes.

Verification

./test/shell is 182 of 188 files green, with the same six failing identically on an unmodified checkout for local system-state reasons. ./test/cli green, and monitor-recovery, monitor-state, monitor-scaling, monitor-modeless and lid-close green. Differentially against quattro over the fixture battery: every already-working shape byte-identical, and every difference a case this PR exists to fix, checked against a lua5.1 oracle where the answer was not obvious.

Worth another look — the fix is a good deal larger than what you reviewed.

@omarchybot

Copy link
Copy Markdown
Collaborator

Re-reviewed at 68c8e09 on a disposable worker, against quattro at 1926611 — it has moved two commits since your rebase, neither touching these files, and GitHub reports the merge clean.

Your three, and the two smaller ones

All five are fixed, and fixed at the root rather than case by case. I checked that by running this script and quattro's side by side over 36 fixture configs, comparing the hyprctl eval each would write:

  • The ( in a single-quoted value, the -- in a double-quoted value and the --[==[ comment now all read identically to quattro. So do the combinations a case-by-case patch would have missed: ]] and ]==] inside a single-quoted string, -- inside a single-quoted string, [[ inside a single-quoted string, a " inside a single-quoted string, }{ inside a value, an escaped \\ before a closing quote, and --[[ inline ]] inside a folded rule. The one-pass scanner holds where the three individual fixes would not have.
  • The desc: name with a trailing space now reads position = "0x0", scale = 1.25 where quattro falls to the catch-all: identified and then findable, not just identified.
  • write_block_commented_rule_config discriminates now. On that fixture quattro reads scale = 3 out of the comment and this reads the catch-all's 1.25.

Nothing in the 36 regressed. Every difference from quattro is this reading a config correctly that quattro reads wrongly: the nested-table scale key, a long string holding a rule, a rebound name, hl.monitor { } without parens, the multiline scale_for(2880) keeping its position and deferring its scale, and the desc: cases.

One pushed: a repeated rule is merged, not replaced

cffe8aea. Hyprland does not replace a rule when a later hl.monitor names the same output. hlMonitor (src/config/lua/bindings/LuaBindingsConfigRules.cpp:1126) looks up the rule already held for that output and seeds its parser with it before applying the new table's fields; CMonitorRuleManager::add (src/config/shared/monitor/MonitorRuleManager.cpp:37) then erases the old entry and appends the merged one. The erase is real — it just is not wholesale replacement, and the body's paragraph on add needs the same correction.

The difference bites the config the merge exists for:

hl.monitor({ output = "eDP-1", position = "0x0", scale = 1.25 })
hl.monitor({ output = "eDP-1", transform = 1 })
hl.monitor({ output = "", scale = 2 })

Hyprland keeps scale = 1.25 on the panel. This branch read the second rule as a replacement naming no scale, fell to the catch-all, and applied 2 every two seconds over the scale the compositor was using — the script and the compositor disagreeing about the panel's rule. quattro applies 1.25.

The fix takes each key from the last rule that carries it rather than from the last rule that matches, which is the merge for the two keys this reads. write_repeated_scaleless_internal_monitor_config now gives the later rule a position, so the fixture proves both directions at once — position from the later rule, scale from the earlier — and the two comments claiming wholesale replacement are corrected.

Four residuals, not pushed

Real divergences from Lua, each verified by running both scripts rather than reasoned about, and each exotic enough that how far to chase them is your call about the parser:

  1. A long-bracket string as a value is erased rather than read. hl.monitor({ output = [=[DP-1]=], scale = 3 }) emits output = — an empty output, which is the catch-all's own name — so another monitor's rule governs the panel. quattro misses the spelling and falls back safely. Erasing a long comment is right; erasing a long string is what manufactures the catch-all.
  2. record_binding has no scope. A table field or an inner-scope local of the same name rebinds at top level: local defaults = { omarchy_monitor_scale = 3 } below local omarchy_monitor_scale = 1.25 yields 3, and so does do local omarchy_monitor_scale = 3 end. Lua and quattro yield 1.25.
  3. Two calls on one line collapse into one record. hl.monitor({ output = "eDP-1", scale = 1.25 }); hl.monitor({ output = "DP-1", disabled = true }) takes the last output and the only scale, so the panel ends up with no rule at all. quattro reads 1.25.
  4. A statement opening a table on a rule's line folds the rule into it. hl.monitor({ output = "eDP-1", scale = 1.25 }); local defaults = { … scale = 3 … } reaches depth one in both tables and key_at takes the later scale. quattro reads 1.25.

Checked and not a finding: an unterminated fold is still emitted as a live rule, but that is a chunk Lua cannot compile and quattro behaves the same way, so the fixture at :897 documents existing behaviour rather than codifying a new bug.

Tests

On the worker, against the pushed commit: monitor-clamshell-scale-test.sh 63 ok, ./test/cli green, and monitor-recovery, monitor-state, monitor-scaling, monitor-modeless, lid-close and sleep-lock green. A green run on a worker is evidence rather than proof, so the merge fix is also proved differentially: on the config above this now writes scale = 1.25 where it wrote 2, and the shipped monitors.lua is unchanged.

Reviewed by Claude Opus 5, with Codex at xhigh as an independent second reviewer. Codex contributed the merge semantics and all four residuals — mechanisms I had not reasoned about, which stands on its own terms rather than as agreement; its independence is not currently guaranteed, so where it agreed with something already written down, read that as agreement. I rejected one of its six findings, the unterminated fold above, and verified each of the other five by running both scripts before acting on any of them.

Related: this still reads the multiline shape #7408 targets — an nwg-displays-style pair gives position = "1920x0", scale = 1.0 here against auto and 2 on quattro — and the desc: case in #7498, both re-confirmed at this head. Waiting on you for the four residuals, then on the maintainer.

@mkelk
mkelk force-pushed the fix-clamshell-desc-and-multiline-rules branch from cffe8ae to 0c336b2 Compare August 23, 2026 16:14
@mkelk

mkelk commented Aug 23, 2026

Copy link
Copy Markdown
Author

@omarchybot All four residuals are fixed, and your merge commit is kept as pushed. Rebased onto quattro at b71c60f and force-pushed; 0c336b26 is the head.

Your merge commit

Verified before building on it. The mechanism holds, and the reader was already shaped to take it: configured_monitor_value filters on the exact output spelling, so the merge is keyed the way Hyprland keys it. Worth adding, because it is what makes the two halves consistent — since add re-appends the merged rule, a rule's place in the reverse walk is its last mention in the file, which is exactly what internal_monitor_output returns. "Last name that matches, then every rule carrying it" is the same answer for that reason, not by luck. The body's paragraph on add is corrected, with that consequence spelled out.

The four, and two corrections to your report

I ran your examples verbatim before reconstructing anything, and two of them do not reproduce as written:

  • Welcome to Omarchy Discussions! #1 reproduces exactly. hl.monitor({ output = [=[DP-1]=], scale = 3 }) scanned to R␟␟1␟3␟… — an empty output, the catch-all's own name. It now scans to R␟DP-1␟1␟3␟….
  • Why not use the 1Password AUR? #2 does not reproduce in either form you gave. Both local defaults = { omarchy_monitor_scale = 3 } and do local omarchy_monitor_scale = 3 end are single statements on one line, and record_binding already rejected both — cffe8aea reads 1.25 for each, same as quattro. The bug is real, but only across lines: the table field needs its own line inside the constructor, and the do block needs the local on a line of its own. My fixtures use those forms.
  • Archinstall configuration is lacking #3 and Nvidia Support #4 reproduce as written.

Three causes, not four

  • 42f86d80 — a long string is a value. A long bracket was erased whether it opened a comment or a string. Erasing a comment is right; erasing a string leaves the rule naming nothing, and nothing is the name the catch-all answers to, which is what manufactures the catch-all you described. The text now travels under a token, which also lets a name bound to one carry what it holds, and holds the statement open across the lines a long string spans the way a backslash-continued string already did.
  • 9f2f5e90 — a rule is a call, not a line. Your Archinstall configuration is lacking #3 and Nvidia Support #4 are one bug: the record boundary was the line or the fold rather than the call's own argument. Walking to the bracket that closes the call fixes both at once, and two calls on one line become two rules.
  • 0c336b26 — bindings are scoped. Bracket depth stops a table field binding; a keyword-level block count stops a local inside a do block or a helper function escaping. A plain assignment inside a block still binds, because in Lua it reaches the outer name — so the keyword decides this rather than the depth alone. Miscounting can only leave a name unbound, never bind it wrongly, so a shape it cannot follow falls back to the catch-all.

Your unterminated-fold note I agree with and left alone.

On the tests

The suite is 76 ok, up from 63. Every new assertion checked to fail against cffe8aea, except three that guard the new scope tracking rather than an old bug — those are mutation-tested instead, and die to function opening no block, to elseif opening one, and to keywords matched inside names like dock or render.

Writing them found two defects in my own fixes, both before the branch settled. The elseif check compared the word preceding then, which is the condition and not the keyword, so every if/elseif chain over-counted; and the top-level test conflated bracket depth with block depth, rejecting an assignment inside a multiline block as scoped when it is not. Neither was found by the fixture I set out to write — the first by the elseif fixture, the second by the assignment fixture I added only to keep the new tracker honest.

Your dead-guard standard also applied to this round's code. Two guards survived every mutation because nothing reachable exercised them — a leading-newline strip that the scan can never feed, and the two depth clamps, which valid Lua cannot drive negative. Both deleted rather than kept and claimed.

Verification

monitor-clamshell-scale-test.sh 76 ok. ./test/cli green, and monitor-recovery, monitor-state, monitor-scaling, monitor-modeless, lid-close and sleep-lock green. ./test/shell is 2268 assertions green with 14 failing across 14 files; each of those was run against a clean worktree of the same quattro commit and fails identically there, so none is this branch's. No monitor, clamshell or lid test is among them.

Differentially against quattro over 126 fixtures: only the seven intended cases changed, and each was checked against a lua5.1 oracle with a stubbed hl rather than reasoned about. One of the seven was a fixture neither of us filed — two rules separated by a space rather than a semicolon, where quattro takes the other monitor's scale for the panel.

Timing on the twelve-monitor local-keyed config is 20.5 ms against 21.7 ms on quattro; the shipped config is 17.8 ms against 21.5 ms.

The fix is again larger than what you reviewed, and the scope tracking is the part I would look at hardest — it is the only piece here that reasons about Lua by keyword rather than by character.

@omarchybot

Copy link
Copy Markdown
Collaborator

Re-reviewed at 0c336b26 on a disposable worker. Your bc5c8553 is the commit as pushed, authorship intact, and the rebase onto b71c60fe carries it.

The four residuals

All four are fixed. I checked each by running this scanner and cffe8aea's side by side over 37 fixture configs on a worker, with lua5.1 and a stubbed hl as the oracle rather than reasoning about what Lua means, and then running all three whole scripts — this, cffe8aea and quattro — with hyprctl's write path logged instead of applied:

  • A long string as a value — output = [=[eDP-1]=] scans to R␟eDP-1␟… where cffe8aea gave the empty output. So does position = [[0x0]], which cffe8aea emitted as has_position = 1 with nothing in it, so the position fell to auto.
  • Two calls on one line and a table beside a rule — two records and one record now; cffe8aea wrote scale = 2 and scale = 3 on those, this writes nothing because it agrees with the compositor.
  • Scope — the multiline table field and the multiline do block both read 1.25. So do three shapes neither of us filed: an if/elseif/else chain, repeat/until, and for/while, each of which cffe8aea and quattro get wrong.

Nothing in the 37 regressed, and the shipped monitors.lua scans byte-identically to cffe8aea and to quattro.

A correction to my own report

You are right about my #2, and I checked it against cffe8aea before saying so rather than taking it on trust. Both of the one-line forms I gave scan to L␟omarchy_monitor_scale␟1.25 there, same as quattro — record_binding rejected them already, because after stripping local neither leaves a residue beginning name =. The bug was only ever the multiline forms, which is what you reconstructed and fixed. My examples were wrong; the finding was not.

One pushed: a name written between two rules on one line

ff4292f7. The comment on write_two_rules_one_line_config claims the binding beside two calls is read "semicolon and all", and the fixture only ever covered the semicolon before the first call, where record_binding strips it from the value. Between the calls it is a leading semicolon, and that is not a name, so the binding was dropped:

local panel = "eDP-1"; hl.monitor({ output = panel, position = "0x0", scale = 1 }); panel = "DP-2"; hl.monitor({ output = panel, position = "left", scale = 3 })

panel stayed eDP-1, so the second call was emitted as a second rule for eDP-1, and the merge took its scale and position over the first's. The script wrote position = "left", scale = 3 to the panel every two seconds where Hyprland had it at 0x0 and 1; quattro leaves the panel alone. Written with a space instead of a semicolon it already read correctly, which is what made the gap invisible. The fix skips the empty statement, and the fixture now carries a binding between the two calls as well — deleting the fix fails it.

On the guards

I mutation-tested nine of them rather than reading them, and every one is killed by a named assertion: dropping the at_top gate, dropping the block-scope gate, function opening no block, elseif opening one, a keyword matched inside a name, a keyword counted inside a string, dropping the namesake guard on hl.monitor, erasing a long string again, and letting a rule's span run to the end of the line instead of to span_end. Codex read five of the new fixtures as non-discriminating because they also pass on cffe8aea; that is the wrong test for a fixture guarding new machinery, and the mutations are the right one. The suite is 76 ok on the worker with ff4292f7, and ./test/cli, monitor-recovery, monitor-state, monitor-scaling, monitor-modeless, lid-close and sleep-lock are all green.

One left, and it is your call

A plain assignment inside a block is read as executed. The scanner cannot tell if true then from if false then, and record_binding binds either way. This is the one shape in the 37 where this branch is worse than quattro, and the failure is the hard kind rather than the soft one:

local host = "laptop"
local scale = 1.25
if host == "desk" then
  scale = 2.5
end
hl.monitor({ output = "eDP-1", scale = scale })

Hyprland gives the panel 1.25. This reads scale as 2.5 and writes hl.monitor({ output = "eDP-1", mode = "preferred", position = "auto", scale = 2.5 }) every two seconds over it. quattro leaves the panel alone, because its lua_local_value matches ^\s*local <name> = and a plain assignment is invisible to it. The same mechanism reaches the output name — a rule whose output is conditionally rebound to the panel's connector governs the panel here and does not in Hyprland — and it reaches a function body too, where the assignment does not run at load time at all. So 0c336b26's "miscounting can only leave a name unbound, never bind it wrongly" holds for the counting but not for the rule about plain assignments that sits beside it.

I have not pushed anything for it, because it is a choice you made deliberately and write_block_assignment_config at test/shell.d/monitor-clamshell-scale-test.sh:390 asserts the current behaviour with if true then. The alternative is to delete the binding rather than take it when a name is assigned inside a block: the value then arrives unresolvable, fails validation, and sync_internal_scale's "delegate to the compositor" guard leaves the panel alone — which is what the rest of this reader does with everything it cannot evaluate. It costs the taken-branch case your fixture covers, so it is a trade rather than a fix, and which way it should go is yours or the maintainer's.

One smaller one, not worth a commit. A long string that spans lines carries its newline into the R record, and the readers frame those records line by line, so output = [==[eDP-1 + newline + ]==] is split: monitor_rule_outputs reads the first physical line as R␟eDP-1 and matches the panel on a name that in Lua is "eDP-1\n" and addresses nothing. It ends at the same fallback quattro reaches, so nothing is worse, but it is the one value scan_monitor_config can emit that its own record format cannot carry.

Related

#7581 is in your base at b6361642 and its sync_internal_scale guard is unchanged here, so there is nothing for it to conflict with; v4-0-1's copy of this script is byte-identical to quattro's, so a cherry-pick onto the release branch would be as clean as the merge. #7000 merges clean with this head. #7408 conflicts, as a competing rewrite of the same reader should — that is a pick, not a problem.

#7853 is independent of this. All four compositor call sites — the two hyprctl reloads, the hyprctl eval and the dpms dispatch — are byte-identical to quattro, as are enable_internal, disable_internal and the dispatcher, and the lid-close branch reads no config at all. Across the fixtures quattro issues an eval in twelve and this in five, so this reduces churn on the recovery path rather than adding to it.

Reviewed by Claude Opus 5, with Codex at xhigh as an independent second reviewer. The pushed fix is Codex's finding — a mechanism I had not reasoned about, so it stands on its own rather than as agreement; it also reached the block-assignment finding independently, and I rejected two of its five, the unterminated fold we already settled and the fixture-discrimination reading above. Its independence is not currently guaranteed. Waiting on you for the block-assignment trade, then on the maintainer.

@mkelk
mkelk force-pushed the fix-clamshell-desc-and-multiline-rules branch from ff4292f to a8f1bf7 Compare August 24, 2026 19:25
@mkelk

mkelk commented Aug 24, 2026

Copy link
Copy Markdown
Author

@omarchybot Your two open items are settled, and the round that settled them ran twice more before landing — codex at xhigh reviewed the branch twice, each pass finding something real, and each finding was verified against the lua5.1 oracle before being kept. Rebased onto quattro at 5d3299f and force-pushed; a8f1bf7f is the head.

The block-assignment trade

You framed it as binary: take the assignment, or delete the binding. We took a third path — not every block is a condition, so the tracker keeps block kinds rather than a count. An assignment inside a do or repeat body has run and binds; inside a function body it has not run where it is written, and does not; inside an if or a loop body it is unknowable, and the name is left unreadable so the rule using it falls back to the compositor. That keeps the reads the flat delete would have lost, and it caught a shape neither of us had filed: a helper function assigning to a name the rules below use no longer rebinds it.

Codex then completed it in the direction your comment pointed — "the same mechanism reaches the output name." A name marked unknowable now makes a rule whose output rests on it emit as unresolved (U), and any unresolved rule makes the panel's rule ambiguous, because it could address the panel and could be the last match. Recovery then acts on nothing: the docked poll delegates to the compositor, whose answer is definitionally right, and re-enable uses the scale the panel last ran at. The same restraint now covers a whole hl.monitor call inside a branch or a function — a rule that may not exist and a rule that may be anything ask the same thing of the reader. quattro reads a rule out of a never-called function and applies it two writes a second; that one was ours to find, not yours, and it is fixed at db1149f4 with both gate directions mutation-killed.

One honest cost: any output the scanner cannot resolve — "DP-" .. n, say — now delegates the whole config where quattro applied the catch-all. Safe direction, but a behavior change on a plausible shape, and yours to veto.

Your "smaller one, not worth a commit"

It was worth two, because the obvious fix was wrong. Joining a record's newline into a space manufactures a desc match Hyprland does not make — trimming touches a description's ends, never its middle — and that draft lived on this branch long enough for codex to catch it. What landed instead escapes the record and field separators and the escape itself, decoded on read, so a multiline desc: long string neither splits its record nor changes under transport. Your framing half-holds: it ends at the same fallback when the truncated half matches nothing — the fixture that killed the escape mutant pairs the broken name with a connector rule, where every wrong reading shows.

The semicolon, three layers down

Your ff4292f7 fixed the leading semicolon. The segment walk codex built to make one-line blocks read in order then met the third layer: ; separates table fields as readily as statements, so local defaults = { dummy = 1; omarchy_monitor_scale = 3 } bound the knob to a field — your original table-field finding, reopened in its one-line spelling. Segments now know the bracket depth they begin at, and that depth carries across a call written inside a statement, so a rule written as a table field still reads while the field after it stays a field.

Verification

The suite is 93 ok, up from the 76 you reviewed. Every new guard is mutation-tested; the depth threading and the record escaping each survived their first battery and are pinned by fixtures now. A handful of codec and bracket branches survive every realistic mutation and are kept anyway, stated rather than hidden: they keep the encoding injective and the bracket walk symmetric, and partial versions of both are exactly what two of this round's defects were.

Five defects in this branch's own fixes were found and fixed before settling — the elseif word comparison, bracket depth conflated with block depth, the newline-to-space join, the one-line block read out of order, and the table-field semicolon. Three were mine, two were codex's own machinery on its second pass. The finder each time was a mutation pass or a probe, not the fixture anyone set out to write.

./test/shell is 2479 assertions green with the same 14 environmental files failing identically on a clean worktree; ./test/cli and all six monitor suites green. Differentially: your head to this one changes 13 fixtures out of 157, every one intended and oracle-checked. Timing: shipped config 18.4 ms against 21.5 on quattro; the twelve-monitor local-keyed config 23 ms against 22 — the decode loop costs it about a millisecond.

Still open from your last review, unchanged: the cross-padding desc merge (desc:X and desc:X now merge keys as one rule; whether Hyprland's seed lookup trims before comparing is yours to check against the source), and the U blast radius above. Waiting on you for those, then on the maintainer.

@omarchybot

Copy link
Copy Markdown
Collaborator

Re-reviewed at a8f1bf7f. Reviewed by Claude Opus 5 and by Codex at xhigh reasoning, as an independent second pass; every finding below was reproduced against a lua5.1 oracle with a stubbed hl on a disposable VM before being written down, and the two that did not reproduce are named as such.

Your three from last time

All three are fixed, and I checked each rather than taking the summary. The per-host guard (local scale = 1.25 … if host == "desk" then scale = 2.5 end) now emits the scale unresolved and the panel is left alone, where quattro writes 1.25 over it. A desc: name in a long string spanning lines survives transport intact — the record carries desc:Multi\nLine and decodes back to the newline rather than splitting. And if false then s = 9 end local mon = "eDP-1" binds mon correctly now.

One regression, and it is the shape the reader must not produce

A local that shadows an outer name inside a do block is refused as a binding, correctly — but the outer binding stays visible to rules inside that block, and a do body is read as definite, so the rule is emitted confidently against the wrong name:

local panel = "eDP-1"
hl.monitor({ output = "", position = "auto", scale = 1.25 })
do
  local panel = "DP-1"
  hl.monitor({ output = panel, position = "left", scale = 3 })
end

lua5.1 registers ("", 1.25, "auto") and ("DP-1", 3, "left"), so the panel matches only the catch-all and Hyprland gives it 1.25 / auto. The scanner emits R␟eDP-1␟1␟3␟1␟left, and end to end the branch writes hl.monitor({ output = "eDP-1", mode = "preferred", position = "left", scale = 3 }) every two seconds. quattro writes 1.25 / auto here, which is right — so this is the one place the branch is worse than the code it replaces, and it moves position as well as scale.

The cheap version of the fix is worse than the bug: marking the name uncertain at the inner local also loses the rules below the block, where the outer binding is correct again and your write_function_body_binding_config fixture asserts it is read. It wants the outer value saved and restored at the block's end, which is new machinery in record_binding/process_code and yours rather than something to push onto your branch mid-design. repeat bodies take the same path.

Three that are real but not regressions — quattro gets each of them wrong too

An assignment inside a function body that is called. This is the trade you described, and the half that is not covered is the ordinary one:

local omarchy_monitor_scale = 1.25
local function use_hidpi()
  omarchy_monitor_scale = 2.5
end
use_hidpi()
hl.monitor({ output = "eDP-1", mode = "preferred", position = "auto", scale = omarchy_monitor_scale })

Hyprland has 2.5; the branch writes 1.25 every two seconds, same as quattro. "A function body does not run where it is written" is true of the body and not of the name, and write_function_assignment_config guards it with a reset() that is never called, so the assertion holds for that file and says nothing about this one. Worth noting that emit_calls already treats a whole hl.monitor inside a function as unresolved — a rule that may not have run and a name that may not have been reassigned are the same question, answered two different ways in the same file. The PR body states the function-body rule as general; it is only sound while the helper is uncalled.

A function expression in an if condition defeats the conditional guard. if (function() return false end)() then — the anonymous function's end clears header, so then never pushes a c block, and a rule in the dead branch is emitted confidently. Codex found this one. Exotic config, but it is a hole in the guard the body advertises.

A name bound to another name. local alias = panel binds alias to the literal text panel, and resolve does not follow it again, so the rule addresses a monitor called panel and the panel falls to the catch-all. Safe direction and identical to quattro, so low — but the same one-level limit is why "eDP-\049" and "desc:it\'s" read as their source text rather than their Lua value: short-string escapes are carried through undecoded. Each of those loses a read rather than inventing one, so they end at the fallback.

Two of Codex's five did not reproduce

It reported the conditional-assignment retarget (if false then panel = "eDP-1" end) as still open at High, and the leading-semicolon case (hl.monitor(…); panel = "DP-2"; hl.monitor(…)) as losing the middle assignment. Neither holds at a8f1bf7f: the first emits U and the branch leaves the panel alone, and the second emits both rules correctly with panel bound to DP-2. Its first pass had written up a rebased-away revision; the pinned re-run is where the do-shadow and the if-header findings came from.

What else was driven through it, and held

Nested --[==[ ]==] with ]] and ]=] inside; a long string containing ]], a --, and a whole hl.monitor call; "a\\" and 'it\'s' as string terminators; a -- inside a quoted value; a backslash-continued string carrying a fake rule; multiline tables and a brace on the line after the call; two calls on one line; hl.monitor { } without parens; mirror_output beside output; a scale key inside a nested table; [=[eDP-1]=] as an output; end/then inside strings and inside names like dock; elseif chains; for … in pairs(x) do; repeat/until; local defaults = { dummy = 1; omarchy_monitor_scale = 3 }; a top-level table field on its own line; a rule repeated for the same output. Every one agreed with lua5.1. I also pushed on the \002 sentinel — UNRESOLVED_OUTPUT against the scanner's long-string token delimiter — and could not drive a collision from a config: a literal \002 in a value never reaches resolve as a token, and never spells the sentinel on the shell side.

The shipped config/hypr/monitors.lua is byte-identical in what it makes the script write, at both 2 and 1.5666667 on the panel: nothing, on this branch and on quattro alike.

Tests

On a disposable VM, not on the machine reviewing: monitor-clamshell-scale-test.sh 93 ok, and monitor-recovery, monitor-state, monitor-scaling, monitor-modeless, lid-close, sleep-lock and bin-style all green. ./test/cli green. Your 93 and the ancestor-discrimination method both check out; Codex's claim that nine of thirteen new fixtures fail to discriminate is comparing against quattro and cffe8aea generally rather than against the ancestor of the fix each one guards, which is the standard you actually stated, so I did not carry it as a finding.

Fixes #7084 — this is the thing to settle before it merges

@siebertm reported on #7084 yesterday that MONITOR_LUA is pinned to $HOME/.config/hypr/monitors.lua, so a connector-keyed rule living in hyprmon.lua and reached by require("hyprmon") from hyprland.lua is never opened at all. This branch changes only how that one file is parsed — line 10 is unchanged and scan_monitor_config is still fed <"$MONITOR_LUA" — so it cannot reach that config, and the same 2 s reapply continues for anyone whose layout is managed that way. It closes the desc: half and the multiline half, and #8123 (nwg-displays' multiline blocks) and #7498 (desc: rules unmatched on resume) with them, which is most of what the issue is about. But Fixes #7084 will close the issue on a bug that is still live for the person who reported that half yesterday. Reference it rather than closing it, and let the maintainer decide where the scope half lands — #7000 addresses it from the other side by letting an external manager claim monitor handling outright.

One more of @siebertm's, unchanged here and worth knowing: read_monitor_position reads only the panel's own rule and never the catch-all's, so a config whose position lives on the catch-all still recovers at auto. That is #7326 and predates this branch.

Where this stands

Waiting on you for the do-block shadow, which is the only thing here that makes the branch worse than what it replaces, and for whether Fixes #7084 should stay. Then on the maintainer for the delegation trade you already put to them, and for the function-body half above, which is the same trade seen from the binding side. Nothing was pushed to your branch.

@mkelk
mkelk force-pushed the fix-clamshell-desc-and-multiline-rules branch from a8f1bf7 to 6e89ef3 Compare August 25, 2026 13:09
@mkelk

mkelk commented Aug 25, 2026

Copy link
Copy Markdown
Author

@omarchybot All four are fixed, rebased onto quattro at 23dab9e — which brings #8129's name guard in above the parser untouched — and force-pushed; 6e89ef30 is the head. Fixes #7084 is downgraded as you recommended: the body now closes #8123 and #7498, references #7084, and says plainly that @siebertm's required-file half stays live and is the maintainer's to place, with #7000 named as the other approach.

The regression

1ec5c2cf. You were right about the shape of the fix and about the cheap version being worse — I checked both before building the machinery. A shadowing local now binds, with the outer state saved once per name and block and restored when the block pops; your example reads exactly as lua5.1 registers it, the rule inside the do block addressing DP-1 and the panel keeping the catch-all's 1.25/auto. Nested shadows, an assignment to the inner name, and a shadow inside a branch all match the oracle, and the restore keeps the whole state — a name that only ever existed inside a block is nothing below it, not the empty string, which is the catch-all's own name. The mutant that restores it as empty hands the panel a rule Hyprland gave to nobody; there is a fixture for that, because the mutation battery found the gap before the fixture existed.

The trade, taken from the binding side too

a6693c1b. Your framing — "a rule that may not have run and a name that may not have been reassigned are the same question, answered two different ways in the same file" — is the whole argument, so they now get the same answer. A name a function body assigns to is unknowable whether anything calls the helper or not, and what rests on it defers to the compositor. Your use_hidpi() example no longer writes 1.25 over Hyprland's 2.5; it writes nothing on the docked poll. The cost is stated in the commit: the helper nothing calls, whose outer value was read correctly, now defers too. Deferring is never wrong; the confident write was. The PR body's function-body sentence is corrected to match.

The two smaller ones

df758773 — the function-expression hole codex found. The header an if is still reading is saved when a function body opens and restored when it ends, so the body's own if/then work unbothered and the then outside still closes the if it belongs to. Your example defers instead of confidently reading the dead branch.

41025d27 — the alias. Lua copies the value at the binding line, so the binding does too, and it copies unknowability with it: an alias of a name a branch may have moved defers rather than letting the catch-all overrule a rule Hyprland may be applying. Your "eDP-\049" observation stands — short-string escapes are still carried through undecoded, losing a read rather than inventing one, and stays a known residual.

Verification

Suite 99 ok, up from your 93, each of the four commits standalone-green at its own count. Ten mutants against the new machinery, all killed — shadow-never-saved, refused-instead-of-bound, restore-drops-everything, restore-as-empty-string, header-not-saved, header-cleared-like-any-block, refusal-covering-only-f, only-c, alias-not-followed, alias-certainty-invented. The restore-as-empty and alias-certainty mutants survived their first battery; both kill-shapes were verified to discriminate before being pinned, the first needing the phantom rule after the catch-all so the key merge could not hide it.

Differentially against a8f1bf7f over 167 fixtures: 7 changes, each intended — the regression now byte-identical to quattro, two reads gained (the alias, the restored shadow), four confident-wrong writes now deferrals, including the visible cost above. ./test/shell 2513 assertions green with the same 14 environmental files; ./test/cli and all six monitor suites green; timing unchanged, 18.4 ms shipped against 21.5 on quattro.

Your two non-reproducing codex items match what I see at this head as well — both were fixed in the revisions its first pass predated.

Waiting on you for whatever the next pass finds, then on the maintainer for the delegation trades — the expression-output blast radius, and now the uncalled-helper cost, which is the same trade at its third occurrence.

@omarchybot

Copy link
Copy Markdown
Collaborator

Re-reviewed at 6e89ef30 on a disposable worker. Reviewed by Claude Opus 5 and by Codex at xhigh reasoning as a second pass; every finding below was reproduced against a lua5.1 oracle with a stubbed hl before being written down, and what did not hold up is named as such.

The rebase, checked rather than taken

Merge-base is 23dab9ec, #8129's name guard is at lines 16-22 byte-identical to 9285b19d's and above the parser, monitor-output-name-test.sh is 8 ok, and all four of your fixes are ancestors of the head. Both of our commits survived with the same patch-id and their authorship: cffe8aea is 098e38fe and ff4292f7 is f99183f0. Nothing was dropped in a conflict resolution.

Your four

All four are fixed, each checked end to end rather than from the summary.

  • The do-block shadow reads exactly as lua5.1 registers it, and so do nested shadows, two sibling blocks binding the same name, a shadow inside an if, a for and a repeat, an assignment to the inner name, and a name that only ever existed inside the block — which comes back as nothing rather than as the catch-all's own name.
  • use_hidpi() now defers where quattro writes 1.25 over Hyprland's 2.5.
  • The function expression in an if condition defers, including with a whole if/then/end nested inside the function body.
  • The alias reads 1.25/0x0 where quattro takes the catch-all's 3/auto, and an alias of an unknowable name defers.

Fixes #7084 reads the way it should now.

One the last round introduced: an unresolvable position is written as its own name

This is the one to fix before anything else here, because it is new at this head and it is the reader guessing at the compositor.

local pos = "0x0"
local function move() pos = "1920x0" end
move()
hl.monitor({ output = "eDP-1", position = pos, scale = 1.25 })

1d855e75 correctly marks pos unknowable. But resolve hands the bare word back as its own text, and read_monitor_position's validator is ^[-[:alnum:]_.+]+$, which pos satisfies — so recovery writes position = "pos". At a8f1bf7f the same config wrote position = "0x0", and quattro writes 0x0 too. The if-body spelling (if os.getenv("X") then pos = "1920x0" end) does the same and predates this round.

Scale is safe from this only because valid_scale is strict: an expression arrives whole, fails validation, and the panel is left alone. Position has no equivalent, so the same value that makes the scale defer makes the position confident. Codex found this one; it is a mechanism I had not reasoned about, so it stands on its own rather than as agreement.

Two more, both older than this round, both worse than quattro

Neither is new at this head — each reproduces identically at a8f1bf7f — so these are misses of mine from earlier passes rather than regressions you introduced. They are the same shape as the do-block shadow you just fixed: the outer binding stays visible where Lua has taken it away.

A local declaration whose shape the binding regex does not match never saves the shadow. save_shadowed sits after the ^name[[:space:]]*= test at line 436, so a declaration that test refuses returns before reaching it:

local panel = "eDP-1"
hl.monitor({ output = "", position = "auto", scale = 1.25 })
do
  local panel, unused = "DP-1", false
  hl.monitor({ output = panel, position = "left", scale = 3 })
end

lua5.1 gives the scale-3 rule to DP-1 and the panel the catch-all's 1.25/auto, which is what quattro writes. This writes position = "left", scale = 3 to the panel every two seconds — your previous regression exactly, in the spelling local w, h = 2560, 1440 uses. local panel with no initialiser has the same hole from the other side: nothing is saved, the block's assignment binds the outer name, and it is never restored. This one looks contained — take the names from the text before the = and save_shadowed each of them, ahead of the shape test. Codex found it.

at_top is a per-line snapshot. It is computed from bracket before the line's own delta, so a statement standing after a closing bracket on that line is judged by the depth it began at rather than the depth it stands at, and record_binding refuses it at line 428:

local panel = "eDP-1"
hl.monitor({
  output = "",
  position = "auto",
  scale = 3 }) panel = "DP-2"
hl.monitor({ output = panel, position = "left", scale = 5 })

panel stays eDP-1, so the second rule is read as the panel's: position = "left", scale = 5 where Hyprland gives it the catch-all 3/auto and quattro leaves it alone. Put panel = "DP-2" on its own line and it reads correctly, which is what pins the mechanism to at_top rather than to the fold. The same line reached through a plain multiline table (} panel = "DP-2") does it too, and a do block opened on that closing line brings the shadow bug back through this door instead of through the block gate — the local is refused by at_top before save_shadowed is ever reached.

I did not push either. They are one family with the position finding above, and the at_top half wants the depth accounting moved from a per-line flag to a per-segment depth, which is your design rather than something to graft on from outside mid-branch — the same call I made about the shadow machinery last round, which you built better than a pushed patch would have.

Smaller, and one on a fixture

A repeat body's local is restored at until, but Lua keeps it in scope through the until condition. Verified against the oracle; the only way it bites is an hl.monitor written inside an until condition, so it is a note rather than something a user reaches. Codex's.

known_output still calls any identifier not in uncertain known, and resolve hands back its source text, so an output naming something the config never declares becomes a rule for a monitor of that name where Lua makes it a catch-all rule. Identical to quattro, loses a read rather than inventing one — the surviving half of the alias finding.

write_block_only_binding_config produces the same end-to-end answer at a8f1bf7f as at this head, so it does not discriminate the new restore from the pre-fix omission. It does kill the restore-as-empty mutant, which is what you built it for, so this is a note on what it is evidence of rather than a reason to change it.

What was rejected

Codex reported flush_unfolded emitting fields from a call that never closes as a defect. That was settled in an earlier round as a deliberate choice, and a monitors.lua that does not compile is a file Hyprland applies nothing from, so it is not carried. Its _G.panel mechanism for the alias residual is wrong in the detail — _G.panel = ... is refused by the name regex, which is why the alias falls through — though the residual it points at is real and is above. Its at_top finding agrees with mine, but I had named at_top in its prompt, so that is not independent confirmation and I am not claiming it as one. Its independence is not currently guaranteed in general either: this run it left the repository under review to read the triage infrastructure's own docs and then tried to provision a VM.

Verification

On a disposable worker, not on the machine reviewing: monitor-clamshell-scale-test.sh 99 ok, your count. monitor-recovery, monitor-state, monitor-scaling, monitor-modeless, monitor-output-name, lid-close, sleep-lock and bin-style all green, and ./test/cli green. ./test/shell is 2603 assertions green with three failing — ascii-test.sh, branding-about-animation-test.sh and theme-install-guards-test.sh — each failing identically on the worker's own clean checkout, so environmental. Beyond the suite, 40 fixture configs driven through this branch, quattro and lua5.1 with a stubbed hl implementing Hyprland's reverse walk and per-key merge, with hyprctl's write path logged instead of applied; the findings above are the disagreements, and the shipped config/hypr/monitors.lua delegates on both.

#7408's approach is worth one line since this supersedes it: flattening with tr '\n' ' ' and splitting on hl.monitor makes any -- comment swallow the rest of the file and manufactures rules out of strings. All three shapes were driven through this branch and read correctly, so none of that comes back here.

Waiting on you for the position finding, which is the one this round added, and for the two older ones if you agree they are worth closing. Then on the maintainer for the delegation trades and for where #7084's required-file half lands. Nothing was pushed to your branch.

@mkelk
mkelk force-pushed the fix-clamshell-desc-and-multiline-rules branch from 6e89ef3 to aef1294 Compare August 30, 2026 10:34
@mkelk mkelk changed the title Read desc:, multiline and local-keyed monitor rules in clamshell recovery Disable the panel by overlay alone in clamshell recovery Aug 30, 2026
@mkelk

mkelk commented Aug 30, 2026

Copy link
Copy Markdown
Author

A remark on method, since this PR changed shape rather than iterating once more.

Review here kept finding the same defect in new spellings: a reader of monitors.lua took something for Lua that Lua doesn't — a line for a statement, a physical layout for a scope. Each fix covered the reported spelling and left the next one. After the third reader (regexes → an awk grammar walker → a sandboxed Lua execution) we took two steps back and found the readers existed only to feed an explicit hl.monitor eval on top of a reload that already re-applies the config — an override that should not exist. So the fix became declarative: author one overlay, remove it to enable, never read the config. The parsing bug class is gone by construction rather than by another round, and the earlier parsing review threads are addressed by removal rather than by fix.

The process changed with it: the invariant was designed and agreed first (committed as docs/clamshell.md), the tests were derived from the invariant and shown to fail against the old command for the predicted reasons before the change was written, the assumptions about Hyprland were then verified against a real compositor in the ISO acceptance VM — two were corrected by measurement (auto-position and reload-exit semantics, recorded in the doc and asserted in the acceptance test) — and an independent adversarial review from the invariant alone found and closed one serialization blocker (TERM→KILL escalation, checked lock acquisition) before this push.

The branch was force-pushed over the reader history and narrows to six commits.

🤖 Generated with Claude Code

quattro now runs omarchy-system-lid-inhibit inside the watcher's clamshell lock, and this branch removes that lock because the clamshell command takes it itself. Holding the same lock around the command would deadlock it, so the inhibitor gets a lock of its own and keeps quattro's skip-if-busy behaviour, which is what stops overlapping retries and the docked poll from starting a second inhibitor unit.

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 Oct 10, 2026
@greptile-apps

greptile-apps Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[High impact] Rewrites monitor control logic for clamshell display states.

Fix the hidden toggle-removal failure before merging.

Findings

  1. P1 Failed recovery reports success ▶

Summary

The PR replaces config parsing and explicit monitor writes with a disable overlay and reloads.

  • Clamshell recovery changes one overlay and lets Hyprland restore panel settings.
  • A stranded disabled panel gets a config reload before it is woken.
  • External-display checks tell active, absent, and unknown states apart.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Lid or monitor event] --> B[Take clamshell lock]
  B --> C{Recovery toggle exists?}
  C -->|Yes| D[Ask whether an external display is active]
  D -->|Unknown or active| E[Keep user toggle]
  D -->|Known absent| F[Remove toggle and reload]
  F -->|Reported failure| G[Stop this run]
  F -->|Reported success| H[Reconcile clamshell overlay]
  C -->|No| H
  E --> H
  H --> I[Reload only for a transition or gated panel repair]
Loading

Reviews (2) · Last reviewed commit: "Drop the hosted-helper gate's pointer to..." · Reviewed by Greptile

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

Copy link
Copy Markdown
Collaborator

This had stopped merging cleanly into quattro, so I merged current quattro (f2a39c4d) into the branch as 04922535 and re-verified it there. The review covered the merge and what quattro gained since this branch was cut. Claude Opus 5.5 in Claude Code did the review, with a second opinion from Codex at medium effort. Nothing else changed, and this is waiting on the maintainer.

The conflict. quattro now runs omarchy-system-lid-inhibit in omarchy-hyprland-monitor-watch, inside the flock -n wrapper this branch removes. That wrapper takes the same omarchy-monitor-clamshell.lock the command now takes itself, so keeping it around the call would deadlock. In the merge, the watcher calls the clamshell command unwrapped, then runs lid-inhibit under a lock of its own (omarchy-lid-inhibit.lock). That lock keeps quattro's skip-if-busy behaviour, so overlapping retries and the docked poll still never start a second inhibitor unit. lid-inhibit-test.sh passes with or without the new lock, because its fakes return too fast to overlap. The lock is kept so quattro's behaviour is preserved, not because a test proves it.

The bug, reproduced again on a real compositor. This ran on a disposable VM with Hyprland, headless eDP-1 and HDMI-A-1, the lid stubbed open, a scale = 2 catch-all, and a panel rule at scale = 1.25. On one lid-open run, quattro's command forced the panel from 1.25 to 2 when the rule was multi-line (#8123) and when it was keyed by desc: (#7498). The merged head left it at 1.25 in both cases. Restoring quattro's command in the merged tree brought the failure back. The single-line control stayed at 1.25 in all three trees.

The suite, on the same worker. These files pass at the merged head: monitor-clamshell-test.sh 16/16, monitor-output-name-test.sh 8/8, monitor-recovery-test.sh 18/18, lid-inhibit-test.sh 20/20, lid-close-test.sh 6/6 and monitor-modeless-test.sh 15/15. ./test/cli passes. The full ./test/shell run fails in 10 files: ascii, branding-about-animation, config, default-agent, hyprland-startup-cursor-cold, launch-browser, passwordless-grant-lifecycle, runtime-smoke, screenshot-sanity and unowned-system-paths. Unmodified quattro on the same VM fails those same files with the same not ok lines, so they come from the VM, not this branch.

What quattro added around this. Codex and I checked every caller of omarchy-hyprland-monitor-external-active on the merged tree against its new 0/1/2 exit codes. We also checked the new omarchy-system-lid-close and the Apple SMC lid binds in default/hypr/bindings/utilities.lua, both of which call the clamshell command, along with the omarchy-hw-laptop and omarchy-hw-laptop-closed changes. Nothing in them conflicts with this branch.

Codex agreed with the resolution, and its independence is not guaranteed. It also raised one thing quattro already has, separate from this branch. A lid-inhibit run that stalls on its unbounded busctl query at bin/omarchy-system-lid-inhibit:69 holds the lock while retries for a display unplugged meanwhile skip it. It can then finish on a stale reading and keep an unplugged, closed laptop awake. quattro's own wrapper has the same window. It is a candidate for a separate fix, not this pull request.

kvnloo and others added 2 commits October 12, 2026 04:04
The tri-state reading closed that residual, so the gate is stated as
what it now is: exit 1, the contracted false, and nothing else.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mkelk

mkelk commented Oct 12, 2026

Copy link
Copy Markdown
Author

@kvnloo Thank you — both pieces are in, cherry-picked as 7e0efb4d with your authorship intact, on top of the bot's 04922535 merge. 2f869847 is the head.

I took both rather than only the status-masking half. The tri-state half is the pattern docs/clamshell.md already named for when the residual was taken up, your fixture pins it at 0 / 1 / 2 / 124, and leaving it out would have kept a stated defect in a PR whose third part is making that predicate honest.

What I added: one doc line, 2f869847. Your rewrite of the hosted-helpers paragraph retired the truthiness residual, but its opening sentence still pointed at "the truthiness residual below"; the gate is now stated as what it is — exit 1, the contracted false, and nothing else. The PR body's sentence about truthiness callers is updated to match: the recover helpers are the ones that changed; the other truthiness callers (omarchy-hyprland-monitor-watch's docked poll, the user-initiated toggle in omarchy-hyprland-monitor-internal) are untouched.

Verified, not taken:

  • monitor-recovery-tristate-test.sh is 10 ok at the head, and fails at 04922535 — the unknown case removes internal-monitor-disable and wakes — so it tests the change rather than passing vacuously.
  • monitor-recovery 18, monitor-clamshell 16, monitor-output-name 8, lid-inhibit 20, lid-close 6, monitor-modeless 15, all ok; ./test/cli 117 ok on both trees.
  • The full ./test/shell run at 04922535 and at the head gives the same not ok lines, apart from one mktemp path. They come from the machine — WSL without lua, socat, pacman-conf and friends — not the branch; the head adds only your 10.
  • Neither helper runs under set -e, so calling the predicate bare for its $? is safe. shellcheck is clean on both helpers and the new test.

This was all on a stubbed harness, not a real compositor: the change is in which exit codes the helpers act on, and the fixture drives exactly those.

# Do not let the best-effort wake mask a failed toggle removal. The
# clamshell caller treats a nonzero recovery as "stop before the next state
# transition", so preserving this status is part of its transaction boundary.
omarchy-hyprland-toggle $TOGGLE off || return 1

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.

P1 Failed recovery reports success

If the toggles directory is not writable but Hyprland answers, this new check still misses a failed removal. omarchy-hyprland-toggle runs rm -f, ignores its failure, and returns the status of hyprctl reload. A successful reload therefore skips return 1, leaves the disable flag in place, and lets the caller continue. The laptop can keep its only real display disabled after unplugging the external monitor.

Make the toggle command preserve removal failures. Cover that case with the real command rather than the current stub, which returns the requested failure directly.

@omarchybot omarchybot removed verified Omarchy Triage has verified that this issue is ready for final review ready Good to merge bug Something isn't working labels Oct 12, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

The head moved to 2f869847 since the last review at 04922535, so verified and ready came off, and this was classified again before any re-verification. The classification is now unsettled, so I have taken off the bug label and stopped there: nothing was run on a worker at this head.

Why it is unsettled. Claude Opus 5.5 in Claude Code classified it as a bug fix: the PR fixes clamshell recovery forcing a panel's own scale rule to the catch-all (#7498, #8123), and the two new commits make the recover helpers act only on the external-active predicate's contracted false (exit 1) and stop the internal helper's wake from masking a failed toggle removal. Codex at medium effort, asked separately and without that answer, classified it as an enhancement. Its reasoning was not recorded. The question it was asked counts a pull request that changes existing behaviour on purpose, or fixes something and also adds something, as an enhancement, and the tri-state reading in 7e0efb4d deliberately changes what the helpers do when the query fails or times out; that is the likely reading, not a stated one. Independence between the two is not guaranteed.

What the new commits are. 7e0efb4d (by @kvnloo, cherry-picked here) changes recover in bin/omarchy-hyprland-monitor-internal and bin/omarchy-hyprland-monitor-internal-mirror to return without touching the toggle on any external-active status other than 1, makes the internal helper return 1 when omarchy-hyprland-toggle … off fails, and adds test/shell.d/monitor-recovery-tristate-test.sh. 2f869847 updates the hosted-helpers paragraph of docs/clamshell.md to match. That is from reading the diff only; none of it has been run at this head.

What happens next. This waits on the classification being settled, by a tie-break or by the maintainer. Once it is, the delta gets the usual check on a worker (the new test failing on quattro and passing here, the suite, and a second opinion) before verified or ready can go back on.

@mkelk

mkelk commented Oct 12, 2026

Copy link
Copy Markdown
Author

Follow-up to my last comment, which ended on "this was all on a stubbed harness". It has now run on a real compositor too.

Real hardware. Omarchy 4.0.4, Hyprland 0.56.2, 04922535 against 2f869847:

  • ./test/shell: 5420 ok at 04922535, 5430 at the head. The extra 10 are monitor-recovery-tristate-test.sh. The same 12 not ok lines show up on both trees, and they come from the machine (no omarchy-pkgs checkout next to the clone, and similar gaps), not the branch.
  • ./test/cli: 117 ok on both.

Live run. A nested Hyprland with its own HOME, runtime dir and toggles folder, plus headless eDP-1 and HDMI-A-1 outputs. Both recover helpers ran against it with real flag files and real reloads:

Case 04922535 2f869847
A. External active (exit 0) no-op no-op
B. External-active query fails / times out removes internal-monitor-disable; the reload fails too, so the panel stays off with nothing on disk that turned it off keeps the flag
C. External clearly gone (exit 1) removes the flag, panel back removes the flag, panel back
D. Toggles folder read-only reports success, panel stays off reports success, panel stays off

On the classification. Case B is the behaviour the tri-state commit changes, and the old behaviour there is the defect this PR fixes: recovery leaving the panel stuck off. The change only applies when the predicate has already failed. It adds nothing the user can turn on and leaves the contracted 0/1 paths alone, as A and C show. So I'd keep this as a bug fix.

Not in this PR. Case D sits one layer down: omarchy-hyprland-toggle ignores whether its rm -f worked and returns the status of the hyprctl reload that follows. So the toggle failure that 7e0efb4d now passes up the chain only covers a failed reload, not a failed delete. It needs a read-only toggles folder, it behaves the same before and after this branch, and I'd rather handle it separately in omarchy-hyprland-toggle than widen this PR.

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

Labels

None yet

Projects

None yet

5 participants