Repository navigation
Description
Context
Spin-off from #633 / PR #634 — the spec's Phase 1 Option C row recommended a defense-in-depth self-PID guard in LockManager.signalOther but filed it as a separate follow-up to keep #633's fix scope-minimal (test-only).
The #633 flake was caused by a test fixture (pid: 9999, hostname: os.hostname()) that assumed PID 9999 was dead — on CI runners with process churn it can be alive, and signalOther would then SIGTERM whatever real process owned that PID, killing the spawned CLI's parent/sibling and producing result.status === null. PR #634 fixed the test by routing around process.kill via a sentinel cross-host hostname; this issue covers the production-code weakness that allowed the flake in the first place.
Proposal
In src/lib/locks/lock-manager.ts:287 (signalOther), add a self-PID / parent-PID guard at the top of the function:
signalOther(holder: LockFile, signal: NodeJS.Signals = "SIGTERM"): boolean {
if (this.orchestratorMode) return false;
if (holder.hostname !== this.hostname) return false;
// Defense-in-depth: never signal ourselves or our parent. A malformed
// or PID-recycled lock file should not be able to SIGTERM the manager.
if (holder.pid === this.pid || holder.pid === process.ppid) return false;
if (!this.isPidAlive(holder.pid)) return false;
try {
process.kill(holder.pid, signal);
return true;
} catch {
return false;
}
}Why this is worth doing
- Zero behavior change for valid input — a real lock file's
pidshould never be the current process's own PID or its parent's, by construction. - Narrowed failure mode — if a stale lock file's PID is reused by the OS (POSIX recycles PIDs aggressively under low
pid_max), this prevents the manager from accidentally SIGTERMing itself or its shell parent. - Production users — the bug(test): locks-cli.integration.test.ts:201 flake — signal-other takeover returns null status #633 flake was a test artifact, but the underlying weakness (
signalOthertrusts the lock file's claimed PID unconditionally once same-host + alive checks pass) is real production code.
Known limitations
- This guard does NOT cover the sibling-vitest-worker case (a separate PID from both
this.pidandprocess.ppid). That is the harder bug, and it's the one fix(#633): eliminate locks-cli takeover test flake via cross-host sentinel #634 actually fixed by avoidingprocess.killentirely in the integration test. So this is a narrowed guard, not a full fix. - Strict equality on
process.ppidis the right call (don't try to walk up the process tree — flaky and platform-dependent).
Verification
- Unit test in
src/lib/locks/lock-manager.test.ts: construct aLockManager, build a holder withpid: process.pidand same hostname, callsignalOther(holder), assert it returnsfalsewithout invoking the stubbedisPidAlive(use a spy or counter). - Same for
pid: process.ppid. - Existing same-host-alive test should still pass unchanged.
Out of scope
- Walking the process ancestry beyond
process.ppid. - Process-group checks (
process.kill(-pid, 0)semantics). - Refactoring the test in fix(#633): eliminate locks-cli takeover test flake via cross-host sentinel #634 — that fix stands on its own.
References
- bug(test): locks-cli.integration.test.ts:201 flake — signal-other takeover returns null status #633 (root flake)
- fix(#633): eliminate locks-cli takeover test flake via cross-host sentinel #634 (test-side fix)
src/lib/locks/lock-manager.ts:287(signalOtherimplementation)feedback_flaky_test_fixes.md(no widening tolerances — production-code hardening is a legitimate follow-up, not a workaround)
Activity
admarble commentedon May 13, 2026
Complexity: Simple (3 ACs, 1 directory)
AC Quality Check
Issue body already includes a verification section with concrete test cases; no vague/unmeasurable language. AC formally extracted below.
Scope Assessment
Non-Goals: Walking process ancestry beyond
process.ppid; process-group checks; refactoring the #634 test.src/lib/locks/)Verdict: ✅ SCOPE_OK — narrow defense-in-depth follow-up to #633/#634.
Acceptance Criteria
AC-1: signalOther returns false when holder.pid equals this.pid, without invoking isPidAlive
Verification: Unit Test
Scenario: Given a
LockManagerwithpid: 1and a spyisPidAlive→ WhensignalOther({ pid: 1, hostname: <same-host>, ... })is called → Then return value isfalseAND theisPidAlivespy is not invoked (call count = 0).Assumptions: Test seam
pidconstructor option already exists.AC-2: signalOther returns false when holder.pid equals process.ppid, without invoking isPidAlive
Verification: Unit Test
Scenario: Given a
LockManagerconstructed withpid: 999(any value different fromprocess.ppid) and a spyisPidAlive→ WhensignalOther({ pid: process.ppid, hostname: <same-host>, ... })is called → Then return value isfalseAND the spy is not invoked.Assumptions:
process.ppidis read at call time insidesignalOther; we compare against the liveprocess.ppid. Test does not stubprocess.ppid.AC-3: Existing same-host-alive signalOther test passes unchanged
Verification: Unit Test
Scenario: The current
signalOther only signals same-host alive PIDstest inlock-manager.test.ts:294continues to pass — its holder PID (9999) is neitherthis.pid(1) norprocess.ppid, so the new guard does not engage.Implementation Plan
Phase 1: Production code
src/lib/locks/lock-manager.ts:287(signalOther). After the existingorchestratorModeand hostname checks, insert a self/parent PID guard before theisPidAliveprobe:isPidAlivecheck (line 290). This ensures the spy assertion in AC-1/AC-2 holds.Phase 2: Tests
LockManager — forceAcquire / signalOtherdescribe block insrc/lib/locks/lock-manager.test.ts(around line 333):pid: 1, build holder withpid: 1same host, spy onisPidAlive, assert returnsfalseand spy not called.pid: 999(≠process.ppid), holderpid: process.ppidsame host, same assertions.Phase 3: Verify
npx vitest run src/lib/locks/lock-manager.test.ts— all existing tests + 2 new must pass.npm run build— TypeScript clean.Design Review
Where does this logic belong?
LockManager.signalOtheritself — single chokepoint for anyprocess.killcall originating from the lock manager. No upstream caller (e.g.--forceflow inbin/cli.ts) needs to know about this guard.What existing pattern does this follow? Defense-in-depth guards within signal-sending code paths. The function already short-circuits on orchestrator mode and cross-host; self/parent PID is the third short-circuit in the same shape.
Open Questions
None — the issue body provides a complete implementation and verification recipe.
Recommended Workflow
Phases: exec → qa
Quality Loop: disabled (single-file change, very small surface)
Reasoning: No UI; defense-in-depth narrow-scope fix; verification is pure unit-test.
Label Review
Current:
enhancementRecommended:
enhancement(keep as-is)Reason: Adding
simple-fixwould be accurate but isn't required for routing.admarble commentedon May 13, 2026
QA Verdict: READY_FOR_MERGE
Diff: 74 lines (5-line guard insert + 2 unit tests). Reviewed inline (under the 600-line worktree-agent threshold).
AC Coverage
isPidAlive. Test assertsprobed === 0.isPidAlive. Test constructs manager withpid: process.pid(POSIX guaranteesprocess.pid !== process.ppid) and holderpid: process.ppid.signalOther only signals same-host alive PIDstest (line 294) passes unchanged. Full suite: 45/45 ✅.Quality
isPidAliveprobe (required for AC-1/AC-2 spy assertion).Adversarial pass
process.pid === process.ppidimpossible on POSIX → AC-2 test is well-formed.process.ppidin CI → vanishingly unlikely; if it ever happened the test would signal correct new behavior, not regression.admarble commentedon May 13, 2026
/fullsolve Complete
Issue: #637
Status: READY_FOR_MERGE
PR: #639
Summary
Iterations
Ready for human review and merge.
refactor(#637): signalOther returns discriminated reason; accurate ca…
fix(#637): guard signalOther against self/parent PID (#639)
admarble commentedon May 14, 2026
Documentation Updated
This was an internal hardening fix with one user-visible change (more specific
--force --signal-otherlog lines). Existing feature doc already covered the command, so updated in-place rather than generating a new template.File:
docs/features/concurrency-locks.md(--force --signal-othersection)Added
--signal-othercan print, one per refusal/success branchPR: #641
docs(#637): document signal-other refusal reasons + self-or-parent gu…