Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Fix Dutlink timeout handling after refactor#235

Merged
NickCao merged 1 commit intomainfrom
fix-dutlink-timeout
Jan 26, 2025
Merged

Fix Dutlink timeout handling after refactor#235
NickCao merged 1 commit intomainfrom
fix-dutlink-timeout

Conversation

@mangelajo
Copy link
Copy Markdown
Member

@mangelajo mangelajo commented Jan 26, 2025

Some DUTLink targets have very long-running power on/off commands because those are
scripted internally and can take 10-15s, the timeout_s needs to be passed down to all
objects.

Summary by CodeRabbit

  • Configuration Updates
    • Added a configurable timeout setting for USB operations
    • Default timeout set to 20 seconds
    • Improved timeout handling across USB-related classes

@mangelajo mangelajo requested a review from NickCao January 26, 2025 20:26
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 26, 2025

Walkthrough

The pull request modifies the DutlinkConfig and Dutlink classes in the Dutlink driver module. A new timeout_s attribute is introduced to the DutlinkConfig class with a default value of 20 seconds. The __post_init__ method is updated to convert this timeout to milliseconds for the device configuration. The Dutlink class now passes the timeout_s parameter when instantiating its child classes DutlinkPower and DutlinkStorageMux, ensuring consistent timeout configuration across the USB operation classes.

Changes

File Change Summary
packages/jumpstarter-driver-dutlink/jumpstarter_driver_dutlink/driver.py - Added timeout_s attribute to DutlinkConfig with default 20 seconds
- Updated __post_init__ to set default_timeout in milliseconds
- Modified Dutlink class to pass timeout_s to child class constructors

Possibly related PRs

Poem

🐰 Timeout Tango, USB's New Dance

Seconds tick, milliseconds prance,
Dutlink driver takes a stance,
Configuration with elegant grace,
Timeout settings find their place!

Hop hop hooray! 🚀

✨ 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.

@mangelajo mangelajo requested a review from bennyz January 26, 2025 20:26
@mangelajo
Copy link
Copy Markdown
Member Author

@bennyz @NickCao The change is tested, and working. I need it for the demo tomorrow, appreciate the quick merge. Thanks

@NickCao NickCao merged commit 93dbcc1 into main Jan 26, 2025
Copy link
Copy Markdown
Contributor

@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: 1

🧹 Nitpick comments (3)
packages/jumpstarter-driver-dutlink/jumpstarter_driver_dutlink/driver.py (3)

27-27: LGTM! Consider making the timeout configurable via environment variable.

The default timeout of 20 seconds is reasonable given that power commands can take 10-15 seconds. However, to improve flexibility, consider making this configurable via an environment variable.

-    timeout_s: int = field(default=20)  # 20 seconds, power control sequences can block USB for a long time
+    timeout_s: int = field(default=int(os.getenv('DUTLINK_TIMEOUT_S', '20')))  # power control sequences can block USB for a long time

256-258: Fix line formatting for better readability.

The line continuation could be formatted better.

-        self.children["storage"] = DutlinkStorageMux(serial=self.serial, storage_device=self.storage_device,
-                                                     timeout_s=self.timeout_s)
+        self.children["storage"] = DutlinkStorageMux(
+            serial=self.serial,
+            storage_device=self.storage_device,
+            timeout_s=self.timeout_s
+        )

Line range hint 211-225: Move timeout_s documentation to DutlinkConfig class.

The docstring describes the timeout_s parameter, but this parameter is defined in the DutlinkConfig class. Consider moving this documentation to the appropriate class.

@dataclass(kw_only=True)
class DutlinkConfig:
+    """
+    Parameters:
+    ----------
+    serial : str or None
+        The serial number of the DUTLink device. Default is None.
+    timeout_s : int
+        The timeout in seconds for USB operations. Default is set to 20 seconds.
+    """
     serial: str | None = field(default=None)
     timeout_s: int = field(default=20)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1c41c83 and eda305d.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (1)
  • packages/jumpstarter-driver-dutlink/jumpstarter_driver_dutlink/driver.py (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: pytest-matrix (3.13)
  • GitHub Check: pytest-matrix (3.12)
  • GitHub Check: pytest-matrix (3.11)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-devspace .devfile/Containerfile.client)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-dev .devfile/Containerfile)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter Dockerfile)
