Skip to content

🐛 Restart the USB input reader after it fails - #1

Open
X-15 wants to merge 2 commits into
aisk:masterfrom
X-15:fix-usb-reader-recovery
Open

X-15 wants to merge 2 commits into
aisk:masterfrom
X-15:fix-usb-reader-recovery

Conversation

@X-15

@X-15 X-15 commented Oct 11, 2026

Copy link
Copy Markdown

Over USB, the controller sometimes stops sending input for good. Games keep seeing the buttons it last reported as held, and only replugging the cable brings it back. For me it happened every so often in hectic fights, several times a day.

Cause

When the continuous reader on the interrupt IN pipe fails, EvtUsbReadersFailed returns TRUE, which should make the framework reset the pipe and send the readers again. In UMDF that never happens. The framework first asks whether the port is connected (fxusbpipe.cpp), and FxUsbDevice::IsConnected simply returns STATUS_UNSUCCESSFUL in user mode (fxusbdevice.cpp). The readers are then never sent again.

I caught one of these live, by logging the status report next to XInput:

  • Input was flowing until the status report showed last error 0xC0000001.
  • No raw reports arrived for 13 s while I kept pressing buttons. The driver kept answering the status report in under 0.3 ms, so it was not hung.
  • XInput reported the last state the whole time (RT held, left stick pushed) until I replugged.

Change

  • 🐛 Restart the USB input reader after it fails. On a reader failure the driver releases all controls, so nothing stays held, and returns FALSE. A work item then stops the input target, resets the pipe and starts the target again. WdfUsbTargetPipeResetSynchronously goes through while the target is stopped (fxusbpipeapi.cpp). The stop is needed because WdfIoTargetStart only sends the readers again after a stop. If the reset fails, or the reader fails again within 5 s, the work item calls WdfDeviceSetFailed(WdfDeviceFailedAttemptRestart). UsbStop clears a running flag and flushes the work item, so a recovery cannot restart the reader during power down.
  • 🩺 Report USB reader failures and recoveries in the status report (separate commit, optional). It adds the USBD status of the last failure, counts of failures, pipe resets and device restarts, and the number of input reports. Setting the status report with command 1 runs the recovery on demand; status.ps1 -TestRecovery uses it, and the README mentions it.

Tested

USB only, Windows 11 build 26300. Nothing on the Bluetooth path changes; its transport just gets NULL for the test hook.

  • About 3 hours of play with the patch: 3 real reader failures (0xC0000001, USBD status 0x00000000), all recovered by pipe resets, 0 device restarts, input kept working.
  • -TestRecovery while moving a stick: input keeps flowing after each pipe reset. A second failure within 5 s goes to the device restart.

Things I found on the way, in case they help:

  • I first had a port reset (WdfUsbTargetDeviceResetPortSynchronously) between the pipe reset and the device restart. The reset itself succeeded, but the next rumble write on the interrupt OUT pipe never completed, despite its 500 ms timeout. That held RumbleLock, so I dropped the port reset.
  • On USB, WdfDeviceSetFailed(WdfDeviceFailedAttemptRestart) removes the interface (Kernel-PnP event 1011), and it stays away until the cable is replugged. That still beats stuck buttons, but it is not a real restart. If you know a better last step for UMDF, I'm happy to change it.
  • The controller only reports when something changes. A button held through a recovery therefore reads as released until the next change.

🤖 Generated with Claude Code

X-15 and others added 2 commits October 11, 2026 03:15
In UMDF, returning TRUE from EvtUsbTargetPipeReadersFailed never resets
the pipe or restarts the reader. The framework first checks that the port
is connected, and FxUsbDevice::IsConnected always fails in user mode, so
one transient read error left the controller silent until it was
replugged, with the buttons it last reported still held.

The driver now releases all controls when the reader fails, and a work
item resets the input pipe and starts the reader again. When the reset
fails, or the reader fails again within 5 s, it asks for a device restart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The status report gains the USBD status of the last reader failure, the
counts of reader failures, pipe resets and device restarts, and the number
of input reports received. Setting the status report with command 1 runs
the recovery as if the reader had failed, which status.ps1 -TestRecovery
uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T01:21:17.615557Z 9de7f14 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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