Skip to content

feat: auto-discover available ports when defaults are in use#614

Merged
stefandevo merged 4 commits intov0.13.0rcfrom
feature/auto-port-discovery
Jan 19, 2026
Merged

feat: auto-discover available ports when defaults are in use#614
stefandevo merged 4 commits intov0.13.0rcfrom
feature/auto-port-discovery

Conversation

@stefandevo
Copy link
Collaborator

@stefandevo stefandevo commented Jan 19, 2026

Summary

When launching Automaker in web mode while the Electron app is already running (or any other process using ports 3007/3008), the launcher now provides smart port conflict resolution with auto-select as the default option.

This enables seamless development workflows where you can:

  • Run the built Electron app for daily use
  • Simultaneously run web dev mode in worktrees without port conflicts

Changes

  • Add find_next_available_port() function - Searches up to 100 ports in sequence to find an available one
  • Enhanced port conflict UI - When ports are in use, users see a centered menu with options:
    • [Enter] Auto-select available ports (default, recommended)
    • [K] Kill processes and use default ports
    • [C] Choose custom ports manually
    • [X] Cancel
  • PID display fix - Multiple PIDs are now shown on a single line for proper centering

User Experience

When ports 3007/3008 are in use:

                        Port 3007 in use (PID: 24572 61640)
                        Port 3008 in use (PID: 24572 61550)

                        What would you like to do?

                [Enter] Auto-select available ports (Recommended)
                [K] Kill processes and use default ports
                [C] Choose custom ports
                [X] Cancel

                            Choice [Enter]: _

Pressing Enter instantly auto-selects the next available ports (e.g., 3009/3010) and continues launching.

Test plan

  • Run Electron app (uses ports 3007/3008)
  • Run ./start-automaker.sh and select web mode
  • Verify port conflict is detected and menu is shown
  • Press Enter to auto-select ports
  • Verify web mode starts on alternative ports (3009/3010)
  • Test [K] option kills processes correctly
  • Test [C] option allows manual port entry
  • Test [X] option cancels gracefully

Summary by CodeRabbit

  • New Features

    • Automatic port discovery now resolves conflicts by scanning for and selecting available ports, eliminating most interactive prompts and auto-selecting alternatives when needed.
  • Bug Fixes

    • Improved port conflict messages: shows process IDs and concise, standardized port-selection output for clearer visibility and easier troubleshooting.

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

Instead of prompting the user to kill processes or manually enter
alternative ports, the launcher now automatically finds the next
available ports when the defaults (3007/3008) are already in use.

This enables running the built Electron app alongside web development
mode without conflicts - web dev will automatically use the next
available ports (e.g., 3009/3010) when Electron is running.

Changes:
- Add find_next_available_port() function that searches up to 100 ports
- Update resolve_port_conflicts() to auto-select ports without prompts
- Update check_ports() for consistency (currently unused but kept)
- Add safety check to ensure web and server ports don't conflict
When ports are in use, users can now choose:
- [Enter] Auto-select available ports (default, recommended)
- [K] Kill processes and use default ports
- [C] Choose custom ports manually
- [X] Cancel

Pressing Enter without typing anything will auto-select the next
available ports, making it easy to quickly continue when running
alongside an existing Electron instance.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 19, 2026

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

A shell script was enhanced to auto-discover and assign free ports. A new find_next_available_port(start_port) function and PORT_SEARCH_MAX_ATTEMPTS constant were added. Port checks now automatically reassign conflicting WEB_PORT and SERVER_PORT values and show associated PIDs instead of prompting interactively.

Changes

Cohort / File(s) Summary
Port Auto-Discovery & Conflict Resolution
start-automaker.sh
Added PORT_SEARCH_MAX_ATTEMPTS and find_next_available_port(start_port) to scan a bounded range for free ports. Rewrote check_ports() and resolve_port_conflicts logic to auto-select non-conflicting WEB_PORT and SERVER_PORT, display normalized PIDs for in-use ports, and remove interactive prompts in favor of an auto-selection flow.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I sniffed the sockets, hopped around,

Found empty ports on common ground.
No asking now — I pick with flair,
PIDs shown, conflicts handled fair.
Hooray! The automaker breathes fresh air. 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 'feat: auto-discover available ports when defaults are in use' directly and clearly summarizes the main change: automatic port discovery when default ports are occupied.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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 and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @stefandevo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the user experience when launching Automaker in web mode by introducing intelligent port conflict resolution. It allows developers to seamlessly run the Electron app and web dev mode concurrently without manual intervention, as the system now automatically discovers and assigns available ports if the defaults are occupied. This streamlines development workflows by reducing friction caused by port clashes and provides a clearer, more user-friendly interface for managing conflicts.

Highlights

  • Port Auto-Discovery: Implemented an automatic port discovery mechanism that finds the next available ports when default ports (3007/3008) are already in use, searching up to 100 sequential ports.
  • Enhanced Port Conflict Resolution UI: Introduced a new interactive menu for port conflicts, offering 'Auto-select available ports' as the default and recommended option, alongside 'Kill processes and use default ports' and 'Choose custom ports manually'.
  • Improved PID Display: Fixed the display of process IDs (PIDs) so that multiple PIDs for a single port are shown on a single line, improving readability and proper centering in the terminal output.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces an excellent feature for automatically handling port conflicts, which significantly improves the developer experience. The implementation is solid, and the new interactive menu for port resolution is well-designed. I've identified a few areas for improvement, primarily concerning code maintainability and readability. My review includes suggestions to remove some dead code, replace a magic number with a constant, and simplify a complex command pipeline. Overall, this is a great enhancement.

Copy link
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

🤖 Fix all issues with AI agents
In `@start-automaker.sh`:
- Around line 456-474: The find_next_available_port function currently echoes
the original start_port on failure which can mislead callers; change
find_next_available_port to suppress any echo when it fails (echo nothing) and
return non‑zero so callers can detect failure, and update any callers that use
find_next_available_port (e.g., places that auto-select or print an
"auto-selected" port) to check the function's exit status or whether the
returned value is empty and then handle the error path explicitly (prompt the
user, abort with a clear error, or retry) instead of assuming a valid port was
returned.

Address PR review feedback:
- Extract magic number 100 to PORT_SEARCH_MAX_ATTEMPTS constant
- Fix find_next_available_port to return nothing on failure instead of
  the busy port, preventing misleading "auto-selected" messages
- Update all callers to handle port discovery failure with clear error
  messages showing the searched range
- Simplify PID formatting using xargs instead of tr|sed|sed pipeline
@stefandevo stefandevo merged commit 02a7a54 into v0.13.0rc Jan 19, 2026
6 checks passed
@stefandevo stefandevo deleted the feature/auto-port-discovery branch January 19, 2026 22:36
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