Skip to content

feat: stable device indexing across hot-plug events #9

@malpern

Description

@malpern

Summary

Make device indices survive unplug/replug cycles by mapping devices to persistent identifiers instead of using monotonically increasing counters.

Builds on the device identity pipeline from PR #5.

What this includes

  1. Persistent device identification — Use a combination of vendor ID, product ID, device name, and optionally serial number or physical port path to create a stable device fingerprint
  2. Index reservation — When a known device disconnects and reconnects, it gets the same index back
  3. Config-driven ordering — If (defdevice ...) is used (feat: name-based device matching and defdevice config #6), the config order can determine stable indices
  4. Graceful handling of new devices — Devices not seen before get the next available index

Why

Currently next_device_index increments on every register_device() call, including re-registrations after rediscover_devices(). This means a USB keyboard that gets bumped out and plugged back in gets a different index, breaking any (device N) rules.

Platform considerations

  • Linux: Can use /dev/input/by-id/ symlinks or evdev device properties (vendor, product, uniq)
  • Windows: Interception provides device handles with stable HW IDs
  • macOS: IOHIDManager provides vendor/product ID and transport info

Dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions