@@ -268,24 +268,26 @@ var serviceUpCmd = &cobra.Command{
268268 modified = re .ReplaceAllString (modified , repl )
269269 }
270270
271- // Then replace http://localhost:PORT → https://domain for declared prefixes
272- localhostRe := regexp .MustCompile (`http://localhost:\d+` )
271+ // Then replace http://localhost:PORT → https://domain for declared prefixes only.
272+ // If env_rewrite_vars is empty, skip rewriting entirely — projects that need
273+ // localhost URLs rewritten must declare which prefixes explicitly. The previous
274+ // behavior of rewriting ALL localhost URLs when no prefixes are declared would
275+ // undo env_transforms that intentionally set localhost for backend-to-backend calls.
273276 rewritePrefixes := ctx .spec .Sync .EnvRewriteVars
274- var rewrittenLines []string
275- for _ , line := range strings .Split (modified , "\n " ) {
276- if len (rewritePrefixes ) > 0 {
277+ if len (rewritePrefixes ) > 0 {
278+ localhostRe := regexp .MustCompile (`http://localhost:\d+` )
279+ var rewrittenLines []string
280+ for _ , line := range strings .Split (modified , "\n " ) {
277281 for _ , prefix := range rewritePrefixes {
278282 if strings .HasPrefix (line , prefix ) {
279283 line = localhostRe .ReplaceAllString (line , domain )
280284 break
281285 }
282286 }
283- } else {
284- line = localhostRe .ReplaceAllString (line , domain )
287+ rewrittenLines = append (rewrittenLines , line )
285288 }
286- rewrittenLines = append (rewrittenLines , line )
289+ modified = strings . Join (rewrittenLines , " \n " )
287290 }
288- modified = strings .Join (rewrittenLines , "\n " )
289291
290292 changed := modified != envContent
291293 if ! changed {
@@ -423,12 +425,15 @@ var serviceUpCmd = &cobra.Command{
423425 if len (preFuserCmds ) > 0 {
424426 remotessh .Exec (ctx .keyPath , ctx .user , ctx .addr , strings .Join (preFuserCmds , "; " )+ "; true" )
425427 }
426- // Use pgrep to find PIDs first, then kill them in one batch (avoids
427- // pkill matching itself and avoids race conditions between passes) .
428+ // Kill orphaned processes scoped to THIS project only.
429+ // Find PIDs by project path in cmdline or cwd, then kill in one batch .
428430 remotessh .Exec (ctx .keyPath , ctx .user , ctx .addr ,
429431 fmt .Sprintf (
430- "{ pgrep -f '%s.*(turbo|tsx|next)'; pgrep -x air; pgrep -f '^sh -c.*(tsx|air|next|PORT=)'; } 2>/dev/null | sort -u | xargs -r kill -9 2>/dev/null; true" ,
431- remotePath ))
432+ "{ pgrep -f '%s.*(turbo|tsx|next|air)'; " +
433+ "for pid in $(pgrep -x air; pgrep -f '^sh -c.*(tsx|air|next|PORT=)'); do " +
434+ " readlink /proc/$pid/cwd 2>/dev/null | grep -q '%s' && echo $pid; " +
435+ "done; } 2>/dev/null | sort -u | xargs -r kill -9 2>/dev/null; true" ,
436+ remotePath , remotePath ))
432437
433438 // 6. Run lifecycle.start
434439 if ctx .spec .Lifecycle .Start != "" {
@@ -552,12 +557,15 @@ var serviceDownCmd = &cobra.Command{
552557 // Use the saved PID file (now written in both foreground and detach modes)
553558 // to kill the entire process group. As a fallback, also pkill known patterns.
554559 remotePath := ctx .spec .Remote .Path
555- // Use pgrep to find PIDs first, then kill them in one batch (avoids
556- // pkill matching itself and avoids race conditions between passes) .
560+ // Kill orphaned processes scoped to THIS project only.
561+ // Find PIDs by project path in cmdline or cwd, then kill in one batch .
557562 remotessh .Exec (ctx .keyPath , ctx .user , ctx .addr ,
558563 fmt .Sprintf (
559- "{ pgrep -f '%s.*(turbo|tsx|next)'; pgrep -x air; pgrep -f '^sh -c.*(tsx|air|next|PORT=)'; } 2>/dev/null | sort -u | xargs -r kill -9 2>/dev/null; true" ,
560- remotePath ))
564+ "{ pgrep -f '%s.*(turbo|tsx|next|air)'; " +
565+ "for pid in $(pgrep -x air; pgrep -f '^sh -c.*(tsx|air|next|PORT=)'); do " +
566+ " readlink /proc/$pid/cwd 2>/dev/null | grep -q '%s' && echo $pid; " +
567+ "done; } 2>/dev/null | sort -u | xargs -r kill -9 2>/dev/null; true" ,
568+ remotePath , remotePath ))
561569
562570 // Stop Docker dependencies if --all
563571 if all && len (ctx .spec .Dependencies .Docker ) > 0 {
0 commit comments