Skip to content

Prompt when serial devices share USB identifiers#1326

Open
RCGV1 wants to merge 1 commit into
meshtastic:mainfrom
RCGV1:agent/fix-serial-selection
Open

Prompt when serial devices share USB identifiers#1326
RCGV1 wants to merge 1 commit into
meshtastic:mainfrom
RCGV1:agent/fix-serial-selection

Conversation

@RCGV1

@RCGV1 RCGV1 commented Jul 22, 2026

Copy link
Copy Markdown
Member

Summary

  • Auto-select a serial port only when exactly one authorized device matches the saved USB vendor/product identifiers.
  • Fall back to the browser's serial chooser when multiple authorized devices share the same identifiers.
  • Add regression coverage for duplicate VID/PID devices.

Root cause

The transport used find() and silently selected the first authorized match. Multiple Meshtastic boards can expose identical USB vendor/product identifiers, so a saved connection could attach to the wrong physical node.

Impact

Users with multiple identical boards are prompted to select the intended device instead of being connected to an arbitrary match.

Validation

  • NODE_OPTIONS=--no-experimental-webstorage pnpm vitest run apps/web/src/core/connections/transports.test.ts: 1 test passed.
  • pnpm --filter meshtastic-web build: passed.
  • pnpm lint: passed with existing warnings.
  • git diff --check: passed.
  • GitHub E2E (real device): passed in 1m48s.

Notes

  • Vercel preview requires Meshtastic team authorization for fork deployments.

Summary by CodeRabbit

  • Bug Fixes

    • Improved serial-port selection when multiple matching devices are available.
    • Automatically connects when exactly one matching port is found.
    • Prompts for a port selection when multiple matches are detected and prompting is enabled.
  • Tests

    • Added coverage for multi-port serial selection behavior.

@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

@RCGV1 is attempting to deploy a commit to the Meshtastic Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

openSerial now handles multiple matching USB serial ports by prompting for user selection when permitted, while retaining automatic selection for a single match. A new test verifies the prompt and selected-port construction flow.

Changes

Serial port selection

Layer / File(s) Summary
Matching port resolution and validation
apps/web/src/core/connections/transports.ts, apps/web/src/core/connections/transports.test.ts
openSerial collects matching USB VID/PID ports, auto-selects one match, prompts for multiple matches when allowed, and tests creation from the selected port.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

I’m a rabbit with ports in a row,
Two matching paths? Now we know:
“Please pick one,” the chooser sings,
Then createFromPort does its thing.
Hop, hop—no silent first-choice flow!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: prompting the user when multiple serial devices share the same USB identifiers.
Description check ✅ Passed The description covers the problem, solution, impact, and validation, though it doesn't follow the exact template sections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@RCGV1
RCGV1 marked this pull request as ready for review July 22, 2026 16:49

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/src/core/connections/transports.ts`:
- Around line 182-183: Update the allowPrompt branch in transports.ts to pass
the saved usbVendorId and usbProductId to serial.requestPort via its filters
option. In transports.test.ts, update the serial picker assertion to verify
requestPort receives the corresponding VID/PID filter.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 287fd0f1-bcac-4dd3-8da3-d7b849561026

📥 Commits

Reviewing files that changed from the base of the PR and between 1eeabea and 5a7b286.

📒 Files selected for processing (2)
  • apps/web/src/core/connections/transports.test.ts
  • apps/web/src/core/connections/transports.ts

Comment on lines +182 to +183
if (opts.allowPrompt) {
port = await serial.requestPort({});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n## transports.ts\n'
sed -n '1,260p' apps/web/src/core/connections/transports.ts

printf '\n## transports.test.ts\n'
sed -n '1,220p' apps/web/src/core/connections/transports.test.ts

printf '\n## search for requestPort usage\n'
rg -n "requestPort\\(" apps/web/src/core/connections -S

Repository: meshtastic/web

Length of output: 10620


Pass the saved VID/PID into the serial picker.
requestPort({}) can surface unrelated devices here; pass filters: [{ usbVendorId, usbProductId }] and assert that argument in the serial test.

📍 Affects 2 files
  • apps/web/src/core/connections/transports.ts#L182-L183 (this comment)
  • apps/web/src/core/connections/transports.test.ts#L46-L49
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/core/connections/transports.ts` around lines 182 - 183, Update
the allowPrompt branch in transports.ts to pass the saved usbVendorId and
usbProductId to serial.requestPort via its filters option. In
transports.test.ts, update the serial picker assertion to verify requestPort
receives the corresponding VID/PID filter.

@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
web-test Ready Ready Preview, Comment Jul 22, 2026 6:10pm

Request Review

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