Repository navigation
fix(#866): freeze TUI ElapsedTimer at completedAt instead of counting forever - #869
Merged
admarble merged 5 commits intoJul 30, 2026
Conversation
… 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
Closed
8 tasks
…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
deleted the
feature/866-fix-tui-completed-issue-box-keeps-counting-elapsed
branch
July 30, 2026 02:57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Ink TUI's completed-issue header kept counting up forever: a
passed/failedissue's body cell readcompletedwhile the header clock climbed (phase 3/3 • 24:07 → 25:09 → 25:14).ElapsedTimeraccepted onlystartedAtand always measured against a liveDate.now(), andIssueBoxnever passed the already-populatedstate.completedAt.ElapsedTimeraccepts an optionalcompletedAtand, when set, renders the frozencompletedAt - startedAtduration — parity with the plain renderer, which already freezes a done issue at that span (run-renderer.tsstatusHeader).completedAt?.getTime() ?? now), so an issue transitioningrunning → passedon 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.ElapsedTimerdrops its own per-issue interval and reads the single 1 HznowthatAppalready owns and threads throughIssueBox— 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.IssueBoxpassesstate.completedAtandnowthrough.now); an issue with nostartedAtstill 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
completedAtfroze a running headercompletedAtis not exclusively terminal.run-orchestrator.tsstamps it on a non-loop phase failure, and the #766 quality-loop recovery then flips the issue back torunningfor iteration 2 without clearing it (findOrAppendPhasereuses the slot by name).ElapsedTimerread the field unconditionally, so the header sat frozen for the entire recovery window while the body cell readworking…and the spinner spun. Reproduced against the real orchestrator driven through the exact sequencerun-state.test.tsalready documents, rendering the realApp: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:1259measures a running issue asthis.now() - phase.startedAt).Fixed at both layers, deliberately:
run-orchestratorclearsstate.completedAtwhen 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).startedAtis untouched — the header measures total wall clock across iterations.IssueBoxgates the prop onisTerminalStatus, mirroring the plain renderer's status branch, so the TUI stays correct even if another producer publishes a stale stamp.isTerminalStatusis new intheme.ts;row-cap'sisActivenow derives from it instead of repeating the status split.Gate hardening
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 aboutTTYRendererthrough the same span on a controlled clock and compares seconds three ways (TUI ↔ plain ↔ true span)ElapsedTimerowns no interval: fake timers advance 5 s with no parent re-render and the frame must not movestartedAtrenders a ~29,756,227-minute header), so the async-flush property AC-7 mandates went unexercisedadvanceTimersByTimeAsyncthe thing that makes the test realAC Verification
completedAtfreezes durationElapsedTimer.tsx:24;ElapsedTimer.test.tsx"freezes at completedAt - startedAt"IssueBoxpassescompletedAtIssueBox.tsx, gated onisTerminalStatus; data flowrun-orchestrator→cloneIssueState→App→IssueBox→ElapsedTimerElapsedTimer.test.tsx"freezes in render on a running → passed transition"now, no own intervalElapsedTimer.tsx(interval removed);ElapsedTimer.test.tsx"owns no interval" (mutation M3)startedAt→--:--ElapsedTimer.test.tsxtwo casesElapsedTimer.test.tsxcross-renderer parity gate (mutation M4); parity now holds in the running case tooadvanceTimersByTimeAsync+ commentApp.test.tsxfreeze test; the async form is now load-bearing (mutation M6)Mutation verification (AC-8)
Every gate was mutation-verified against the committed tree, one mutation at a time.
state.completedAt = undefinedfromapplyProgressEvent'sstartbranch1 failed | 61 passed (62)— only "clears the stale completedAt when iteration 2 restarts the issue (#866)"isTerminalStatusgate inIssueBox(passstate.completedAtunconditionally)1 failed | 61 passed (62)— only "keeps a running issue's header advancing when a stale completedAt survives"ElapsedTimer1 failed | 42 passed (43)— only "owns no interval — the frame only moves when a parent re-renders (AC-4)"statusHeader→this.now() - startedAt)expected 1447 to be 1509completedAtfromIssueBoxentirelyApp.test.tsx:100fails — the post-advance assertion, not the pre-advance oneadvanceTimersByTimein place of the async formM4 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 equalscompletedAt— a frozen duration and a live one are identical there. Reading the last match (the post-completion repaint) is what makes M4 fail. Fixed in4344855a.Test plan
npx tsc --noEmit— cleannpm run lint— passes (0 warnings)npm test(full suite) — 225 files, 4645 passed, 1 expected fail, 2 skippednpx 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 passedCloses #866