Files
PaperClipAI/ui/src/components/task-chat/TaskChatLiveRunPill.test.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

124 lines
4.7 KiB
TypeScript

// @vitest-environment jsdom
import { act } from "react";
import { createRoot, type Root } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { ExecutionProjection } from "@paperclipai/shared";
import type { TranscriptEntry } from "../../adapters";
import { TaskChatLiveRunPill, toolCountSummaryFromEntries } from "./TaskChatLiveRunPill";
function toolCall(overrides: Partial<Extract<TranscriptEntry, { kind: "tool_call" }>>): TranscriptEntry {
return { kind: "tool_call", ts: "2026-08-08T00:00:00.000Z", name: "read_file", input: {}, ...overrides };
}
describe("toolCountSummaryFromEntries", () => {
it("returns null when there are no tool calls", () => {
expect(toolCountSummaryFromEntries([])).toBeNull();
expect(
toolCountSummaryFromEntries([{ kind: "assistant", ts: "t", text: "hi" } as TranscriptEntry]),
).toBeNull();
});
it("counts commands and other tools separately with pluralization", () => {
const entries: TranscriptEntry[] = [
toolCall({ name: "bash", input: { command: "ls" }, toolUseId: "c1" }),
toolCall({ name: "command_execution", input: { command: "pwd" }, toolUseId: "c2" }),
toolCall({ name: "read_file", input: { path: "a.ts" }, toolUseId: "t1" }),
];
expect(toolCountSummaryFromEntries(entries)).toBe("ran 2 commands, called 1 tool");
});
it("dedupes re-emitted tool_calls that share a toolUseId", () => {
const entries: TranscriptEntry[] = [
toolCall({ name: "read_file", input: {}, toolUseId: "t1" }),
toolCall({ name: "read_file", input: { path: "a.ts" }, toolUseId: "t1" }),
toolCall({ name: "read_file", input: { path: "a.ts" }, toolUseId: "t1" }),
];
expect(toolCountSummaryFromEntries(entries)).toBe("called 1 tool");
});
});
describe("TaskChatLiveRunPill", () => {
let container: HTMLDivElement;
let root: Root;
beforeEach(() => {
container = document.createElement("div");
document.body.appendChild(container);
root = createRoot(container);
});
afterEach(() => {
act(() => root.unmount());
container.remove();
vi.useRealTimers();
});
it("shimmers 'Working' with elapsed + tool summary while streaming", () => {
const startedAtMs = Date.now() - 65_000; // ~1 minute ago
act(() => {
root.render(
<TaskChatLiveRunPill
status="running"
startedAtMs={startedAtMs}
toolSummary="called 3 tools"
/>,
);
});
const pill = container.querySelector('[data-testid="task-chat-live-run-pill"]');
expect(pill).not.toBeNull();
const shimmer = container.querySelector(".shimmer-text");
expect(shimmer?.textContent).toBe("Working");
expect(pill?.textContent).toContain("for 1 minute");
expect(pill?.textContent).toContain("called 3 tools");
});
it.each(["reconnecting", "retry_scheduled"] as const)(
"keeps Working animated and the timer advancing with a %s projection",
(phase) => {
vi.useFakeTimers();
vi.setSystemTime(new Date("2026-09-11T12:00:00Z"));
const startedAtMs = Date.now() - 6_000;
const execution = { phase } as ExecutionProjection;
const render = (status: string) => act(() => root.render(
<TaskChatLiveRunPill status={status} execution={execution}
startedAtMs={startedAtMs} finishedAtMs={startedAtMs + 8_000}
toolSummary="called 2 tools" />,
));
render("running");
expect(container.querySelector(".shimmer-text")?.textContent).toBe("Working");
expect(container.querySelector(".animate-spin")).not.toBeNull();
expect(container.textContent).toContain("for 6 seconds");
expect(container.textContent).toContain("called 2 tools");
act(() => vi.advanceTimersByTime(2_000));
expect(container.textContent).toContain("for 8 seconds");
render("succeeded");
expect(container.textContent).toContain("Worked");
expect(container.querySelector(".animate-spin")).toBeNull();
render("failed");
expect(container.textContent).toContain("Stopped");
expect(container.textContent).not.toContain("Reconnecting");
},
);
it("settles to a static 'Worked' summary once the run is terminal", () => {
const startedAtMs = 1_000;
act(() => {
root.render(
<TaskChatLiveRunPill
status="succeeded"
startedAtMs={startedAtMs}
finishedAtMs={startedAtMs + 42_000}
toolSummary="ran 1 command"
/>,
);
});
const pill = container.querySelector('[data-testid="task-chat-live-run-pill"]');
expect(container.querySelector(".shimmer-text")).toBeNull();
expect(pill?.textContent).toContain("Worked");
expect(pill?.textContent).toContain("for 42 seconds");
expect(pill?.textContent).toContain("ran 1 command");
});
});