Skip to content

feat(transport): add WebUSB transport logging for firmware update diagnosis#710

Draft
wabicai wants to merge 3 commits intoonekeyfrom
feat/webusb-transport-logging
Draft

feat(transport): add WebUSB transport logging for firmware update diagnosis#710
wabicai wants to merge 3 commits intoonekeyfrom
feat/webusb-transport-logging

Conversation

@wabicai
Copy link
Copy Markdown
Member

@wabicai wabicai commented Mar 26, 2026

Summary

  • Add detailed debug logging to WebUsbTransport to diagnose firmware update hangs (especially the 99% stuck issue on Windows ARM64)

Background

A user on Windows ARM64 (Snapdragon X, build 10.0.26200) experienced firmware update stuck at 99% on a Classic 1S device. Log analysis revealed:

  1. FirmwareUpload sent successfully, but transferIn hung for 31 minutes with zero diagnostic info
  2. Bridge process (onekeyd.exe) failed to start on win-arm64 (Unsupported system: win-arm64), causing 130k+ zombie process log lines
  3. Retry created concurrent firmwareUpdateV2 requests on the same device (errorCode 107: Device interrupted)
  4. WakeLock failed because page was not visible during the update

Current transport layer logs only record command names — no timing, no packet counts, no progress during large transfers like FirmwareUpload.

Changes

Logging added to packages/hd-transport-web-device/src/webusb.ts:

Location What's logged
connectToDevice() Connection path, first-connect flag, reset errors, success
call() send phase Total packet count & byte size, per-10% progress (for large transfers >100 packets)
call() send complete Total send duration in ms
call() receive phase Response wait duration in ms
receiveData() First packet typeId & total length, total received packet count
release() Release lifecycle

Expected log output (FirmwareUpload example)

[WebUsbTransport] call FirmwareUpload: sending 8500 packets (544000 bytes)
[WebUsbTransport] call FirmwareUpload: sent 850/8500 packets (10%)
[WebUsbTransport] call FirmwareUpload: sent 1700/8500 packets (20%)
...
[WebUsbTransport] call FirmwareUpload: all 8500 packets sent in 12340ms, waiting for response...
[WebUsbTransport] receiveData: waiting for first packet...
[WebUsbTransport] receiveData: first packet received, typeId=2, totalLength=8
[WebUsbTransport] call FirmwareUpload: response received in 65000ms

With this, if the 99% hang recurs, we can see exactly whether it's stuck in send or receive, and how long each phase takes.

Test plan

  • Verify logging appears in desktop app logs during normal device operations (Initialize, GetFeatures)
  • Verify FirmwareUpload shows packet progress for large firmware transfers
  • Verify no performance regression from logging overhead
  • Confirm logs are at debug level and don't pollute production output

🤖 Generated with Claude Code

Add comprehensive debug logging to WebUsbTransport for diagnosing
firmware update issues (especially the 99% hang on Windows ARM64).

Logs added:
- connectToDevice: connection path, first-connect flag, reset errors
- call: total packets count, send progress (every 10%), send duration
- call: response wait time after all packets sent
- receiveData: first packet typeId/length, total received packets
- release: device release lifecycle

This addresses a firmware update timeout issue where FirmwareUpload
was followed by a 31-minute transferIn hang with no diagnostic info.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@revan-zhang
Copy link
Copy Markdown
Contributor

revan-zhang commented Mar 26, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

wabicai added 2 commits March 26, 2026 15:55
Add connection deduplication in noble-ble-handler to prevent race
conditions when two IPC CONNECT requests arrive simultaneously for
the same device. The second caller now awaits the first's Promise
instead of starting a parallel connection flow that causes service
discovery timeouts.

Also fix prettier formatting issues in webusb.ts logging statements.
Only print detailed send/receive logs for large transfers (>100 packets)
or slow responses (>1000ms). Normal commands like GetFeatures no longer
produce 6 extra debug lines per call.

Logging behavior:
- Small commands (1-100 packets): only existing call- log, no extras
- Large transfers (>100 packets): full progress with send/receive timing
- Slow responses (>1s): response duration logged regardless of size
- Multi-packet receive: packet count logged
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.

2 participants