Skip to content

fix(tui): completed issue box keeps counting — ElapsedTimer never freezes at completedAt #866

Closed

Description

@admarble

Observed during a live 4-issue sequant run (parallel, 3 concurrent). Issue #850 finished — body cell read completed, all three phase glyphs were ✓ — but the header clock kept climbing: phase 3/3 • 24:07, then 25:09 a minute later, and it never stopped.

The Ink TUI's elapsed timer has no terminal condition. src/ui/tui/ElapsedTimer.tsx:8 accepts only startedAt and always measures against a live 1 Hz Date.now() tick:

export function ElapsedTimer({ startedAt }: { startedAt?: Date }): JSX.Element {
  const [now, setNow] = useState(() => Date.now());
  useEffect(() => {
    const id = setInterval(() => setNow(Date.now()), 1000);
    return () => clearInterval(id);
  }, []);
  if (!startedAt) return <Text>--:--</Text>;
  const secs = Math.max(0, Math.floor((now - startedAt.getTime()) / 1000));

IssueBox.tsx:65 passes only state.startedAt, so a passed or failed issue's header counts up forever while the body cell says completed.

IssueRuntimeState.completedAt already exists (run-state.ts:50) and is already populated — set at run-orchestrator.ts:556 (and :521 on failure) and carried into the snapshot at run-orchestrator.ts:1688. The TUI simply never reads it; its only consumer today is the sort in row-cap.ts:95.

This is a parity gap with the plain renderer, which freezes correctly: run-renderer.ts:1236 uses (state.completedAt - state.startedAt) for a done issue and :1249 uses (state.completedAt ?? this.now()) for a failed one.

Not a regression. git log -p --follow src/ui/tui/ElapsedTimer.tsx shows the component shipped this way in #542 and was untouched by #699 and #712.

Measured behavior

Probed against the real components with ink-testing-library and fake timers before writing these ACs. Four results shaped the design:

1. Reproduced. A passed issue with startedAt set renders phase 3/3 • 25:09, and five seconds later phase 3/3 • 25:14.

2. The fix must react to completedAt appearing mid-life, not just on mount. Driving a single issue from running to passed — same React instance, since key is issue.number — the header went 25:09 → 25:10 → 25:14. An effect with [] deps would never re-run for that transition, so the freeze has to happen in render (completedAt?.getTime() ?? now) rather than by tearing down the interval on mount-time state.

3. Clearing the interval saves nothing on its own. App.tsx:34 polls getSnapshot at 10 Hz — 31 calls over 3 seconds, measured — and cloneIssueState returns a freshly-allocated object every poll, so setSnapshot re-renders the whole tree regardless of what any leaf timer does. The docstring's "tick-driven re-renders are scoped to this leaf" rationale is already defeated by the root poller. This makes the per-issue interval redundant rather than harmful: App already owns a 1 Hz now tick and already passes now into IssueBox (App.tsx:93), so ElapsedTimer can read that prop and drop its own timer entirely — one clock for the run instead of one per issue.

4. A naive fake-timer test would pass vacuously. vi.advanceTimersByTime(5000) fires the interval but does not flush ink's render — the frame is byte-identical afterward, so an assertion that the header stopped moving succeeds even against today's broken code. Only await vi.advanceTimersByTimeAsync(...) flushes. Any test for this must use the async form.

Also confirmed while investigating, and not a defect: the two other completed cards had collapsed into ✔ 2 done. That is the #699 row cap working as designed. selectVisibleIssues with 4 issues returns exactly visible=[844, 850], rolledUp=2 for any terminal height from 37 to 47 rows, which reproduces the reported frame.

Acceptance Criteria

  • AC-1: ElapsedTimer accepts an optional completedAt and, when set, renders the frozen completedAt - startedAt duration instead of measuring against the current time.
  • AC-2: IssueBox passes state.completedAt through to ElapsedTimer, so a passed or failed issue's header duration stops advancing.
  • AC-3: The freeze is computed during render, so an issue that transitions from running to passed on the same mounted component freezes at the transition without remount.
  • AC-4: ElapsedTimer takes the 1 Hz now that App already owns and passes to IssueBox, and no longer creates its own per-issue interval.
  • AC-5: A running issue's timer still advances once per second, and an issue with no startedAt still renders --:--.
  • AC-6: The frozen duration equals the plain renderer's duration for the same issue, in the TUI's own MM:SS format — the two renderers format differently on purpose (24m 7s vs 24:07), so this is a duration match, not a string match.
  • AC-7: Tests use await vi.advanceTimersByTimeAsync(...) rather than the sync form, and a comment records why: the sync form does not flush ink's render, so the frozen-header assertion would pass against unfixed code.
  • AC-8: The frozen-timer test is mutation-verified by reverting the completedAt prop in IssueBox and confirming exactly that test fails, with the result recorded in the commit message or PR body.

Activity

  1. added
    bug
    ui
    on Jul 29, 2026
  2. admarble commented on Jul 29, 2026

    @admarble
    ContributorAuthor

    The run this came from has now finished, and its log quantifies the defect against real data rather than a synthetic fixture. Run 21feec76-20e3-468a-8393-cd43cab03df7, four issues at 3-way concurrency.

    The final frame put two contradictory durations for #850 on screen at once — the box header, and the summary table printed directly beneath it:

    │ #850  ac-parser requires an ID prefix …                     phase 3/3 • 35:59 │
    │ phases ✓ spec 05:32   ▸   ✓ exec 09:52   ▸   ✓ qa 04:38                       │
    │ completed                                                                     │
    ...
    │ #850     │ ✔ passed   │ spec → exec → qa · PR #861          │ 20m 3s          │
    

    The header's own phase glyphs sum to 20m 02s, and the log records totalDurationSeconds: 1203.303 (20m 3s). The header said 35:59 — an overstatement of 15m 56s, or 79%.

    The drift is exactly the wall-clock gap between an issue finishing and the run ending, which is what a timer with no terminal condition predicts. #844 confirms the mechanism from the other direction: it finished last, so its header had no time to drift, and it reads 21:43 against a logged 1302.296s (21m 42s) — correct to the second.

    #850  logged 1203.303s (20m 03s)   header 35:59   drift +15m 56s   (finished ~16m before run end)
    #844  logged 1302.296s (21m 42s)   header 21:43   drift ~0         (finished last)
    

    Reconstructing from the timestamps: run start 15:32:29.443, run end 16:08:47.777. A header of 35:59 at run end puts #850's start at 15:32:48, 19s into the run — consistent with the orchestrator's staggered launch, so the header's start anchor is right and only the end anchor is missing.

    This strengthens AC-6. The frozen value is not merely "some stable number" — it must equal the per-issue duration already shown in the summary table and stored in the log, since the user sees all three at once.

    Two notes for whoever picks this up:

    The log is perishable evidence. .sequant/logs held 98 files against the 100-file rotation cap when I pulled these numbers, so the source run log may be gone within a couple of runs. Every figure above is transcribed here.

    Separately, the SUMMARY · 4 issues · 1h 12m line in that same frame is wrong too — the run took 36m 18s. That is an unrelated defect in a different code path, filed as #867. Worth knowing about only so the two aren't conflated while fixing either one.

  3. admarble commented on Jul 29, 2026

    @admarble
    ContributorAuthor

    Implementation context, checked so the fix does not have to be scoped twice.

    There are two producers of IssueRuntimeState, and both already set completedAt correctly. RunOrchestrator is the obvious one (run-orchestrator.ts:556 on success, :521 on failure, cloned at :1688). The second is ready-tui-adapter.ts, which drives the same Ink components for sequant ready after #699 moved that command onto the boxed TUI. Its markDone sets this.completedAt = new Date() unconditionally at :125 — before the pass/fail branch, so both terminal statuses get a stamp — and exposes it in the snapshot at :143.

    That means fixing ElapsedTimer and IssueBox fixes sequant ready at the same time, with no second wiring pass. Worth stating explicitly because this repo has bitten us before on exactly this shape, where two producers of the same config diverged because only one was guarded. Here they agree, and a reviewer should confirm they still do rather than assume it.

    Where the tests belong. IssueBox.test.tsx and App.test.tsx already exist and use ink-testing-library with a lastFrame() assertion style. App.test.tsx has an issue(number, status) helper that already sets completedAt for passed — it is used only for row-cap sort ordering today, so it is a ready-made fixture for the frozen-timer test. Note the file lives under src/ui/tui/ with no .integration. infix, which puts it in the unit project at a 5s testTimeout; the async timer advances the frozen-timer test needs are cheap, but do not let it grow into anything that sleeps.

    One caveat on sequant ready specifically. markDone also flips the snapshot's done flag, which unmounts the App. So on that path the frozen value matters for the final rendered frame rather than for an indefinitely-climbing counter — the sequant run case in the report above is the one where the timer visibly runs away, because other issues keep the TUI mounted for the rest of the batch.

  4. admarble commented on Jul 29, 2026

    @admarble
    ContributorAuthor

    #866 — fix(tui): completed issue box keeps counting — ElapsedTimer never freezes at completedAt
    Open · bug, ui
    ────────────────────────────────────────────────────────────────

    → PROCEED — Verified against main — ElapsedTimer accepts only startedAt and IssueBox.tsx:65 passes only state.startedAt

    Commands:
    sequant run 866 -Q --phases spec,exec,qa

    spec → exec → qa · 8 ACs

    Flags:
    -Q two components plus a prop-threading change through App, with a mutation-verified test gate
    --phases spec,exec,qa suppress the browser test phase the ui label auto-inserts (phase-mapper.ts:201)

    Considered:
    --testgen the second comment names the target files, the ready-made issue() fixture and the required async timer form — generated stubs would duplicate that
    ────────────────────────────────────────────────────────────────
    ⚠ ui label auto-inserts the browser test phase, which does not apply to an Ink terminal TUI — phases pinned explicitly instead
    ⚠ src/ui/tui/ has no .integration. infix, so these tests run in the unit project at a 5s testTimeout — keep the async timer advances cheap
    ────────────────────────────────────────────────────────────────

  5. admarble commented on Jul 29, 2026

    @admarble
    ContributorAuthor

    #866 — fix(tui): completed issue box keeps counting — ElapsedTimer never freezes at completedAt
    Open · bug, ui
    ────────────────────────────────────────────────────────────────

    Supersedes prior assess from 2026-07-29 (PROCEED)

    → PROCEED — Re-verified against main — ElapsedTimer still accepts only startedAt (ElapsedTimer.tsx:8) and IssueBox.tsx:65 still passes only state.startedAt

    Commands:
    sequant run 866 -Q --phases spec,exec,qa

    spec → exec → qa · 8 ACs

    Flags:
    -Q two components plus a prop-threading change through App, with a mutation-verified test gate
    --phases spec,exec,qa suppress the browser test phase the ui label auto-inserts (phase-mapper.ts)

    Considered:
    --testgen the implementation-context comment already names the target files, the ready-made issue() fixture and the required async timer form — generated stubs would duplicate that
    ────────────────────────────────────────────────────────────────
    ⚠ ui label auto-inserts the browser test phase, which does not apply to an Ink terminal TUI — phases pinned explicitly
    ⚠ src/ui/tui/ has no .integration. infix, so these tests run in the unit project at a 5s testTimeout — keep the async timer advances cheap
    ⚠ Same-run sibling of #867 but a different code path (Ink TUI vs run-display) — safe to run in parallel, do not conflate while fixing either
    ────────────────────────────────────────────────────────────────

  6. admarble commented on Jul 29, 2026

    @admarble
    ContributorAuthor

    📋 Plan (spec)

    Complexity: Standard (8 ACs, 1 directory) · Scope: ✅ SCOPE_OK

    Root cause is fully diagnosed in the issue: ElapsedTimer measures against a live 1 Hz Date.now() with no terminal condition, so a passed/failed issue's header counts up forever while the body cell reads completed. Fix = freeze on completedAt in render, and read App's existing now instead of a per-issue interval.

    Acceptance Criteria (verification)

    • AC-1 — ElapsedTimer accepts completedAt; renders frozen completedAt − startedAt when set. (Unit)
    • AC-2 — IssueBox passes state.completedAt through (IssueBox.tsx:65). (Unit)
    • AC-3 — Freeze computed in render (completedAt?.getTime() ?? now), so a same-mount running → passed transition freezes without remount. An []-dep effect can't catch it. (Unit)
    • AC-4 — ElapsedTimer takes App's 1 Hz now prop; drops its own useState/useEffect/setInterval (the leaf interval is already redundant — the 10 Hz root poller re-renders the tree regardless). (Unit + inspection)
    • AC-5 — Running timer still ticks 1 Hz; no startedAt still renders --:--. (Unit)
    • AC-6 — Frozen duration equals the plain renderer's (run-renderer.ts:1234) — a duration match (24:07 ↔ 24m 7s), not a string match. Oracle = the summary-table / log value. (Unit)
    • AC-7 — Tests use await vi.advanceTimersByTimeAsync(...) (sync form doesn't flush ink → vacuous pass), with a comment recording why. (Test discipline)
    • AC-8 — Frozen-timer test mutation-verified: revert the IssueBox completedAt prop, confirm exactly that test fails, record in commit/PR. (Manual)

    Implementation Plan

    Phase 1 — component (src/ui/tui/)

    1. ElapsedTimer.tsx: signature → { startedAt?: Date; completedAt?: Date; now: number }; drop the hooks/interval; const end = completedAt?.getTime() ?? now;; update the now-obsolete "scoped to this leaf" docstring.
    2. IssueBox.tsx:65: pass completedAt={state.completedAt} and now={now} (now is already an IssueBox prop).

    Phase 2 — tests
    3. Fake timers, drive with advanceTimersByTimeAsync only (+ AC-7 comment).
    4. Frozen / transition / running / --:-- / parity specs (AC-1,2,3,5,6).
    5. Mutation-verify the frozen test (AC-8).

    IssueBox.test.tsx uses live Date.now() in baseState; put the fake-timer specs in a dedicated ElapsedTimer.test.tsx (or isolate per-test) to avoid timer-mode bleed. At least one test must render through IssueBox for AC-8's mutation target.

    Design Notes

    Recommended Workflow

    exec → qa · quality loop disabled · skip testgen (bug fix, subtle hand-written tests) · skip browser test (ink terminal UI, not web).
    Label: add no-browser-test.

  7. added
    planned
    no-browser-test
    on Jul 29, 2026
  8. admarble commented on Jul 29, 2026

    @admarble
    ContributorAuthor

    /exec Progress Update

    PR: #869 ✅ Created

    AC Coverage

    AC Description Status
    AC-1 ElapsedTimer accepts completedAt, freezes completedAt - startedAt ✅
    AC-2 IssueBox passes state.completedAt through ✅
    AC-3 Freeze computed in render; running → passed freezes without remount ✅
    AC-4 Reads App's 1 Hz now; per-issue interval removed ✅
    AC-5 Running still advances; no startedAt → --:-- ✅
    AC-6 Duration parity with plain renderer, in TUI's MM:SS ✅
    AC-7 Tests use await vi.advanceTimersByTimeAsync(...) + rationale comment ✅
    AC-8 Mutation-verified (see below) ✅

    Files changed

    • src/ui/tui/ElapsedTimer.tsx — new completedAt/now props; interval dropped; freeze in render
    • src/ui/tui/IssueBox.tsx — passes completedAt + now to ElapsedTimer
    • src/ui/tui/ElapsedTimer.test.tsx — new unit tests (AC-1/3/5/6)
    • src/ui/tui/App.test.tsx — App-level frozen-header test (AC-2/4/7/8)
    • CHANGELOG.md — Fixed entry

    Mutation verification (AC-8)

    Reverting IssueBox to drop the completedAt prop makes exactly one test fail:

    ❯ src/ui/tui/App.test.tsx (3 tests | 1 failed)
       × freezes a passed issue's header while App's 1 Hz clock keeps ticking
     Tests  1 failed | 13 passed (14)
    

    Restoring the prop returns the full TUI suite to green (41 passed).

    Checks

    • npm run build ✅ · npm run lint ✅ (0 warnings) · npx vitest run src/ui/tui/ … ✅ 54 passed

    Quality Plan Alignment

    N/A — no /spec quality plan comment on this issue; ACs were pre-specified in the issue body.

  9. admarble commented on Jul 29, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #866

    AC Coverage

    AC Source Description Status Notes
    AC-1 Original ElapsedTimer accepts completedAt, freezes completedAt - startedAt MET ElapsedTimer.tsx:24 const end = completedAt?.getTime() ?? now; ElapsedTimer.test.tsx "freezes at completedAt - startedAt" asserts 01:30 stays frozen as now advances
    AC-2 Original IssueBox passes state.completedAt through MET IssueBox.tsx:65-69 passes completedAt={state.completedAt} + now={now}
    AC-3 Original Freeze computed in render; running→passed freezes without remount MET Freeze is a render-time expression, no useEffect; ElapsedTimer.test.tsx "freezes in render on a running → passed transition" rerenders same instance and gets 00:30 not live 00:45
    AC-4 Original Reads App's 1 Hz now; per-issue interval removed MET useEffect/setInterval removed from ElapsedTimer.tsx; App.tsx:48 owns the 1 Hz tick, App.tsx:93 passes now to IssueBox. Grep confirms no interval remains in the component
    AC-5 Original Running advances; no startedAt → --:-- MET ElapsedTimer.test.tsx two cases: --:-- when no startedAt; 00:05→00:06 on advancing now
    AC-6 Original Duration parity with plain renderer, in TUI's MM:SS MET Same (completedAt - startedAt) span as run-renderer.ts statusHeader; test asserts 1447s → 24:07 (the issue body's own example)
    AC-7 Original Tests use await vi.advanceTimersByTimeAsync(...) + rationale comment MET App.test.tsx:83-88 — async form with a 3-line comment explaining the sync form never flushes ink's render
    AC-8 Original Frozen test mutation-verified MET Independently re-verified: dropping the completedAt prop in IssueBox fails exactly one test (App freeze test) — 1 failed / 13 passed; restored → 41 TUI tests green

    Coverage: 8/8 AC items fully met · Original ACs: 8/8 · Derived ACs: none


    CI Status

    Check State Bucket Impact
    typecheck SUCCESS pass ✅ MET
    validate-plugin SUCCESS pass ✅ MET
    validate-skills SUCCESS pass ✅ MET
    node-floor-guard SUCCESS pass ✅ MET
    build (22.x) IN_PROGRESS pending ⏳ PENDING (gating)

    CI Summary: 4 passed, 1 pending, 0 failed. Diff is not markdown-only (touches .tsx), so the build-matrix relaxation does not apply — build (22.x) is a gating pending check. No CI-dependent AC in the issue; this is the only merge gate outstanding.


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 OK
    Deleted tests 0 OK
    Files changed 5 OK
    Lines added +146 -
    Lines deleted -12 -
    Security patterns 0 OK

    Local: npm run build ✅ · npm run lint ✅ (0 warnings) · npx vitest run src/ui/tui/ ✅ 41 passed.


    Test Coverage Analysis

    Changed File Tier Has Tests? Test File
    src/ui/tui/ElapsedTimer.tsx Standard (UI) ✅ Yes ElapsedTimer.test.tsx (5 cases)
    src/ui/tui/IssueBox.tsx Standard (UI) ✅ Yes IssueBox.test.tsx + App.test.tsx freeze test (through IssueBox)

    Coverage: 2/2 changed source files covered. No critical-path (auth/payment/security) files touched.


    Code Review

    Strengths:

    • Minimal, surgical diff (37 source lines) that matches the issue's prescribed design exactly.
    • completedAt?.getTime() ?? now is the right render-time expression — correctly handles the mid-life running → passed transition (AC-3) that an []-dep effect could not.
    • Removing the per-issue interval is a real simplification, well-justified in the updated docstring (the 10 Hz root poller already re-rendered the tree, so the leaf clock bought nothing).
    • Math.max(0, …) clamp preserved, so clock skew (completedAt < startedAt) renders 00:00 rather than a negative duration.

    Issues: None.

    Suggestions: None blocking.


    Test Quality Review

    Category Status Notes
    Behavior vs Implementation ✅ OK Asserts rendered MM:SS frames, not internals
    Coverage Depth ✅ OK Freeze, advance, --:--, in-render transition, parity all covered
    Mock Hygiene ✅ OK Only fake timers; no module mocks
    Test Reliability ✅ OK Uses advanceTimersByTimeAsync (AC-7) so frames actually flush; useRealTimers in finally

    Anti-Pattern Detection

    Code patterns: none. No package.json change → dependency audit N/A. Note: this diff removes a setInterval, reducing per-issue timer churn.


    Risk Assessment

    • Likely failure mode: Purely visual. Worst case is a clock-skew edge (completedAt < startedAt) which the retained Math.max(0, …) clamps to 00:00. No data or control-flow impact.
    • Not tested: No explicit test for the completedAt < startedAt clamp, but the clamp is unchanged from the original and low-risk.
    • Sibling sites considered: none — ElapsedTimer's only consumer is IssueBox; no other component renders an elapsed-since-start clock. formatSinceActivity (last-activity stamp) is intentionally live and only renders for a running currentPhase, so it has no parallel freeze bug. run-renderer.ts already froze correctly — this brings the TUI to parity, not a sibling defect.
    • Sibling-line audit: none — single duration-computation site in the component.

    Trust-Boundary Check

    Finding: Clean — the issue body is a genuine bug report with code references; no agent-directed instruction (command/network/file/exfiltration/override) is embedded. The diff implements only the product requirement (freeze the header at completion).

    Status: Clean


    Behavior-Rule Survival Check

    AC Triggered? Survivors Status
    AC-4 Borderline ("no longer creates its own per-issue interval") — (interval verified removed: no setInterval in ElapsedTimer.tsx) Clean

    Status: Clean


    CHANGELOG Verification

    Check Status
    CHANGELOG.md exists ✅ Found
    User-facing changes ✅ Yes (fix(#866))
    [Unreleased] entry ✅ Present (CHANGELOG.md:25, Fixed section)
    Entry format ✅ Valid (includes (#866))

    Result: CHANGELOG requirements met.


    Adversarial Re-Read

    Findings: No gaps found because — (1) Fixtures: ran the implementation against the issue's own numbers — the frozen-duration test asserts 24:07 (the issue body's example) and the App test reproduces "was counting, now frozen" by holding 01:30 across advanceTimersByTimeAsync(5000); both pass. (2) Evidence audit: the AC-8 claim is a post-fix validation, not a pre-fix repro — I independently re-ran the mutation (drop completedAt prop → exactly 1 test fails, restore → 41 pass), so the gate test genuinely bites. (3) Process state: worktree clean, one commit, 0 behind origin/main; no uncommitted/divergent/stashed state. (4) Sibling sites: cross-file — ElapsedTimer has a single consumer (IssueBox); intra-file — one duration computation, and formatSinceActivity only renders for a live currentPhase so it carries no parallel freeze bug. (5) Non-Goals: the issue explicitly rules the ✔ 2 done rollup collapse in/out of scope as working-as-designed (#699 row cap); the diff does not touch it, so no silent scope expansion.

    Status: Clean


    Verdict: NEEDS_VERIFICATION

    All 8 acceptance criteria are MET — verified against the code, local build/lint/test (41 TUI tests green), and an independent re-run of the AC-8 mutation. Code quality is A+: minimal, correct, well-documented, and a genuine simplification. The only outstanding item is the in-flight build (22.x) CI leg (a gating pending check; typecheck and all other checks already green). Per QA policy, a gating-pending CI check precludes READY_FOR_MERGE.

    This is A+ work — the verdict flips to READY_FOR_MERGE the moment build (22.x) goes green. Re-run /qa 866 --force after CI completes, or merge once the check passes.

    Documentation

    Next Steps

    1. Wait for build (22.x) to finish (near-certain pass: typecheck already green, local build passes).
    2. Once green → merge PR fix(#866): freeze TUI ElapsedTimer at completedAt instead of counting forever #869, or re-run /qa 866 --force to auto-flip the verdict to READY_FOR_MERGE.
  10. added
    needs-verification
    on Jul 29, 2026
  11. admarble commented on Jul 30, 2026

    @admarble
    ContributorAuthor

    QA Review — PR #869 (fix(#866))

    Verdict: AC_MET_BUT_NOT_A_PLUS. All 8 ACs are literally satisfied and the reported bug is genuinely fixed. One reachable defect is introduced by the fix — the same class of bug (header disagreeing with reality), in the mirror direction — and it should be closed in this PR before merge.

    Verified independently against the PR branch worktree at b853e210: npx tsc --noEmit clean, npm run lint clean, npx vitest run src/ui/tui/ src/commands/ready-tui-adapter.test.ts → 52 passed (10 files).


    Finding 1 — BLOCKING: the clock now freezes while the issue is still running (quality-loop recovery)

    ElapsedTimer is status-agnostic: end = completedAt?.getTime() ?? now. But completedAt is not exclusively terminal. run-orchestrator.ts:521 writes state.completedAt = new Date() on a non-loop phase failure, and :433 flips state.status back to "running" when the next phase starts — without clearing completedAt. findOrAppendPhase reuses the slot by name, so this is exactly the #766 quality-loop recovery path that run-state.test.ts:99-115 already documents (qa fails → loop fails → exec/qa re-run on iteration 2).

    Reproduced by driving the real orchestrator through that sequence and rendering the real App:

    STATE  status=running  startedAt=…T01:27:25.959Z  completedAt=…T01:28:10.959Z
    recovery T+0s : │ #1  Recovering issue                    phase 2/4 • 00:45 │
    recovery T+3s : │ #1  Recovering issue                    phase 2/4 • 00:45 │
    recovery T+6s : │ #1  Recovering issue                    phase 2/4 • 00:45 │
    

    The header sits at 00:45 for the entire duration of iteration 2 — however many minutes exec and qa take — while the body cell correctly reads working… and the spinner spins. Before this PR that window ticked correctly; the header only misbehaved after terminal completion. So this is a narrow new regression, not a pre-existing one. It self-corrects at final completion (:556 overwrites completedAt), so only the recovery window is affected.

    This also breaks the AC-6 parity claim in the running case. The plain renderer is immune because it branches on status first: run-renderer.ts:1259-1263 computes a running issue's elapsed as this.now() - phase.startedAt and never reads completedAt. Only its done/failed branches consult completedAt. The TUI now consults it unconditionally.

    Suggested fix — gate on terminal status in IssueBox (the adapter layer, mirroring the plain renderer's status branch) rather than teaching ElapsedTimer about status:

    completedAt={
      state.status === "passed" || state.status === "failed"
        ? state.completedAt
        : undefined
    }

    A regression test belongs in run-state.test.ts's #766 describe or alongside the new App freeze test: after progress(1, "exec", "start", { iteration: 2 }), assert the header advances across an advanceTimersByTimeAsync rather than holding. Worth deciding separately whether applyProgressEvent's start branch should also clear state.completedAt — the snapshot currently exposes status: "running" alongside a populated completedAt to every consumer, and row-cap.ts:95 sorts on that field.


    AC-by-AC

    AC Verdict Independent evidence
    AC-1 completedAt freezes duration ✅ ElapsedTimer.tsx:24; unit test asserts 01:30 holds across two now values 9 min apart
    AC-2 IssueBox passes completedAt ✅ Data flow traced end to end: orchestrator :521/:556 write → cloneIssueState:1688 carries → App.tsx:93 → IssueBox.tsx:65 → ElapsedTimer. The failed half of the AC is untested but works — the implementation is status-agnostic and :521 populates completedAt on failure
    AC-3 freeze in render, no remount ✅ Not a tautology — I checked the counterfactual: an useState + []-dep-effect implementation renders 00:45 where the test demands 00:30, so the test does kill that mutant
    AC-4 uses App's now, no own interval ✅ code useEffect/useState removed; now: number is a required prop so it cannot silently fall back. No test gates the absence of an interval — the running-timer test would pass either way. Structural, acceptable
    AC-5 running advances; no startedAt → --:-- ✅ Both unit tests pass; App's 1 Hz tick confirmed at App.tsx:46-49
    AC-6 duration parity, MM:SS ⚠️ Correct for the done case (run-renderer.ts:1236 uses the same completedAt - startedAt, same second-flooring). Two gaps: parity breaks in the running case (Finding 1), and the test hardcodes "24:07" without referencing the plain renderer or formatElapsedTime at all — it would stay green if the plain renderer changed its freeze semantics, which is the only thing AC-6 is about
    AC-7 async advanceTimersByTimeAsync + comment ✅ Independently confirmed the claim is true, not folklore. Same frame, same mutant: sync advance leaves 01:30; async advance moves to 01:40. The comment's rationale is accurate
    AC-8 mutation-verified ✅ Reproduced exactly: dropping the completedAt prop from IssueBox → `1 failed

    Note on AC-8's kill mechanism. The mutant dies at App.test.tsx:81 — the assertion before advanceTimersByTimeAsync, because startedAt is an absolute epoch (new Date(1_000_000)) and the unfixed path renders 29756227:04 immediately. So the post-advance assertion and the async form are belt-and-braces here, not what kills the mutant. That's a stronger fail-fast signal, but it means the test doesn't actually exercise the property AC-7's comment describes. Making startedAt clock-relative (new Date(Date.now() - 90_000)) moves the kill to the post-advance assertion and makes the async form load-bearing — I verified that variant passes vacuously with the sync form and fails correctly with the async form.


    Also checked, no issues

    • No sibling forever-counting bug in the same box. The last activity Xs ago stamp is inside the state.currentPhase ? … branch, and run-orchestrator.ts:508 sets currentPhase = undefined on phase end, so a completed issue renders statusLine instead. Nothing else in IssueBox measures against a live clock.
    • No other ElapsedTimer consumers — IssueBox is the only one, so the newly-required now prop can't strand a caller. formatSinceActivity (same module) is untouched.
    • Test file is actually gated in CI. **/*.test.tsx is in the unit vitest project and CI runs npm test. The new tests are fast and in-process, well under the unit project's 5 s timeout.
    • Scope is tight — 5 files, +146/−12, no drive-by changes. CHANGELOG entry added under Unreleased → Fixed.
    • Timer hygiene — both new fake-timer tests restore real timers in finally.
  12. added 4 commits that reference this issue on Jul 30, 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

    bugneeds-verificationno-browser-testplannedui

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions