Skip to content

fix(agent): reuse inventory channels for input capture - #522

Open
safonin wants to merge 4 commits into
AprilNEA:masterfrom
safonin:fix/agent-capture-channel-sharing
Open

fix(agent): reuse inventory channels for input capture#522
safonin wants to merge 4 commits into
AprilNEA:masterfrom
safonin:fix/agent-capture-channel-sharing

Conversation

@safonin

@safonin safonin commented Aug 5, 2026

Copy link
Copy Markdown

Summary

Make Agent input capture reuse the HID++ channel already owned by persistent
inventory instead of opening a competing handle for the same OS node.

This is an infrastructure-only change. It does not change the IPC or config
schema and does not add GUI behavior.

Changes

  • hid: add a node-owned ChannelRegistry that publishes exact direct,
    Bolt, and Unifying routes from settled inventory, with stable collision
    handling and quiescent retirement before a node is reopened.
  • hid: run capture on the registry-selected channel in Agent mode, fail
    closed on a registry miss, and preserve route-opening behavior for standalone
    callers.
  • agent-core: distinguish graceful capture shutdown from connection
    revocation, and wait for the old capture epoch to release its listener and
    channel before starting a replacement.
  • agent: keep one registry in SharedRuntime and pass it to both the
    persistent inventory and gesture watchers.
  • tests: cover exact-route lookup, competing-node promotion, poisoned-lock
    recovery, publication and retirement, registry misses, stale connection
    revocation, teardown ordering, replacement acknowledgement, and standalone
    compatibility.

Testing

cargo test -p openlogi-hid gesture -- --nocapture
cargo test -p openlogi-agent-core watchers -- --nocapture
cargo test -p openlogi-agent pairing -- --nocapture
cargo fmt --all -- --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
RUSTDOCFLAGS=-Dwarnings cargo doc -p openlogi-hid --no-deps --document-private-items
git diff --check upstream/master...HEAD

The same registry/capture implementation was runtime-tested on macOS with an
MX Keys connected over Bluetooth-direct while validating the full feature
stack: inventory remained visible and the keyboard remained usable. This
reduced branch was not rerun independently on hardware after extraction.

Receiver hardware was not runtime-tested for this PR.

Part of #521

@greptile-apps

greptile-apps Bot commented Aug 5, 2026

Copy link
Copy Markdown

Greptile Summary

The PR makes Agent input capture reuse channels owned by persistent HID inventory, coordinating channel publication, retirement, revocation, teardown, and replacement without changing IPC or configuration schemas.

  • Adds an exact-route channel registry with stable collision selection.
  • Publishes settled inventory channels and retires stale connections before reopening nodes.
  • Adds registry-backed capture and explicit graceful-versus-revoked shutdown behavior.
  • Coordinates capture epochs so replacement waits for listener, channel, and receiver-lease teardown.
  • Wires one shared registry through the Agent runtime and expands lifecycle coverage.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete changed-code failure remaining after reviewing channel publication, retirement, capture revocation, replacement ordering, and pairing exclusion.

Registry removal makes stale capture connections observable, capture teardown releases listeners and channel references before acknowledgement, and deferred reopening prevents concurrent ownership of the same HID node while preserving standalone route-opening behavior.

Important Files Changed

Filename Overview
crates/openlogi-hid/src/channel_registry.rs Introduces exact-route publication, stable collision winners, identity-based currentness checks, and poison-safe publisher updates.
crates/openlogi-hid/src/inventory.rs Adds active/retiring channel ownership, registry publication from settled inventory, and deferred reopening after stale channels become quiescent.
crates/openlogi-hid/src/gesture.rs Refactors capture onto supplied shared channels and distinguishes graceful disarming from stale-connection revocation.
crates/openlogi-agent-core/src/watchers/gesture.rs Adds registry-backed capture lifecycle management and waits for stopped epochs to release resources before replacement.
crates/openlogi-agent-core/src/watchers/inventory.rs Adds a registry-aware persistent inventory watcher while preserving the standalone watcher entry point.
crates/openlogi-agent-core/src/orchestrator.rs Adds one shared channel registry to the Agent runtime.
crates/openlogi-agent/src/main.rs Passes the same registry to inventory and gesture watchers so capture reuses inventory-owned channels.

Sequence Diagram

sequenceDiagram
  participant Inventory as Inventory watcher
  participant Registry as ChannelRegistry
  participant Capture as Gesture watcher
  participant Device as HID++ channel

  Inventory->>Device: Open and probe node
  Inventory->>Registry: Publish exact routes and channel
  Capture->>Registry: Lookup active target route
  Registry-->>Capture: Shared inventory-owned channel
  Capture->>Device: Arm controls and listen
  Inventory->>Registry: Remove stale publication
  Capture->>Registry: Check channel identity
  Registry-->>Capture: Connection revoked
  Capture->>Capture: Clear slot and drop listener/channel
  Capture-->>Inventory: Old channel becomes quiescent
  Inventory->>Device: Reopen on a later poll
  Inventory->>Registry: Publish replacement channel
  Capture->>Registry: Lookup and start replacement
Loading

Reviews (1): Last reviewed commit: "fix(agent): wire shared capture registry" | Re-trigger Greptile

@davidbudnick
davidbudnick self-requested a review August 8, 2026 19:26
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.

1 participant