Skip to content

feat(#574): -q mode liveness heartbeat + one-shot stall warning - #595

Merged
admarble merged 2 commits into
mainfrom
feature/574-feat-run-q-mode-silent-for-entire-phase-duration-n
May 7, 2026
Merged

admarble merged 2 commits into
mainfrom
feature/574-feat-run-q-mode-silent-for-entire-phase-duration-n

Conversation

@admarble

@admarble admarble commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • New LivenessHeartbeat (src/lib/workflow/heartbeat.ts) closes the silent--q-window gap from issue feat(run): -q mode silent for entire phase duration — no liveness or stall signal #574 — TTY-only \r-rewritten heartbeat every 30s + one-shot stall warning when .sequant/state.json mtime gap exceeds 5m.
  • Liveness source uses existing infrastructure: StateManager.saveState() writes 3-10x per phase. The issue body's run-*.json-mtime premise was wrong (LogWriter.finalize() is the only writer); the spec call-out caught this and routed to state.json instead.
  • Wired in src/commands/run.ts only when options.quiet === true && !tuiEnabled. Single shared setInterval, unref-ed so it never keeps the event loop alive. try/finally cleanup on completion; ShutdownManager cleanup mirrors PhaseSpinner pattern.

Pre-PR AC Verification

AC Source Description Status Evidence
AC-1 Original TTY-detected liveness heartbeat (\r rewrite every 30s, no-op non-TTY) ✅ Implemented src/lib/workflow/heartbeat.ts:170-220 (tick + writeHeartbeat); 5 unit tests cover TTY/non-TTY/format/stop/parallel
AC-2 Original One-shot stall warning at 5m mtime gap, resets on activity, TTY+non-TTY, optional timeout suffix ✅ Implemented heartbeat.ts:196-244 (warningFired flag + writeStallWarning); 6 unit tests cover fire-once, no-rerun, reset, both modes, suffix present/absent
AC-3 Original ≤30s cadence, single shared timer, one fs.stat per phase per tick, suppressed when not quiet, ShutdownManager cleanup ✅ Implemented heartbeat.ts:120-163 (single setInterval, enabled gate, dispose); 6 unit tests (cadence, parallel, disabled, ShutdownManager registration)
AC-4 Original Tests cover all of the above ✅ Implemented src/lib/workflow/heartbeat.test.ts (21 tests) + __tests__/integration/heartbeat.integration.test.ts (8 tests against real state.json on disk)

Quality Plan Alignment

Quality Dimension Items Addressed Notes
Concurrency safety ✅ One line per phase in parallel mode (test: parallel-mode 2-issue scenario)
Output integrity ✅ Heartbeat gated to quiet === true only, where onProgress would otherwise be undefined — no \r interleaving
CI/log-capture safety ✅ Non-TTY suppresses heartbeat (test verified); stall warning is unconditional but informational
No new dependency ✅ Pure Node fs.statSync + reuse of formatElapsedTime from phase-spinner.ts

Test plan

  • npm run build — passes
  • npm run lint — passes (max-warnings 0)
  • npm test -- src/lib/workflow/heartbeat.test.ts — 21/21 pass
  • npm test -- __tests__/integration/heartbeat.integration.test.ts — 8/8 pass
  • npm test -- src/lib/workflow/ — 804/804 pass (no regressions)
  • Manual TTY check: npx sequant run <issue> -q in real TTY — heartbeat rewrites every 30s
  • Manual pipe check: npx sequant run <issue> -q | cat — no heartbeat output
  • Manual stall check: induce a >5m phase stall — ⚠ warning appears once

Closes #574

Surfaces a TTY liveness line and a stall warning during quiet runs so
users can distinguish "agent working" from "process hung" without
inspecting state.json or ps/lsof.

- AC-1: TTY-only \r-rewritten line every 30s with elapsed + mtime age
- AC-2: One-shot ⚠ warning when state.json mtime gap > 5m, resets on
  activity, fires in both TTY and non-TTY (CI logs benefit too)
- AC-3: Single shared setInterval, fs.stat per active phase, fully
  suppressed when not quiet; ShutdownManager cleanup
- AC-4: 21 unit tests + 8 integration tests against real state.json

Liveness source: .sequant/state.json mtime (StateManager.saveState
writes 3-10x per phase). Issue body's run-*.json premise was incorrect
(LogWriter.finalize is the only writer); the spec design call-out
caught this.

Wired in src/commands/run.ts only when options.quiet && !tuiEnabled.
`stop()` previously called `dispose()` when `phases.size` hit 0, which set
`stopped = true` and silently no-op'd every subsequent `start()`. In a
single-issue sequential run (spec → stop → exec → stop → ...), this killed
the heartbeat after the first phase — exactly the use case that closes
#574 was supposed to cover.

Parallel runs masked the bug because phases.size rarely drops to 0 between
the staggered stop/start pairs. The 21-test suite missed it because
parallel-mode tests start two phases first, and the lone stop()-using test
terminates the lifecycle.

Fix: in `stop()`, only clear the timer when phases empty out (no orphaned
polls). Don't set `stopped = true`. Explicit dispose() from run.ts's
`finally` block remains the terminal teardown path.

Adds a sequential start → stop → start regression test.
@admarble
admarble merged commit be68489 into main May 7, 2026
5 checks passed
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(run): -q mode silent for entire phase duration — no liveness or stall signal

1 participant