Skip to content

fix(#866): freeze TUI ElapsedTimer at completedAt instead of counting forever - #869

Merged
admarble merged 5 commits into
mainfrom
feature/866-fix-tui-completed-issue-box-keeps-counting-elapsed
Jul 30, 2026
Merged

admarble merged 5 commits into
mainfrom
feature/866-fix-tui-completed-issue-box-keeps-counting-elapsed

Conversation

@admarble

@admarble admarble commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The Ink TUI's completed-issue header kept counting up forever: a passed/failed issue's body cell read completed while the header clock climbed (phase 3/3 • 24:07 → 25:09 → 25:14). ElapsedTimer accepted only startedAt and always measured against a live Date.now(), and IssueBox never passed the already-populated state.completedAt.

  • AC-1/AC-6: ElapsedTimer accepts an optional completedAt and, when set, renders the frozen completedAt - startedAt duration — parity with the plain renderer, which already freezes a done issue at that span (run-renderer.ts statusHeader).
  • AC-3: The freeze is computed in render (completedAt?.getTime() ?? now), so an issue transitioning running → passed on the same mounted component (key = issue.number) freezes at the transition without a remount — an []-dep effect would never re-run for that in-place transition.
  • AC-4: ElapsedTimer drops its own per-issue interval and reads the single 1 Hz now that App already owns and threads through IssueBox — one clock for the run. The root 10 Hz snapshot poller already re-renders the whole tree each tick, so the per-issue interval bought no re-render scoping.
  • AC-2: IssueBox passes state.completedAt and now through.
  • AC-5: A running issue still advances once per second (via now); an issue with no startedAt still renders --:--.

Post-QA revision — the mirror-image bug, and three weak gates

QA of the first commit found that the fix introduced the inverse of the bug it killed, plus three gates weaker than the ACs they claimed. Both are addressed in 8125499a / 4344855a.

A stale completedAt froze a running header

completedAt is not exclusively terminal. run-orchestrator.ts stamps it on a non-loop phase failure, and the #766 quality-loop recovery then flips the issue back to running for iteration 2 without clearing it (findOrAppendPhase reuses the slot by name). ElapsedTimer read the field unconditionally, so the header sat frozen for the entire recovery window while the body cell read working… and the spinner spun. Reproduced against the real orchestrator driven through the exact sequence run-state.test.ts already documents, 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 │

Before this PR that window ticked correctly — the header only misbehaved after terminal completion — so it was a new regression. It also broke the AC-6 parity claim in the running case: the plain renderer is immune because it branches on status before reading completedAt (run-renderer.ts:1259 measures a running issue as this.now() - phase.startedAt).

Fixed at both layers, deliberately:

  • run-orchestrator clears state.completedAt when a phase start makes an issue live again, restoring the invariant a completion time implies a terminal status for every snapshot consumer (row-cap's rollup sort reads the same field). startedAt is untouched — the header measures total wall clock across iterations.
  • IssueBox gates the prop on isTerminalStatus, mirroring the plain renderer's status branch, so the TUI stays correct even if another producer publishes a stale stamp. isTerminalStatus is new in theme.ts; row-cap's isActive now derives from it instead of repeating the status split.

Gate hardening

Gate Was Now
AC-6 expect(lastFrame()).toBe("24:07") — never touched the plain renderer, so it would stay green if the plain renderer changed which span it freezes, the only thing AC-6 is about Drives a real TTYRenderer through the same span on a controlled clock and compares seconds three ways (TUI ↔ plain ↔ true span)
AC-4 No gate at all A test proves ElapsedTimer owns no interval: fake timers advance 5 s with no parent re-render and the frame must not move
AC-8 The mutant died at the pre-advance assertion (absolute-epoch startedAt renders a ~29,756,227-minute header), so the async-flush property AC-7 mandates went unexercised The span is anchored to the fake clock, moving the kill to the post-advance assertion and making advanceTimersByTimeAsync the thing that makes the test real

AC Verification

AC Description Status Evidence
AC-1 completedAt freezes duration ✅ ElapsedTimer.tsx:24; ElapsedTimer.test.tsx "freezes at completedAt - startedAt"
AC-2 IssueBox passes completedAt ✅ IssueBox.tsx, gated on isTerminalStatus; data flow run-orchestrator → cloneIssueState → App → IssueBox → ElapsedTimer
AC-3 Freeze in render, no remount ✅ ElapsedTimer.test.tsx "freezes in render on a running → passed transition"
AC-4 Uses App's now, no own interval ✅ ElapsedTimer.tsx (interval removed); ElapsedTimer.test.tsx "owns no interval" (mutation M3)
AC-5 Running advances; no startedAt → --:-- ✅ ElapsedTimer.test.tsx two cases
AC-6 Duration parity with plain renderer, MM:SS ✅ ElapsedTimer.test.tsx cross-renderer parity gate (mutation M4); parity now holds in the running case too
AC-7 Tests use advanceTimersByTimeAsync + comment ✅ App.test.tsx freeze test; the async form is now load-bearing (mutation M6)
AC-8 Mutation-verified ✅ six mutations below

Mutation verification (AC-8)

Every gate was mutation-verified against the committed tree, one mutation at a time.

# Mutation Result
M1 Remove state.completedAt = undefined from applyProgressEvent's start branch 1 failed | 61 passed (62) — only "clears the stale completedAt when iteration 2 restarts the issue (#866)"
M2 Drop the isTerminalStatus gate in IssueBox (pass state.completedAt unconditionally) 1 failed | 61 passed (62) — only "keeps a running issue's header advancing when a stale completedAt survives"
M3 Re-add a per-issue 1 Hz interval to ElapsedTimer 1 failed | 42 passed (43) — only "owns no interval — the frame only moves when a parent re-renders (AC-4)"
M4 Make the plain renderer stop freezing (statusHeader → this.now() - startedAt) AC-6 parity gate fails: expected 1447 to be 1509
M5 Drop completedAt from IssueBox entirely App.test.tsx:100 fails — the post-advance assertion, not the pre-advance one
M6 M5 plus advanceTimersByTime in place of the async form Vacuous pass (4/4) — confirms the async form is what makes the freeze assertion real, exactly as AC-7's comment claims

M4 initially passed and exposed a real weakness in the gate I had just written: the parity test read the first done · … · frame, which is emitted at completion where the renderer's clock still equals completedAt — a frozen duration and a live one are identical there. Reading the last match (the post-completion repaint) is what makes M4 fail. Fixed in 4344855a.

Test plan

  • npx tsc --noEmit — clean
  • npm run lint — passes (0 warnings)
  • npm test (full suite) — 225 files, 4645 passed, 1 expected fail, 2 skipped
  • npx vitest run src/ui/tui/ src/lib/workflow/run-state.test.ts src/lib/cli-ui/ src/commands/ready-tui-adapter.test.ts src/lib/workflow/recovered-failure.integration.test.ts — 200 passed
  • Six mutations verified (table above)

Closes #866

… forever

A passed/failed issue's header clock climbed indefinitely (`phase 3/3 •
25:09 → 25:14`) while its body cell read `completed`, because ElapsedTimer
accepted only `startedAt` and always measured against a live Date.now(),
and IssueBox never passed the already-populated `state.completedAt`.

- ElapsedTimer accepts optional `completedAt`; when set, freezes at
  `completedAt - startedAt` (AC-1), computed in render so a running → passed
  transition freezes without a remount (AC-3). Parity with the plain
  renderer's frozen duration in MM:SS (AC-6).
- ElapsedTimer drops its own per-issue interval and reads the 1 Hz `now`
  App already owns and threads through IssueBox (AC-4); IssueBox passes
  `completedAt` + `now` through (AC-2).
- Running timer still advances via `now`; no `startedAt` still renders
  `--:--` (AC-5).

Tests use `await vi.advanceTimersByTimeAsync(...)` with a comment on why the
sync form is vacuous — it fires App's interval but never flushes ink's render
(AC-7).

Mutation-verified (AC-8): reverting IssueBox to drop the `completedAt` prop
makes ONLY the App freeze test fail (1 failed | 13 passed); restoring it
returns the full TUI suite to green (41 passed).

Entire-Checkpoint: 92a3c6fc3d4f
admarble added 4 commits July 29, 2026 20:41
…gates

QA of PR #869 found the fix introduced the mirror-image bug it set out to
kill, plus three gates weaker than the ACs they claimed.

Stale completedAt froze a *running* header. `completedAt` is not exclusively
terminal: applyProgressEvent stamps it on a non-loop phase failure, and the
#766 quality-loop recovery then flips the issue back to `running` for
iteration 2 without clearing it. ElapsedTimer read it unconditionally, so the
header sat frozen for the whole recovery window while the body cell read
`working…` and the spinner spun. Reproduced against the real orchestrator +
App: status=running, completedAt set, header pinned at 00:45 across a 6s
advance. The plain renderer is immune because it branches on status *before*
reading completedAt (run-renderer.ts statusHeader), so this also broke the
AC-6 parity claim in the running case.

Fixed at both layers:
- run-orchestrator clears `state.completedAt` when a phase start makes an
  issue live again, restoring the invariant "completion time implies terminal
  status" for every snapshot consumer. `startedAt` is untouched — the header
  measures total wall clock across iterations.
- IssueBox gates the prop on `isTerminalStatus`, mirroring the plain
  renderer's status branch, so the TUI stays correct even if another producer
  publishes a stale stamp. `isTerminalStatus` is new in theme.ts and row-cap's
  `isActive` now derives from it rather than repeating the status split.

Gate hardening:
- AC-6 was a hardcoded `expect("24:07")` that never touched the plain
  renderer — it would have stayed green if the plain renderer changed which
  span it freezes, the only thing AC-6 is about. It now drives a real
  TTYRenderer through the same span on a controlled clock and compares
  seconds three ways (TUI ↔ plain ↔ true span).
- AC-4 had no gate at all; a test now proves ElapsedTimer owns no interval by
  advancing fake timers with no parent re-render.
- AC-8's mutant died at the *pre*-advance assertion, because `startedAt` was
  an absolute epoch — so the async-flush property AC-7 mandates went
  unexercised. The span is now anchored to the fake clock, moving the kill to
  the post-advance assertion and making `advanceTimersByTimeAsync` the thing
  that makes the test real.

Mutation results recorded in the PR body. Full suite: 4645 passed.
Mutation testing caught the gate I had just added. Making the plain renderer
stop freezing (statusHeader measuring `this.now() - startedAt` instead of
`completedAt - startedAt`) left the AC-6 parity test GREEN: it read the first
`done · … ·` match in the write buffer, and that frame is emitted at
completion — where the renderer's clock still equals completedAt, so a frozen
duration and a live one are identical.

Reading the last match instead picks the post-completion `tickNow()` repaint,
which is the only frame that distinguishes them. Same mutation now fails with
`expected 1447 to be 1509`.
CHANGELOG conflict: both PRs prepended to `### Fixed`. Kept both entries,
newest-first, matching the section's existing merge-recency ordering.

run-orchestrator.ts auto-merged cleanly and is semantically disjoint: #867's
work is run-level wall clock in `run()`/`RunResult`, mine is per-issue
`state.completedAt` in `applyProgressEvent`. Verified #868 reads `completedAt`
nowhere — the only readers are the #866 code and `cloneIssueState`.

Post-merge the tautology detector started failing (3 tests, exit 1). Cause is
scope, not quality: `git diff main...HEAD` now includes run-state.test.ts —
my new #866 block pulled the whole file in — exposing 16 pre-existing blocks
plus mine at 58.6%. Every block there drives production via a helper-built
RunOrchestrator and its captured `onProgress` callback, which the detector's
imported-name body scan cannot follow. Same limitation and same pragma as
run-renderer-672.test.ts; the #866 block is mutation-verified, so its
production coverage is proven rather than asserted. App.test.tsx and
ElapsedTimer.test.tsx pass the detector unskipped.
Only CHANGELOG.md conflicted, and only additively: #858 prepended three #853
entries to the same [Unreleased] → Fixed block this PR appends to. Resolved as
a union — verified programmatically that all 20 of main's Fixed entries survive
and this PR adds exactly one.

No source-file overlap: #858 touches phase-executor / ready-gate / ready /
qa SKILL.md, none of which this PR goes near. Main's stray blank line inside
the Fixed list (an artifact of #858's own entry, which splits the bullet list
in rendered Markdown) is preserved verbatim rather than silently cleaned up
here — it belongs to that PR, not this one.

Verified on the merged tree: tsc clean, lint clean, tautology detector exit 0,
full suite 227 files / 4668 passed.
@admarble
admarble merged commit 33d5c4a into main Jul 30, 2026
5 checks passed
@admarble
admarble deleted the feature/866-fix-tui-completed-issue-box-keeps-counting-elapsed branch July 30, 2026 02:57
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.

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

1 participant