Skip to content

Harden brainstorm stop-server stale pid handling#1703

Open
VeraPyuyi wants to merge 1 commit into
obra:devfrom
VeraPyuyi:codex/stop-server-stale-pid
Open

Harden brainstorm stop-server stale pid handling#1703
VeraPyuyi wants to merge 1 commit into
obra:devfrom
VeraPyuyi:codex/stop-server-stale-pid

Conversation

@VeraPyuyi

Copy link
Copy Markdown

Summary

  • harden brainstorm stop-server.sh so stale or reused state/server.pid values do not kill unrelated processes
  • verify process ownership before SIGTERM and again before SIGKILL using the Node server.cjs entrypoint plus matching session ownership
  • fail closed as {status:stale_pid} when ownership cannot be proven, while preserving {status:stopped} for real brainstorm servers
  • add regression coverage for unrelated PIDs, fake server.cjs argv mentions, different-session brainstorm servers, paths with spaces, and real server shutdown

Validation

  • C:\Program Files\Git\bin\bash.exe tests/brainstorm-server/stop-server.test.sh -> 9 passed, 0 failed
  • C:\Program Files\Git\bin\bash.exe tests/brainstorm-server/windows-lifecycle.test.sh -> 12 passed, 0 failed, 0 skipped
  • C:\Program Files\Git\bin\bash.exe -n skills/brainstorming/scripts/stop-server.sh
  • C:\Program Files\Git\bin\bash.exe -n tests/brainstorm-server/stop-server.test.sh
  • git diff --check
  • git diff --cached --check

Note: scripts/lint-shell.sh skills/brainstorming/scripts/stop-server.sh tests/brainstorm-server/stop-server.test.sh could not run locally because shellcheck is not installed on PATH.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant