mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-21 00:05:49 +02:00
## Thinking Path > - Paperclip lets people manage AI agents and review their work. > - Task confirmations must use the work produced by their source run. > - The server blocks approval while that run still needs to sync its workspace. > - The card currently enables approval before that check can pass, so an ordinary click produces an error. > - This PR exposes the existing readiness check and shows “Preparing approval…” with acceptance disabled. > - The card refreshes itself and enables approval when the source workspace settles. ## Linked Issues or Issue Description **What happened?** A confirmation appears while its source run is still preparing or syncing its workspace. Its enabled approval button returns a conflict asking the user to retry after syncing. **Steps to reproduce** 1. Run an agent in an isolated workspace. 2. Have it create a confirmation before workspace finalization completes. 3. Click the approval button while the source workspace is still active. **Expected behavior** The card explains that approval is preparing. Acceptance becomes available automatically when the same server check permits it. Reject and revise remain available. Related work: #10770 handles this conflict after a click with retries. #9520 proposes changing the workspace acceptance barrier. This PR preserves that barrier and exposes readiness before the click, including in compact task chat. It preserves the terminal-finalize behavior from #10099. ## What Changed - Add an optional, read-only `acceptanceBlocker` to interaction responses. Readiness uses the existing source-run workspace predicate, with one check per pending source run. - Disable acceptance and show a shared preparation notice in classic and compact confirmation cards, including checkbox and secret-binding confirmations. - Refresh preparing cards every two seconds in task detail, attention, pipelines, and Skill Studio. Restore each surface's previous polling cadence when preparation clears. - Preserve live tool reviews, questions, rejection, revision, and the server acceptance barrier. No automatic acceptance occurs. - Document the preparation state and cover readiness, terminal sync outcomes, unrelated runs, historical cards, and automatic refresh. ## Verification - Focused service, card, query-refresh, and helper tests: 217 passed across five files. - `pnpm -r typecheck`: passed. - `pnpm build`: passed. - `pnpm build-storybook`: passed. - `pnpm check:token-gates`: passed. - `pnpm test:run`: incomplete locally. Stopped after about 17 minutes once it reproduced seven existing environment failures: two Slack tests and two email tests lack ancestor-directory skill fixtures; three company-skills tests fail on macOS runtime-cache staging permissions. These are outside this change. The full CI test matrix passed. - CI: all 53 checks passed; two optional Storybook jobs were skipped. The branch has no conflicts with `master`. - Greptile: 5/5 on commit `8a6f216d8d`, with no review threads. - Reviewed added lines and new files for credentials, private URLs, internal task references, user paths, and run artifacts. None found. ## Risks - No database migration or change to acceptance authorization. Readiness is advisory; the server still enforces its existing gate at acceptance. - An open preparing card adds a read every two seconds. This cadence stops after readiness clears; historical cards add no workspace checks. - Failed or stale finalization retains the existing server behavior. This PR does not change recovery policy. ## Model Used OpenAI GPT-6 through Codex. The exact serving model ID and context-window size are not exposed in this session. Used reasoning, repository inspection, tool execution, and automated tests. No sub-agents. ## 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 (217 focused tests; full local-suite limitations are recorded 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>
170 lines
6.4 KiB
TypeScript
170 lines
6.4 KiB
TypeScript
import { useMemo } from "react";
|
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { Loader2 } from "lucide-react";
|
|
import type { Agent } from "@paperclipai/shared";
|
|
import { issuesApi } from "../api/issues";
|
|
import { queryKeys } from "../lib/queryKeys";
|
|
import {
|
|
interactionReadinessRefetchInterval,
|
|
isIssueThreadInteraction,
|
|
type AskUserQuestionsAnswer,
|
|
type AskUserQuestionsInteraction,
|
|
type IssueThreadInteraction,
|
|
type RequestCheckboxConfirmationInteraction,
|
|
type RequestConfirmationInteraction,
|
|
type RequestItemVerdictsInteraction,
|
|
type RequestItemVerdictValue,
|
|
type SuggestTasksInteraction,
|
|
} from "../lib/issue-thread-interactions";
|
|
import { IssueThreadInteractionCard } from "./IssueThreadInteractionCard";
|
|
|
|
interface AttentionInteractionResolverProps {
|
|
companyId: string;
|
|
issueId: string;
|
|
interactionId: string;
|
|
agentMap?: Map<string, Agent>;
|
|
currentUserId?: string | null;
|
|
userLabelMap?: ReadonlyMap<string, string> | null;
|
|
/** Called after a resolution so the parent can refresh the feed. */
|
|
onResolved?: () => void;
|
|
}
|
|
|
|
export function replaceResolvedInteraction(
|
|
current: IssueThreadInteraction[] | undefined,
|
|
resolvedInteraction: IssueThreadInteraction,
|
|
): IssueThreadInteraction[] {
|
|
const existing = current ?? [];
|
|
const index = existing.findIndex((entry) => entry.id === resolvedInteraction.id);
|
|
if (index < 0) return [...existing, resolvedInteraction];
|
|
return existing.map((entry, entryIndex) =>
|
|
entryIndex === index ? resolvedInteraction : entry,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Lazily fetches the full issue-thread interaction referenced by an attention
|
|
* row and renders the existing {@link IssueThreadInteractionCard} inline, so
|
|
* confirmations and questions are answerable in-row without leaving the queue
|
|
* (converged PAP-12628). Reviews never reach here — they deep-link.
|
|
*/
|
|
export function AttentionInteractionResolver({
|
|
companyId,
|
|
issueId,
|
|
interactionId,
|
|
agentMap,
|
|
currentUserId,
|
|
userLabelMap,
|
|
onResolved,
|
|
}: AttentionInteractionResolverProps) {
|
|
const queryClient = useQueryClient();
|
|
|
|
const { data: interactions, isLoading, error } = useQuery({
|
|
queryKey: queryKeys.issues.interactions(issueId),
|
|
queryFn: () => issuesApi.listInteractions(issueId),
|
|
enabled: !!issueId,
|
|
refetchInterval: (query) => interactionReadinessRefetchInterval(query.state.data),
|
|
});
|
|
|
|
const interaction = useMemo<IssueThreadInteraction | null>(() => {
|
|
const match = (interactions ?? []).find((entry) => entry.id === interactionId);
|
|
return match && isIssueThreadInteraction(match) ? match : null;
|
|
}, [interactions, interactionId]);
|
|
|
|
const invalidate = (resolvedInteraction?: IssueThreadInteraction) => {
|
|
// The accept route returns the fully stitched interaction (including
|
|
// secretProposal.executed/failed). Put that receipt in the cache before
|
|
// invalidating so the attention surface never flashes a generic Accepted
|
|
// state while the refetch catches up.
|
|
if (resolvedInteraction) {
|
|
queryClient.setQueryData<IssueThreadInteraction[] | undefined>(
|
|
queryKeys.issues.interactions(issueId),
|
|
(current) => replaceResolvedInteraction(current, resolvedInteraction),
|
|
);
|
|
}
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.issues.interactions(issueId) });
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.attention(companyId) });
|
|
onResolved?.();
|
|
};
|
|
|
|
const acceptMutation = useMutation({
|
|
mutationFn: (input: {
|
|
interaction: SuggestTasksInteraction | RequestConfirmationInteraction | RequestCheckboxConfirmationInteraction;
|
|
selectedClientKeys?: string[];
|
|
selectedOptionIds?: string[];
|
|
rememberAction?: boolean;
|
|
}) =>
|
|
issuesApi.acceptInteraction(issueId, input.interaction.id, {
|
|
selectedClientKeys: input.selectedClientKeys,
|
|
selectedOptionIds: input.selectedOptionIds,
|
|
rememberAction: input.rememberAction,
|
|
}),
|
|
onSuccess: invalidate,
|
|
});
|
|
|
|
const rejectMutation = useMutation({
|
|
mutationFn: (input: { interactionId: string; reason?: string }) =>
|
|
issuesApi.rejectInteraction(issueId, input.interactionId, input.reason),
|
|
onSuccess: invalidate,
|
|
});
|
|
|
|
const respondMutation = useMutation({
|
|
mutationFn: (input: { interactionId: string; answers: AskUserQuestionsAnswer[] }) =>
|
|
issuesApi.respondToInteraction(issueId, input.interactionId, { answers: input.answers }),
|
|
onSuccess: invalidate,
|
|
});
|
|
|
|
const cancelMutation = useMutation({
|
|
mutationFn: (input: { interactionId: string }) =>
|
|
issuesApi.cancelInteraction(issueId, input.interactionId),
|
|
onSuccess: invalidate,
|
|
});
|
|
|
|
const verdictsMutation = useMutation({
|
|
mutationFn: (input: {
|
|
interactionId: string;
|
|
verdicts: { id: string; verdict: RequestItemVerdictValue; reason?: string }[];
|
|
}) => issuesApi.submitInteractionVerdicts(issueId, input.interactionId, input.verdicts),
|
|
onSuccess: invalidate,
|
|
});
|
|
|
|
if (isLoading) {
|
|
return (
|
|
<div className="flex items-center gap-2 py-3 text-xs text-muted-foreground">
|
|
<Loader2 className="h-3.5 w-3.5 animate-spin" /> Loading decision…
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (error || !interaction) {
|
|
return (
|
|
<p className="py-3 text-xs text-muted-foreground">
|
|
This decision is no longer available — it may have been resolved elsewhere.
|
|
</p>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<IssueThreadInteractionCard
|
|
interaction={interaction}
|
|
agentMap={agentMap}
|
|
currentUserId={currentUserId}
|
|
userLabelMap={userLabelMap}
|
|
onAcceptInteraction={(target, selectedClientKeys, selectedOptionIds, rememberAction) =>
|
|
acceptMutation.mutateAsync({ interaction: target, selectedClientKeys, selectedOptionIds, rememberAction }).then(() => undefined)
|
|
}
|
|
onRejectInteraction={(target, reason) =>
|
|
rejectMutation.mutateAsync({ interactionId: target.id, reason }).then(() => undefined)
|
|
}
|
|
onSubmitInteractionAnswers={(target: AskUserQuestionsInteraction, answers) =>
|
|
respondMutation.mutateAsync({ interactionId: target.id, answers }).then(() => undefined)
|
|
}
|
|
onCancelInteraction={(target: AskUserQuestionsInteraction) =>
|
|
cancelMutation.mutateAsync({ interactionId: target.id }).then(() => undefined)
|
|
}
|
|
onSubmitInteractionVerdicts={(target: RequestItemVerdictsInteraction, verdicts) =>
|
|
verdictsMutation.mutateAsync({ interactionId: target.id, verdicts }).then(() => undefined)
|
|
}
|
|
/>
|
|
);
|
|
}
|