Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(connect): do not release device when device is going to be discon… #16843

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

mroz22
Copy link
Contributor

@mroz22 mroz22 commented Feb 5, 2025

this could be a solution to this #15013 (comment)

Copy link

coderabbitai bot commented Feb 5, 2025

Walkthrough

The changes focus on updating the onCallFirmwareUpdate function. Two separate instances of await reconnectedDevice.release(); have been removed so that the device is not released immediately after each firmware upload. Instead, additional logging has been introduced to provide clear markers when the main firmware upload and the intermediary firmware upload occur. Furthermore, the parameter definitions in the Params type have been expanded to include optional properties: language, baseUrl, btcOnly, and binary. These adjustments alter the control flow during firmware updates and enhance log traceability.

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • szymonlesisz
  • martykan
  • marekrjpolak

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/connect/src/core/onCallFirmwareUpdate.ts (1)

515-532: Consider adding error handling for language update failures.

While the language update failure is logged, it's silently caught. Consider:

  1. Notifying the user about the language update failure
  2. Allowing retry of the language update
 try {
     log.info(
         'onCallFirmwareUpdate',
         'changing language for fresh device to: ',
         params.language,
     );
     await reconnectedDevice.changeLanguage({ language: params.language });
 } catch (err) {
     log.error('onCallFirmwareUpdate', 'changeLanguage failed silently: ', err);
+    postMessage(
+        createUiMessage(UI.FIRMWARE_PROGRESS, {
+            device: reconnectedDevice.toMessageObject(),
+            operation: 'language-update-failed',
+            error: err.message,
+        }),
+    );
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c89c834 and 2356d3a.

📒 Files selected for processing (1)
  • packages/connect/src/core/onCallFirmwareUpdate.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: PR-check / node-authorizeCoinjoin cancelCoinjoinAuthorization passphrase unlockPath setBusy checkFirmwareAuthenticity keepSession cancel.test info.test resetDevice-api
  • GitHub Check: PR-check / web-override init-api-flaky
  • GitHub Check: PR-check / node-override init-api-flaky
  • GitHub Check: PR-check / web-authorizeCoinjoin cancelCoinjoinAuthorization passphrase unlockPath setBusy checkFirmwareAuthenticity keepSession cancel.test info.test resetDevice-api
  • GitHub Check: build-deploy
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: prepare_android_test_app
  • GitHub Check: Setup and Cache Dependencies
🔇 Additional comments (3)
packages/connect/src/core/onCallFirmwareUpdate.ts (3)

487-487: LGTM! Enhanced logging improves traceability.

The added log statements provide clear markers for tracking the firmware update process, making it easier to debug issues.

Also applies to: 490-491


566-567: Verify device release timing.

The device is only released after firmware validation is complete or when validation is omitted. This is the correct approach as it ensures all necessary operations are completed before releasing the device.

Also applies to: 578-579


480-508: Verify firmware upload sequence.

The removal of await reconnectedDevice.release() after firmware upload is a good fix. Previously, releasing the device immediately after upload could cause issues when:

  1. An intermediary firmware needs to be installed
  2. The device needs to be reconnected for further operations

This change aligns with the PR objective to fix device disconnection issues.

Let's verify if there are any other instances in the codebase where devices are prematurely released during firmware updates:

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Search for device release calls near firmware upload operations
ast-grep --pattern 'uploadFirmware($$$).then($$$release()$$$)'

# Search for any direct release calls after firmware upload
rg -B 5 -A 5 'uploadFirmware.*\n.*release\(\)'

Length of output: 305


🏁 Script executed:

#!/bin/bash
echo "Searching for device release calls using ast-grep (with multiline flag):"
ast-grep -U --pattern 'uploadFirmware($$$).then($$$release()$$$)'

echo -e "\nSearching for direct release calls after uploadFirmware within surrounding lines using rg (with multiline enabled):"
rg -U -nH -C10 'await\s+uploadFirmware(.*\n){1,3}\s*await\s+.*release\(' .

echo -e "\nSearching for explicit release calls on reconnectedDevice:"
rg -U -nH -C5 'await\s+reconnectedDevice\.release\(' .

Length of output: 2978


Firmware Update Sequence Verified.

The shell script output confirms that the only remaining calls to await reconnectedDevice.release() occur later in the firmware update sequence (after performing the firmware hash check), rather than immediately after the initial firmware upload. This aligns with the intended fix of removing an early release that could disrupt intermediary firmware updates.

• No premature device release calls are found near the firmware upload operation.
• The remaining release calls (at lines 566 and 578) occur in the appropriate control flow for post-update validation.

@bosomt
Copy link
Contributor

bosomt commented Feb 5, 2025

QA OK

bridge 2.x - 1 of 1 OK /worked before/
bridge 3.x - 3 of 3 OK

Info:

  • Suite version: desktop 25.3.0 (2356d3a)
  • Browser: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) TrezorSuiteDev/25.3.0 Chrome/128.0.6613.186 Electron/32.2.6 Safari/537.36
  • OS: MacIntel
  • Screen: 1470x956
  • Device: Trezor T1B1 1.12.1 bitcoin-only (revision 1eb0eb9d91b092e571aac63db4ebff2a07fd8a1f)
  • Transport: BridgeTransport 2.0.33

@mroz22 mroz22 added the release Will be included in the upcoming release. Needs to be backported to the release branch. label Feb 5, 2025
@mroz22
Copy link
Contributor Author

mroz22 commented Feb 5, 2025

cc @MiroslavProchazka and @komret - cherrypick candidate

@mroz22 mroz22 merged commit a7f0b3c into develop Feb 5, 2025
59 of 63 checks passed
@mroz22 mroz22 deleted the fw-update-release-device branch February 5, 2025 14:12
@bosomt
Copy link
Contributor

bosomt commented Feb 11, 2025

QA OK

#15013 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release Will be included in the upcoming release. Needs to be backported to the release branch.
Projects
Status: ✅ Approved
Development

Successfully merging this pull request may close these issues.

3 participants