feat(interactions): add interaction withdrawal and terminal-issue expiry (#10251)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Agents and boards coordinate through issue-thread interactions
(request_confirmation, ask_user_questions, suggest_tasks, …) that wait
as `pending` cards until someone resolves them
> - Two lifecycle gaps existed: an interaction's creator could not take
back a card it no longer stands behind, and interactions left `pending`
on issues that reached a terminal status lingered forever as
live-looking approval requests
> - Stale pending cards mislead humans (they look actionable), distort
attention/liveness signals, and in the worst case invite acting on a
proposal whose issue is already closed or cancelled
> - This pull request adds an explicit withdraw route for pending
interactions and automatically expires pending interactions when their
issue reaches a terminal status (including a catch-up sweep for issues
closed before this change)
> - The benefit is that interaction cards now faithfully reflect
reality: only genuinely actionable requests stay pending, and creators
can retract requests that events have overtaken

## Linked Issues or Issue Description

Fixes #5787
Refs #7403

Related prior PRs found while searching for duplicates (all overlap
partially; none combine both lifecycle paths or the route-level
authorization used here): #6709 and #7312 (creator-withdraw attempts),
#8169 (terminal expiry), #8081 and #5137 (generalized cancel/expire
endpoints), #6094 (stale confirmation auto-resolve). Related merged
context: #9568 (agent cancel for ask_user_questions), #10119 (tolerating
legacy `withdrawn_by_creator` result outcomes — the reader side of the
outcome this PR writes).

## What Changed

- New route `POST /issues/:id/interactions/:interactionId/withdraw` that
resolves a `pending` interaction to status `withdrawn` with a structured
result (`outcome: "withdrawn"`, optional trimmed `reason`), stamps
`resolvedBy*`/`resolvedAt`, touches the issue, logs activity, and emits
resolved-interaction telemetry
- Withdrawal authorization: board users, the interaction's creator
agent, or the issue's current assignee agent (assignees additionally
pass the standard issue-mutation gate); task-watchdog runs are
explicitly rejected, and authorization-boundary plus low-trust
control-plane checks apply
- Withdrawing an already-resolved interaction returns `409`;
unknown/cross-issue/cross-company interaction ids return `404`
- New service method `expirePendingInteractionsForTerminalIssue`: when
an issue transitions to a terminal status, all of its `pending`
interactions are resolved to `expired` with `outcome: "issue_closed"`,
guarded by a `status = 'pending'` predicate so concurrent resolutions
are not overwritten
- The same expiry runs as a catch-up when interactions are listed on an
already-terminal issue, so cards stranded by issues closed before this
change also get cleaned up; expired request_confirmations are logged
with a distinguishing source
- Shared package: new `withdrawIssueThreadInteractionSchema` validator,
`WithdrawIssueThreadInteraction` type, and `withdrawn` / `issue_closed`
result-outcome support for all interaction kinds (kind-aware result
shapes for `ask_user_questions` and `request_item_verdicts`)
- UI helper `ui/src/lib/issue-thread-interactions.ts` recognizes the new
outcomes for card rendering
- Docs: bundled skill API reference updated with the withdraw endpoint
- Review follow-up: terminal expiry moved from the HTTP route hooks into
`issueService.update`'s status-transition block, so direct service
callers (tree control, recovery, pipelines, status cards) expire pending
cards too; the list-endpoint catch-up remains for issues closed before
this change
- Review follow-up: withdrawing or issue-close-expiring a
`request_confirmation` also settles its linked `tool_action_requests`
row (withdraw -> `cancelled`, issue closed -> `expired`), so a parked
tool call cannot stay approvable after its card is gone
- Review follow-up: interaction cards render dedicated copy for the new
outcomes ("Withdrawn" with the reason, "Expired when issue closed")
instead of falling through to superseded-by-comment / stale-target
variants; withdrawn plan reviews badge as "Withdrawn" rather than
"Changes requested"

## Screenshots

