Skip to content

fix(agent): prefer online device for input capture#453

Open
Phecda wants to merge 2 commits into
AprilNEA:masterfrom
Phecda:fix/prefer-online-capture-target
Open

fix(agent): prefer online device for input capture#453
Phecda wants to merge 2 commits into
AprilNEA:masterfrom
Phecda:fix/prefer-online-capture-target

Conversation

@Phecda

@Phecda Phecda commented Jul 23, 2026

Copy link
Copy Markdown

Summary

Keep programmable input capture on a usable device when the persisted GUI selection is offline.

Changes

  • openlogi-agent-core: prefer the saved GUI selection while it is online, otherwise use the first online device, and preserve the saved selection when every device is offline.
  • Rebuild the live bindings and HID++ capture target when an online-state transition changes the runtime selection without changing device keys or routes.
  • Add regression coverage for saved online, saved offline, all-offline, and online-only transition cases.

Testing

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test --workspace
  • Hardware-tested on macOS 26.5.2 with an MX Master 3S over Bluetooth direct while an offline Unifying device was selected; programmable buttons remained active through the online fallback.

Fixes #452

@Phecda
Phecda marked this pull request as ready for review July 23, 2026 07:24
@greptile-apps

greptile-apps Bot commented Jul 23, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes input capture falling silent when the persisted GUI device selection is offline. pick_current now prefers the saved selection only while it is online, falls back to the first online device otherwise, and preserves the saved selection when all devices are offline so configuration stays stable until a device reconnects.

  • pick_current is rewritten with a three-step chain: saved-if-online → first-online → saved-offline-fallback → index 0.
  • refresh_inventory computes next_current eagerly and folds it into the changed predicate, so an online-state transition that shifts the active device triggers a rebuild() even when device keys, routes, and capabilities are unchanged.
  • Four unit/integration tests cover saved-online, saved-offline-fallback, all-offline, and the online-transition-without-set-change path.

Confidence Score: 5/5

Safe to merge — the online-preference logic in pick_current is correct, the changed guard correctly triggers a rebuild on selection shifts, and reload_config naturally inherits the same semantics.

The three-step fallback chain in pick_current handles all four cases (saved online, saved offline with online peer, all offline, no saved selection) correctly, confirmed by manual trace and the four new tests. The changed predicate extension is a superset of the previous check: it fires on every case the old predicate did, plus online-state-induced selection changes. No pre-existing invariants are broken.

No files require special attention.

Important Files Changed

Filename Overview
crates/openlogi-agent-core/src/orchestrator.rs Core logic change: pick_current gains online-aware fallback; refresh_inventory adds next_current != self.current to the changed guard and moves selection before plan_reapply. Tests cover all documented cases. Logic is correct and consistent with the reload_config path.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[pick_current: devices + saved key] --> B{saved key in device list?}
    B -- No --> E
    B -- Yes, index S --> C{devices at S is online?}
    C -- Yes --> D[return S - prefer online saved]
    C -- No --> E{any online device?}
    E -- Yes --> F[return first online index]
    E -- No --> G[return S - all-offline preserve]
    D --> Z[current index]
    F --> Z
    G --> Z
    Z --> I{next_current != self.current?}
    I -- Yes --> J[self.current = next_current + rebuild shared maps]
    I -- No --> K[update devices only, skip rebuild]
Loading

Reviews (2): Last reviewed commit: "docs(agent): clarify inventory selection..." | Re-trigger Greptile

@Phecda Phecda closed this Jul 23, 2026
@Phecda Phecda reopened this Jul 23, 2026
@Phecda
Phecda force-pushed the fix/prefer-online-capture-target branch 2 times, most recently from 21fba99 to b9e84f3 Compare July 23, 2026 08: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.

[Bug]: Offline saved device steals input capture from online device

1 participant