Skip to content

feat(cli): sequant ready — wire live phase-matrix renderer (parity with sequant run) #697

Closed

Description

@admarble

Summary

sequant ready <issue> runs a full-weight qa → loop → qa pipeline that can take several minutes, but unlike sequant run it shows no live progress — after the static header it sits silent until the final report prints. Users can't tell it's working or what phase it's in. This was observed on the first real sequant ready run (#694).

Root cause

sequant ready and sequant run were built on different output paths. ready ships as a thin synchronous command with no renderer wiring:

src/commands/ready.ts:

  1. Prints a static ui.headerBox("SEQUANT READY") + muted config lines (:132-150)
  2. Calls runReadyGate(...) synchronously, passing only a runPhase callback — no progress/phase-plan callbacks, no renderer, no heartbeat (:153-169)
  3. Prints the final markdown result.report at the end (:218)

By contrast src/commands/run.ts builds the live UI via buildProgressWiring (RunRenderer, #618) + renderTui, plus LivenessHeartbeat (#574), and wires onProgress / onPhasePlan into the renderer (run.ts:105-140).

sequant run sequant ready
Live phase matrix (pending → running → ✔/✘) ✅ ❌
Liveness heartbeat / spinner ✅ ❌
Progress callbacks wired to a renderer ✅ ❌
During-run feedback live grid silence

The phase executor (executePhaseWithRetry) is shared between both commands, so the progress signal exists — ready just doesn't capture it into a renderer.

Acceptance Criteria

  • sequant ready <issue> shows live, in-place progress while the qa → loop → qa gate runs (current phase + iteration visible), instead of going silent between header and final report.
  • The live UI reuses the existing renderer infrastructure (buildProgressWiring / RunRenderer feat(cli): unified run renderer — two-zone live grid + events #618 + the phase-matrix) rather than a bespoke second renderer — visual parity with sequant run.
  • A liveness/heartbeat indicator (feat(run): -q mode silent for entire phase duration — no liveness or stall signal #574) is present so a long-running, output-quiet phase is distinguishable from a hang.
  • --json output is unchanged (no live rendering when piping / --json); rendering is gated on TTY the same way run is.
  • --verbose continues to work and does not double-render.
  • The final structured report (result.report) still prints after the live zone is disposed (no clobbering, clean scrollback — same dispose pattern as run.ts:185-186).

Non-Goals

  • Changing the ready gate logic, policy, or report content — this is purely the progress-rendering layer.
  • Animating the single-phase case differently from the multi-iteration case beyond what the existing renderer already does.

Notes

Activity

  1. added
    enhancement
    on Jun 2, 2026
  2. admarble commented on Jun 2, 2026

    @admarble
    ContributorAuthor

    📋 Spec — Issue #697

    Complexity: Standard (6 ACs, 2 directories)

    AC Quality Check

    All 6 ACs are concrete and verifiable. Minor notes:

    • AC-1 ("shows live, in-place progress … current phase + iteration visible") — measurable: assert progress events are emitted per phase/iteration. ✅
    • AC-2 ("reuses the existing renderer infrastructure … visual parity") — "visual parity" is a design constraint, not a runtime assertion; verified by code review that buildProgressWiring/RunRenderer is reused (no bespoke second renderer). ✅ (review-verified)
    • AC-3 / AC-4 / AC-5 / AC-6 — all crisp: heartbeat present, --json unchanged, --verbose no double-render, report prints after dispose. ✅

    No vague/unmeasurable/open-ended patterns. No title/body tension.


    Scope Assessment

    Non-Goals (from issue):

    • Changing the ready gate logic, policy, or report content — purely the progress-rendering layer.
    • Animating the single-phase case differently from the multi-iteration case beyond what the renderer already does.
    Metric Value Status
    Feature count 1 ✅
    AC items 6 ⚠️
    Directory spread 2 (src/commands/, src/lib/workflow/) ✅

    Verdict: ⚠️ SCOPE_WARNING — triggered solely by the AC-count proxy (6 ≥ yellow). The change is a single cohesive feature; several "ACs" are really constraints on one edit (TTY gating, verbose, dispose). Effectively SCOPE_OK — no split recommended.


    Acceptance Criteria

    AC-1: Live, in-place progress during the qa → loop → qa gate

    Verification: Unit Test (event emission) + Manual Test (TTY)
    Scenario: Given sequant ready <issue> on a TTY → When the gate runs qa/loop iterations → Then the renderer receives start/complete events per phase with the loop iteration set, and the live zone shows the current phase + iteration instead of silence.
    Assumptions: runReadyGate is the orchestrator here (not RunOrchestrator), so it must emit the progress events itself around each runPhase call.

    AC-2: Reuse existing renderer (buildProgressWiring / RunRenderer #618 + phase-matrix)

    Verification: Unit Test + Review
    Scenario: Given the ready command → When it builds its live UI → Then it calls the shared buildProgressWiring(...) (from src/commands/run-progress.ts) and the single-issue RunRenderer, not a new bespoke renderer. Visual parity with sequant run.
    Assumptions: buildProgressWiring is reusable as-is for a single issue; single-issue frame styling was fixed in #690.

    AC-3: Liveness/heartbeat indicator present (#574)

    Verification: Unit Test
    Scenario: Given a long, output-quiet phase → When no completion event fires for a while → Then a heartbeat/spinner or stall indicator distinguishes work-in-progress from a hang (same mechanism run uses — RunRenderer's live-zone tick / stallThresholdMs, or LivenessHeartbeat).
    Assumptions: The RunRenderer live-zone tick + stallThresholdMs already supplies liveness; an explicit LivenessHeartbeat is only needed for the quiet path (ready has no --quiet).

    AC-4: --json output unchanged; rendering gated on TTY like run

    Verification: Integration Test
    Scenario: Given sequant ready <issue> --json (or piped/non-TTY) → When the gate runs → Then no live rendering occurs and stdout is exactly the existing JSON object. The renderer is only built when !options.json; the renderer itself degrades to non-TTY line mode when piping (parity with run).
    Assumptions: Building the wiring is skipped entirely under --json so no stray writes corrupt the JSON.

    AC-5: --verbose works and does not double-render

    Verification: Integration Test + Review
    Scenario: Given sequant ready <issue> --verbose → When a phase streams agent output → Then the renderer is paused during streaming and resumed after (no duplicated frames). Achieved by passing the RunRenderer as the PhasePauseHandle (7th arg) into executePhaseWithRetry.
    Assumptions: RunRenderer satisfies PhasePauseHandle (it implements pause/resume/appendNotice).

    AC-6: Final result.report prints after the live zone is disposed

    Verification: Integration Test
    Scenario: Given any completed ready run → When the gate returns → Then the live zone is disposed first and the markdown report prints to clean scrollback (no clobbering), mirroring run.ts:185-186 (displaySummary(...); renderer?.dispose();).
    Assumptions: Dispose ordering must happen before the console.log(result.report) write.


    Implementation Plan

    Phase 1: Thread progress callbacks through the gate engine

    1. src/lib/workflow/ready-gate.ts — Add onProgress?: ProgressCallback and (optionally) onPhasePlan?: PhasePlanCallback to RunReadyGateOptions (import from ./types.js).
    2. In runReadyGate, wrap each opts.runPhase("qa"|"loop", …) call: emit onProgress(issueNumber, phase, "start", { iteration }) before, "complete" (with durationSeconds) on success and "failed" (with error) on the LOOP_FAILED / catch paths. Use the existing iterations counter as the iteration value so the matrix renders loop N/M.
    3. Keep callbacks optional so the existing ready-gate.test.ts injection-based unit tests (which never pass callbacks) stay green.

    Phase 2: Wire the renderer in the command shell

    1. src/commands/ready.ts — When !options.json, call buildProgressWiring({ tuiEnabled: false, quiet: false, issueNumbers: [issueNumber], phaseTimeoutSeconds: phaseTimeout, maxLoopIterations: maxIterations }) (from ./run-progress.js). Do not pre-seed basePhases — the ready pipeline is dynamic (1–N qa/loop passes), so stream phases as they fire (matches auto-detect streaming). (Open Question 1.)
    2. Pass onProgress into runReadyGate(...).
    3. Pass the renderer as the PhasePauseHandle (7th positional arg) into the runPhase wrapper: executePhaseWithRetry(issueNumber, phase, config, undefined, wt, undefined, renderer ?? undefined) — this gives verbose streaming the pause/resume behavior (AC-5).
    4. Register the single issue: renderer?.registerIssue({ issueNumber }).
    5. Replace the final console.log(result.report) with: dispose the live zone first, then print — renderer?.dispose(); console.log(result.report); (AC-6). Add a SIGINT handler that calls renderer?.dispose() before ShutdownManager's banner (mirror run.ts:159-162), and dispose any heartbeat in a finally.

    Phase 3: Tests

    1. ready-gate.test.ts — add a case asserting onProgress fires start/complete with correct phase + iteration across a 2-iteration qa → loop → qa run, and failed on LOOP_FAILED.
    2. ready.test.ts — assert: (a) renderer NOT built under --json (clean JSON, no live writes); (b) renderer built + registerIssue called on the non-json path; (c) dispose() called before the report write; (d) verbose passes the renderer as pause handle.

    Design Review

    1. Where does this logic belong? Two layers, matching the existing run split: event emission belongs in the orchestrator (runReadyGate, since it owns the phase loop here), and renderer construction/disposal belongs in the command shell (ready.ts). No new module needed.
    2. What's the simplest correct approach? Reuse buildProgressWiring + RunRenderer verbatim with issueNumbers: [issueNumber]. Rejected: a bespoke ready-only renderer (violates AC-2) and refactoring RunOrchestrator to drive ready (out of scope, over-engineered — the gate engine already owns the loop).
    3. What existing pattern does this follow? The run.ts wiring pattern exactly: buildProgressWiring → wire onProgress → pass renderer as phasePauseHandle → dispose() after summary (run.ts:107-191).
    4. What would a senior reviewer challenge? "Why emit events from the engine instead of from executePhaseWithRetry?" — because executePhaseWithRetry has no onProgress param (it's RunOrchestrator/batch-executor that emits in the run path); the ready engine is the equivalent orchestrator and is the natural emit site. Also: "Does seeding no phase plan still show a matrix?" — yes; streaming mode renders cells as phases fire (auto-detect parity), avoiding a stuck-pending loop cell when the gate stops after the first qa.

    Feature Quality Planning

    All standard checks pass. Notable items:

    • No new public API surface beyond two optional callback fields on RunReadyGateOptions — backward-compatible; existing injected-runner tests unaffected.
    • Resource cleanup is the main risk area (per feedback_qa_self_eval_cleanup): the live-zone timer and any heartbeat must be disposed on every exit path — success, the catch block (ready.ts:170-179), and SIGINT. Ensure the early catch path disposes the renderer too, not just the happy path.
    • CLI wiring: no new flags, so no bin/cli.ts .option() change required (avoids the usual CLI-wiring-gap pitfall).

    Derived ACs

    Source Derived AC Priority
    Resource cleanup Renderer/heartbeat disposed on ALL exit paths (success, catch, SIGINT) — not just the happy path High

    Open Questions

    1. Pre-seed a phase plan or stream? — Recommendation: stream (no plannedPhases). The ready pipeline length is dynamic (could stop after one qa, or run N qa/loop passes), so a fixed ["qa","loop"] seed would leave a loop cell stuck pending when the gate stops early. Streaming renders cells as phases fire (auto-detect parity). Impact if wrong: cosmetic only (a stale pending cell); easy to revisit.
    2. Heartbeat: rely on RunRenderer live tick, or add LivenessHeartbeat? — Recommendation: rely on the renderer's live-zone tick + stallThresholdMs (which is what run's non-quiet path uses). LivenessHeartbeat is the quiet-mode mechanism and ready has no --quiet. Impact if wrong: AC-3 under-served; mitigated by passing phaseTimeoutSeconds so stallThresholdMs is derived.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled (single cohesive change; SCOPE_WARNING is an AC-count artifact, not real complexity)
    Reasoning: CLI/TypeScript change with existing test files to extend (ready.test.ts, ready-gate.test.ts); no UI/browser surface (terminal rendering is unit/integration-tested, not browser-tested). testgen is optional — the two existing test files already provide the stubs to extend, so a dedicated testgen phase adds little. No security surface.


    Label Review

    Current: enhancement
    Recommended: enhancement (+ planned added by this phase)
    Reason: Single-feature enhancement; no complex/breaking/ui warranted. No no-browser-test needed since no .tsx/.jsx involved (terminal renderer).
    Quality Loop: Won't auto-enable — SCOPE_WARNING here is the 6-AC proxy, not genuine multi-feature scope.

  3. added
    planned
    on Jun 2, 2026
  4. admarble commented on Jun 2, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #697

    PR: #698 (feature/697-…) — closes #697 · HEAD: 029b93b · CI: 4/4 green

    AC Coverage

    AC Source Description Status Notes
    AC-1 Original Live, in-place progress (phase + iteration) instead of silence MET runReadyGate emits start/complete/failed with 1-based QA-pass iteration via runPhaseTracked; wired to renderer.onEvent. Tested: ready-gate.test.ts asserts exact event sequence across qa→loop→qa.
    AC-2 Original Reuse buildProgressWiring/RunRenderer #618, no bespoke renderer MET ready.ts calls the shared buildProgressWiring({tuiEnabled:false,quiet:false,issueNumbers:[issueNumber],…}); registerIssue happens inside the shared wiring. Test asserts the call + args.
    AC-3 Original Liveness/heartbeat for output-quiet phases (#574) MET (review) Served by RunRenderer's live-zone tick: stallThresholdMs = phaseTimeoutSeconds*1000/2, and phaseTimeout is threaded in. Matches run's non-quiet path; LivenessHeartbeat (quiet-only) correctly stays null. Per spec Open-Q2.
    AC-4 Original --json/non-TTY unchanged, rendering gated like run MET Renderer built only under !options.json. Test AC-4 invokes readyCommand(…,{json:true}) → buildProgressWiring not called, onProgress undefined, pause-handle arg undefined, no report marker in stdout.
    AC-5 Original --verbose works, no double-render MET Renderer passed as 7th positional arg (spinner: PhasePauseHandle) to executePhaseWithRetry — same pause/resume mechanism as run.ts. Test asserts arg [6] === renderer.
    AC-6 Original Final report prints after live zone disposed MET Non-json branch: renderer?.dispose(); console.log(result.report). Test asserts dispose invocation order precedes the report console.log.
    AC-D1 Derived (cleanup) Renderer/heartbeat disposed on ALL exit paths MET Happy (json: renderer null; non-json: disposed pre-report), catch (renderer?.dispose(); heartbeat?.dispose(); process.off), SIGINT (renderer?.dispose()). Error-path test asserts dispose + exitCode 2.

    Coverage: 7/7 AC items fully met (6 original + 1 derived)


    CI Status

    Check State Impact
    build (22.x) SUCCESS ✅ MET
    typecheck SUCCESS ✅ MET
    validate-plugin SUCCESS ✅ MET
    validate-skills SUCCESS ✅ MET

    CI Summary: 4 passed, 0 pending, 0 failed. No CI-gating AC items pending.


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 new (test doubles use justified as unknown as casts) OK
    Deleted tests 0 OK
    Files changed 5 (2 src, 2 test, CHANGELOG) OK
    Lines added +394 OK
    Lines deleted -10 OK
    tsc --noEmit clean OK
    vitest run ready.test.ts ready-gate.test.ts 38 passed OK

    Test Coverage Analysis

    Changed File Tier Has Tests? Test File
    src/commands/ready.ts Standard ✅ Yes ready.test.ts (drives readyCommand for AC-2/4/5/6 + error path)
    src/lib/workflow/ready-gate.ts Standard ✅ Yes ready-gate.test.ts (AC-1 emission, LOOP_FAILED, throw, back-compat)

    Coverage: 2/2 changed source files have tests. No critical-tier (auth/payment/security) paths touched.


    Code Review

    Strengths:

    • Clean two-layer split that mirrors run exactly: event emission in the gate engine (runReadyGate, the owner of the qa→loop→qa loop), renderer construction/disposal in the command shell. No new module.
    • runPhaseTracked correctly emits failed on both phaseResult.success === false and a thrown runner (re-throws after emitting), so a renderer reflecting the failed cell is what ready.ts's catch path then disposes.
    • Optional onProgress keeps all existing injection-based gate tests green — verified by the "no-op when omitted" test.
    • Disposal is genuinely covered on every exit path (the historical risk area called out in the spec's Feature Quality Planning).

    Issues: None blocking.

    Suggestions (non-blocking):

    • buildProgressWiring is called without autoDetectPhases, so registerIssue records autoDetect: undefined. Behavior is correct (streaming renders cells as events fire, no stuck-pending cell), but passing autoDetectPhases: true would make the streaming intent explicit and match the run auto-detect path 1:1. Purely cosmetic — defer.

    Test Quality Review

    Category Status Notes
    Behavior vs Implementation ✅ OK Asserts emitted events, dispose ordering (invocationCallOrder), and the json/non-json output — not internals.
    Coverage Depth ✅ OK Happy path, LOOP_FAILED, thrown runner, back-compat omission, and gate-throws cleanup all covered.
    Mock Hygiene ✅ OK Mocks only the command's external collaborators; gate-engine tests use a scripted runner, not deep mocks.
    Test Reliability ✅ OK Deterministic; no timers/sleeps. process.exitCode saved/restored in afterEach.

    Anti-Pattern Detection

    No N+1, empty catch (the two catch {} are intentional best-effort with documented rationale), hardcoded secrets, or uncleared timers in the diff. package.json unchanged → no dependency audit.


    Call-Site Review

    New exported surface: RunReadyGateOptions.onProgress? (optional field, not a new exported function) and internal runPhaseTracked. The two prior opts.runPhase("qa"|"loop", …) call sites were both migrated to runPhaseTracked — no un-migrated sibling call sites remain in runReadyGate. Verified by reading the diff hunks.


    Execution Evidence

    Test Type Command Result
    Typecheck npx tsc --noEmit exit 0
    Unit/integration npx vitest run src/commands/ready.test.ts src/lib/workflow/ready-gate.test.ts 38 passed

    readyCommand is invoked directly (with mocked collaborators) in the AC-4/5/6 + error-path tests, exercising the real command shell wiring end-to-end. No new flags added → no bin/cli.ts change required (confirmed). Evidence status: Complete.


    CLI Registration Verification

    Option interface modified: RunReadyGateOptions gained onProgress? — but this is an internal engine option (set programmatically from the command shell), not a user-facing CLI flag. No mergedOptions.X-style runtime consumption, no bin/cli.ts registration needed. Status: N/A (internal-only field).


    Skill Command Verification / Detection Pattern Verification

    N/A — no .claude/skills/**/*.md changes in this diff.


    Risk Assessment

    • Likely failure mode: A renderer not disposed on some exit path would leave the terminal's alternate live zone active and clobber subsequent output. Mitigated — all four paths (json, non-json, catch, SIGINT) dispose, with the error path explicitly tested.
    • Not tested: The actual runtime pause/resume during --verbose streaming (the test asserts the renderer is passed as the pause handle, not that frames are de-duplicated at runtime). Acceptable: the pause mechanism is run.ts's proven, shared code path — this PR only changes who is passed in, not the mechanism.
    • Sibling sites considered: The root "gate command that doesn't wire the renderer" pattern existed only in ready vs run; run already has the wiring and this PR brings ready to parity. No other gate-style command shares the gap. PR feat(tui): upgrade sequant ready to the boxed Ink TUI + harden TUI (#699) #700/feat(tui): upgrade sequant ready to the boxed Ink TUI + harden TUI for large batches #699 (boxed Ink TUI for ready) is an explicit follow-up, not an overlapping fix.
    • Sibling-line audit: Both intra-runReadyGate runPhase call sites (qa and loop) were migrated to runPhaseTracked — no adjacent un-instrumented call site remains.

    Adversarial Re-Read

    Findings: No gaps found because: (1) traced all four exit paths in ready.ts (json / non-json / catch / SIGINT) and confirmed each disposes the renderer + heartbeat and removes the SIGINT listener — no leak, no double-dispose; (2) confirmed buildProgressWiring returns a non-null renderer for tuiEnabled:false, quiet:false and a null heartbeat, so AC-3 liveness is genuinely served by the renderer's stallThresholdMs tick (not a silently-null heartbeat); (3) verified the executePhaseWithRetry 7th positional arg is spinner: PhasePauseHandle and the renderer satisfies it (implements pause/resume/appendNotice); (4) ran the suite (38 pass) and tsc (clean) myself rather than trusting the PR body; (5) checked the issue's Non-Goals — no gate-logic/policy/report change crept in (the diff only adds emission + renderer plumbing); (6) the iteration value is the iterations counter (1-based QA-pass index), matching the AC's "loop N/M" requirement, and the test asserts the exact iteration progression.

    Status: Clean


    Verdict: READY_FOR_MERGE

    All 6 original ACs + the derived cleanup AC are MET with behavior-focused test coverage. CI is fully green, tsc is clean, and 38 tests pass locally. The change is a tight, single-purpose parity fix that reuses run's shared renderer infrastructure exactly as the spec prescribed, respects every Non-Goal, and disposes resources on all exit paths. The one suggestion (explicit autoDetectPhases: true) is cosmetic and does not affect correctness.

    Documentation

    Documentation: Before merging, optionally run /docs 697 — though the CHANGELOG entry already covers the user-visible behavior change.

    Next Steps

    1. Merge PR feat(cli): wire live phase-matrix renderer into sequant ready (#697) #698.
    2. (Optional, follow-up) Pass autoDetectPhases: true into buildProgressWiring for explicit streaming parity with run.
    3. (Tracked) PR feat(tui): upgrade sequant ready to the boxed Ink TUI + harden TUI (#699) #700/feat(tui): upgrade sequant ready to the boxed Ink TUI + harden TUI for large batches #699 upgrades ready to the boxed Ink TUI — separate effort, not blocking.
  5. added
    ready-for-review
    on Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementplannedready-for-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions