7428fb956f
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - The affected subsystem is the heartbeat execution path that turns issue assignment into adapter-backed work in a selected workspace. > - PAP-10409 and sibling follow-ups failed before useful adapter output because project/workspace identity became incoherent. > - A project-workspace-linked child issue could keep `projectWorkspaceId` / execution workspace state while losing `projectId`, then a git-sensitive local adapter could fall through toward an invalid fallback cwd. > - Paperclip needs to treat coherent workspace identity as part of the live-path contract, not only as post-failure cleanup. > - This pull request documents that rule, repairs issue inheritance, and blocks git-sensitive adapter launch before it can run from the wrong cwd. > - The benefit is a bounded recovery path: affected issues are repaired explicitly, future malformed workspaces fail fast with a clear recovery action, and the UI surfaces that reason. ## Linked Issues or Issue Description Refs #7646 Bug report fields: - Summary: adapter-backed follow-up issues can fail before doing work when issue creation/inheritance preserves workspace ids but drops project identity. - Affected issues: internal Paperclip issues PAP-10408 through PAP-10412, especially PAP-10409. - Steps to reproduce: create a project-scoped parent/follow-up tree where a child issue keeps `projectWorkspaceId` or an inherited execution workspace but has `projectId: null`, then launch a git-sensitive local adapter such as `codex_local`. - Expected behavior: Paperclip derives or preserves coherent project identity during issue creation, and heartbeat refuses malformed git-sensitive workspace launches with one clear recovery action. - Actual behavior before this PR: the run could reach adapter bootstrap with an incoherent workspace context and fail with git errors such as `fatal: not a git repository (or any parent up to mount point /srv)`. - Root cause: child/follow-up issue inheritance preserved workspace execution context without coherent project context. That let heartbeat workspace resolution/adapter launch reach a fallback cwd instead of refusing the malformed workspace state up front. ## What Changed - Documented the adapter workspace-coherence live-path precondition in `doc/execution-semantics.md`. - Updated issue creation/inheritance so workspace-inheriting issues preserve or derive project identity, while existing mismatch validation still rejects incoherent project/workspace combinations. - Added a heartbeat preflight guard for git-sensitive local adapters that validates effective cwd, persisted workspace identity, project workspace identity, and required git metadata before launch. - Added `workspace_validation` recovery actions for this failure class and ensured the source issue gets a visible, idempotent recovery comment. - Surfaced workspace-validation recovery state in issue rows, blocked notices, and recovery action cards, including the manual-repair wake policy label. - Added focused regression coverage for issue inheritance, all heartbeat workspace-validation guard branches, recovery display helpers, and UI recovery components. ## Verification - `pnpm exec vitest run server/src/__tests__/heartbeat-workspace-session.test.ts` - Result: 1 test file passed, 68 tests passed. - `pnpm exec vitest run ui/src/components/IssueRecoveryActionCard.test.tsx` - Result: 1 test file passed, 12 tests passed. - `pnpm exec vitest run ui/src/components/IssueBlockedNotice.test.tsx ui/src/components/IssueRecoveryActionCard.test.tsx` - Result: 2 test files passed, 18 tests passed. - `pnpm --filter @paperclipai/ui typecheck` - Result: passed. - `pnpm exec vitest run server/src/__tests__/heartbeat-plugin-environment.test.ts server/src/__tests__/issues-service.test.ts server/src/__tests__/heartbeat-workspace-session.test.ts server/src/__tests__/heartbeat-process-recovery.test.ts ui/src/components/IssueBlockedNotice.test.tsx ui/src/components/IssueRecoveryActionCard.test.tsx ui/src/lib/recovery-display.test.ts` - Result: 7 test files passed, 200 tests passed before the final guard-branch additions; the changed server file was re-run above. - UI coverage: `ui/storybook/stories/source-issue-recovery.stories.tsx` contains rendered scenarios for the generic recovery chip, workspace-validation recovery chip, blocked notice indicator, recovery action card, and issue-row chip. - Screenshot capture attempt: Storybook started successfully on `http://127.0.0.1:6016/`, but screenshots could not be captured in this runner because `agent-browser` launched an unusable Chrome binary and Playwright Chromium failed on missing system library `libatk-1.0.so.0`; the runner is non-root and lacks passwordless sudo for installing browser dependencies. - Hosted CI on final commit `969594e7` is green, including `verify`, `Build`, `Typecheck + Release Registry`, `General tests (server)`, workspace suites, serialized server suites, `Canary Dry Run`, and `e2e`. - Roadmap checked: no duplicate roadmap item; this is a tightly scoped reliability fix for existing heartbeat/workspace behavior. - Duplicate PR search checked: no open PR matched `workspace coherence adapter cwd`. ## Risks - Medium risk: heartbeat launch is stricter for git-sensitive local adapters and can now block malformed workspace states before adapter execution. - Mitigation: the guard is limited to local git-sensitive adapters and records a source-scoped recovery action with structured evidence instead of retrying indefinitely. - Compatibility: valid project/workspace execution paths continue normally; explicit project/workspace mismatches remain rejected. > 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 OpenAI Codex, GPT-5-based `codex_local` coding agent with terminal/tool use. Work was produced through Paperclip issue execution with focused local 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 run tests locally and they pass - [x] I have added or updated tests where applicable - [ ] If this change affects the UI, I have included before/after screenshots - [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>
428 lines
14 KiB
TypeScript
428 lines
14 KiB
TypeScript
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
import type { ReactNode } from "react";
|
|
import type { IssueRecoveryAction, IssueRelationIssueSummary } from "@paperclipai/shared";
|
|
import { Eye, ExternalLink, OctagonAlert, RefreshCw, TriangleAlert } from "lucide-react";
|
|
import { IssueRecoveryActionCard } from "@/components/IssueRecoveryActionCard";
|
|
import { IssueRow } from "@/components/IssueRow";
|
|
import { IssueBlockedNotice } from "@/components/IssueBlockedNotice";
|
|
import { storybookAgentMap, storybookAgents, createIssue } from "../fixtures/paperclipData";
|
|
|
|
const claudeAgent = storybookAgents.find((agent) => agent.name.toLowerCase().startsWith("claude")) ?? storybookAgents[0]!;
|
|
const codexAgent = storybookAgents.find((agent) => agent.name.toLowerCase().startsWith("codex")) ?? storybookAgents[0]!;
|
|
|
|
function StoryFrame({ title, description, children }: { title: string; description?: string; children: ReactNode }) {
|
|
return (
|
|
<main className="min-h-screen bg-background p-4 text-foreground sm:p-8">
|
|
<div className="mx-auto max-w-5xl space-y-5">
|
|
<header>
|
|
<div className="text-xs font-medium uppercase tracking-[0.2em] text-muted-foreground">
|
|
Source-issue recovery
|
|
</div>
|
|
<h1 className="mt-1 text-2xl font-semibold">{title}</h1>
|
|
{description ? (
|
|
<p className="mt-2 max-w-3xl text-sm text-muted-foreground">{description}</p>
|
|
) : null}
|
|
</header>
|
|
{children}
|
|
</div>
|
|
</main>
|
|
);
|
|
}
|
|
|
|
function buildAction(overrides: Partial<IssueRecoveryAction> = {}): IssueRecoveryAction {
|
|
return {
|
|
id: "00000000-0000-0000-0000-0000000000aa",
|
|
companyId: "company-storybook",
|
|
sourceIssueId: "00000000-0000-0000-0000-0000000000ff",
|
|
recoveryIssueId: null,
|
|
kind: "missing_disposition",
|
|
status: "active",
|
|
ownerType: "agent",
|
|
ownerAgentId: claudeAgent.id,
|
|
ownerUserId: null,
|
|
previousOwnerAgentId: codexAgent.id,
|
|
returnOwnerAgentId: codexAgent.id,
|
|
cause: "missing_disposition",
|
|
fingerprint: "fp",
|
|
evidence: {
|
|
summary: "Run finished without picking a disposition. The PR has tests passing on CI.",
|
|
sourceRunId: "7accd7a4-c9ca-4db2-9233-3228a037cc09",
|
|
correctiveRunId: "2606404d-3859-4142-ba37-3228a037cc09",
|
|
},
|
|
nextAction: "Choose and record a valid issue disposition without copying transcript content.",
|
|
wakePolicy: { type: "wake_owner" },
|
|
monitorPolicy: null,
|
|
attemptCount: 1,
|
|
maxAttempts: 3,
|
|
timeoutAt: null,
|
|
lastAttemptAt: "2026-04-20T11:55:00.000Z",
|
|
outcome: null,
|
|
resolutionNote: null,
|
|
resolvedAt: null,
|
|
createdAt: "2026-04-20T11:55:00.000Z",
|
|
updatedAt: "2026-04-20T11:55:00.000Z",
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function CardPanel({ caption, action, forcedState, canFalsePositive }: {
|
|
caption: string;
|
|
action: IssueRecoveryAction;
|
|
forcedState?: React.ComponentProps<typeof IssueRecoveryActionCard>["forcedState"];
|
|
canFalsePositive?: boolean;
|
|
}) {
|
|
return (
|
|
<section className="space-y-2">
|
|
<div className="text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground">
|
|
{caption}
|
|
</div>
|
|
<IssueRecoveryActionCard
|
|
action={action}
|
|
agentMap={storybookAgentMap}
|
|
forcedState={forcedState}
|
|
onResolve={() => {}}
|
|
canFalsePositive={canFalsePositive}
|
|
/>
|
|
</section>
|
|
);
|
|
}
|
|
|
|
function AllStatesPanel() {
|
|
return (
|
|
<div className="grid gap-5 lg:grid-cols-1">
|
|
<CardPanel caption="State 1 · Recovery needed (default)" action={buildAction()} canFalsePositive />
|
|
<CardPanel
|
|
caption="State 2 · Recovery in progress"
|
|
action={buildAction({ outcome: "delegated", attemptCount: 2 })}
|
|
forcedState="in_progress"
|
|
canFalsePositive
|
|
/>
|
|
<CardPanel
|
|
caption="State 3 · Observing active run (watchdog)"
|
|
action={buildAction({
|
|
kind: "active_run_watchdog",
|
|
wakePolicy: { type: "monitor", intervalLabel: "in 4m" },
|
|
evidence: { summary: "The active run has been silent for 7 minutes. Last log: 'continuing checks…'" },
|
|
nextAction: "Observe the active run; intervene only if the silence persists past timeout.",
|
|
})}
|
|
/>
|
|
<CardPanel
|
|
caption="State 4 · Recovery escalated"
|
|
action={buildAction({
|
|
status: "escalated",
|
|
attemptCount: 3,
|
|
wakePolicy: { type: "board_escalation" },
|
|
evidence: {
|
|
summary: "Three corrective wakes failed. The recovery owner has not produced a disposition.",
|
|
sourceRunId: "7accd7a4-c9ca-4db2-9233-3228a037cc09",
|
|
},
|
|
nextAction: "Board operator: assign an invokable owner or record a manual resolution.",
|
|
})}
|
|
canFalsePositive
|
|
/>
|
|
<CardPanel
|
|
caption="State 5 · Recovery resolved"
|
|
action={buildAction({
|
|
status: "resolved",
|
|
outcome: "restored",
|
|
resolvedAt: "2026-04-20T12:01:00.000Z",
|
|
nextAction: "Issue restored to a valid disposition.",
|
|
})}
|
|
/>
|
|
<CardPanel
|
|
caption="State 6 · Workspace validation (kind: workspace_validation)"
|
|
action={buildAction({
|
|
kind: "workspace_validation",
|
|
cause: "workspace_validation_failed",
|
|
fingerprint: "fp-workspace",
|
|
evidence: {
|
|
latestRunErrorCode: "workspace_validation_failed",
|
|
sourceRunId: "7accd7a4-c9ca-4db2-9233-3228a037cc09",
|
|
},
|
|
nextAction:
|
|
"Repair the source issue workspace link, project workspace cwd, or git checkout before resuming adapter execution.",
|
|
})}
|
|
canFalsePositive
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function buildBlocker(
|
|
overrides: Partial<IssueRelationIssueSummary> = {},
|
|
): IssueRelationIssueSummary {
|
|
return {
|
|
id: "blocker-1",
|
|
identifier: "PAP-9065",
|
|
title: "Add full company search page",
|
|
status: "in_progress",
|
|
priority: "medium",
|
|
assigneeAgentId: claudeAgent.id,
|
|
assigneeUserId: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function BlockerNoticePanel() {
|
|
return (
|
|
<div className="space-y-4">
|
|
<IssueBlockedNotice
|
|
issueStatus="blocked"
|
|
blockers={[
|
|
buildBlocker({ activeRecoveryAction: buildAction() }),
|
|
buildBlocker({
|
|
id: "blocker-2",
|
|
identifier: "PAP-9099",
|
|
title: "Watchdog: PR review pipeline silent",
|
|
activeRecoveryAction: buildAction({ kind: "active_run_watchdog" }),
|
|
}),
|
|
buildBlocker({
|
|
id: "blocker-3",
|
|
identifier: "PAP-9073",
|
|
title: "Recovery escalated for stranded run",
|
|
status: "blocked",
|
|
activeRecoveryAction: buildAction({ status: "escalated" }),
|
|
}),
|
|
buildBlocker({
|
|
id: "blocker-4",
|
|
identifier: "PAP-9051",
|
|
title: "Bare blocker without recovery state",
|
|
}),
|
|
buildBlocker({
|
|
id: "blocker-5",
|
|
identifier: "PAP-10409",
|
|
title: "Phase 6 follow-up failed: git workspace lost",
|
|
status: "blocked",
|
|
activeRecoveryAction: buildAction({
|
|
kind: "workspace_validation",
|
|
cause: "workspace_validation_failed",
|
|
fingerprint: "fp-workspace-blocker",
|
|
evidence: { latestRunErrorCode: "workspace_validation_failed" },
|
|
nextAction:
|
|
"Repair the source issue workspace link, project workspace cwd, or git checkout before resuming adapter execution.",
|
|
}),
|
|
}),
|
|
]}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
type RunCardRecoveryState = "needed" | "in_progress" | "observe_only" | "escalated";
|
|
|
|
const RUN_CARD_RECOVERY_TONE: Record<RunCardRecoveryState, { icon: typeof TriangleAlert; label: string; className: string }> = {
|
|
needed: {
|
|
icon: TriangleAlert,
|
|
label: "Recovery needed",
|
|
className: "border-amber-500/60 bg-amber-500/15 text-amber-700 dark:text-amber-300",
|
|
},
|
|
in_progress: {
|
|
icon: RefreshCw,
|
|
label: "Recovery in progress",
|
|
className: "border-sky-500/60 bg-sky-500/15 text-sky-700 dark:text-sky-300",
|
|
},
|
|
observe_only: {
|
|
icon: Eye,
|
|
label: "Observing active run",
|
|
className: "border-border bg-muted text-muted-foreground",
|
|
},
|
|
escalated: {
|
|
icon: OctagonAlert,
|
|
label: "Recovery escalated",
|
|
className: "border-red-500/60 bg-red-500/15 text-red-700 dark:text-red-300",
|
|
},
|
|
};
|
|
|
|
function ActiveRunRecoveryChip({ state }: { state: RunCardRecoveryState }) {
|
|
const tone = RUN_CARD_RECOVERY_TONE[state];
|
|
const Icon = tone.icon;
|
|
return (
|
|
<span
|
|
className={`inline-flex shrink-0 items-center gap-0.5 rounded-full border px-1.5 py-0.5 text-[10px] font-medium ${tone.className}`}
|
|
role="status"
|
|
aria-label={tone.label}
|
|
>
|
|
<Icon className="h-2.5 w-2.5" aria-hidden />
|
|
{tone.label}
|
|
</span>
|
|
);
|
|
}
|
|
|
|
function ActiveRunCardMock({
|
|
identifier,
|
|
title,
|
|
recoveryState,
|
|
}: {
|
|
identifier: string;
|
|
title: string;
|
|
recoveryState: RunCardRecoveryState;
|
|
}) {
|
|
return (
|
|
<div className="flex h-[260px] w-full max-w-[320px] flex-col overflow-hidden rounded-xl border border-cyan-500/25 bg-cyan-500/[0.04] shadow-[0_16px_40px_rgba(6,182,212,0.08)]">
|
|
<div className="border-b border-border/60 px-3 py-3">
|
|
<div className="flex items-start justify-between gap-2">
|
|
<div className="min-w-0">
|
|
<div className="flex items-center gap-2">
|
|
<span className="relative flex h-2.5 w-2.5 shrink-0">
|
|
<span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-cyan-400 opacity-70" />
|
|
<span className="relative inline-flex h-2.5 w-2.5 rounded-full bg-cyan-500" />
|
|
</span>
|
|
<span className="text-sm font-medium">CodexCoder</span>
|
|
</div>
|
|
<div className="mt-2 flex items-center gap-2 text-[11px] text-muted-foreground">
|
|
<span>Live now</span>
|
|
</div>
|
|
</div>
|
|
<span className="inline-flex items-center gap-1 rounded-full border border-border/70 bg-background/70 px-2 py-1 text-[10px] text-muted-foreground">
|
|
<ExternalLink className="h-2.5 w-2.5" />
|
|
</span>
|
|
</div>
|
|
<div className="mt-3 rounded-lg border border-border/60 bg-background/60 px-2.5 py-2 text-xs">
|
|
<span className="line-clamp-2 text-cyan-700 dark:text-cyan-300">
|
|
{identifier} - {title}
|
|
</span>
|
|
<div className="mt-1.5">
|
|
<ActiveRunRecoveryChip state={recoveryState} />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="flex-1 px-3 py-2 text-[11px] text-muted-foreground">Live transcript…</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function ActiveRunPanel() {
|
|
return (
|
|
<div className="grid gap-4 sm:grid-cols-2">
|
|
<ActiveRunCardMock
|
|
identifier="PAP-9065"
|
|
title="Add full company search page"
|
|
recoveryState="needed"
|
|
/>
|
|
<ActiveRunCardMock
|
|
identifier="PAP-9099"
|
|
title="Watchdog: PR review pipeline silent"
|
|
recoveryState="observe_only"
|
|
/>
|
|
<ActiveRunCardMock
|
|
identifier="PAP-9073"
|
|
title="Recovery escalated for stranded run"
|
|
recoveryState="escalated"
|
|
/>
|
|
<ActiveRunCardMock
|
|
identifier="PAP-9101"
|
|
title="Recovery in progress: delegated"
|
|
recoveryState="in_progress"
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function InboxRowPanel() {
|
|
const baseIssue = createIssue();
|
|
return (
|
|
<div className="rounded-lg border border-border/70 bg-background/80">
|
|
<IssueRow
|
|
issue={{
|
|
...baseIssue,
|
|
identifier: "PAP-9065",
|
|
title: "Add full company search page",
|
|
status: "in_progress",
|
|
activeRecoveryAction: buildAction(),
|
|
}}
|
|
/>
|
|
<IssueRow
|
|
issue={{
|
|
...baseIssue,
|
|
id: "issue-recovery-watch",
|
|
identifier: "PAP-9099",
|
|
title: "Watchdog: PR review pipeline silent",
|
|
status: "in_progress",
|
|
activeRecoveryAction: buildAction({ kind: "active_run_watchdog" }),
|
|
}}
|
|
/>
|
|
<IssueRow
|
|
issue={{
|
|
...baseIssue,
|
|
id: "issue-recovery-escalated",
|
|
identifier: "PAP-9073",
|
|
title: "Recovery escalated for stranded run",
|
|
status: "blocked",
|
|
activeRecoveryAction: buildAction({ status: "escalated" }),
|
|
}}
|
|
/>
|
|
<IssueRow
|
|
issue={{
|
|
...baseIssue,
|
|
id: "issue-recovery-workspace",
|
|
identifier: "PAP-10409",
|
|
title: "Phase 6 follow-up failed: git workspace lost",
|
|
status: "blocked",
|
|
activeRecoveryAction: buildAction({
|
|
kind: "workspace_validation",
|
|
cause: "workspace_validation_failed",
|
|
fingerprint: "fp-workspace-row",
|
|
evidence: { latestRunErrorCode: "workspace_validation_failed" },
|
|
nextAction:
|
|
"Repair the source issue workspace link, project workspace cwd, or git checkout before resuming adapter execution.",
|
|
}),
|
|
}}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const meta = {
|
|
title: "Paperclip/Source Issue Recovery",
|
|
component: AllStatesPanel,
|
|
parameters: { layout: "fullscreen" },
|
|
} satisfies Meta<typeof AllStatesPanel>;
|
|
|
|
export default meta;
|
|
|
|
type Story = StoryObj<typeof meta>;
|
|
|
|
export const RecoveryActionCardStates: Story = {
|
|
render: () => (
|
|
<StoryFrame
|
|
title="Recovery action card states"
|
|
description="Five states required by the source-issue recovery contract: needed, in progress, observe-only watchdog, escalated, resolved."
|
|
>
|
|
<AllStatesPanel />
|
|
</StoryFrame>
|
|
),
|
|
};
|
|
|
|
export const InboxRowChips: Story = {
|
|
render: () => (
|
|
<StoryFrame
|
|
title="Inbox row recovery chips"
|
|
description="Source rows expose recovery state inline; no synthetic sibling row appears for source-scoped recovery."
|
|
>
|
|
<InboxRowPanel />
|
|
</StoryFrame>
|
|
),
|
|
};
|
|
|
|
export const BlockerNoticeRecoveryIndicators: Story = {
|
|
render: () => (
|
|
<StoryFrame
|
|
title="Blocker notice recovery indicators"
|
|
description="Blocker chips inline a recovery indicator when the blocker has an active recovery action. Plain blockers stay clean."
|
|
>
|
|
<BlockerNoticePanel />
|
|
</StoryFrame>
|
|
),
|
|
};
|
|
|
|
export const ActiveRunPanelRecoveryChips: Story = {
|
|
render: () => (
|
|
<StoryFrame
|
|
title="Active run panel recovery chips"
|
|
description="Active run cards on the dashboard expose recovery state on the linked source issue."
|
|
>
|
|
<ActiveRunPanel />
|
|
</StoryFrame>
|
|
),
|
|
};
|