Harden brainstorm stop-server stale pid handling#1703
Open
VeraPyuyi wants to merge 1 commit into
Open
Conversation
5 tasks
5 tasks
arittr
pushed a commit
that referenced
this pull request
Jun 11, 2026
stop-server.sh read server.pid and SIGKILL'd that PID with no checks. After a
reboot or PID wraparound the pid file can point at an unrelated, live process —
which we would then kill.
Verify the PID is actually our server (a running 'node ... server.cjs') before
signalling it. If ownership can't be proven, fail closed: remove the stale pid
file and report {status: stale_pid} without killing anything. Real servers still
stop ({status: stopped}); a missing pid file still reports not_running.
Adds stop-server.test.sh covering: an unrelated reused PID is left alone, a real
server is stopped, and a missing pid file.
Refs #1703
arittr
pushed a commit
that referenced
this pull request
Jun 11, 2026
The node+server.cjs command match (from the adversarial review) still matched any unrelated node process running a file named server.cjs. When we recorded the bound port (state/server-info) and lsof is available, additionally require the PID to be the process actually LISTENING on this session's port — which rules out a different project's server.cjs / editor task runner that recycled the stale PID. Falls back to the command match when the port or lsof isn't available. Test: a 'node server.cjs' process not listening on the recorded port is spared. Refs #1703
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
stop-server.shso stale or reusedstate/server.pidvalues do not kill unrelated processesserver.cjsentrypoint plus matching session ownership{status:stale_pid}when ownership cannot be proven, while preserving{status:stopped}for real brainstorm serversserver.cjsargv mentions, different-session brainstorm servers, paths with spaces, and real server shutdownValidation
C:\Program Files\Git\bin\bash.exe tests/brainstorm-server/stop-server.test.sh-> 9 passed, 0 failedC:\Program Files\Git\bin\bash.exe tests/brainstorm-server/windows-lifecycle.test.sh-> 12 passed, 0 failed, 0 skippedC:\Program Files\Git\bin\bash.exe -n skills/brainstorming/scripts/stop-server.shC:\Program Files\Git\bin\bash.exe -n tests/brainstorm-server/stop-server.test.shgit diff --checkgit diff --cached --checkNote:
scripts/lint-shell.sh skills/brainstorming/scripts/stop-server.sh tests/brainstorm-server/stop-server.test.shcould not run locally becauseshellcheckis not installed on PATH.