fix: Ensure consistent Langflow startup in Windows scripts#9917
Conversation
WalkthroughBoth Windows run scripts now change to the project root before launching uv/uvicorn. When using an env file, they log a message and use a literal ".env" from the project root instead of variable-based paths. Non-env execution remains unchanged. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant User
participant Script as Windows Script (bat/ps1)
participant UV as uv
participant Langflow as langflow run
User->>Script: Execute build_and_run
Script->>Script: cd to PROJECT_ROOT
alt USE_ENV_FILE set
Note over Script: Log "Using env file: .env"
Script->>UV: uv run --env-file ".env" langflow run
else no env file
Script->>UV: uv run langflow run
end
UV->>Langflow: start server
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests
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. Comment |
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
scripts/windows/build_and_run.ps1 (1)
90-90: Make Set-Location failure terminating to hit the catch block.Without forcing a terminating error, some navigation failures may not be caught. Use
-ErrorAction Stop.- Set-Location $projectRoot + Set-Location -Path $projectRoot -ErrorAction Stop
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
scripts/windows/build_and_run.bat(1 hunks)scripts/windows/build_and_run.ps1(1 hunks)
🔇 Additional comments (1)
scripts/windows/build_and_run.ps1 (1)
89-93: Project-root Set-Location and fixed.envusage are solid.Switching to
$projectRootbeforeuvand always using.envfrom root improves predictability. 👍
| REM Change to project root directory for uv | ||
| cd "%PROJECT_ROOT%" | ||
| if defined USE_ENV_FILE ( | ||
| uv run --env-file "%ENV_PATH%" langflow run | ||
| echo Using env file: .env | ||
| uv run --env-file ".env" langflow run | ||
| ) else ( | ||
| uv run langflow run | ||
| ) |
There was a problem hiding this comment.
Use cd /d or, better, pushd/popd to handle cross‑drive and UNC paths.
Plain cd won’t switch drives; cd /d will. pushd is even safer (maps UNC to a temp drive and restores on popd). This prevents running uv from the wrong drive when the repo is on D: and the caller’s prompt is on C:. (learn.microsoft.com)
Minimal fix (keep current structure):
-REM Change to project root directory for uv
-cd "%PROJECT_ROOT%"
+REM Change to project root directory for uv (switch drives too)
+cd /d "%PROJECT_ROOT%"Preferred fix (restores CWD and works with UNC):
-REM Change to project root directory for uv
-cd "%PROJECT_ROOT%"
+REM Change to project root directory for uv (supports UNC, restores on exit)
+pushd "%PROJECT_ROOT%"
if defined USE_ENV_FILE (
echo Using env file: .env
uv run --env-file ".env" langflow run
) else (
uv run langflow run
)
+popdReferences: Microsoft cd docs (/d switches drive) and pushd behavior for UNC mapping. (learn.microsoft.com)
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| REM Change to project root directory for uv | |
| cd "%PROJECT_ROOT%" | |
| if defined USE_ENV_FILE ( | |
| uv run --env-file "%ENV_PATH%" langflow run | |
| echo Using env file: .env | |
| uv run --env-file ".env" langflow run | |
| ) else ( | |
| uv run langflow run | |
| ) | |
| REM Change to project root directory for uv (switch drives too) | |
| cd /d "%PROJECT_ROOT%" | |
| if defined USE_ENV_FILE ( | |
| echo Using env file: .env | |
| uv run --env-file ".env" langflow run | |
| ) else ( | |
| uv run langflow run | |
| ) |
| REM Change to project root directory for uv | |
| cd "%PROJECT_ROOT%" | |
| if defined USE_ENV_FILE ( | |
| uv run --env-file "%ENV_PATH%" langflow run | |
| echo Using env file: .env | |
| uv run --env-file ".env" langflow run | |
| ) else ( | |
| uv run langflow run | |
| ) | |
| REM Change to project root directory for uv (supports UNC, restores on exit) | |
| pushd "%PROJECT_ROOT%" | |
| if defined USE_ENV_FILE ( | |
| echo Using env file: .env | |
| uv run --env-file ".env" langflow run | |
| ) else ( | |
| uv run langflow run | |
| ) | |
| popd |
🤖 Prompt for AI Agents
In scripts/windows/build_and_run.bat around lines 88-95, the script uses plain
CD which won't switch drives or handle UNC paths; change the directory change to
use "cd /d" if you want a minimal fix that also switches drives, or preferably
use pushd "%PROJECT_ROOT%" at the start and popd at the end to support UNC paths
and automatically restore the original CWD; keep the rest of the conditional
unchanged and ensure that popd is called (or placed in a finally/cleanup block)
so the working directory is restored after running uv.



This pull request updates the Windows build and run scripts to ensure consistent behavior when starting the Langflow application, particularly regarding the use of environment files and the working directory. The changes improve reliability and user feedback during the startup process.
Script improvements for running Langflow:
build_and_run.batandbuild_and_run.ps1now explicitly change to the project root directory before executing theuvcommand, ensuring the correct context for running Langflow. [1] [2].envdirectly and display a message indicating that.envis being used, providing clearer feedback to the user. [1] [2]Summary by CodeRabbit
Bug Fixes
Chores