@@ -293,9 +293,9 @@ function Invoke-Setup {
293293 # Check for .env file
294294 if (-not (Test-Path " .env" )) {
295295 Write-Warning " .env file not found"
296- if (Test-Path " .env.template " ) {
297- Write-Info " Copying .env.template to .env..."
298- Copy-Item " .env.template " " .env"
296+ if (Test-Path " .env.sample " ) {
297+ Write-Info " Copying .env.sample to .env..."
298+ Copy-Item " .env.sample " " .env"
299299 Write-Warning " Please update .env with your Azure resource values"
300300 }
301301 } else {
@@ -357,9 +357,9 @@ function Invoke-EnvGeneration {
357357 Write-Warning " Azure Developer CLI not found or no azure.yaml"
358358 Write-Info " Please manually update .env with your Azure resource values"
359359
360- if (-not (Test-Path " .env" ) -and (Test-Path " .env.template " )) {
361- Copy-Item " .env.template " " .env"
362- Write-Info " Created .env from template "
360+ if (-not (Test-Path " .env" ) -and (Test-Path " .env.sample " )) {
361+ Copy-Item " .env.sample " " .env"
362+ Write-Info " Created .env from .env.sample "
363363 }
364364 }
365365
@@ -423,6 +423,8 @@ function Start-Backend {
423423 Push-Location $BackendDir
424424 try {
425425 # Use hypercorn for async support
426+ # Output filter suppresses benign Ctrl+C shutdown noise from Python (InterruptedError tracebacks,
427+ # sys.exit, frozen importlib). Real startup/runtime errors appear before these patterns.
426428 if (Test-Command " hypercorn" ) {
427429 hypercorn app:app -- bind " 0.0.0.0:$BackendPort " -- reload 2>&1 | ForEach-Object {
428430 if ($_ -notmatch " Traceback|File.*frozen|InterruptedError|sys\.exit" ) {
@@ -437,7 +439,7 @@ function Start-Backend {
437439 }
438440 }
439441 } catch {
440- # Suppress Ctrl+C exceptions
442+ # Suppress Ctrl+C PipelineStoppedException — not a real error
441443 } finally {
442444 Pop-Location
443445 }
@@ -481,6 +483,33 @@ function Start-All {
481483
482484 Set-Location $ProjectRoot
483485
486+ # Handle .env: generate if missing, or prompt to refresh if exists
487+ if (-not (Test-Path " .env" )) {
488+ Write-Warning " .env file not found. Generating from Azure resources..."
489+ Invoke-EnvGeneration
490+ # Fallback to .env.sample if generation didn't produce .env
491+ if (-not (Test-Path " .env" ) -and (Test-Path " .env.sample" )) {
492+ Write-Warning " Env generation did not create .env. Copying .env.sample as fallback..."
493+ Copy-Item " .env.sample" " .env"
494+ Write-Info " Created .env from .env.sample. Update the file with your Azure resource values."
495+ }
496+ if (-not (Test-Path " .env" )) {
497+ Write-Error " Failed to create .env. Run '.\scripts\local_dev.ps1 -Command env' or create .env manually from .env.sample."
498+ exit 1
499+ }
500+ } else {
501+ Write-Success " Found existing .env file"
502+ $overwrite = Read-Host " Do you want to overwrite it with fresh values from Azure deployment? (y/N)"
503+ if ($overwrite -eq ' y' -or $overwrite -eq ' Y' ) {
504+ Write-Info " Regenerating .env from Azure resources..."
505+ Remove-Item " .env" - Force
506+ Invoke-EnvGeneration
507+ Write-Success " Environment variables refreshed."
508+ } else {
509+ Write-Info " Preserving existing .env. Using local configuration."
510+ }
511+ }
512+
484513 # Auto-run setup if prerequisites are missing
485514 $needsSetup = $false
486515 if (-not (Test-Path " .venv" )) {
@@ -495,12 +524,6 @@ function Start-All {
495524 Invoke-Setup
496525 }
497526
498- # Auto-run env generation if .env is missing
499- if (-not (Test-Path " .env" )) {
500- Write-Warning " .env file not found. Generating from Azure resources..."
501- Invoke-EnvGeneration
502- }
503-
504527 # Ensure Azure roles
505528 Ensure- AzureLogin
506529 Ensure- AzureAIUserRole
@@ -572,8 +595,15 @@ function Start-All {
572595 }
573596 }
574597
575- if ($backendJob.State -eq ' Failed' -or $frontendJob.State -eq ' Failed' ) {
576- Write-Error " One of the services failed"
598+ # Break if either job is no longer running
599+ $backendState = $backendJob.State
600+ $frontendState = $frontendJob.State
601+ if ($backendState -ne ' Running' -or $frontendState -ne ' Running' ) {
602+ if ($backendState -eq ' Failed' -or $frontendState -eq ' Failed' ) {
603+ Write-Error " One of the services failed (backend: $backendState , frontend: $frontendState )"
604+ } else {
605+ Write-Warning " A service has stopped (backend: $backendState , frontend: $frontendState )"
606+ }
577607 break
578608 }
579609
0 commit comments