Skip to content

Conversation

@gmegidish
Copy link
Member

@gmegidish gmegidish commented Nov 29, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved WebDriverAgent startup reliability with automatic fallback mechanisms and enhanced error handling for installation failures
    • Better artifact management with improved cleanup logic
    • Automatic process termination to prevent dangling WebDriverAgent instances on startup failures
  • Chores

    • Optimized artifact selection and download sourcing based on system architecture

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Nov 29, 2025

Walkthrough

The changes enhance WebDriverAgent installation by introducing architecture-aware artifact selection (arm64 vs x86_64), attempting local binary retrieval first before falling back to GitHub download, improving error handling with proper error wrapping, and adding process termination fallback when agent startup fails.

Changes

Cohort / File(s) Summary
Architecture-aware artifact selection
devices/simulator.go
Added getWebdriverAgentFilename(arch) and getWebdriverAgentDownloadUrl(arch) helper functions to choose platform-specific WebDriverAgent versions based on runtime architecture
GitHub download integration
devices/simulator.go
Implemented downloadWebDriverAgentFromGitHub() method to fetch WDA from GitHub, replacing hardcoded download flow
Enhanced InstallWebDriverAgent flow
devices/simulator.go
Modified to attempt local WDA binary retrieval from MOBILECLI_WDA_PATH or default GOARCH-based location first, with fallback to GitHub download if not found; added conditional cleanup of downloaded artifacts
Improved error handling & StartAgent fallback
devices/simulator.go
Wrapped unzip and download errors with %w for proper error chaining; added process termination fallback in StartAgent when WaitForAgent fails to prevent dangling WDA instances
Environment-driven WDA port discovery
devices/simulator.go
Introduced environment-based port discovery logic in start flow while preserving existing progression when WDA starts successfully

Sequence Diagram

sequenceDiagram
    participant SimDev as SimulatorDevice
    participant LocalFS as Local Filesystem
    participant GitHub as GitHub
    participant WDA as WebDriverAgent
    
    rect rgb(200, 220, 255)
    Note over SimDev,WDA: InstallWebDriverAgent Flow
    SimDev->>SimDev: Detect architecture (arm64/x86_64)
    SimDev->>LocalFS: Check MOBILECLI_WDA_PATH<br/>(or default location)
    alt Local binary exists
        LocalFS-->>SimDev: WDA binary found
        SimDev->>SimDev: Log: using local WDA
    else Local binary not found
        rect rgb(255, 240, 200)
        SimDev->>GitHub: Download WDA from GitHub
        GitHub-->>SimDev: WDA binary + dependencies
        SimDev->>SimDev: Unzip artifacts
        end
    end
    SimDev->>SimDev: Conditional cleanup of downloads
    end
    
    rect rgb(220, 255, 220)
    Note over SimDev,WDA: StartAgent Flow
    SimDev->>SimDev: Environment-driven port discovery
    SimDev->>WDA: Start WebDriverAgent process
    SimDev->>WDA: WaitForAgent
    alt WaitForAgent succeeds
        WDA-->>SimDev: Agent ready
    else WaitForAgent fails
        rect rgb(255, 200, 200)
        SimDev->>WDA: Terminate WDA process (fallback)
        end
        SimDev-->>SimDev: Return error
    end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Areas requiring attention:
    • Verify the fallback logic between local and GitHub download paths handles all edge cases (missing env vars, file permissions, partial downloads)
    • Confirm error wrapping with %w properly chains errors in both unzip and download failure scenarios
    • Validate the process termination fallback in StartAgent doesn't introduce race conditions or resource leaks
    • Review cleanup logic to ensure downloaded artifacts are only removed when appropriate (e.g., not when using local binaries)

Poem

🐰 A bunny's tale of artifacts so fine,
Architecture-aware, now they align!
Local first, then GitHub's door,
Fallback flows—no dangling anymore!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately reflects the main change: termination fallback when starting WebDriverAgent fails on simulator, which is a key feature added in the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-kill-wda-if-timeouts-to-start

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

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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e3bec98 and 064f156.

📒 Files selected for processing (1)
  • devices/simulator.go (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
devices/simulator.go (2)
utils/logger.go (1)
  • Verbose (19-23)
utils/zipfile.go (1)
  • Unzip (12-25)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: lint
  • GitHub Check: Analyze (go)
🔇 Additional comments (5)
devices/simulator.go (5)

11-11: LGTM!

The runtime import is correctly added to support architecture detection.


294-299: LGTM!

The architecture detection logic correctly maps Go's "amd64" to x86_64 and defaults to arm64.


306-329: LGTM!

The download logic is well-structured with proper error handling, cleanup on failure, and informative logging.


331-414: LGTM!

The refactored installation logic correctly implements the two-tier approach (local file first, GitHub fallback) with appropriate conditional cleanup. The error wrapping improvements and verbose logging enhance maintainability.


608-610: LGTM! This correctly implements the fix described in the PR title.

The termination fallback properly cleans up the WDA process when agent startup fails, preventing dangling processes. Ignoring the termination error is appropriate since the original WaitForAgent error is more important to surface.

Comment on lines +301 to +304
tmpFile, err := os.CreateTemp("", "wda-*.zip")
if err != nil {
return "", fmt.Errorf("failed to create temp file: %v", err)
}
_ = tmpFile.Close()

utils.Verbose("Downloading WebDriverAgent to: %s", tmpFile.Name())

err = utils.DownloadFile(url, tmpFile.Name())
if err != nil {
_ = os.Remove(tmpFile.Name())
return "", fmt.Errorf("failed to download WebDriverAgent: %w", err)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify WebDriverAgent v9.15.1 and check for latest version

echo "=== Checking WebDriverAgent v9.15.1 ==="
if gh api repos/appium/WebDriverAgent/releases/tags/v9.15.1 --jq '.tag_name, .published_at' 2>/dev/null; then
  echo "✓ Version v9.15.1 found"
else
  echo "✗ Version v9.15.1 NOT found"
fi

echo -e "\n=== Checking latest WebDriverAgent release ==="
gh api repos/appium/WebDriverAgent/releases/latest --jq '.tag_name, .published_at' 2>/dev/null

echo -e "\n=== Checking recent releases (last 5) ==="
gh api repos/appium/WebDriverAgent/releases --jq '.[0:5] | .[] | "\(.tag_name) - \(.published_at)"' 2>/dev/null

Repository: mobile-next/mobilecli

Length of output: 432


Update the hardcoded WebDriverAgent version from v9.15.1 to the latest stable release.

The version v9.15.1 (released July 2025) is outdated. The latest stable release is v10.2.3 (released November 2025). This represents a full major version gap and 4+ months of updates. Consider updating the hardcoded version to v10.2.3 or implementing a mechanism to automatically fetch the latest release to avoid future manual updates.

🤖 Prompt for AI Agents
In devices/simulator.go around lines 301 to 304, the WebDriverAgent download URL
is hardcoded to release v9.15.1; update the string to use v10.2.3 (the current
stable) or replace the hardcoded version with a small helper that fetches the
latest release tag from GitHub API and uses that tag to construct the URL.
Ensure any HTTP call handles errors and falls back to a sensible default tag,
and update unit/integration tests if they assert the old URL.

@gmegidish gmegidish merged commit 3fa440f into main Nov 29, 2025
15 checks passed
@gmegidish gmegidish deleted the fix-kill-wda-if-timeouts-to-start branch November 29, 2025 13:24
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