🔇 Additional comments (1)
packages/jumpstarter-driver-dutlink/jumpstarter_driver_dutlink/driver.py (1)

56-56: LGTM! Verify timeout application at runtime.

The conversion from seconds to milliseconds is correct and appropriately set at the USB device level.

Run this script to verify the timeout is properly applied:

✅ Verification successful

✅ Timeout implementation verified as correct and isolated

The timeout setting in __post_init__ is the only instance of timeout configuration in the codebase, ensuring it won't be accidentally overridden elsewhere.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for any other places where USB timeouts might be set or overridden
# This helps ensure our timeout setting isn't being overridden elsewhere

rg -l "default_timeout|set_timeout|timeout.*=|\.timeout" --type python

Length of output: 103


Script:

#!/bin/bash
# Search for timeout and USB device configuration patterns in Python files
rg -l "default_timeout|set_timeout|timeout.*=|\.timeout|usb.*timeout" "*.py"

# Also search specifically in the driver directory
fd -e py . packages/jumpstarter-driver-dutlink/jumpstarter_driver_dutlink/ -x rg -l "default_timeout|set_timeout|timeout.*=|\.timeout|usb.*timeout" {}

Length of output: 351

Comment on lines +256 to +258
self.children["power"] = DutlinkPower(serial=self.serial, timeout_s=self.timeout_s)
self.children["storage"] = DutlinkStorageMux(serial=self.serial, storage_device=self.storage_device,
timeout_s=self.timeout_s)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Add timeout_s parameter to DutlinkSerial instantiation

For consistency with DutlinkPower and DutlinkStorageMux, pass the timeout_s parameter to DutlinkSerial:

  • self.children["console"] = DutlinkSerial(serial=self.serial, baudrate=self.baudrate, timeout_s=self.timeout_s)
🔗 Analysis chain

Verify if DutlinkSerial needs the timeout parameter.

The timeout is propagated to DutlinkPower and DutlinkStorageMux, but DutlinkSerial might also need it since it inherits from DutlinkConfig.

Run this script to analyze the inheritance and timeout usage:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Analyze DutlinkSerial's inheritance chain and timeout usage

# Search for DutlinkSerial class definition and its base classes
ast-grep --pattern 'class DutlinkSerial($_)'

# Search for timeout usage in PySerial
rg -A 5 "timeout" --type python | grep -C 5 "class PySerial"

Length of output: 138


Script:

#!/bin/bash
# Search for DutlinkSerial class definition and inheritance
ast-grep --pattern 'class DutlinkSerial'

# Find all references to DutlinkSerial
rg "DutlinkSerial" -A 5 --type py

# Search for DutlinkConfig class and its timeout usage
ast-grep --pattern 'class DutlinkConfig'
rg "DutlinkConfig.*timeout" --type py

# Find timeout parameter usage in constructor
ast-grep --pattern 'def __init__($$$timeout$$$)'

Length of output: 984


Script:

#!/bin/bash
# Get DutlinkConfig implementation
rg -A 10 "class DutlinkConfig" --type py

# Get implementation of similar classes
rg -A 10 "class DutlinkPower|class DutlinkStorageMux" --type py

# Find all timeout-related parameters in the file
rg "timeout" --type py packages/jumpstarter-driver-dutlink/jumpstarter_driver_dutlink/driver.py

Length of output: 4217

@mangelajo
Copy link
Copy Markdown
Member Author

Oh thanks Nick!, that was quick! :D

@NickCao NickCao deleted the fix-dutlink-timeout branch January 29, 2025 14:38
@mangelajo mangelajo added this to the 0.6.0 milestone May 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants