Repository navigation
Description
Summary
Running sequant run with multiple issues in parallel mode produces zero terminal output between the initial progress line and the first issue completion — a gap that can last 20–30 minutes. During investigation, a race condition in reconcileState() was also discovered: it performs an unlocked read-modify-write cycle on state.json while the running process holds file locks for its own updates, causing state regression.
Regression note: emitProgressLine was added in #421/#435 for MCP progress notifications and is called at every phase start/complete/fail — but it's gated behind process.env.SEQUANT_ORCHESTRATOR, so CLI gets nothing. The data is there, it just needs a CLI output path.
Reproduction
npx sequant run 461 460 -qTerminal output stops after:
Progress: #461 ⏳ #460 ⏳
No further output for ~25 minutes until the first issue completes, despite active phase execution underneath.
Calling sequant_status via MCP during the run triggers the race condition.
Root Cause Analysis
1. Parallel mode has no intermediate progress output
In src/commands/run.ts, the updateProgress() function (line 766) is the only terminal output source in parallel mode. It fires exclusively on issue completion — there are no per-phase updates, no heartbeat, no spinner.
In src/lib/workflow/batch-executor.ts, per-issue logging is explicitly suppressed:
const log = config.parallel ? () => {} : console.log.bind(console);And PhaseSpinner is disabled:
const specSpinner = config.parallel ? undefined : new PhaseSpinner({...});emitProgressLine (batch-executor.ts:48-64) fires at every phase transition but is gated:
if (!process.env.SEQUANT_ORCHESTRATOR) return; // CLI never sees these eventsThis means with concurrency 3 and complex issues (spec → exec → qa with quality loops), the terminal is completely silent for the entire duration of the first issue to complete.
2. reconcileState() bypasses file locks — state race condition
reconcileState() in src/lib/workflow/reconcile.ts performs a full read-modify-write on state.json using getState()/saveState() methods that have no file locking, and the gap includes slow GitHub API calls:
const state = await stateManager.getState(); // no lock — reads stale snapshot
// ... GitHub API calls (seconds) ...
// ... modifies state in memory ...
await stateManager.saveState(state); // no lock — overwrites concurrent updatesMeanwhile, the running sequant run process uses withLock() for all its state updates (updatePhaseStatus, initializeIssue, etc.).
Race sequence:
reconcileStatereads state (issue Streamline /assess output format — reduce verbosity for scan-friendly results #453 shows phase="spec")- Running process acquires lock → updates Streamline /assess output format — reduce verbosity for scan-friendly results #453 to phase="exec" → writes → releases
reconcileStatewrites its stale snapshot → reverts Streamline /assess output format — reduce verbosity for scan-friendly results #453 to phase="spec"
The entire read-modify-write (including GitHub API calls) must be wrapped in a single withLock() call.
Acceptance Criteria
Progress visibility (UX)
- AC-1: In parallel mode, emit a per-phase status line when each phase starts/completes (e.g.,
#453: exec started,#452: spec ✓ (4m 6s)). Implementation: add anonProgresscallback parameter torunIssueWithLogging; call it alongside every existingemitProgressLinecall; inrun.tsparallel mode, pass a callback that renders to stdout. - AC-2: If no phase event fires within 60 seconds, emit a heartbeat line with elapsed time so the terminal never appears frozen
- AC-3: Per-phase lines are single-line atomic
console.log()calls — no buffering needed since each line is independent
State race condition (bug)
- AC-4:
reconcileState()must wrap its entire read-modify-write cycle (including GitHub API calls) in a singlewithLock()so no concurrentupdatePhaseStatuscan interleave - AC-5:
getState()andsaveState()should be private (or clearly documented as lock-unaware) to prevent future callers from bypassing locks - AC-6: Add a unit test that simulates concurrent reconcileState + updatePhaseStatus and verifies no state regression
Validation
- AC-7: Run 3+ issues in parallel — terminal shows per-phase progress within 10 seconds of each phase transition
- AC-8: Call
sequant_statusvia MCP during an active run — state file reflects the running process's latest phase, not a stale reconcile snapshot
Files to modify
| File | Change |
|---|---|
src/lib/workflow/batch-executor.ts |
Add onProgress callback parameter to runIssueWithLogging; call it alongside every emitProgressLine |
src/commands/run.ts |
Pass onProgress callback in parallel mode that renders per-phase lines to stdout; add 60s heartbeat timer |
src/lib/workflow/reconcile.ts |
Wrap entire read-modify-write in withLock() |
src/lib/workflow/state-manager.ts |
Make getState/saveState private or document as lock-unaware; expose locked reconcile helper |
Context
- Discovered during investigation of run
1656c682(5 issues, 65 min wall clock, 3/5 passed) - Run log:
.sequant/logs/run-2026-03-26T01-56-12-1656c682-aa92-4a08-9fd7-8bf079e1abfd.json emitProgressLineadded in MCP server: add progress notifications for sequant_run #421 / MCP: add progress notifications for sequant_run with graceful fallback #435 — already fires at every phase transition, just needs CLI output path- File locking was added in State manager: concurrent writes to state.json cause data loss #409 / fix(#409): prevent concurrent state write data loss with file locking #417 but
reconcileStatewas not updated to use it - Parallel execution was added in Default execution mode is serial despite being labeled parallel #404 / feat(#404): parallel execution as default mode for multi-issue runs #419 without intermediate progress output
Activity
admarble commentedon Mar 26, 2026
→ PROCEED — Both root causes confirmed in codebase, detailed ACs
spec → exec → qa · 8 ACs · -q (dual concern: UX + race condition across 4 files)
admarble commentedon Mar 26, 2026
Spec Plan — #458
AC Checklist
onProgresscallbackconsole.log()outputreconcileState()wrapped inwithLock()for entire read-modify-writegetState()/saveState()documented as lock-unawaresequant_statusvia MCP reflects latest phase during active runImplementation Plan
Phase 1 — Progress callback (
batch-executor.ts)onProgresscallback parameter torunIssueWithLoggingonProgressat all 9 existingemitProgressLinecall sitesPhase 2 — Parallel renderer (
run.ts)3. Create progress callback:
#453: exec started/#452: spec ✓ (4m 6s)4. Add 60s heartbeat timer with elapsed time display
Phase 3 — State lock fix (
reconcile.ts,state-manager.ts)5. Make
withLock()public on StateManager6. Wrap
reconcileState()inwithLock()(including GitHub API calls)7. Add JSDoc warnings to
getState()/saveState()as lock-unawarePhase 4 — Tests (
reconcile.test.ts)8. Add concurrent race condition test (AC-6)
Design Decisions
onProgresscallback follows existinglogWriterpattern — minimal API surface, no new abstractionsgetState()/saveState()stay public with JSDoc warnings —reconcile.tsneeds direct accessConflict Note
Issue #461 also modifies
batch-executor.ts(label matching), but touches different functions. Low merge conflict risk.Workflow
Phases: spec → exec → qa
Quality Loop: enabled (8 ACs, dual concern)
feat(#458): add parallel progress lines and fix reconcileState race c…
admarble commentedon Mar 26, 2026
QA Review for Issue #458
AC Coverage
onProgresscallback added torunIssueWithLogging, called at all 9emitProgressLinesites. Parallel renderer in run.ts formats#N: phase started/✓/✗setInterval(60_000)emits elapsed time. Cleared onPromise.allSettledcompletionconsole.log()outputconsole.log(line)— single atomic callreconcileState()wrapped inwithLock()stateManager.withLock(). Lock timeout increased to 30s for new StateManager instancesgetState()/saveState()documented as lock-unawarewithLockmade public with enhanced docsreconcileState+updatePhaseStatusconcurrently, asserts no data corruptionnpx sequant run <a> <b> <c>sequant_statusduring active runCoverage: 6/8 AC items MET, 2 PENDING (manual verification required)
Quality Metrics
any)CI Status
Note: CI failures were caused by stale
lastProgressTimereference. Fix committed (316c814) and pushed. Awaiting CI re-run.Test Coverage Analysis
src/commands/run.tssrc/mcp/tools/run.test.tssrc/lib/workflow/batch-executor.tssrc/lib/workflow/reconcile.tsreconcile.test.ts(32 tests, including new AC-6 test)src/lib/workflow/state-manager.tsstate-manager.test.ts(49 tests)Coverage: 3/4 changed source files have corresponding tests
Code Review
Strengths:
logWriterdesignemitProgressLinesites covered withonProgresscallsIssues found during QA (fixed):
lastProgressTimevariable removed but reference remained inonProgresswrapper. Fixed by removing the unnecessary wrapper and passingonPhaseProgressdirectly (316c814)ProgressCallbacktype was inserted betweenemitProgressLine's JSDoc and the function. Fixed by reordering type above JSDoc (553d211)Suggestions (non-blocking):
onProgresscalls are repetitive. A future cleanup could extract a helper, but the current approach is correct and explicit.batch-executor.tslacks direct test coverage. Issue Add batch-executor unit tests for label-based phase shortcuts #460 is adding tests — no gap for this PR.Self-Evaluation
clearIntervalif there's a race betweenPromise.allSettledresolving and the timer callback. This is benign — worst case is one extra heartbeat line.Verdict: NEEDS_VERIFICATION
All code-reviewable ACs are MET (6/8). AC-7 and AC-8 require manual verification with a real parallel run. CI is re-running after the typecheck fix.
Documentation
Next Steps
npx sequant run <issue1> <issue2> <issue3>— verify per-phase lines appearsequant_statusvia MCP during active run — verify no state regressionadmarble commentedon Mar 26, 2026
QA Verification Update — #458
Manual Verification Complete
execphase, not stale snapshotCI Status: All Green
Updated Verdict: READY_FOR_MERGE
All 8 ACs fully MET. CI green. Ready for human review and merge.
feat(#458): parallel run progress lines + reconcileState race fix (#466)
docs(#458): update parallel execution and status reconciliation docs
admarble commentedon Mar 26, 2026
Documentation Updated
Files updated:
docs/features/parallel-execution.md— Added per-phase progress lines, heartbeat timer, and updated troubleshootingdocs/features/status-reconciliation.md— Added concurrent access safety sectionSections Added:
Committed directly to main (85b1f0a).
feat(#618): unified run renderer — two-zone live grid + events log (#620