Files
PaperClipAI/ui/src/lib/issueActiveRun.test.ts
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

79 lines
3.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { Issue } from "@paperclipai/shared";
import type { ActiveRunForIssue, LiveRunForIssue } from "../api/heartbeats";
import { resolveIssueActiveRun, shouldTrackIssueActiveRun } from "./issueActiveRun";
describe("issueActiveRun", () => {
const makeIssue = (
overrides: Partial<Pick<Issue, "status" | "executionRunId">>,
): Pick<Issue, "status" | "executionRunId"> => ({
status: "todo",
executionRunId: null,
...overrides,
});
it("refreshes the selected run from the polled list after startup confirmation", () => {
const issue = makeIssue({ status: "in_progress", executionRunId: "run-1" });
const initialRun = {
id: "run-1",
status: "running",
execution: { phase: "reconnecting", label: "Confirming execution" },
} as ActiveRunForIssue;
const refreshedRun = {
...initialRun,
execution: { phase: "working", label: "Working" },
currentToolName: "Read file",
} as LiveRunForIssue;
const otherRun = { ...refreshedRun, id: "run-2" };
expect(resolveIssueActiveRun(issue, initialRun)).toBe(initialRun);
expect(resolveIssueActiveRun(issue, initialRun, [otherRun, refreshedRun])).toBe(refreshedRun);
expect(resolveIssueActiveRun(issue, initialRun, [otherRun])).toBe(initialRun);
expect(resolveIssueActiveRun(issue, null, [refreshedRun])).toBe(refreshedRun);
expect(resolveIssueActiveRun(makeIssue({ status: "done" }), initialRun, [refreshedRun])).toBeNull();
});
it("selects the task's replacement run instead of the cached predecessor", () => {
const issue = makeIssue({ status: "in_progress", executionRunId: "run-new" });
const oldRun = { id: "run-old", status: "running" } as LiveRunForIssue;
const newRun = { id: "run-new", status: "running" } as LiveRunForIssue;
expect(resolveIssueActiveRun(issue, oldRun, [oldRun, newRun])).toBe(newRun);
expect(resolveIssueActiveRun(issue, oldRun, [oldRun])).toBeNull();
expect(resolveIssueActiveRun(issue, oldRun)).toBeNull();
expect(resolveIssueActiveRun(issue, null, [newRun])).toBe(newRun);
expect(resolveIssueActiveRun(makeIssue({ status: "in_progress" }), oldRun, [oldRun, newRun])).toBe(oldRun);
});
it("tracks active runs while an issue is still in progress", () => {
expect(shouldTrackIssueActiveRun(makeIssue({ status: "in_progress" }))).toBe(true);
});
it("tracks active runs while an execution run id is still attached", () => {
expect(shouldTrackIssueActiveRun(makeIssue({ status: "done", executionRunId: "run-123" }))).toBe(true);
});
it("drops stale cached active runs once the issue is closed and unlocked", () => {
const staleActiveRun: ActiveRunForIssue = {
id: "run-123",
status: "running",
invocationSource: "assignment",
triggerDetail: "system",
startedAt: "2026-04-13T01:29:00.000Z",
finishedAt: null,
createdAt: "2026-04-13T01:29:00.000Z",
agentId: "agent-1",
agentName: "Builder",
adapterType: "codex_local",
issueId: "issue-1",
};
expect(
resolveIssueActiveRun(
makeIssue({ status: "done" }),
staleActiveRun,
),
).toBeNull();
});
});