Skip to content

fix: freeze elapsed timer for completed entries + 3s retention (v0.2.3)#1

Merged
psh4607 merged 1 commit intomainfrom
fix/completed-timer-and-retention
May 8, 2026
Merged

fix: freeze elapsed timer for completed entries + 3s retention (v0.2.3)#1
psh4607 merged 1 commit intomainfrom
fix/completed-timer-and-retention

Conversation

@psh4607
Copy link
Copy Markdown
Owner

@psh4607 psh4607 commented May 8, 2026

Summary

  • Bug: "Done" entries displayed an ever-climbing elapsed time, looking like they were still running (e.g. `librarian Done 84m 2s` → `84m 3s` → `84m 4s` …).
  • Fix: `completeEntry` now stamps `completedAt` only on the first terminal transition.
  • Tweak: `COMPLETION_RETENTION_MS` 10s → 3s so completed rows fade faster.
  • Bumped to v0.2.3.

Root cause

`completeEntry` unconditionally wrote `entry.completedAt = completedAt` on every call. That was fine in isolation, but the surrounding code re-invokes it once per second:

  1. `tickTimer` calls `setNow(current)` every 1s while any agent is live.
  2. The reactive `insert` callback re-runs (it depends on `now()` and `version()`) and calls `scanSessionState(sessionID)`.
  3. `scanSessionState` walks every message part again. The `[ALL BACKGROUND TASKS COMPLETE …]` system reminder text is permanent in the message history, so its regex matches on every scan.
  4. `completeEntry` is invoked again with `completedAt = Date.now()`, overwriting the original timestamp.

`renderAgentLine` computes `entry.completedAt - entry.startedAt`, so as `completedAt` advanced 1s per tick, the displayed elapsed time advanced 1s per tick. The entry was "Done" (gray) but visually behaved like it was still running.

It also caused unnecessary `bumpVersion` calls (since `completedAt` mismatch was reported as mutated), inflating render churn.

Change

```ts
const completeEntry = (entry: AgentEntry, status: AgentStatus, completedAt: number): boolean => {
const nextStatus = status === "error" ? "error" : "completed";
const statusChanged = entry.status !== nextStatus;
// Stamp completedAt only on the first transition to a terminal state.
// Re-stamping (e.g. when scanSessionState re-matches the same
// [ALL BACKGROUND TASKS COMPLETE] system reminder on every 1s tick) would
// make the elapsed timer keep climbing past completion, so a "Done" entry
// visually behaves like it's still running.
const stampChanged = entry.completedAt === undefined;
if (stampChanged) entry.completedAt = completedAt;
if (statusChanged) entry.status = nextStatus;
return statusChanged || stampChanged;
};
```

Status can still flip (e.g. `completed` → `error`) but the original completion timestamp is preserved.

Verification

  • `bun run typecheck` ✅
  • `bun run build` ✅ (dist/ regenerated)
  • LSP diagnostics clean on `src/tui.ts`
  • Manual: needs install + TUI restart to confirm visually; the call paths impacted are `upsertMainMessage`, `upsertToolPart`, and `handleBackgroundStatusText`. The first two only re-invoke `completeEntry` when their respective time fields change (idempotent), so this fix is targeted at the `handleBackgroundStatusText` re-match path that causes the visible bug.

Files changed

  • `src/tui.ts` — fix + retention constant + version bump
  • `package.json` — version 0.2.2 → 0.2.3
  • `dist/tui.js`, `dist/tui.js.map`, `dist/tui.d.ts.map` — regenerated build output (committed per repo convention so `github:` installs are zero-config)

…o 3s (v0.2.3)

completeEntry stamped completedAt on every call. Combined with
scanSessionState re-running on every 1s tick (since now() is reactive)
and re-matching the persistent [ALL BACKGROUND TASKS COMPLETE] system
reminder text, the stamp advanced by 1s per tick. Result: a 'Done' entry
displayed an ever-growing elapsed time, looking like it was still
running.

Stamp completedAt only on the first transition to a terminal state.
Status can still flip (e.g. completed -> error) but the timestamp is
preserved.

Also drop COMPLETION_RETENTION_MS from 10s to 3s so completed entries
fade faster, per user feedback.
Copilot AI review requested due to automatic review settings May 8, 2026 04:46
@psh4607 psh4607 merged commit 5a35e15 into main May 8, 2026
3 checks passed
@psh4607 psh4607 deleted the fix/completed-timer-and-retention branch May 8, 2026 04:46
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a UI bug in the TUI sidebar where completed (“Done”) agent entries kept showing an increasing elapsed time due to repeated rescans re-stamping completedAt, and shortens the post-completion retention window.

Changes:

  • Make completeEntry stamp completedAt only on the first transition into a terminal state, preventing elapsed time from continuing to climb after completion.
  • Reduce completed-entry retention from 10s to 3s so completed rows disappear sooner.
  • Bump plugin/package version to 0.2.3 and regenerate distribution artifacts.

Reviewed changes

Copilot reviewed 2 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/tui.ts Freezes completedAt on first terminal transition; reduces completion retention; bumps plugin version constant.
package.json Bumps package version to 0.2.3.
dist/tui.js Regenerated build output reflecting the completeEntry and constants changes.
dist/tui.js.map Updated sourcemap from regenerated build.
dist/tui.d.ts.map Updated type-definition sourcemap from regenerated build.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants