Files
PaperClipAI/ui/src/components/ExecutionBlockerNotice.test.tsx
T
DottaandClaude Opus 5.5 4420a5adcf fix(issues): a Retry held by a blocked subtask names it instead of failing silently (#20109)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The board's Retry is the one action a person takes when a task
stops; it must either start work or say why it can't yet
> - Restart chaos t05 left a parent task blocked on a blocked subtask.
The board clicked Retry twice; each was accepted and nothing happened
> - The Retry was saved and the queue deferred it behind the unresolved
blocker, which is correct. But the task still looked failed with Retry
offered, so the wait was invisible
> - This pull request presents a saved Retry that waits only on
unfinished blockers as waiting, names the blocked subtask and links it
> - The benefit is that the board sees what to act on (the subtask's own
Retry) instead of clicking a Retry that cannot run

## Linked Issues or Issue Description

Refs #19831 (durable ownership plan). Restart chaos wave
`w-20261108T200620-s9701`, task t05 (claude, M1, K4).

**Problem:** parent CHA-5 was blocked by subtask CHA-10, which was
itself blocked on a board recovery action. The board pressed Retry on
CHA-5 at 20:27:46 and 20:40:46. Each `POST /issues/:id/retry` returned
202, and the saved Retry stayed `deferred_issue_execution` behind
CHA-10, so no run started. The task's interruption presentation kept
saying `failed` with `canRetry: true` and gave no reason.

## What Changed

- `server/src/services/task-interruption-presentation.ts`:
- For tasks with a saved (deferred, user-requested) Retry, the loader
reads the queue's own dependency readiness (`listDependencyReadiness`).
That counts cancelled blockers and done blockers whose workspace has not
finalized, like the queue does.
- When the saved Retry for the latest run is held only by unfinished
blockers (no execution wait, no preparation), the task is presented as
`working` with `canRetry: false` and `retryWait: { reason:
"dependency_blocked", message }`.
  - The message has three forms:
    - a blocked blocker: "Retry or unblock it";
- a cancelled blocker: "Remove or replace that dependency to continue",
because the queue keeps it unresolved;
    - otherwise: waiting for the blockers to finish.
- The presentation carries no blocker names or ids. Issue reads return
it to restricted agents too.
- The Retry response (`POST /issues/:id/retry`) already returns this
presentation, so the API says the Retry is waiting on dependencies as
soon as it is saved. The blockers themselves are in the issue's
`blockedBy`, which issue reads already filter per viewer.
- `ui/src/components/ExecutionBlockerNotice.tsx` takes `blockers` (the
issue's `blockedBy`, from `IssueDetail`). For a `dependency_blocked`
wait it lists each readable unfinished blocker with a link and what it
needs: "Blocked: open it to Retry" or "Cancelled: remove or replace it".
Tokens only; `pnpm check:token-gates` is clean.
- No shared type change, and no code comments added.

## Verification

Red/green:
- `server/src/__tests__/task-interruption-query.test.ts` "explains a
saved Retry held by unfinished blockers instead of offering Retry again
(restart chaos t05)". It sets up a parent with a failed run, a saved
Retry deferred, and a blocked subtask that blocks it.
  - On master: `{ state: "failed", canRetry: true }`, no reason.
- With this PR: `working`, `canRetry: false`, `dependency_blocked`. The
presentation has no blocker title or identifier.
- A cancelled blocker gets the remove-or-replace message. Once the
blocker is done, the dependency wait is gone.
- `ui/src/components/ExecutionBlockerNotice.test.tsx`: the notice links
the blocked and the cancelled blockers with their actions, skips the
done one, and offers no second Retry.

Regression: `task-interruption-query` (25 tests) and
`ExecutionBlockerNotice` (16 tests) pass, as do the presentation unit
tests, workspace-recovery admission, gates and copyback tests, and
`heartbeat-dependency-scheduling`. `tsc --noEmit` is clean for `server`
and `ui`.

## Risks

- One more batched read (dependency readiness plus blocker statuses),
only for tasks in the page that have a saved Retry.
- Presentation only. Admission is unchanged: the queue still runs the
saved Retry when the blockers are done.
- A Retry saved before a blocker was added shows the same wait, which is
accurate, because the queue holds it too.

## Model Used

Anthropic Claude Opus 5.5 (`claude-opus-5-5`), via Claude Code, with
tool use (shell, file editing).

## 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 (#20069)
- [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
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes (code
comments; no user docs affected)
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green (pending)
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
(pending)
- [x] I will address all Greptile and reviewer comments before
requesting merge

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 17:18:55 -06:00

157 lines
11 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// @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 { TaskInterruptionPresentation } from "@paperclipai/shared";
import type { AnchorHTMLAttributes } from "react";
import { ExecutionBlockerNotice } from "./ExecutionBlockerNotice";
vi.mock("@/lib/router", () => ({
Link: ({ children, to, ...props }: AnchorHTMLAttributes<HTMLAnchorElement> & { to: string }) => <a href={to} {...props}>{children}</a>,
}));
const failed: TaskInterruptionPresentation = {
intentId: "intent", responsibility: "system", state: "failed", nextRetryAt: null,
canRetry: true, userAction: null, sourceRunIds: ["source"], observedRunId: "source",
};
describe("ordinary task interruption", () => {
let root: Root;
let container: HTMLDivElement;
const retry = vi.fn();
beforeEach(() => {
retry.mockReset(); container = document.createElement("div"); document.body.append(container);
root = createRoot(container);
});
afterEach(async () => { await act(async () => root.unmount()); container.remove(); vi.useRealTimers(); });
const render = async (presentation = failed, options: { canRetry?: boolean; optimistic?: boolean; takingLonger?: boolean; error?: Error } = {}) => {
await act(async () => root.render(<ExecutionBlockerNotice presentation={presentation} canRetry onRetry={retry} {...options} />));
};
it("offers one Retry without delegating infrastructure chores", async () => {
await render();
expect(container.textContent).toContain("Couldn’t finish this attempt. Your message is saved.");
expect(container.querySelectorAll("button")).toHaveLength(1);
await act(async () => container.querySelector<HTMLButtonElement>("button")!.click());
expect(retry).toHaveBeenCalledOnce();
expect(container.querySelector("a, details, input, textarea")).toBeNull();
expect(container.textContent).not.toMatch(/service attention|process|receipt|workspace/i);
});
it("shows persisted backoff with a usable Retry", async () => {
vi.useFakeTimers(); vi.setSystemTime(new Date("2026-10-20T00:00:00Z"));
await render({ ...failed, state: "retry_scheduled", nextRetryAt: "2026-10-20T00:00:30Z" });
expect(container.textContent).toContain("Trying again in 30s");
await act(async () => { await vi.advanceTimersByTimeAsync(5_000); });
expect(container.textContent).toContain("Trying again in 25s");
expect(container.querySelector("button")?.textContent).toBe("Retry");
});
it.each(["working", "resolved"] as const)("does not duplicate the thread indicator for %s", async state => {
await render({ ...failed, state }); expect(container.textContent).toBe("");
});
it("names the admission hold a task that has not started waits for", async () => {
await render({ ...failed, state: "working", canRetry: false, sourceRunIds: [], observedRunId: null,
retryWait: { reason: "budget.blocked", message: "Waiting for the budget to allow new work. The task starts automatically when it does." } });
expect(container.textContent).toBe("Waiting for the budget to allow new work. The task starts automatically when it does.");
expect(container.querySelector("button")).toBeNull();
});
it("names and links the readable blockers a saved Retry waits on, with no second Retry (restart chaos t05)", async () => {
const message = "Retry is waiting on a blocked task this one depends on. Retry or unblock it; this task continues when it is done. Your Retry is saved.";
const summary = (id: string, identifier: string, title: string, status: string) =>
({ id, identifier, title, status, priority: "medium", assigneeAgentId: null, assigneeUserId: null }) as never;
await act(async () => root.render(<ExecutionBlockerNotice presentation={{ ...failed, state: "working", canRetry: false,
retryWait: { reason: "dependency_blocked", message } }} canRetry onRetry={retry}
blockers={[summary("child", "CHA-10", "Part 2", "blocked"), summary("gone", "CHA-11", "Part 3", "cancelled"),
summary("done", "CHA-9", "Part 1", "done")]} />));
expect(container.textContent).toContain(message);
const links = [...container.querySelectorAll<HTMLAnchorElement>("[data-testid='retry-waiting-on'] a")].map(link => link.getAttribute("href"));
expect(links).toHaveLength(2);
expect(links[0]).toContain("CHA-10");
expect(container.textContent).toContain("Blocked: open it to Retry");
expect(container.textContent).toContain("Cancelled: remove or replace it");
expect(container.textContent).not.toContain("Part 1");
expect(container.querySelector("button")).toBeNull();
});
it("shows a locked blocker without reading its status, and a finished blocker still saving files", async () => {
const message = "Retry is waiting for a finished task this one depends on to save its files. Your Retry is saved.";
await act(async () => root.render(<ExecutionBlockerNotice presentation={{ ...failed, state: "working", canRetry: false,
retryWait: { reason: "dependency_blocked", message } }} canRetry onRetry={retry}
blockers={[{ id: "secret", identifier: "CHA-12", locked: true } as never]} />));
expect(container.querySelector("[data-testid='locked-issue-chip']")?.textContent).toContain("CHA-12");
await act(async () => root.render(<ExecutionBlockerNotice presentation={{ ...failed, state: "working", canRetry: false,
retryWait: { reason: "dependency_blocked", message } }} canRetry onRetry={retry}
blockers={[{ id: "done", identifier: "CHA-9", title: "Part 1", status: "done", priority: "medium",
assigneeAgentId: null, assigneeUserId: null } as never]} />));
expect(container.querySelector("[data-testid='retry-waiting-on'] a")?.getAttribute("href")).toContain("CHA-9");
expect(container.textContent).toContain("Saving its files");
});
it("names the saved-work recovery step instead of a bare queue", async () => {
await render({ ...failed, state: "working", canRetry: false, recoveryStep: "saving_previous_files" });
expect(container.textContent).toBe("Saving files from the previous attempt…");
expect(container.querySelector("button")).toBeNull();
});
it("names the step a scheduled recovery will retry", async () => {
vi.useFakeTimers(); vi.setSystemTime(new Date("2026-10-20T00:00:00Z"));
await render({ ...failed, state: "retry_scheduled", nextRetryAt: "2026-10-20T00:00:30Z", recoveryStep: "checking_previous_run" });
expect(container.textContent).toContain("Checking that the previous attempt stopped. Trying again in 30s…");
expect(container.querySelector("button")?.textContent).toBe("Retry");
});
it("names the recovery step inside a provider failure notice", async () => {
vi.useFakeTimers(); vi.setSystemTime(new Date("2026-10-20T00:00:00Z"));
await render({ ...failed, state: "retry_scheduled", nextRetryAt: "2026-10-20T00:00:30Z", recoveryStep: "checking_previous_run",
providerFailure: { schema: "paperclip.provider-failure.v1", provider: "openai", phase: "startup", category: "overloaded",
retryability: "unknown", message: "Try later." } });
expect(container.textContent).toContain("Checking that the previous attempt stopped. Trying again in 30s…");
expect(container.textContent).not.toContain("Paperclip will retry automatically.");
});
it("leaves genuine user decisions to their specific action surface", async () => {
await render({ ...failed, responsibility: "user", state: "waiting_for_user", userAction: "approval", canRetry: false });
expect(container.textContent).toBe("");
});
it("does not give read-only users a mutation", async () => {
await render(failed, { canRetry: false }); expect(container.querySelector("button")).toBeNull();
});
it("removes the stale failure immediately while admission is pending", async () => {
await render(failed, { optimistic: true }); expect(container.textContent).toBe("");
await render(failed, { optimistic: true, takingLonger: true });
expect(container.textContent).toContain("Taking longer than usual…");
});
it("shows a definitive admission rejection instead of silently dropping Retry", async () => {
await render(failed, { error: new Error("Your task access changed. Refresh the task.") });
expect(container.querySelector('[role="alert"]')?.textContent).toContain("Your task access changed.");
expect(container.querySelectorAll("button")).toHaveLength(1);
});
it("shows workspace preparation failures as plain text while keeping retry permissions", async () => {
const workspaceFailure = { message: 'Could not prepare the project folder <img src=x onerror=alert(1)>.' };
await render({ ...failed, workspaceFailure }, { canRetry: false });
expect(container.textContent).toContain("Couldn’t prepare the task folders.");
expect(container.textContent).toContain(workspaceFailure.message);
expect(container.querySelector("img, button")).toBeNull();
await render({ ...failed, workspaceFailure });
await act(async () => container.querySelector<HTMLButtonElement>("button")!.click());
expect(retry).toHaveBeenCalledOnce();
await render({ ...failed, workspaceFailure, state: "working" });
expect(container.textContent).toBe("");
});
it("shows why an accepted Retry is waiting and keeps another attempt available", async () => {
const retryWait = { reason: "remote_cleanup", message: "Retry is waiting for the previous environment to stop. Your message is saved." };
await render({ ...failed, retryWait });
expect(container.textContent).toContain(retryWait.message);
expect(container.textContent).not.toContain("Couldn’t finish this attempt.");
await act(async () => container.querySelector<HTMLButtonElement>("button")!.click());
expect(retry).toHaveBeenCalledOnce();
await render({ ...failed, retryWait }, { canRetry: false });
expect(container.textContent).toContain(retryWait.message);
expect(container.querySelector("button")).toBeNull();
});
it("shows an unknown provider's original explanation as text and preserves read-only access", async () => {
const providerFailure = { schema: "paperclip.provider-failure.v1" as const, provider: "new-provider", phase: "startup" as const,
category: "unknown" as const, retryability: "unknown" as const, httpStatus: 429,
message: "Upstream failure <img src=x onerror=alert(1)>" };
await render({ ...failed, providerFailure }, { canRetry: false });
expect(container.textContent).toContain(providerFailure.message);
expect(container.textContent).toContain("Failed before work started");
expect(container.textContent).toContain("HTTP 429");
expect(container.querySelector("img, button")).toBeNull();
await render({ ...failed, providerFailure, state: "resolved" });
expect(container.textContent).toBe("");
});
});