Skip to content

fix: Ensure consistent Langflow startup in Windows scripts#9917

Merged
Cristhianzl merged 1 commit into
mainfrom
cz/fix-env-loc-windows-script
Sep 24, 2025
Merged

fix: Ensure consistent Langflow startup in Windows scripts#9917
Cristhianzl merged 1 commit into
mainfrom
cz/fix-env-loc-windows-script

Conversation

@Cristhianzl
Copy link
Copy Markdown
Member

@Cristhianzl Cristhianzl commented Sep 18, 2025

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:

  • Both build_and_run.bat and build_and_run.ps1 now explicitly change to the project root directory before executing the uv command, ensuring the correct context for running Langflow. [1] [2]
  • When using an environment file, both scripts now always reference .env directly and display a message indicating that .env is being used, providing clearer feedback to the user. [1] [2]

Summary by CodeRabbit

  • Bug Fixes

    • Ensured Windows run scripts execute from the project root for more reliable startup.
    • Standardized environment file resolution to use .env from the project root, reducing path-related issues.
  • Chores

    • Updated Windows scripts to display “Using env file: .env” when applicable for clearer diagnostics.
    • Minor script adjustments to streamline launch flow without changing user-facing commands.

@Cristhianzl Cristhianzl self-assigned this Sep 18, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 18, 2025

Walkthrough

Both 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

Cohort / File(s) Summary of Changes
Windows run scripts
scripts/windows/build_and_run.bat, scripts/windows/build_and_run.ps1
Added directory switch to project root before running uv. Replaced variable-based env-file path with literal ".env" and added a console message indicating its use. Else branch (no env file) remains the same.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

bug, lgtm

Suggested reviewers

  • ogabrielluiz
  • deon-sanchez
  • edwinjosechittilappilly

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "fix: Ensure consistent Langflow startup in Windows scripts" succinctly and accurately captures the primary change by indicating a fix and the affected area (Windows startup scripts); it matches the PR objectives and the file-level edits to build_and_run.bat and build_and_run.ps1 and is clear for teammates scanning history.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cz/fix-env-loc-windows-script

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.

@github-actions github-actions Bot added the bug Something isn't working label Sep 18, 2025
@sonarqubecloud
Copy link
Copy Markdown

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Sep 18, 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 (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

📥 Commits

Reviewing files that changed from the base of the PR and between 7792b7a and 3820634.

📒 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 .env usage are solid.

Switching to $projectRoot before uv and always using .env from root improves predictability. 👍

Comment on lines +88 to 95
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
)
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.

⚠️ Potential issue

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
 )
+popd

References: 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.

Suggested change
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
)
Suggested change
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.

Copy link
Copy Markdown
Collaborator

@lucaseduoli lucaseduoli left a comment

Choose a reason for hiding this comment

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

lgtm

@github-actions github-actions Bot added the lgtm This PR has been approved by a maintainer label Sep 18, 2025
@Cristhianzl Cristhianzl added this pull request to the merge queue Sep 18, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 18, 2025
@Cristhianzl Cristhianzl added this pull request to the merge queue Sep 24, 2025
Merged via the queue into main with commit 925767d Sep 24, 2025
19 checks passed
@Cristhianzl Cristhianzl deleted the cz/fix-env-loc-windows-script branch September 24, 2025 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants