Skip to content

omamobile-shell: serialize overlapping power-key actions - #508

Merged
derekross merged 3 commits into
derekross:mainfrom
Gr-linkk:power-key-serialization
Nov 10, 2026
Merged

derekross merged 3 commits into
derekross:mainfrom
Gr-linkk:power-key-serialization

Conversation

@Gr-linkk

@Gr-linkk Gr-linkk commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

A second short power-key release can arrive while the first action is still locking and turning the panel off. Both actions then see a lit screen, and the second can save zero brightness or leave the phone dark when it should wake.

Serialize short actions with flock so each sees the completed display transition. Capture the release timestamp before waiting so presses within the existing 800 ms debounce interval still count as bounce. Close the lock descriptor in the action subprocess so background helpers cannot retain it.

In response to Derek's review, limit lock acquisition to five seconds. If it fails, drop that press with omamobile-keys: short-press lock wait failed; dropping press on stderr, without changing debounce or display state. This preserves mutual exclusion instead of starting concurrent display transitions. It does not kill or repair the original stuck helper; fresh presses can act once that action releases the lock.

The host regression now uses an eight-second lock helper to verify bounded waiting, diagnostic output, unchanged state and a successful wake after release. Its PATH contains only stubs and explicitly linked test utilities, so future unstubbed desktop commands cannot run on the host.

Offline validation

  • Original overlap regression reproduces the wrong screen state on main and passes with serialization: later wake, 0.2-second debounce, preserved brightness and no lock-descriptor inheritance.
  • New blocked-press regression fails against the previous PR head's unbounded wait and passes with the five-second bound.
  • Touched package suite tests/packages omamobile-shell passes.
  • Focused independent review: no findings.
  • Repository tests/all, tools/pr-check against the PR base, and whitespace checks pass.

Remaining phone qualification — keep draft

No phone was accessed for this follow-up. A phone-smoke report at the updated candidate and the following physical checks remain required: presses about one second apart during screen-off restore the old brightness; presses about 0.2 seconds apart produce one action; secure-lock press reaches the PIN pad; long press still opens the system menu. Derek offered to perform this on his Pixel 7 Pro if the Pixel 6 is unavailable. The Pixel 6 remains reserved for separate battery work.

Historical Pixel 6 evidence from 2026-11-05 used local shell 0.2.15 and kernel 7.3.0-rc6-oriole-hsi1-late-dev0-g4bd35d34abb9-dirty: guarded software overlap restored brightness/DPMS and the owner observed a physical off/wake pair. That is not validation of this candidate. Secure-lock, physical rapid-overlap and reboot paths remain unqualified here.

The existing draft package version is 0.2.102; Derek will assign the final version at merge. Independent of #421 (no battery/glyph changes). #420 changes the same handler; whichever lands second must reconcile it and rerun the overlap test.

Prepared with AI assistance (Codex).

A second short press can arrive while the first is still locking and
powering the panel off. Serialize short actions so the later press sees
the completed transition. Use the captured release time for debounce,
and close the lock descriptor in the action subprocess so background
helpers cannot keep it held.

The focused host regression fails against main with the wrong screen
state and passes with this fix, covering wake, debounce, brightness
preservation and lock descriptor inheritance.

Co-Authored-By: Codex <noreply@openai.com>
@derekross

Copy link
Copy Markdown
Owner

Thank you, @Gr-linkk, for chasing this. The double press that left the phone dark is a real annoyance, and serializing the short action is a clean way to fix it. I like the details: the release time is taken before the wait, so the 800 ms debounce still means what it did, and the lock fd is closed in the subshell, so omamobile-sleepd now & can't hold it. Your new test fails with main's script and passes with yours, which is exactly what I want from a regression test.

One change, please: bound the wait. flock "$short_lock" waits forever, so if one short-press action hangs (a stuck omarchy-shell IPC call or hyprctl, say), every later Power press queues behind it and the key stops working until that one returns. Before this change, a hung press only hurt itself. I tried it in your harness with omarchy-system-lock sleeping 12 s: with your change the second press acted 15 s after the first, against 1.6 s on main. Something like flock -w 5 "$short_lock" || true would keep your fix for the normal case and let the key work again after a few seconds if something hangs. Dropping the press with a log line would be fine too; just say which you chose. A test case with a lock stub that sleeps longer than the bound would round it off.

Before it merges it also needs a run on a phone at this head. The shell runs on every phone, and this changes the power key on my 7 Pro too. If you can boot it on your Pixel 6, please paste a tools/phone-smoke report and say how these went: two presses about a second apart while the screen is going dark (it should wake at the old brightness), two about 0.2 s apart (one action), a press with a secure lock (PIN pad), and a long press (still the system menu). Otherwise I'll do the same on my 7 Pro.

A small, optional one: test/power-overlap.sh keeps the host's PATH after your fakes. Everything it reaches today is stubbed, but if a future change calls an Omarchy command you didn't stub, the test would run the real one on the build machine, and on an Omarchy desktop that can lock it or turn its screen off. Linking just the real tools it needs (jq, flock, date) into $t/bin and using that alone as PATH would rule that out.

I'll set the version at merge, since 0.2.102 is also taken by a few other open shell PRs, and the title will become omamobile-shell 0.2.1xx: serialize power-key actions. #420 changes the same handler, so whichever lands second gets your overlap test re-run. Thanks again!

Drop a short press with a diagnostic after five seconds waiting for the
previous action. Keep display transitions serialized without queueing
later presses indefinitely behind a stuck helper.

The regression fails against the previous unbounded wait and passes with
the timeout, preserving debounce/display state and recovering after the
holder exits. Restrict its PATH to explicit utilities and desktop stubs.
Keep the existing draft version; the maintainer will assign it at merge.

Co-Authored-By: Codex <noreply@openai.com>
@derekross

Copy link
Copy Markdown
Owner

Thank you, @Gr-linkk. The bound is exactly what I was after: a press
that can't get the lock in 5 s is dropped with a log line, the debounce
and the screen are left alone, and your new test proves both sides, the
drop and the press that works again afterwards. Thanks for tightening the
test's PATH too.

#420 (double tap to wake) merged last night and changes the same script.
Your branch merges with it except for the version file, which I'll set
at merge (main is at 0.2.107 now), and I ran your overlap test on the
merged tree: both cases pass.

One question that #420 raises, not a condition: its two new actions,
double-tap (wake) and dark-unlocked (lock and darken), also change
the screen, and they don't take your lock. The windows are narrow (a
double tap just as a Power press finishes darkening and asks for sleep,
for example), but taking the same lock with the same bound in those two
would make "one screen change at a time" hold for every caller. Would you
like to extend it here, or leave it for a follow-up? Either is fine.

Since your Pixel 6 is busy with the battery work, I'll do the phone run
on my 7 Pro with main plus your change: the double press about a second
apart while it darkens, two quick presses, a press on the secure lock, a
long press, and a double tap right after Power darkens the screen. I'll
post the results here and merge once they pass. Thanks again!

# Conflicts:
#	packages/omamobile-shell/test/all
#	packages/omamobile-shell/version
@derekross
derekross merged commit 3734c82 into derekross:main Nov 10, 2026
2 checks passed
@derekross

Copy link
Copy Markdown
Owner

Merged as omamobile-shell 0.2.112. On my 7 Pro the overlapping presses, the two quick presses, the locked wake, the long press and a double tap just after Power all behaved. Thank you, @Gr-linkk. The open question about #420's double-tap and dark-unlocked actions taking the same lock can be a follow-up if you think it's worth it.

robertzas pushed a commit to robertzas/omarchy-mobile that referenced this pull request Nov 14, 2026
…ekross#508)

* omamobile-shell 0.2.102: serialize power key actions

A second short press can arrive while the first is still locking and
powering the panel off. Serialize short actions so the later press sees
the completed transition. Use the captured release time for debounce,
and close the lock descriptor in the action subprocess so background
helpers cannot keep it held.

The focused host regression fails against main with the wrong screen
state and passes with this fix, covering wake, debounce, brightness
preservation and lock descriptor inheritance.

Co-Authored-By: Codex <noreply@openai.com>

* omamobile-shell 0.2.102: bound the power-key lock wait

Drop a short press with a diagnostic after five seconds waiting for the
previous action. Keep display transitions serialized without queueing
later presses indefinitely behind a stuck helper.

The regression fails against the previous unbounded wait and passes with
the timeout, preserving debounce/display state and recovering after the
holder exits. Restrict its PATH to explicit utilities and desktop stubs.
Keep the existing draft version; the maintainer will assign it at merge.

Co-Authored-By: Codex <noreply@openai.com>

---------

Co-authored-by: Gr-linkk <280405187+Gr-linkk@users.noreply.github.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Derek Ross <derekross@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants