Repository navigation
Conversation
…tinel The takeover test wrote a lock with pid: 9999 and hostname: os.hostname(), then invoked `sequant locks acquire --force --signal-other`. signalOther's same-host branch (lock-manager.ts:290) then called process.kill(9999, 'SIGTERM'). On a busy CI runner PID 9999 can be a live sibling/ancestor process (linux pid_max default 32768; PIDs assigned sequentially), so the SIGTERM landed on a real process — when that process was an ancestor of the spawned CLI it tore down the stdout pipe and the CLI died with SIGPIPE, surfacing as result.status === null. Fix: set hostname to a sentinel non-host string so signalOther's cross-host short-circuit (lock-manager.ts:289) returns false without ever calling process.kill. The CLI emits the same 'Could not signal PID 9999 for #77 (cross-host or already exited)' line, matching the existing regex assertion. Same fix applied to the sibling --force-without-signal-other fixture for consistency. Same-host-dead-PID branch retains unit coverage in lock-manager.test.ts:294 via the isPidAlive constructor seam. Verified: 20/20 local repeats of the takeover test pass; full locks surface (59 tests across 3 files) green.
The test title still claimed "for dead PID" after the cross-host fix even though the test no longer exercises the dead-PID branch — signalOther short-circuits on the cross-host check before isPidAlive runs. Rename to match what the test actually verifies. Tighten the stdout regex to anchor on the full "(cross-host or already exited)" suffix so a future refactor that accidentally takes the "Signaled ..." (sent) branch would fail loudly instead of slipping through a loose substring match. Expand the explanatory comment to document the CLI-message-level limitation: the same suffix is printed for both signalOther false branches (cross-host vs same-host-dead-PID), so the integration assertion cannot distinguish which internal branch ran. The same-host-dead-PID branch retains unit coverage at lock-manager.test.ts:294 via the isPidAlive constructor seam.
admarble
deleted the
feature/633-bug-test-locks-cli-integration-test-ts-201-flake-s
branch
May 13, 2026 23:11
3 tasks done
admarble
added a commit
that referenced
this pull request
May 14, 2026
* fix(#637): guard signalOther against self/parent PID 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 * refactor(#637): signalOther returns discriminated reason; accurate caller 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
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
hostname: os.hostname()in the--signal-othertakeover fixture (and its sibling fixture) with a sentinel non-host string soLockManager.signalOthertakes the cross-host short-circuit (src/lib/locks/lock-manager.ts:289) and never invokesprocess.kill(9999, 'SIGTERM').feedback_flaky_test_fixes.md).Root cause
On a busy CI runner, PID 9999 can be a live sibling/ancestor process (Linux
pid_maxdefault 32768; PIDs assigned sequentially). The same-host branch ofsignalOthersent a real SIGTERM to that PID. When the victim was an ancestor of the spawned CLI (vitest main/worker), the stdout pipe collapsed and the CLI died with SIGPIPE, surfacing asresult.status === nullatlocks-cli.integration.test.ts:201. The setup looked safe locally (where PID 9999 is rarely allocated) and only flaked under CI process pressure.AC Verification
signalOthershort-circuits on the cross-host check beforeisPidAlive/process.kill— verifiable insrc/lib/locks/lock-manager.ts:287-297--signal-otherCLI wiring still exercised--signal-other; CLI emitsCould not signal PID 9999 for #77 (cross-host or already exited)viasrc/commands/locks.ts:189, matched by the existing regex/Could not signal PID 9999 for #77/expect(result.status).toBe(0)preserved verbatim; stdout regex preserved;after.pid !== 9999preserved (see diff)process.killis no longer invoked on a guessed PIDCoverage note
The integration test now exercises the cross-host branch of
signalOtherinstead of the same-host-dead-PID branch. The same-host-dead-PID branch retains unit coverage insrc/lib/locks/lock-manager.test.ts:294(uses theisPidAliveconstructor seam to stubprocess.killcleanly). No coverage gap.Test plan
npm run build— cleannpm run lint— cleannpx vitest run src/commands/__tests__/locks-cli.integration.test.ts— 13/13 passnpx vitest run src/lib/locks src/commands/__tests__/locks-cli.integration.test.ts— 59/59 passfor i in {1..20}; do npx vitest run … -t "skill takeover"; done) — 20/20 passOptional follow-up (not in scope)
The plan flagged Option C (defense-in-depth self-PID guard in
LockManager.signalOther) as a potential follow-up. Not adopted here — the test fix is sufficient and doesn't require touching production code.Closes #633