Repository navigation
Description
Problem
`src/commands/tests/locks-cli.integration.test.ts:201` — `sequant locks acquire --force --signal-other --skip-pid-check` (skill takeover) — fails intermittently in CI with:
```
AssertionError: expected null to be +0 // Object.is equality
- Expected: 0
- Received: null
❯ src/commands/tests/locks-cli.integration.test.ts:201:27
201| expect(result.status).toBe(0);
```
The assertion is on `result.status` from a `spawnSync` of `dist/bin/cli.js`. `status === null` indicates the child was terminated by a signal (rather than exiting with an exit code), so the CLI process was killed mid-execution.
Frequency
Observed on PR #630 (issue #605): first build matrix run failed on both Node 20.x AND 22.x; re-run of the same commit passed cleanly on both. So roughly 1/2 attempts on a single push — high enough to bite future PRs.
Verbatim CI evidence
- Failed run (Node 22.x): https://github.com/sequant-io/sequant/actions/runs/25778066723/job/75714721701
- Passing re-run (same commit `5973f03`): both build (20.x) and build (22.x) green.
The diff under test was completely unrelated to the locks subsystem (it touched bin/cli.ts, run-orchestrator.ts, github.ts/test, run-command.md, merger skill mirrors), so the trigger is not in the test's own input — it's environmental.
Why this matters
This is the only `--signal-other` test in the suite. The CLI under test calls `process.kill(9999, 'SIGTERM')` (per `--signal-other --force` with a long-dead PID 9999). The test expects the CLI to:
- SIGTERM PID 9999 → ESRCH (no such process)
- Print `Could not signal PID 9999 for feat(#74): implement graceful shutdown for sequant run #77`
- Continue and successfully claim the lock with exit code 0
When the CLI returns `status === null`, the CLI process itself died — most likely from a signal it propagated to its own group, or from vitest worker cleanup interrupting the spawn boundary.
Reproduction notes
- Not reliably reproducible locally; only surfaces under CI process-group pressure.
- The test added in feat(#625): per-issue concurrency lock prevents concurrent sequant sessions #626 (merge `6b70fe7`). It passed on prior CI runs and only flaked on the next push.
Suggested investigation directions
(For the assignee — do not implement blind.)
- Process-group leak: verify the CLI's signal-other implementation doesn't accidentally signal its own group (e.g. `kill(-pid, 'SIGTERM')` with a negative pid that could match itself). `process.kill` with a positive PID is safe; with a negative PID it signals the group.
- `spawnSync` env passthrough: `runCli` spreads `process.env` and adds `SEQUANT_ORCHESTRATOR: ""`. Empty-string env vars are still set on POSIX — verify this doesn't trip the orchestrator no-op path partially (e.g. detecting set-but-empty).
- Vitest worker isolation: if vitest's worker pool runs this in parallel with another test that touches the same lock dir or PID space, signal-other could race. The test does isolate via `mkdtempSync` per-test, so this is less likely but worth confirming concurrency settings.
- Per `feedback_flaky_test_fixes.md`: eliminate the non-determinism, do NOT widen tolerances (don't retry, don't loosen the `expect(status).toBe(0)` to `.not.toBeNull()`).
Severity
Low — re-run passes cleanly. Filed because it caused an unnecessary CI roundtrip on #630 and will keep biting future PRs until fixed.
References
- Test added in: feat(#625): per-issue concurrency lock prevents concurrent sequant sessions #626 (commit `6b70fe7`)
- Failed CI run that triggered this filing: PR feat(#605): --stacked flag — chain-mode PR base to predecessor branch #630, run 25778066723
- `feedback_flaky_test_fixes.md`: "Flaky test fixes must eliminate non-determinism, not widen tolerances"
Activity
admarble commentedon May 13, 2026
→ PROCEED — Flake fix; spec must convert investigation directions into concrete ACs
Workflow: spec → exec → qa
Command:
npx sequant run 633 -qNo explicit
- [ ]checkbox ACs — the body provides a concrete failure signature (status === null at test:201) and four investigation directions. /spec is responsible for choosing a hypothesis and producing testable ACs. Perfeedback_flaky_test_fixes.md: fix must eliminate non-determinism, NOT widen tolerances (do not loosenexpect(status).toBe(0)). -q recommended because flaky-test fixes routinely need a second pass to confirm determinism.admarble commentedon May 13, 2026
Plan (
/spec 633)Complexity: Standard (5 ACs, 1 directory)
AC Quality Check
Issue body has no
- [ ]checkbox ACs —/specsynthesizes them from the four investigation directions per the/assesscomment. ACs below are written to be measurable (specific assertions preserved, file paths named, repeat-count threshold for non-determinism).Scope Assessment
Non-Goals: No explicit Non-Goals section. Implied: do NOT loosen the
expect(result.status).toBe(0)assertion or any other existing assertion in the test (perfeedback_flaky_test_fixes.md).src/commands/__tests__/) —src/lib/locks/only if optional defensive guard adoptedVerdict: ✅ SCOPE_OK
Root-Cause Hypothesis
Reading
signalOther(src/lib/locks/lock-manager.ts:287) anddefaultIsPidAlive(src/lib/locks/lock-manager.ts:95), the CLI under test does:forceAcquire(77, ..., { skipPidCheck: true })— succeeds, returnsprevious = { pid: 9999, hostname: os.hostname(), ... }.signalOther(previous):holder.hostname === this.hostname→ continues (same host).isPidAlive(9999)callsprocess.kill(9999, 0).isPidAlivereturnstrue.process.kill(9999, "SIGTERM")is then sent to that real process.console.log→result.status === null.PID 9999 is well within the live-PID range on a Linux CI VM after a few minutes of process churn (Linux default
pid_maxis 32768 or 4194304; PIDs are assigned sequentially). The issue body's investigation direction #1 ("process-group leak") is close in spirit but the wrong mechanism — it's not negative-PID group signaling, it's a hard-coded "I assume this PID is dead" assumption that holds locally but breaks under CI process pressure.This also explains the other observations cleanly:
The investigation directions #2 (orchestrator env passthrough) and #3 (vitest worker isolation) don't survive inspection:
Boolean("") === falseso the orchestrator no-op is not triggered, andmkdtempSyncper-test means lock-dir collisions can't happen.Acceptance Criteria
AC-1: Test fixture no longer relies on a hardcoded PID being dead
Verification: Integration Test
Scenario: Given the flaky test at
src/commands/__tests__/locks-cli.integration.test.ts:177-212→ When the test fixture is rewritten to remove thepid: 9999assumption → ThensignalOtherdoes not invokeprocess.killon any potentially-live PID, andresult.status === nullcannot occur.Assumptions: The chosen approach (cross-host hostname OR spawn-and-wait PID) reliably hits a code path that returns
falsefromsignalOtherwithout ever callingprocess.killon a real PID.AC-2:
--signal-otherCLI flag wiring is still exercisedVerification: Integration Test
Scenario: Given the modified test → When the CLI is invoked with
--force --signal-other→ Then stdout matches/Could not signal PID \d+ for #77/(the exact PID number may change with the fix; the assertion uses a regex or matches against the new fixture's PID literal).Assumptions: The test asserts on the message format, not on whether
process.killsucceeded.AC-3: Existing assertions remain intact — no widening of tolerances
Verification: Integration Test
Scenario: Given the modified test → Then
expect(result.status).toBe(0)is preserved verbatim (perfeedback_flaky_test_fixes.md);expect(result.stdout).toContain("✓ Acquired lock for #77 (forced)")is preserved;expect(after.command).toBe("/fullsolve 77 (takeover)")is preserved;expect(after.pid).not.toBe(<fixture pid>)is updated only if the fixture PID changes.Assumptions: None of
.toBe(0)→.not.toBeNull(), retry wrappers, or--repeatflags are introduced as a workaround.AC-4: Determinism is demonstrated under repeat execution
Verification: Integration Test
Scenario: Given the fixed test → When run 20 times locally (
npx vitest run src/commands/__tests__/locks-cli.integration.test.ts -t "skill takeover" --repeat 20or equivalent loop) and in CI (the implementer's PR triggers ≥1 CI run) → Then 20/20 local runs pass and CI is green without retry.Assumptions: Local reproduction is hard (the issue body confirms this), so the determinism evidence is primarily the architectural guarantee that
process.killis no longer invoked on a guessed PID, plus a clean CI pass on the fix PR.AC-5: Root cause is documented in code
Verification: Manual Test (code review)
Scenario: Given the fix → When a reviewer reads the test file → Then a comment (≤4 lines) above the modified fixture explains why the previous PID 9999 approach was brittle and which
signalOtherbranch the new fixture exercises, so a future maintainer doesn't regress it.Assumptions: The comment is concise and points at the hostname/spawn-and-wait choice, not a generic "flaky test fix" tag.
Implementation Plan
Phase 1: Decide approach (no code yet)
The exec phase should pick ONE of these. Recommendation: Option A.
hostname: "definitely-not-this-host"in the pre-written77.lock.signalOthershort-circuits on the cross-host check (lock-manager.ts:289) and returnsfalsewithout touchingisPidAliveorprocess.kill....cross-host or already exited) — unchanged wording matches the existing regex assertion.src/lib/locks/lock-manager.test.ts:294already, so no coverage gap.node -e "process.exit(0)"subprocess, awaitchild.on("exit"), capture its PID, use that PID in the fixture.exitandprocess.kill(0). Smaller chance on a quiet box but not zero — still a flake source. More test code.toLockManager.signalOther` as defense-in-depth.Phase 2: Apply Option A
src/commands/__tests__/locks-cli.integration.test.ts:181-190— changehostname: require("os").hostname()tohostname: "definitely-not-this-host". Add a 2-3 line explanatory comment./Could not signal PID 9999 for #77/still matches; the CLI message is"Could not signal PID 9999 for #77 (cross-host or already exited)"(src/commands/locks.ts:189), so the existing regex passes.Phase 3: Apply the same hostname-cross-host pattern to the sibling test (sibling-site scan)
src/commands/__tests__/locks-cli.integration.test.ts:214-238("--force without --signal-other does NOT print the signal line") also writespid: 9999withhostname: require("os").hostname()at line 218. It is not currently flaky (the test does not pass--signal-other, sosignalOtheris never invoked). But applying the same defensive pattern keeps the file internally consistent and protects against future test edits that add--signal-other. Lightweight win — do it in the same PR.Phase 4: Verify
npm run build && npx vitest run src/commands/__tests__/locks-cli.integration.test.ts— green.for i in {1..20}; do npx vitest run src/commands/__tests__/locks-cli.integration.test.ts -t "skill takeover" || break; done— 20/20 green.Optional follow-up issue (not in scope here)
File a separate issue to add Option C (defense-in-depth self-PID guard in
signalOther) if the team wants to harden the production code. Marked optional because it doesn't change behavior for any valid input — only narrows the failure mode if a future caller passes the manager's own PID.Sibling-Site Scan
pid: 9999appears at:src/commands/__tests__/locks-cli.integration.test.ts:184— the flaky test (in scope).src/commands/__tests__/locks-cli.integration.test.ts:218— sibling without--signal-other(not flaky, but covered in Phase 3 above for consistency).src/lib/locks/lock-manager.test.ts(22 occurrences) — safe: all of these unit tests constructLockManagerwith theisPidAliveconstructor seam, so they never invoke the realprocess.kill. Out of scope.Design Review
signalOtherbehavior is correct given its inputs — the bug is the test feeding it inputs that were never guaranteed to be safe. (Optional Option C would belong inLockManager.signalOtheras defense-in-depth.)lock-manager.test.ts:322already tests the cross-host branch ofsignalOther. The integration test gets to exercise the same branch via the actual CLI binary.lock-manager.test.ts:294(which stubsprocess.killcleanly). The integration test's job is to prove the CLI's--signal-otherflag is wired through tosignalOtherand that the negative-result message is printed — both branches ofsignalOtherprint the same message viasrc/commands/locks.ts:189, so either branch satisfies the integration intent.Open Questions
signalOther)? — Recommendation: file as a separate follow-up, not in this PR. Impact if skipped: a future caller could regress and the guard would have caught it; low-probability path.Recommended Workflow
Phases:
spec → exec → qaQuality Loop:
enabled(per the/assesscomment; flake fixes routinely need a second pass)Reasoning: No new feature, no UI, no new unit/integration test stubs needed — the fix IS the test. Skip
testgen. Standard exec → qa is sufficient. Quality loop catches the case where the first fix overshoots (e.g., weakens an assertion or breaks the sibling test).Label Review
Current:
bugRecommended: keep
bug. Noflake/test-flake/cilabels exist in this repo.Quality Loop: Auto-enables via the
/assessdirective (quality-loop=true).admarble commentedon May 13, 2026
--- DRAFT GITHUB ISSUE COMMENT (PROGRESS UPDATE) ---
/exec 633 — Implementation Complete
Approach: Option A from the spec — sentinel cross-host hostname so
signalOthershort-circuits beforeprocess.killis ever invoked. Phase 3 also applied to the sibling fixture for consistency.AC Coverage
--signal-otherCLI flag wiring still exercisedFiles Changed
src/commands/__tests__/locks-cli.integration.test.ts—+12 / -3hostname: require("os").hostname()withhostname: "definitely-not-this-host"in both--signal-otherand sibling--forcefixtures.signalOtherbranch the new fixture exercises.Checks
npm run buildnpm run lintnpx vitest run src/commands/__tests__/locks-cli.integration.test.tsnpx vitest run src/lib/locks src/commands/__tests__/locks-cli.integration.test.ts--repeat 20) of takeover testTest Coverage Analysis
The changed file IS a test file. The coverage shift (same-host-dead-PID → cross-host) is intentional and called out in the spec:
lock-manager.test.ts:322lock-manager.test.ts:294+ integration (flaky)No coverage gap — the same-host-dead-PID branch retains clean unit coverage via the
isPidAliveconstructor seam, which avoids the brittle real-PID assumption.Pre-PR Confidence Check
process.killis no longer called on a guessed PID"), not empirical CI proof. Local repeats can't fully reproduce CI process-group pressure. CI on this PR's first push will provide the final signal.signalOtherbranch to another; both branches print the same CLI message. The unmoved branch (same-host-dead-PID) retains unit-test coverage atlock-manager.test.ts:294.Quality Plan Alignment
Quality Plan Alignment: N/A — no Feature Quality Planning section in the
/speccomment for this issue (flake fixes don't go through/testgen).PR Status
✅ Created: #634
Next Steps
/qa 633to audit.admarble commentedon May 13, 2026
QA Review for Issue #633 (Simple Fix)
Size Gate
AC Coverage
hostname: "definitely-not-this-host"makessignalOthershort-circuit on the cross-host check atlock-manager.ts:289beforeisPidAlive/process.killare touched. No survivingos.hostname()call on the fixture path (only inside the explanatory comment).--signal-otherCLI flag wiring still exercised--signal-otheratlocks-cli.integration.test.ts:205.signalOtheris invoked; cross-host branch returnsfalse; CLI emitsCould not signal PID 9999 for #77 (cross-host or already exited)atlocks.ts:189, which matches the existing/Could not signal PID 9999 for #77/regex.expect(result.status).toBe(0)preserved verbatim at line 208.toContain("✓ Acquired lock for #77 (forced)"), thetoMatchregex,after.pid).not.toBe(9999),command).toBe(...),skipPidCheck).toBe(true)all preserved. NotoBeNull,--repeat, or retry patterns introduced.IN_PROGRESSat QA time — that's the final empirical signal called out in the spec.lock-manager.ts:289, and names the specificsignalOtherbranch the new fixture exercises. Within the ≤4 lines spec target if we count only the explanatory body, slightly over with the visual separator — acceptable.Coverage: 4/5 AC items fully met; AC-4 pending CI completion.
Quality Metrics
any)CI Status
typecheckvalidate-skillsvalidate-pluginbuild (20.x)build (22.x)CI Summary: 3 passed, 2 pending, 0 failed
CI-related AC items: AC-4 ("CI green without retry") → PENDING (build matrix in progress)
The diff is a
.tstest file, not markdown-only — the build matrix is gating, no relaxation applies.Code Review
Strengths:
signalOtherinvokingprocess.killon a PID that's actually alive on the CI runner) is mechanically correct and traced throughlock-manager.ts:287–297.feedback_flaky_test_fixes.md.locks.ts:189deliberately prints the same wording for bothsignalOtherfalse-branches, so the existing regex assertion still passes — no coverage gap surfacing as a brittle assertion.lock-manager.test.ts:294via theisPidAliveconstructor seam, which is the right place for that branch anyway.--signal-othertoday — protects against a future edit that adds the flag.Issues:
Suggestions:
"definitely-not-this-host"is fine, but if you wanted to be defensive against a future where some real machine happens to be named that, a UUID-suffixed sentinel ("sequant-test-host-${randomUUID()}") would be guaranteed-unique. Not worth changing for this PR; flag for follow-up only if you ever see this string elsewhere in the codebase.Test Coverage Analysis
src/commands/__tests__/locks-cli.integration.test.tsCoverage: N/A — the changed file is itself the test. Coverage shift (same-host-dead-PID → cross-host integration branch) is intentional and called out in the spec; the same-host-dead-PID branch retains unit coverage at
lock-manager.test.ts:294.Anti-Pattern Detection
No anti-patterns surfaced — pure fixture / comment change.
Risk Assessment
process.killis no longer invoked on a guessed PID) is airtight, but CI is the verification AC-4 actually requires.pid: 9999across the repo —lock-manager.test.ts(22 occurrences) is safe because those unit tests use theisPidAliveconstructor seam and never call realprocess.kill. No cross-file siblings need fixing.locks-cli.integration.test.ts:221(no--signal-other) was preemptively given the same sentinel hostname, even though it's not currently flaky. This is the right intra-file move — keeps the fixture pattern consistent and future-proofs against an edit that adds--signal-otherto that test.Verdict: NEEDS_VERIFICATION
AC-1, AC-2, AC-3, and AC-5 are fully MET on code review. AC-4's empirical half (CI green without retry) is still in flight — both
build (20.x)andbuild (22.x)areIN_PROGRESS. The architectural guarantee that resolves the flake is in place and locally verified (13/13 on this run, 20/20 per exec), so the expected outcome isREADY_FOR_MERGEonce CI completes — but per spec AC-4 wording (CI is green without retry), I'm not marking READY until those checks actually finish green.Documentation
fix(#633):per conventional commits, but the change isn't user-facing).Next Steps
build (20.x)andbuild (22.x)to complete on PR fix(#633): eliminate locks-cli takeover test flake via cross-host sentinel #634.LockManager.signalOther. Not required for this PR.admarble commentedon May 13, 2026
QA Re-Review for Issue #633 — Verdict Promoted
Diff and HEAD (
1307f04058f5e264979339f90bc0b950f8933931) unchanged from the prior QA at the same SHA. Re-running because AC-4's external gate (CI build matrix) has now resolved. Code review, AC-1/2/3/5 evaluation, risk assessment, and sibling-site scan from the prior comment all still apply verbatim.CI Status (updated)
typecheckvalidate-skillsvalidate-pluginbuild (20.x)build (22.x)CI Summary: 5 passed, 0 pending, 0 failed — green on first attempt after the fix, which is exactly the empirical signal AC-4 was waiting on.
AC Coverage (delta only)
process.killno longer invoked on a guessed PID via the cross-host short-circuit atlock-manager.ts:289) is now backed by clean CI.AC-1, AC-2, AC-3, AC-5 remain MET (unchanged).
Coverage: 5/5 AC items fully met.
Verdict: READY_FOR_MERGE
The prior NEEDS_VERIFICATION verdict was strictly waiting on the build matrix. Both Node 20.x and 22.x are now green on first attempt, satisfying AC-4's
CI is green without retryclause. No code, scope, or risk changes since the prior QA.Next Steps
LockManager.signalOther. Not required for this PR; flagged so it isn't lost.fix(#633): rename takeover test + tighten cross-host assertion
admarble commentedon May 13, 2026
Gap fixes follow-up
Adversarial re-read after the READY_FOR_MERGE verdict surfaced four gaps. Fixed on PR #634 + #637:
"...for dead PID"no longer matched what the test exercises (cross-host branch)."...for cross-host holder"in94efc9e./Could not signal PID 9999 for #77/was loose enough that a future refactor inverting the false-branch (printing the "Signaled..." line) would still pass.(cross-host or already exited)suffix in94efc9e. Documented the residual CLI-message-level limitation (the same suffix is printed for bothsignalOtherfalse-branches) in the explanatory comment.signalOther) not filed.CI on the new commit will re-validate. Verdict still READY_FOR_MERGE for #634 once green.
fix(#633): eliminate locks-cli takeover test flake via cross-host sen…
fix(#637): guard signalOther against self/parent PID (#639)