Files
PaperClipAI/ui/src/components/ExecutionBlockerNotice.test.tsx
T
DottaandClaude a14ae9b5c9 fix(workspaces): name a failed workspace setup command on the task page (#20478)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Before an agent starts, Paperclip prepares the task workspace and
runs the project's configured setup commands (for example the workspace
provision command)
> - When that command fails, the run fails as `setup_failed`, and the
task stops with a Retry
> - The task page shows only "Failed" and a generic recovery notice. The
real error (the command, its exit status and output) is visible only on
the run page
> - The user cannot see from the task which setting is broken or what to
change
> - This pull request records a bounded, named cause for a failed setup
command and shows it on the task page
> - The benefit is that the task names the broken setting and what to
change, and classification, retry and recovery stay the same

## Linked Issues or Issue Description

**What happened?**
The restart-chaos config fault wave CF1 sets a project
`workspaceStrategy.provisionCommand` to `bash
./scripts/provision-worktree.sh`, a script that does not exist. The run
fails as `setup_failed` with `Execution workspace provision command
"bash ./scripts/provision-worktree.sh" failed: bash:
./scripts/provision-worktree.sh: No such file or directory`. The task
page shows "Failed" and "Paperclip automatically retried continuation …
still has no live execution path". The grader fails the task as
`CF1/provision_command:message_only_in_run_detail`.

**Expected behavior**
The task page names the failed setup step, the configured command, its
exit status and a short tail of its output, and says what to change.
Retry behavior stays the same.

**Steps to reproduce**
`node cli/node_modules/tsx/dist/cli.mjs
tests/restart-chaos/config-wave.ts --faults CF1 --adapters codex --tasks
2 --concurrency 2 --restarts K1,K2 --seed 204` on `master`.

**Paperclip version or commit**
`master` at 5ab98b0 (wave `w-20261110T043929-s204-cf`, tasks t01 and
t03).

## What Changed

- `WorkspaceCommandExitError` now carries the setup step
(`workspace_provision`, `workspace_seed`,
`workspace_runtime_provision`), the configured command and the command
output.
- New `server/src/services/workspace-setup-command-failure.ts`: it
builds a bounded, redacted `setupCommandFailure` record (step, command
up to 200 characters, exit code, last 300 characters of output). It also
recognizes the older message format, so runs recorded before this change
still get a name.
- `run-completion.ts` adds `setupCommandFailure` to the setup failure
`resultJson`. The error code (`setup_failed`) and all retry and recovery
fields stay the same.
- `TaskInterruptionPresentation.setupFailure` (shared type) is set for
`setup_failed` runs. It goes through the same per-run secret redaction
and user-name redaction as `workspaceFailure`.
- `ExecutionBlockerNotice` shows "Couldn’t set up the task workspace.
<command> failed with exit code N: <output>. Fix the command in the
project’s workspace settings, then retry." A scheduled transient retry
keeps its countdown and only adds the name.
- The restart-chaos config wave reads `interruption.setupFailure` as a
task-level text for its actionable-message check.

## Verification

- Red before, green after (the tests fail with the source changes
reverted):
- `server/src/__tests__/workspace-runtime.test.ts` — "names a failed
project provision command with its exit status and output (CF1)" runs a
real git worktree with a missing provision script (exit 127).
- `server/src/services/task-interruption-presentation.test.ts` — "setup
command failure presentation (CF1)": names the command, keeps
`state`/`canRetry`/`userAction` identical, recognizes the older message,
keeps a scheduled retry, bounds output and strips credentials from the
command.
- `ui/src/components/ExecutionBlockerNotice.test.tsx` and
`tests/restart-chaos/config-faults.test.ts` cover the notice text and
the harness check.
- `pnpm --filter @paperclipai/shared typecheck`, `pnpm --filter
@paperclipai/server typecheck`, `pnpm --filter @paperclipai/ui
typecheck` pass.
- Live proof: config wave `w-20261110T083227-s204-cf` (CF1, codex, 2
tasks, K1 and K2, seed 204) on commit ae9a4b7: **2/2 pass**. Both tasks
show `The project's workspace provision command "bash
./scripts/provision-worktree.sh" failed with exit code 127: bash:
./scripts/provision-worktree.sh: No such file or directory` on the task,
rest again after the restart, and finish after the repair and Retry. On
`master` the same wave failed both tasks as `message_only_in_run_detail`
(`w-20261110T043929-s204-cf`).

## Risks

- Low risk. The change adds a presentation field. It does not change the
error code, retry, recovery or blocking behavior.
- The command and output are user-configured text. They are bounded,
passed through `redactSensitiveText`, the run's secret registry and
user-name redaction. If redaction fails, the field is omitted, like
`workspaceFailure`.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, used through Claude
Code with tool use (shell, file edits, test runs).

## 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
- [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
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [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 <noreply@anthropic.com>
2026-11-10 02:35:18 -06:00

197 lines
14 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);
// A stable handle for the task's own Retry, the supported path after
// automatic recovery stops.
expect(container.querySelector('[data-testid="task-execution-retry"]')?.textContent).toBe("Retry");
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("keeps the failure visible and names the gate while a saved Retry waits on the budget", async () => {
await render({ ...failed, responsibility: "user", state: "waiting_for_user", userAction: "budget", canRetry: false });
const notice = container.querySelector('[data-testid="task-execution-waiting"]');
expect(notice?.textContent).toContain("Couldn’t finish this attempt. Your message is saved.");
expect(notice?.textContent).toContain("waiting for the budget to allow new work");
// The saved Retry starts by itself; a second Retry would only duplicate it.
expect(container.querySelector("button")).toBeNull();
});
it("does not report a failed attempt for a task the budget held before its first run", async () => {
await render({ ...failed, responsibility: "user", state: "waiting_for_user", userAction: "budget", canRetry: false,
sourceRunIds: [], observedRunId: null });
const notice = container.querySelector('[data-testid="task-execution-waiting"]');
expect(notice?.textContent).toContain("This task has not started.");
expect(notice?.textContent).not.toContain("Couldn’t finish this attempt");
});
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("names a failed workspace setup command and what to change, keeping Retry", async () => {
const setupFailure = { step: "workspace_provision" as const, command: "bash ./scripts/provision-worktree.sh", exitCode: 127,
output: "bash: ./scripts/provision-worktree.sh: No such file or directory",
message: "The project's workspace provision command \"bash ./scripts/provision-worktree.sh\" failed with exit code 127: bash: ./scripts/provision-worktree.sh: No such file or directory" };
await render({ ...failed, setupFailure });
expect(container.textContent).toContain("Couldn’t set up the task workspace.");
expect(container.textContent).toContain(setupFailure.message);
expect(container.textContent).toContain("Fix the command in the project’s workspace settings");
expect(container.textContent).not.toContain("Couldn’t finish this attempt.");
await act(async () => container.querySelector<HTMLButtonElement>("button")!.click());
expect(retry).toHaveBeenCalledOnce();
});
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("names the budget wait alongside a provider failure while a saved Retry is held", async () => {
const providerFailure = { schema: "paperclip.provider-failure.v1" as const, provider: "openai", phase: "startup" as const,
category: "overloaded" as const, retryability: "transient" as const, message: "Provider overloaded" };
await render({ ...failed, providerFailure, responsibility: "user", state: "waiting_for_user", userAction: "budget", canRetry: false });
expect(container.textContent).toContain("Provider overloaded");
expect(container.querySelector('[data-testid="task-execution-waiting"]')?.textContent).toContain("waiting for the budget to allow new work");
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("");
});
});