Skip to content

Fix 'make dev' failure in Windows environment#3236

Open
tanghang97 wants to merge 3 commits into
bytedance:mainfrom
tanghang97:fix-windows-make-dev
Open

Fix 'make dev' failure in Windows environment#3236
tanghang97 wants to merge 3 commits into
bytedance:mainfrom
tanghang97:fix-windows-make-dev

Conversation

@tanghang97
Copy link
Copy Markdown

Summary

This PR resolves the issue where make dev command fails to start properly in Windows environments. The fix addresses compatibility problems with asyncio event loop policy and improves cross-platform support for the development server startup process.

Changes Made

1. Event Loop Policy Configuration (backend/app/gateway/app.py)

  • Added _configure_windows_event_loop_policy() function to handle Windows-specific asyncio requirements
  • Implemented proper event loop policy selection using WindowsSelectorEventLoopPolicy for better async/await compatibility on Windows
  • Ensures smooth operation of async psycopg and other async libraries on Windows platforms

2. Site Customization (backend/sitecustomize.py)

  • Created new site customization module to apply Windows event loop policy at Python process startup
  • Provides system-wide configuration that affects all Python processes in the backend
  • Ensures consistent behavior across different execution contexts

3. Script Improvements (scripts/serve.sh, scripts/wait-for-port.sh)

  • Enhanced port detection logic to support Windows PowerShell commands
  • Added cross-platform compatibility checks using powershell.exe for port listening verification
  • Improved error handling and timeout mechanisms for service startup

Technical Details

  • Platform Detection: Uses sys.platform == "win32" to identify Windows environments
  • Event Loop Policy: Implements WindowsSelectorEventLoopPolicy which is more compatible with async libraries on Windows
  • Port Checking: Extended wait-for-port.sh to use PowerShell's Get-NetTCPConnection on Windows systems
  • Backward Compatibility: All changes maintain full compatibility with Unix/Linux/macOS environments

Testing

  • Verified successful startup of make dev on Windows environments
  • Confirmed no regression on Unix-based systems (Linux, macOS)
  • Tested gateway API functionality after startup
  • Validated frontend-backend communication through nginx proxy

Impact

  • ✅ Fixes critical startup issue preventing Windows developers from running the application
  • ✅ Improves cross-platform development experience
  • ✅ Maintains existing functionality on all supported platforms
  • ✅ No breaking changes to API or user-facing features

Related Issues

Resolves the Windows-specific startup failure that was blocking local development on Windows machines.

Fixes #3212

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to make make dev work reliably on Windows by applying a Windows-compatible asyncio event loop policy and improving cross-platform startup scripting (Python selection + port readiness checks).

Changes:

  • Add Windows-specific asyncio event loop policy configuration (both in gateway startup and via sitecustomize.py).
  • Improve serve.sh Python interpreter selection to work better in Windows/Git Bash environments.
  • Extend wait-for-port.sh to detect listening ports via powershell.exe on Windows.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
scripts/wait-for-port.sh Adds a PowerShell-based port listening probe for Windows.
scripts/serve.sh Adds _pick_python() and uses it for Better Auth secret generation and uv-extras detection.
backend/sitecustomize.py New module to set Windows asyncio event loop policy at Python startup.
backend/app/gateway/app.py Adds Windows asyncio policy setup and modifies lifespan config/runtime initialization.

Comment on lines 193 to 195
# Initialize LangGraph runtime components (StreamBridge, RunManager, checkpointer, store)
async with langgraph_runtime(app, startup_config):
async with langgraph_runtime(app):
logger.info("LangGraph runtime initialised")
Comment thread backend/app/gateway/app.py Outdated
Comment on lines 181 to 185
# Load config and check necessary environment variables at startup
try:
startup_config = get_app_config()
apply_logging_level(startup_config.log_level)
app.state.config = get_app_config()
apply_logging_level(app.state.config.log_level)
logger.info("Configuration loaded successfully")
Comment thread scripts/wait-for-port.sh
Comment on lines +24 to +26
if command -v powershell.exe >/dev/null 2>&1; then
if powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "\$ErrorActionPreference='SilentlyContinue'; if (Get-NetTCPConnection -LocalPort $PORT -State Listen) { exit 0 } else { exit 1 }" >/dev/null 2>&1; then
return 0
Comment thread scripts/serve.sh