Card states rendered from a local ux-lab harness with mocked data ([full
gallery](https://pages.paperclip.ing/pr-10251-interaction-withdrawal-cards/)):

| Light | Dark |
| --- | --- |
| ![All card states,
light](https://pages.paperclip.ing/pr-10251-interaction-withdrawal-cards/all-light.png)
| ![All card states,
dark](https://pages.paperclip.ing/pr-10251-interaction-withdrawal-cards/all-dark.png)
|

## Verification

- `pnpm --filter @paperclipai/shared build` — clean tsc
- `cd server && npx vitest run
src/__tests__/issue-thread-interaction-routes.test.ts` — 22 tests pass,
including new coverage for: creator-agent withdraw success,
non-creator/non-assignee agent 403, watchdog-run 403, double-withdraw
409, and board-user withdraw
- `cd server && npx vitest run
src/services/issue-thread-interactions.test.ts` — 4 tests pass,
including terminal-issue expiry writing `issue_closed` results and
leaving already-resolved interactions untouched
- `cd ui && pnpm typecheck` — clean
- `cd server && npx vitest run src/__tests__/issues-service.test.ts` —
includes a new embedded-Postgres test proving a direct
`issueService.update` terminal transition expires pending interactions
and writes the activity-log entry
- `cd ui && npx vitest run
src/components/IssueThreadInteractionCard.test.tsx` — 32 tests,
including new coverage for withdrawn / issue-closed confirmation and
question cards
- `cd server && npx tsc --noEmit` — matches the pre-existing repo error
baseline exactly (no new errors)
- Manual: `POST /issues/:id/interactions/:interactionId/withdraw` with
`{"reason":"superseded"}` as the creator agent resolves the card to
`withdrawn`; closing an issue with a pending confirmation flips it to
`expired` with `outcome: "issue_closed"`

## Risks

- Interactions on terminal issues now auto-expire (including
retroactively via the list-time catch-up), so consumers that expected to
resolve a pending interaction on a closed issue will get `409`; this is
the intended semantics and matches how the attention feed already wants
to treat dead cards
- New result outcomes (`withdrawn`, `issue_closed`) are written to
stored results; readers were already made tolerant of these outcome
strings in #10119, so mixed-version reads are safe
- No schema/migration changes; per-row conditional updates (`status =
'pending'`) avoid clobbering concurrent resolutions
- Withdrawal is a new mutation surface, but it is strictly narrower than
existing resolve paths (board, creator, or assignee only; watchdog runs
blocked)

## Model Used

Claude Fable 5 (`claude-fable-5`, Anthropic Mythos-class tier) with
extended thinking and agentic tool use (Claude Code harness); commit
authored in a Paperclip-managed engineering session.

## 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
- [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>
This commit is contained in:
DottaandPaperclip authored and GitHub committed 2026-07-27 19:04:46 -05:00
1 parent a3b293e26d
commit f6ab82d490
19 files changed
+882 -37

No files matched your search

@@ -236,6 +236,76 @@ describe("IssueThreadInteractionCard", () => {
expect(host.textContent).not.toContain("Questions expired by comment");
});
it("renders withdrawn confirmations with the withdraw reason", () => {
const host = renderCard({
interaction: {
...pendingRequestConfirmationInteraction,
status: "cancelled",
result: { version: 1, outcome: "withdrawn", reason: "Superseded by the hotfix plan." },
},
onAcceptInteraction: vi.fn(),
onRejectInteraction: vi.fn(),
});
expect(host.textContent).toContain("Withdrawn");
expect(host.textContent).toContain("Superseded by the hotfix plan.");
expect(host.textContent).not.toContain("Decline");
});
it("renders confirmations expired by issue closure with dedicated copy", () => {
const host = renderCard({
interaction: {
...pendingRequestConfirmationInteraction,
status: "expired",
result: { version: 1, outcome: "issue_closed", reason: null },
},
});
expect(host.textContent).toContain("Expired when issue closed");
expect(host.textContent).toContain("The issue was closed before this confirmation was resolved.");
expect(host.textContent).not.toContain("Expired by target change");
});
it("renders withdrawn question interactions with the withdraw reason", () => {
const host = renderCard({
interaction: {
...pendingAskUserQuestionsInteraction,
status: "cancelled",
result: {
version: 1,
outcome: "withdrawn",
reason: "Scope was decided on the parent issue.",
answers: [],
summaryMarkdown: null,
},
},
});
expect(host.textContent).toContain("Questions withdrawn");
expect(host.textContent).toContain("Scope was decided on the parent issue.");
expect(host.textContent).not.toContain("Question cancelled");
});
it("renders question interactions expired by issue closure with dedicated copy", () => {
const host = renderCard({
interaction: {
...pendingAskUserQuestionsInteraction,
status: "expired",
result: {
version: 1,
outcome: "issue_closed",
reason: null,
answers: [],
summaryMarkdown: null,
},
},
});
expect(host.textContent).toContain("Questions expired when issue closed");
expect(host.textContent).toContain("The issue was closed before these questions were answered.");
expect(host.textContent).not.toContain("expired by comment");
});
it("makes child tasks explicit in suggested task trees", () => {
const host = renderCard({
interaction: pendingSuggestedTasksInteraction,
@@ -192,6 +192,7 @@ function requestConfirmationResumeFailure(interaction: IssueThreadInteraction) {
function planStatusClasses(
status: IssueThreadInteraction["status"],
resumeFailure?: ReturnType<typeof requestConfirmationResumeFailure>,
outcome?: string | null,
) {
switch (status) {
case "accepted":
@@ -215,7 +216,7 @@ function planStatusClasses(
return {
shell: "border-2 border-red-500/80 bg-transparent",
badge: "border-red-500/60 bg-red-500/10 text-red-900 dark:bg-red-500/15 dark:text-red-100",
label: "Changes requested",
label: outcome === "withdrawn" ? "Withdrawn" : "Changes requested",
Icon: XCircle,
};
case "failed":
@@ -1154,9 +1155,15 @@ function AskUserQuestionsCard({
</div>
) : interaction.status === "cancelled" ? (
<div className="rounded-2xl border border-rose-300/60 bg-rose-50/85 p-4 text-sm leading-6 text-rose-950 dark:border-rose-500/40 dark:bg-rose-500/10 dark:text-rose-100">
<div className="font-semibold">Question cancelled</div>
<div className="font-semibold">
{interaction.result?.outcome === "withdrawn"
? questions.length === 1 ? "Question withdrawn" : "Questions withdrawn"
: "Question cancelled"}
</div>
{interaction.result?.cancellationReason ? (
<p className="mt-1">{interaction.result.cancellationReason}</p>
) : interaction.result?.reason ? (
<p className="mt-1">{interaction.result.reason}</p>
) : (
<p className="mt-1">No answer was recorded.</p>
)}
@@ -1165,10 +1172,14 @@ function AskUserQuestionsCard({
<div className="rounded-2xl border border-amber-300/70 bg-amber-50/85 p-4 text-sm leading-6 text-amber-950 dark:border-amber-500/40 dark:bg-amber-500/10 dark:text-amber-100">
<div className="flex items-center gap-2 font-semibold">
<AlertTriangle className="h-4 w-4" />
{questions.length === 1 ? "Question expired by comment" : "Questions expired by comment"}
{interaction.result?.outcome === "issue_closed"
? questions.length === 1 ? "Question expired when issue closed" : "Questions expired when issue closed"
: questions.length === 1 ? "Question expired by comment" : "Questions expired by comment"}
</div>
<p className="mt-1">
A later board/user comment superseded this question request. Create a fresh request if answers are still needed.
{interaction.result?.outcome === "issue_closed"
? "The issue was closed before these questions were answered."
: "A later board/user comment superseded this question request. Create a fresh request if answers are still needed."}
</p>
{interaction.result?.commentId ? (
<a
@@ -1346,18 +1357,37 @@ function RequestConfirmationResolution({
);
}
if (interaction.status === "cancelled" && outcome === "withdrawn") {
return (
<div className="space-y-2">
<div className="flex flex-wrap items-center gap-2 text-sm leading-6 text-foreground">
<span className="font-medium">Withdrawn</span>
<RequestConfirmationTargetChip interaction={interaction} target={target} />
</div>
{interaction.result?.reason ? (
<div className="rounded-sm border-l-2 border-rose-500/70 bg-rose-500/10 px-3 py-2 text-sm leading-6 text-rose-900 dark:text-rose-100">
<MarkdownBody>{interaction.result.reason}</MarkdownBody>
</div>
) : null}
</div>
);
}
if (interaction.status === "expired") {
const expiredByComment = outcome === "superseded_by_comment";
const expiredWithIssue = outcome === "issue_closed";
const expiredByTargetChange = outcome === "stale_target";
return (
<div className="space-y-3 rounded-sm border border-amber-500/60 bg-amber-500/10 px-4 py-3 text-sm text-amber-900 dark:text-amber-100">
<div className="text-(length:--text-micro) font-semibold uppercase tracking-(--tracking-eyebrow) text-amber-700">
{expiredByComment ? "Expired by comment" : "Expired by target change"}
{expiredByComment ? "Expired by comment" : expiredWithIssue ? "Expired when issue closed" : "Expired by target change"}
</div>
<p className="leading-6">
{expiredByComment
? "A board comment superseded this confirmation before it was resolved."
: "The requested target changed before this confirmation was resolved."}
: expiredWithIssue
? "The issue was closed before this confirmation was resolved."
: "The requested target changed before this confirmation was resolved."}
</p>
{expiredByComment && interaction.result?.commentId ? (
<Button asChild size="sm" variant="ghost" className="h-7 px-2 text-amber-950 hover:bg-amber-500/15 dark:text-amber-50">
@@ -3028,7 +3058,13 @@ export function IssueThreadInteractionCard({
: null;
const toolActionStyles = toolActionState ? toolActionStatusClasses(toolActionState) : null;
const resumeFailure = requestConfirmationResumeFailure(interaction);
const planStyles = isPlan ? planStatusClasses(interaction.status, resumeFailure) : null;
const planStyles = isPlan
? planStatusClasses(
interaction.status,
resumeFailure,
interaction.result && "outcome" in interaction.result ? interaction.result.outcome : null,
)
: null;
const activeStyles = toolActionStyles ?? planStyles;
const StatusIcon = activeStyles ? activeStyles.Icon : statusIcon(interaction.status);
const iconSpin = toolActionStyles?.spin ?? false;
+5
View File
@@ -178,6 +178,11 @@ export function getRequestConfirmationTargetHref({
export function buildIssueThreadInteractionSummary(
interaction: IssueThreadInteraction,
) {
const administrativeOutcome = interaction.result && "outcome" in interaction.result
? interaction.result.outcome
: null;
if (administrativeOutcome === "withdrawn") return "Withdrawn interaction";
if (administrativeOutcome === "issue_closed") return "Expired when issue closed";
if (interaction.kind === "suggest_tasks") {
const count = interaction.payload.tasks.length;
if (interaction.status === "accepted") {