fix: wrap Makefile subshell cd commands in parentheses - #3333
Conversation
|
|
🧪 Test Suite AvailableThis PR can be tested by a repository admin. |
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe Makefile's ChangesDevelopment Build Targets
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Confidence Score: 5/5Safe to merge — the subshell wrapping correctly scopes directory changes, and the new PID-based cleanup in The core fix (subshell wrapping) is correct and non-breaking. The additional No files require special attention. Important Files Changed
Reviews (5): Last reviewed commit: "fix: wrap Makefile subshell cd commands ..." | Re-trigger Greptile |
cab5a58 to
befa6a2
Compare
The merge-base changed after approval.
befa6a2 to
4e05e6f
Compare
The merge-base changed after approval.
4e05e6f to
49f495f
Compare
The merge-base changed after approval.
49f495f to
4b8c081
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Makefile`:
- Around line 159-178: The cleanup() target currently kills only direct children
found via pgrep -P and leaves deeper descendants running; update it to terminate
entire process trees by targeting process groups or recursive descendants for
both ui_pid and api_pid (the variables ui_pid/api_pid and the cleanup() function
are the relevant symbols). Specifically, when sending TERM/KILL, prefer killing
the whole process group (send signals to negative pid for the process group id)
and/or recursively collect all descendant PIDs before sending signals so no deep
child is left running; keep the existing logging messages and fall back to the
pgrep -P approach only if process-group signaling is unavailable.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
| cleanup() { \ | ||
| $(ECHO) "$(YELLOW)[make dev] cleanup started; ui_pid=$$ui_pid api_pid=$$api_pid$(NC)"; \ | ||
| trap - EXIT INT TERM HUP; \ | ||
| kill %1 %2 2>/dev/null || true; \ | ||
| for pid in "$$ui_pid" "$$api_pid"; do \ | ||
| if [ -n "$$pid" ]; then \ | ||
| children="$$(pgrep -P "$$pid" 2>/dev/null || true)"; \ | ||
| $(ECHO) "$(YELLOW)[make dev] sending TERM to pid $$pid and children: $${children:-none}$(NC)"; \ | ||
| kill -TERM $$children "$$pid" 2>/dev/null || true; \ | ||
| fi; \ | ||
| done; \ | ||
| sleep 1; \ | ||
| kill -KILL %1 %2 2>/dev/null || true; \ | ||
| for pid in "$$ui_pid" "$$api_pid"; do \ | ||
| if [ -n "$$pid" ]; then \ | ||
| children="$$(pgrep -P "$$pid" 2>/dev/null || true)"; \ | ||
| $(ECHO) "$(YELLOW)[make dev] sending KILL to pid $$pid and remaining children: $${children:-none}$(NC)"; \ | ||
| kill -KILL $$children "$$pid" 2>/dev/null || true; \ | ||
| fi; \ | ||
| done; \ | ||
| $(ECHO) "$(YELLOW)[make dev] waiting for background jobs to exit...$(NC)"; \ | ||
| wait 2>/dev/null || true; \ |
There was a problem hiding this comment.
Kill the full process tree during make dev cleanup.
This cleanup only targets direct children of the tracked subshell. With the process chain started at Line 225, that can kill the shell and its first child while leaving a deeper long-lived child behind, so the next make dev can come up with a stale process still holding $(PORT).
♻️ Suggested fix
cleanup() { \
$(ECHO) "$(YELLOW)[make dev] cleanup started; ui_pid=$$ui_pid api_pid=$$api_pid$(NC)"; \
trap - EXIT INT TERM HUP; \
+ kill_tree() { \
+ local sig="$$1" pid="$$2" child; \
+ for child in $$(pgrep -P "$$pid" 2>/dev/null || true); do \
+ kill_tree "$$sig" "$$child"; \
+ done; \
+ kill -s "$$sig" "$$pid" 2>/dev/null || true; \
+ }; \
for pid in "$$ui_pid" "$$api_pid"; do \
if [ -n "$$pid" ]; then \
- children="$$(pgrep -P "$$pid" 2>/dev/null || true)"; \
- $(ECHO) "$(YELLOW)[make dev] sending TERM to pid $$pid and children: $${children:-none}$(NC)"; \
- kill -TERM $$children "$$pid" 2>/dev/null || true; \
+ $(ECHO) "$(YELLOW)[make dev] sending TERM to pid $$pid tree$(NC)"; \
+ kill_tree TERM "$$pid"; \
fi; \
done; \
sleep 1; \
for pid in "$$ui_pid" "$$api_pid"; do \
if [ -n "$$pid" ]; then \
- children="$$(pgrep -P "$$pid" 2>/dev/null || true)"; \
- $(ECHO) "$(YELLOW)[make dev] sending KILL to pid $$pid and remaining children: $${children:-none}$(NC)"; \
- kill -KILL $$children "$$pid" 2>/dev/null || true; \
+ $(ECHO) "$(YELLOW)[make dev] sending KILL to pid $$pid tree$(NC)"; \
+ kill_tree KILL "$$pid"; \
fi; \
done; \🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@Makefile` around lines 159 - 178, The cleanup() target currently kills only
direct children found via pgrep -P and leaves deeper descendants running; update
it to terminate entire process trees by targeting process groups or recursive
descendants for both ui_pid and api_pid (the variables ui_pid/api_pid and the
cleanup() function are the relevant symbols). Specifically, when sending
TERM/KILL, prefer killing the whole process group (send signals to negative pid
for the process group id) and/or recursively collect all descendant PIDs before
sending signals so no deep child is left running; keep the existing logging
messages and fall back to the pgrep -P approach only if process-group signaling
is unavailable.
Merge activity
|
## Summary Wraps `cd ui && ...` commands in subshells `(cd ui && ...)` in the `dev` and `dev-pulse` Make targets to prevent the `cd` from leaking into the parent shell process when backgrounded with `&`. ## Changes - Wrapped 4 `cd ui && npm run dev` invocations in parentheses for both `dev` and `dev-pulse` targets - Without parentheses, `cd ui` changes the working directory of the parent shell when the command is backgrounded, which can cause subsequent commands in the recipe to run from the wrong directory ## Type of change - [x] Bug fix - [ ] Feature - [ ] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [ ] Core (Go) - [ ] Transports (HTTP) - [ ] Providers/Integrations - [ ] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh make dev # Verify both UI dev server and API server start correctly ``` ## Screenshots/Recordings N/A ## Breaking changes - [ ] Yes - [x] No ## Related issues N/A ## Security considerations None. ## Checklist - [x] I read `docs/contributing/README.md` and followed the guidelines - [x] I added/updated tests where appropriate - [x] I updated documentation where needed - [x] I verified builds succeed (Go and UI) - [x] I verified the CI pipeline passes locally if applicable
## Summary Wraps `cd ui && ...` commands in subshells `(cd ui && ...)` in the `dev` and `dev-pulse` Make targets to prevent the `cd` from leaking into the parent shell process when backgrounded with `&`. ## Changes - Wrapped 4 `cd ui && npm run dev` invocations in parentheses for both `dev` and `dev-pulse` targets - Without parentheses, `cd ui` changes the working directory of the parent shell when the command is backgrounded, which can cause subsequent commands in the recipe to run from the wrong directory ## Type of change - [x] Bug fix - [ ] Feature - [ ] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [ ] Core (Go) - [ ] Transports (HTTP) - [ ] Providers/Integrations - [ ] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh make dev # Verify both UI dev server and API server start correctly ``` ## Screenshots/Recordings N/A ## Breaking changes - [ ] Yes - [x] No ## Related issues N/A ## Security considerations None. ## Checklist - [x] I read `docs/contributing/README.md` and followed the guidelines - [x] I added/updated tests where appropriate - [x] I updated documentation where needed - [x] I verified builds succeed (Go and UI) - [x] I verified the CI pipeline passes locally if applicable
## Summary Wraps `cd ui && ...` commands in subshells `(cd ui && ...)` in the `dev` and `dev-pulse` Make targets to prevent the `cd` from leaking into the parent shell process when backgrounded with `&`. ## Changes - Wrapped 4 `cd ui && npm run dev` invocations in parentheses for both `dev` and `dev-pulse` targets - Without parentheses, `cd ui` changes the working directory of the parent shell when the command is backgrounded, which can cause subsequent commands in the recipe to run from the wrong directory ## Type of change - [x] Bug fix - [ ] Feature - [ ] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [ ] Core (Go) - [ ] Transports (HTTP) - [ ] Providers/Integrations - [ ] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh make dev # Verify both UI dev server and API server start correctly ``` ## Screenshots/Recordings N/A ## Breaking changes - [ ] Yes - [x] No ## Related issues N/A ## Security considerations None. ## Checklist - [x] I read `docs/contributing/README.md` and followed the guidelines - [x] I added/updated tests where appropriate - [x] I updated documentation where needed - [x] I verified builds succeed (Go and UI) - [x] I verified the CI pipeline passes locally if applicable

Summary
Wraps
cd ui && ...commands in subshells(cd ui && ...)in thedevanddev-pulseMake targets to prevent thecdfrom leaking into the parent shellprocess when backgrounded with
&.Changes
cd ui && npm run devinvocations in parentheses for bothdevanddev-pulsetargetscd uichanges the working directory of the parent shellwhen the command is backgrounded, which can cause subsequent commands in the
recipe to run from the wrong directory
Type of change
Affected areas
How to test
make dev # Verify both UI dev server and API server start correctlyScreenshots/Recordings
N/A
Breaking changes
Related issues
N/A
Security considerations
None.
Checklist
docs/contributing/README.mdand followed the guidelines