_pick_python() {
local candidate
for candidate in python3 python py; do
Comment thread backend/sitecustomize.py
Comment on lines +4 to +21

import asyncio
import sys


def _configure_windows_event_loop_policy() -> None:
if sys.platform != "win32":
return

selector_policy = getattr(asyncio, "WindowsSelectorEventLoopPolicy", None)
if selector_policy is None:
return

if not isinstance(asyncio.get_event_loop_policy(), selector_policy):
asyncio.set_event_loop_policy(selector_policy())


_configure_windows_event_loop_policy()
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
"""Application lifespan handler."""

# Load config and check necessary environment variables at startup.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please revert the change to the startup_config, which was just updated 5 days ago.

@WillemJiang
Copy link
Copy Markdown
Collaborator

WillemJiang commented May 26, 2026

@tanghang97 thanks for your contribution. Please review the comments and fix the lint errors.

@WillemJiang WillemJiang added reviewing A maintainer is reviewing this PR question Further information is requested labels May 26, 2026
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 27, 2026

CLA assistant check
All committers have signed the CLA.

@tanghang97 tanghang97 force-pushed the fix-windows-make-dev branch from 2cd6101 to 2d21e5e Compare May 27, 2026 01:54
@LittleChenLiya LittleChenLiya requested a review from Copilot May 27, 2026 05:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

Comment thread scripts/wait-for-port.sh
Comment on lines +24 to +28
if command -v powershell.exe >/dev/null 2>&1; then
if powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "\$ErrorActionPreference='SilentlyContinue'; if (Get-NetTCPConnection -LocalPort $PORT -State Listen) { exit 0 } else { exit 1 }" >/dev/null 2>&1; then
return 0
fi
fi
Comment thread scripts/serve.sh
Comment on lines +40 to +49
_pick_python() {
local candidate
for candidate in python3 python py; do
if command -v "$candidate" >/dev/null 2>&1 && "$candidate" -c 'import sys' >/dev/null 2>&1; then
printf '%s\n' "$candidate"
return 0
fi
done
return 1
}
Comment thread backend/app/gateway/app.py Outdated
Comment on lines +35 to +48
def _configure_windows_event_loop_policy() -> None:
"""Use an event loop policy compatible with async psycopg on Windows."""
if sys.platform != "win32":
return

selector_policy = getattr(asyncio, "WindowsSelectorEventLoopPolicy", None)
if selector_policy is None:
return

if not isinstance(asyncio.get_event_loop_policy(), selector_policy):
asyncio.set_event_loop_policy(selector_policy())


_configure_windows_event_loop_policy()
Comment thread backend/sitecustomize.py Outdated
Comment on lines +1 to +21
"""Process-wide Python startup customizations for local development."""

from __future__ import annotations

import asyncio
import sys


def _configure_windows_event_loop_policy() -> None:
if sys.platform != "win32":
return

selector_policy = getattr(asyncio, "WindowsSelectorEventLoopPolicy", None)
if selector_policy is None:
return

if not isinstance(asyncio.get_event_loop_policy(), selector_policy):
asyncio.set_event_loop_policy(selector_policy())


_configure_windows_event_loop_policy()
WillemJiang
WillemJiang previously approved these changes May 28, 2026
@WillemJiang
Copy link
Copy Markdown
Collaborator

@tanghang97, could you take a look at the latest review message of Copilot?

@WillemJiang WillemJiang dismissed their stale review June 3, 2026 07:47

Need to clean up the review message.

- Validate wait-for-port input and avoid PowerShell port interpolation
- Require Python 3 in serve.sh launcher detection
- Keep Windows event loop policy setup in sitecustomize only
- Clarify sitecustomize process-wide backend behavior
@github-actions github-actions Bot added risk:medium Medium risk: regular code changes size/S PR changes 20-100 lines area:ci GitHub Actions, CI config, repo tooling and removed size/S PR changes 20-100 lines risk:medium Medium risk: regular code changes labels Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci GitHub Actions, CI config, repo tooling question Further information is requested reviewing A maintainer is reviewing this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

大家在windows环境能正常用make dev 起来吗? 启用pgsql数据库的那种

4 participants