Files
PaperClipAI/ui/src/components/task-chat/TaskChatLiveRunPill.tsx
T
DottaandPaperclip 1d26ae965e fix(ui): keep active runner status current and say Working (#13238)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - The task transcript shows a running agent's progress.
> - The active-run query stops polling when the live-run list has data.
> - The transcript still preferred that initial snapshot, so an old
execution-confirmation state could remain after work resumed.
> - This pull request uses the refreshed snapshot for the same run and
keeps active status text at Working.
> - Operators can see current activity without connection-state jargon.

## Linked Issues or Issue Description

**What happened?**

The task transcript said Reconnecting while the runner continued sending
messages and calling tools. The stale projection could also hide the
Thinking tail or stop the status spinner and timer.

**Expected behavior**

The selected run uses its current live snapshot. Active transcripts say
Working and show current activity. Completed and failed runs say Worked
and Stopped.

**Steps to reproduce**

1. Open a running task before its execution confirmation arrives.
2. Let the active-run query stop polling when the live-run list returns
the run.
3. Let the list refresh to working while the cached active-run snapshot
still says reconnecting.
4. Inspect the transcript status and activity tail.

**Paperclip version or commit**

Base commit: 52811c6ce.

**Deployment mode**

Built from source. The report concerns the new runner. The fix also
covers legacy transcript status text.

Searched open issues and open/closed pull requests for runner
reconnection work. No duplicate fix found.

## What Changed

- Refresh the selected active run from the polled list by matching the
task execution-run ID. Reject cached predecessors after run replacement.
- Use Working in native and legacy transcripts and active agent cards.
- Keep the active spinner, timer, and Thinking tail independent of
diagnostic execution phases. Terminal status takes precedence.
- Add stale-snapshot, timer, and terminal-state regressions. Update the
recovery story and documentation.

## Verification

- Focused Vitest suite: 148 tests passed across the run resolver, live
pill, runner turn, and task thread.
- `pnpm check:token-gates`: passed.
- `pnpm -r typecheck`: passed.
- Browser: inspected the recovery Storybook with a reconnecting
projection. It renders Working and Thinking.
- `pnpm build`: passed.
- `pnpm build-storybook`: passed.
- Full local `pnpm test:run` reported failures in unchanged server
tests; stopped the remaining general-server run after the equivalent CI
shards passed. The file-resource suite passes on rerun (35/35). Building
`build:runner-binaries` fixed a missing fake-provider binary; the
native-session-resume suite still has one continuity-reason assertion
mismatch (36/37 pass).
- Ran the remaining local test groups separately: both workspace groups
passed. All serialized suites passed except `pipelines-routes.test.ts`,
which still reports a socket hang-up on rerun (18/19 pass). The initial
access-route timeout passed on rerun. No server or runner source files
differ from the base.
- CI: all test shards, browser E2E, typecheck, runner verification, and
build passed on `22069462f30bdfcfb58f295da901a71ae5a47776`; the
aggregate verification gate passed (31 checks passed, 2 optional
Storybook checks skipped). Greptile is 5/5 with all review threads
resolved.

## Risks

- Low risk. This changes UI snapshot selection and presentation. It does
not change server recovery, leases, retry authority, or permissions.
- The live snapshot must match the task execution-run ID. Missing
matches use the cached active run only when its ID also matches.

## Model Used

OpenAI GPT-6 (Codex). The exact deployment identifier and context-window
size are not exposed in this session. Used reasoning, repository
inspection, code execution, and browser verification.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass (focused/UI and workspace
tests; full-suite limitations documented above)
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-09-11 11:34:45 -05:00

94 lines
3.9 KiB
TypeScript

import type { ExecutionProjection } from "@paperclipai/shared";
import { Loader2 } from "lucide-react";
import type { TranscriptEntry } from "../../adapters";
import { cn } from "@/lib/utils";
import { useSecondTick } from "@/hooks/useSecondTick";
import { formatDurationWords } from "@/lib/issue-chat-messages";
import { isCommandTool } from "@/lib/transcriptPresentation";
import { isTerminalRunStatus } from "@/components/task-chat/transcript-adapter";
/**
* "ran N commands, called M tools" for the live tail's status pill, counted off
* the streamed transcript entries. Mirrors IssueChatThread's `toolCountSummary`
* (which counts a settled message's tool-call parts) so the experimental live
* tail reads the same as the default view. Streaming runtimes re-emit a
* tool_call as its status progresses, so calls carrying a `toolUseId` are
* counted once.
*/
export function toolCountSummaryFromEntries(entries: readonly TranscriptEntry[]): string | null {
const seen = new Set<string>();
let commands = 0;
let other = 0;
for (const entry of entries) {
if (entry.kind !== "tool_call") continue;
if (entry.toolUseId) {
if (seen.has(entry.toolUseId)) continue;
seen.add(entry.toolUseId);
}
if (isCommandTool(entry.name, entry.input)) commands += 1;
else other += 1;
}
const parts: string[] = [];
if (commands > 0) parts.push(`ran ${commands} command${commands === 1 ? "" : "s"}`);
if (other > 0) parts.push(`called ${other} tool${other === 1 ? "" : "s"}`);
return parts.length > 0 ? parts.join(", ") : null;
}
/**
* Status pill for the experimental chat-style view's live tail (PAP-461, A1).
*
* Byte-for-byte the same affordance the default view shows above a run's chain
* of thought (IssueChatThread's CoT header): a spinner + shimmering "Working"
* verb + elapsed words + "· called N tools" while the run streams, settling to
* a static emerald dot + "Worked" summary once it terminates. The verb shimmers
* via `.shimmer-text` (reduced-motion aware) exactly as the default view does.
*/
export function TaskChatLiveRunPill({
status,
startedAtMs,
finishedAtMs,
toolSummary,
}: {
status: string;
execution?: ExecutionProjection | null;
/** Run start (startedAt, falling back to createdAt) in ms, or null if unknown. */
startedAtMs: number | null;
/** Run finish in ms once terminal; drives the settled elapsed readout. */
finishedAtMs?: number | null;
toolSummary: string | null;
}) {
const active = !isTerminalRunStatus(status);
// One shared page-wide ticker drives the live elapsed readout, matching the
// default view's `useLiveElapsed`.
useSecondTick(active && startedAtMs != null);
const elapsedMs =
startedAtMs == null ? null : (active ? Date.now() : finishedAtMs ?? Date.now()) - startedAtMs;
const elapsed = elapsedMs != null
? formatDurationWords(elapsedMs)
: null;
const failed = ["failed", "timed_out", "cancelled", "interrupted"].includes(status);
const verb = active ? "Working" : failed ? "Stopped" : "Worked";
const suffix = elapsed ? `for ${elapsed}` : null;
return (
<div
className="flex min-w-0 items-center gap-2.5 px-1 py-2"
data-testid="task-chat-live-run-pill"
>
<span className="inline-flex items-center gap-2 text-sm font-medium text-foreground/80">
{active ? (
<Loader2 className="h-4 w-4 shrink-0 animate-spin text-muted-foreground" />
) : (
<span className="flex h-4 w-4 shrink-0 items-center justify-center">
<span className={cn("h-1.5 w-1.5 rounded-full", (failed || active) ? "bg-muted-foreground/40" : "bg-emerald-500/70")} />
</span>
)}
{active ? <span className={cn("shimmer-text")}>{verb}</span> : verb}
</span>
{suffix ? <span className="text-xs text-muted-foreground/60">{suffix}</span> : null}
{toolSummary ? <span className="text-xs text-muted-foreground/40">· {toolSummary}</span> : null}
</div>
);
}