Skip to content

feat(#625): per-issue concurrency lock prevents concurrent sequant sessions - #626

Merged
admarble merged 5 commits into
mainfrom
feature/625-feat-state-prevent-concurrent-sequant-sessions-fro
May 11, 2026
Merged

admarble merged 5 commits into
mainfrom
feature/625-feat-state-prevent-concurrent-sequant-sessions-fro

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

Adds a per-issue filesystem lock at .sequant/locks/<issue>.lock (atomic open(O_CREAT|O_EXCL)) so two sequant sessions can't target the same issue at the same time. The collision from #604 (10m 38s wasted; 3× exec "no changes" retries) now skips cleanly with a clear error and the rest of the batch continues.

  • New src/lib/locks/ module: LockManager, classifyStaleness, formatLockedMessage
  • RunOrchestrator.run() claims/releases the lock around each issue
  • --force takes over; --force --signal-other also SIGTERMs the prior PID (same-host alive only)
  • Read-only commands (status, merge) warn but proceed
  • New sequant locks list / sequant locks clear <issue> subcommands
  • SEQUANT_ORCHESTRATOR env var no-ops the mechanism (MCP path, matches OrchestratorRenderer)
  • SEQUANT_LOCKS_DIR env var overrides the directory for test isolation

Stale recovery

Scenario Behavior
Same-host, PID alive Blocked
Same-host, PID dead (incl. SIGKILL) Auto-cleared by next run
Cross-host, within 2h Blocked
Cross-host, beyond 2h Auto-cleared by next run

AC coverage

AC Status Evidence
.sequant/locks/ created on demand ✅ LockManager.ensureLocksDir()
Lock acquired at top-level + released via ShutdownManager + process.on('exit') ✅ run-orchestrator.ts:524-578
Sub-skills inherit parent lock (no re-acquire) ✅ Only RunOrchestrator.run() acquires
Read-only commands check + warn but proceed ✅ status.ts, merge.ts
SEQUANT_ORCHESTRATOR no-op ✅ isOrchestratorMode() guard at every method
Stale detection (PID-dead immediate, 2h age fallback) ✅ classifyStaleness() + unit tests
--force claims without signaling ✅ forceAcquire() separated from signalOther()
--force --signal-other SIGTERMs prior PID ✅ signalOther() (same-host alive only)
Error message format ✅ formatLockedMessage() + verbatim test
Batch run policy: skip locked, continue rest ✅ buildLockedResult() synthetic IssueResult
sequant locks list / clear <issue> ✅ src/commands/locks.ts
SEQUANT_LOCKS_DIR env override ✅ resolveLocksDir()
README documents the concurrency model ✅ ## Concurrency section

Test plan

  • npm run build — passes
  • npm run lint — passes (0 warnings)
  • Unit tests (src/lib/locks/lock-manager.test.ts) — 27/27 pass
  • Integration tests (lock-manager.integration.test.ts) — 2/2 pass; two real Node processes race on O_EXCL; SIGKILL leaves a stale lock that next run auto-clears
  • Broader suite (src/lib/ + src/commands/) — 2434/2434 pass
  • Smoke: npx sequant locks list shows fake locks with staleness flags; clear removes them

Closes #625

…ssions

New src/lib/locks/ module with LockManager that claims
.sequant/locks/<issue>.lock via open(O_CREAT|O_EXCL) when sequant run
starts. A second session attempting the same issue is skipped with a
clear error message; the rest of the batch continues.

- Stale detection: same-host PID-dead clears immediately (covers
  SIGKILL); cross-host clears by 2h age fallback.
- --force takes over the lock; --force --signal-other also SIGTERMs the
  prior PID (same-host alive only).
- Read-only commands (status, merge) warn but proceed.
- New sequant locks list/clear subcommands.
- SEQUANT_ORCHESTRATOR env var no-ops the entire mechanism (MCP path).
- SEQUANT_LOCKS_DIR env var overrides the directory for test isolation.

Lock cleanup wired through ShutdownManager and process.on('exit') for
uncaught-exception coverage; SIGKILL recovery happens on the next run.

27 unit tests cover the stale-detection matrix, atomic acquire, force
semantics, orchestrator no-op, error format, and list/clear. Integration
tests spawn real child processes to verify O_EXCL atomicity and
SIGKILL stale-recovery.

Addresses one of the failure modes behind the 29% chain-mode failure
rate documented in #604 / #621.
admarble added 4 commits May 11, 2026 15:52
…-16/AC-18

Addresses the QA AC_NOT_MET gaps on PR #626. The lock primitive shipped
in the prior commit was solid for the CLI path but didn't reach the
motivating example (npx sequant run vs /fullsolve collision) because
the /fullsolve skill never claimed it.

- LockFile schema: add optional skipPidCheck flag. classifyStaleness
  now skips the same-host PID probe when set, falling back to age-only
  (2h). Required because skill shells exit immediately after `locks
  acquire`, leaving the lock's PID dead between acquire and release.
- LockManager: new releaseExternal() releases same-host skipPidCheck
  locks from any PID (the next skill shell's PID, not the original).
- CLI: new `sequant locks acquire/release/check <issue>` subcommands.
- Skills: /fullsolve SKILL.md Phase 0.3 acquires with --skip-pid-check;
  Phase 5.5 releases. /assess Step 1 probes via `locks check --json`
  and surfaces a dashboard warning when held. Mirrored across all
  three skill dirs (.claude/skills, templates/skills, skills).
- Tests: 8 new unit tests for skipPidCheck + releaseExternal,
  1 RunOrchestrator lockedResults flow test (AC-18), 1 SIGINT integration
  test verifying ShutdownManager.gracefulShutdown → releaseAll (AC-16).
  Total: 36 unit + 3 integration = 39 (was 29).
- README §Concurrency and CHANGELOG entry document skill wiring +
  --skip-pid-check rationale (2h orphan window if skill crashes).

QA verdict reference: AC-2 + AC-4 now MET (skill wiring); AC-16
covered by SIGINT integration test; AC-18 covered by orchestrator
lockedResults unit test.
Closes the literal AC-18 gap: prior test exercised the orchestrator's
per-issue acquire loop but didn't verify that buildLockedResult produces
the IssueResult shape the summary depends on (abortReason + locked
metadata flowing into run-display.ts:100). 40 lock tests now pass.
…anup obligations

Addresses gaps surfaced post-QA review:

1. Skill-shell locks now use a SEPARATE 6h TTL (DEFAULT_SKILL_LOCK_TTL_MS)
   instead of inheriting the 2h cross-host staleAgeMs — long /fullsolve runs
   with multi-iteration QA loops no longer risk self-expiring their own
   lock. SEQUANT_SKILL_LOCK_TTL_MS env override.
2. New `sequant locks check-batch <issues...>` subcommand. Text mode emits
   one canonical ⚠ warning line per held issue (ready to paste into the
   /assess dashboard); JSON mode emits structured output. /assess SKILL.md
   updated to use the single batch call instead of per-issue probes.
3. New `locks-cli.integration.test.ts` exercises dist/bin/cli.js for the
   actual SKILL.md contract: acquire→block→release→check sequence,
   check-batch text/JSON/empty/orchestrator modes, and --force --signal-other
   --skip-pid-check skill-lock takeover (Gap 4).
4. /fullsolve SKILL.md now releases the lock on every halt branch (Phase
   1.3 spec failure, Phase 2.3 exec exhausted, Error Recovery section) and
   includes an explicit "release contract" at Phase 0.3 listing all known
   abort branches. Aborted runs no longer wait for the 6h TTL.

Tests: +19 (8 unit for skillLockTtlMs boundary cases + resolveSkillLockTtlMs
env parse; 13 CLI integration tests; minor: 1 SIGINT integration; AC-18
buildLockedResult). Full suite: 3067/3067.

Orchestrator-mode release JSON gains an `issue` field for shape consistency
with the non-orchestrator path.
…e-prevent-concurrent-sequant-sessions-fro

# Conflicts:
#	CHANGELOG.md
@admarble
admarble merged commit 6b70fe7 into main May 11, 2026
8 checks passed
@admarble
admarble deleted the feature/625-feat-state-prevent-concurrent-sequant-sessions-fro branch May 11, 2026 23:28
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.

feat(state): prevent concurrent sequant sessions from targeting the same issue

1 participant