Skip to content

fix(#637): guard signalOther against self/parent PID - #639

Merged
admarble merged 2 commits into
mainfrom
feature/637-defense-lockmanager-signalother-guard
May 14, 2026
Merged

admarble merged 2 commits into
mainfrom
feature/637-defense-lockmanager-signalother-guard

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

Defense-in-depth follow-up to #633/#634. Adds a self-PID / parent-PID short-circuit in LockManager.signalOther before the isPidAlive probe. A malformed lock file or a recycled PID could otherwise let the manager SIGTERM its own shell.

  • src/lib/locks/lock-manager.ts: 5-line guard after the hostname check
  • src/lib/locks/lock-manager.test.ts: two unit tests assert the guard short-circuits before the isPidAlive spy runs (verifies guard ordering, not just the return value)

Why not just rely on #634?

PR #634 fixed the test fixture that caused the flake (cross-host sentinel hostname routes around process.kill). The production-code weakness in signalOther — trusting the lock file's claimed PID once same-host + alive checks pass — was left for this follow-up. Real users with low-pid_max kernels could still hit recycled-PID footguns.

Scope

  • ✅ Self-PID guard
  • ✅ Parent-PID (process.ppid) guard
  • ❌ Process-ancestry walking (out of scope — flaky, platform-dependent)
  • ❌ Process-group checks (out of scope)

Test plan

  • npx vitest run src/lib/locks/lock-manager.test.ts — 45/45 passing (43 existing + 2 new)
  • npm run build — clean
  • Existing signalOther only signals same-host alive PIDs test unchanged (holder.pid=9999, manager.pid=1 — guard does not engage)

Fixes #637

Adds a self-PID / parent-PID short-circuit in `LockManager.signalOther`
before the `isPidAlive` probe. Defense-in-depth follow-up to the #633
flake fixed in #634 — production users can still hit the underlying
weakness if a recycled PID lands on the manager's own PID or its
parent shell.

- src/lib/locks/lock-manager.ts: insert guard after hostname check
- src/lib/locks/lock-manager.test.ts: two new tests assert the guard
  short-circuits BEFORE invoking the isPidAlive spy

Fixes #637
…ller logs

Promotes `LockManager.signalOther` return from `boolean` to
`{ sent: boolean; reason: SignalReason }` so callers can produce a
correct log line in each refusal branch — including the new
self-or-parent guard added earlier in this PR, which previously
collapsed into the misleading "(cross-host or already exited)" suffix.

- src/lib/locks/types.ts: add SignalReason / SignalOtherResult
- src/lib/locks/index.ts: re-export new types
- src/lib/locks/lock-manager.ts: rewrite signalOther to return reason
- src/lib/locks/lock-manager.test.ts: assert reason discriminator in
  existing + #637 tests; AC-1 test now uses process.pid for the
  manager (mirrors production; pid=1 was unrealistic)
- src/commands/locks.ts + run-orchestrator.ts: per-branch log mapper
- src/commands/__tests__/locks-cli.integration.test.ts: anchor on
  the new "(cross-host holder)" suffix
@admarble
admarble merged commit 439e1dc into main May 14, 2026
5 checks passed
@admarble
admarble deleted the feature/637-defense-lockmanager-signalother-guard branch May 14, 2026 02:34
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.

defense: LockManager.signalOther should guard against signaling self/parent PID

1 participant