Skip to content

feat(agent): unify button Down/Up/Cancel lifecycle - #933

Merged
AprilNEA merged 3 commits into
masterfrom
feat/unified-button-lifecycle
Aug 25, 2026
Merged

feat(agent): unify button Down/Up/Cancel lifecycle#933
AprilNEA merged 3 commits into
masterfrom
feat/unified-button-lifecycle

Conversation

@AprilNEA

@AprilNEA AprilNEA commented Aug 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • Establish one source-independent button lifecycle shared by OS hooks, HID++ mouse capture, and HID++ keyboard capture.
  • Model producer inputs and runtime outputs as separate typed enums so invalid combinations such as Up + action or a source-authored cancellation are unrepresentable.
  • Guarantee exactly one terminal Ended event for each accepted press while preserving existing one-shot action and gesture behavior.

Changes

  • openlogi-device
    • Diff complete HID++ held-control snapshots into deduplicated ButtonDown / ButtonUp edges.
    • Keep firmware-only taps as balanced pulses and remove the unused frontmost-PID payload from local capture events.
  • openlogi-agent-core
    • Organize the subsystem under runtime.rs, with the hidden lifecycle state machine in runtime/button.rs and OS-hook interpretation in runtime/hook.rs.
    • Accept typed Down, Up, Pulse, and TriggerWhilePressed inputs and emit Started, Ended(Released | Canceled(reason)), and Triggered outputs.
    • Give every accepted press a unique PressToken; stale timers, gestures, and superseded presses cannot trigger newer lifecycles.
    • Correlate HID++ traffic with an exact device-plus-epoch HidppSessionId rather than independent primitive fields.
    • Keep active state in one bounded, non-blocking worker with generation invalidation, source-scoped cancellation, startup error propagation, and bounded shutdown/join ownership.
    • Replace anonymous watcher tuples and parallel optional state with named session, target, input, and completion types.
    • Move large inline test modules into sibling test files and add coverage for exact identity, stale work rejection, typed cancellation, and shutdown behavior.
  • openlogi-agent
    • Own the lifecycle worker through a named ActionServices aggregate, abort startup when the worker cannot start, and shut it down after the hook stops.
    • Cancel only OS-hook presses on Accessibility loss, leaving independent HID++ capture active.

Testing

  • export RUSTFLAGS="-D warnings"; cargo fmt --all -- --check && cargo clippy --workspace --all-targets -- -D warnings && cargo test --workspace && RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items --exclude openlogi-ui --exclude openlogi-desktop --exclude openlogi-overlay --exclude openlogi-agent
  • cargo test -p openlogi-agent-core -p openlogi-agent
  • cargo clippy -p openlogi-agent-core -p openlogi-agent --all-targets -- -D warnings
  • RUSTDOCFLAGS="-D warnings" cargo doc -p openlogi-agent-core --no-deps --document-private-items
  • cargo xtask ci clippy-windows
  • cargo xtask ci wasm
  • Not runtime-tested on physical Logitech hardware; verified in a Linux orb.

Fixes #930

Co-authored-by: Xuan Zhang <xuan@arcbox.dev>
Copilot AI lite review requested due to automatic review settings August 24, 2026 15:18

Copilot AI left a comment

Copy link
Copy Markdown

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.

@greptile-apps

greptile-apps Bot commented Aug 24, 2026

Copy link
Copy Markdown

Greptile Summary

The PR consolidates OS-hook and HID++ button handling into one tokenized lifecycle worker.

  • Normalizes source events into typed down, up, pulse, and trigger inputs.
  • Correlates presses with source/session identity and rejects stale work.
  • Adds bounded startup and shutdown ownership plus lifecycle regression coverage.
  • Updates gesture and keyboard capture to emit deduplicated lifecycle edges.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
crates/openlogi-agent-core/src/runtime/button.rs Implements the unified tokenized lifecycle state machine and fixes the prior shutdown-bound issue with a separate unbounded shutdown channel.
crates/openlogi-agent-core/src/runtime.rs Owns the lifecycle worker and exposes source-independent action dispatch and cancellation operations.
crates/openlogi-agent-core/src/runtime/hook.rs Adapts OS-hook events to the unified button lifecycle while retaining non-blocking fail-open handling.
crates/openlogi-agent-core/src/watchers/gesture.rs Correlates HID++ gesture input with exact capture sessions and press tokens.
crates/openlogi-agent/src/main.rs Integrates lifecycle-worker startup and bounded shutdown into agent ownership.
crates/openlogi-device/src/session/gesture.rs Converts held-control snapshots into deduplicated edges and balanced firmware-only pulses.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  OS[OS hook] -->|Down / Up| Worker[Button lifecycle worker]
  Mouse[HID++ mouse] -->|Down / Up / Pulse| Worker
  Keyboard[HID++ keyboard] -->|Down / Up / Pulse| Worker
  Worker -->|Started| Executor[Action executor]
  Worker -->|Triggered while token is live| Executor
  Worker -->|Ended: Released or Canceled| Terminal[Terminal lifecycle event]
  Shutdown[Out-of-band shutdown request] --> Worker
Loading

Reviews (3): Last reviewed commit: "refactor(agent): organize action runtime..." | Re-trigger Greptile

Comment thread crates/openlogi-agent-core/src/button_runtime.rs Outdated
AprilNEA and others added 2 commits August 24, 2026 16:12
Co-authored-by: Xuan Zhang <xuan@arcbox.dev>
Co-authored-by: Xuan Zhang <xuan@arcbox.dev>
@AprilNEA
AprilNEA merged commit 8fd2e38 into master Aug 25, 2026
21 checks passed
@AprilNEA
AprilNEA deleted the feat/unified-button-lifecycle branch August 25, 2026 02:44
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.

Unify button Down/Up/Cancel lifecycle across OS hook and HID++ capture

2 participants