fix: self-heal the LCD after USB write failures (reconnect + open() correctness)#2
Open
tekgnosis-net wants to merge 5 commits into
Open
fix: self-heal the LCD after USB write failures (reconnect + open() correctness)#2tekgnosis-net wants to merge 5 commits into
tekgnosis-net wants to merge 5 commits into
Conversation
Pure, hardware-free state machine for failure-streak demote/reconnect decisions, exit-to-systemd timing, and throttled error logging. 7 unit tests.
lcd_failure_threshold, lcd_reconnect_interval_ms, lcd_exit_after_ms, lcd_error_log_interval_ms with sane defaults.
…back Interface 1 is the only display interface (output-only, no hidraw node). The old devices.first() fallback could open interface 0 (input device).
…hrottle) Record every device write outcome into LcdHealth. On a sustained failure streak, drop the handle to None (releasing the libusb claim) so the existing try_lcd_reconnect() reopens it; throttle the error log; and exit-to-systemd as a last resort. Replaces error-propagation at the heartbeat/render call sites.
Replace the hard-coded 30s reconnect rate-limit with lcd_reconnect_interval_ms (default 5s) for faster recovery. The main.rs loop log-throttle is already correct as of 0.8.1, so it is left unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The daemon opens the LCD once at startup. If the device hits a USB write failure or re-enumerates mid-run, nothing re-establishes it — the panel reverts to its built-in default screen and stays there until the service is manually restarted. The existing
try_lcd_reconnect()only triggers when the device was absent at startup (lcd == None); it never fires for a device that was working and then dropped, because nothing ever sets the handle back toNone.Changes
LcdHealth— a small, hardware-free state machine that tracks consecutive write outcomes. After N consecutive failures (default 10) it demotes the handle toNone(dropping theHidDevicereleases the libusb interface claim), which lets the existingtry_lcd_reconnect()reopen the device. If recovery keeps failing past a configurable window, it exits sosystemdrelaunches a fresh process. Transient single failures (interspersed with successes) never trip the threshold.open()correctness — require the display interface (interface 1, output-only) and drop the fallback that could open the wrong (input) interface.lcd_failure_threshold,lcd_reconnect_interval_ms,lcd_exit_after_ms,lcd_error_log_interval_ms).hidrawnode, so hidraw can't drive it.Testing
LcdHealthlogic (threshold, success-reset, exit-only-after-connect, log throttle) — pure, deterministic, no hardware.authorized=0/1; observeddemote after 10 failures → reopen interface 1 → reconnected, fully in-process (no restart).cargo test+clippy -D warningsclean.