feat(agents): reset button + endpoint to clear stuck agent error state
Adds a one-click 'reset agents' action for cases where writer/QA agents
are stuck in Paperclip's error state (triggered by recovery loop or
failed run). Addresses the root cause documented in
reference_paperclip_recovery_loops: reassigns open issues from agents
back to the chair user, and calls reset_agent_session for each error
agent to clear wedged runtime sessions.
Changes:
- paperclip_client.py: reset_case_agents() — reassigns stuck issues +
clears error status in Paperclip DB + calls reset_agent_session
- agent_platform_port.py: exports pc_reset_case_agents (G12 gate)
- app.py: POST /api/cases/{case_number}/agents/reset endpoint
- agents.ts: useResetCaseAgents mutation hook + AgentResetResult type
- agent-status-widget.tsx: 'אפס' button (shown only when error agents
exist) with Dialog confirmation + loading state + toast feedback
Invariants: G12 (Paperclip only via port), G2 (no parallel path —
uses existing reset_agent_session + pc_get_case_issues).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,20 @@
|
||||
"use client";
|
||||
|
||||
import { useAgentActivity } from "@/lib/api/agents";
|
||||
import { useState } from "react";
|
||||
import { useAgentActivity, useResetCaseAgents } from "@/lib/api/agents";
|
||||
import type { PaperclipAgentStatus } from "@/lib/api/agents";
|
||||
import { Bot } from "lucide-react";
|
||||
import { Bot, RotateCcw, Loader2 } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
/* ── Status dot colors ───────────────────────────────────────── */
|
||||
|
||||
@@ -40,6 +52,75 @@ function AgentRow({ agent }: { agent: PaperclipAgentStatus }) {
|
||||
);
|
||||
}
|
||||
|
||||
/* ── Reset button ─────────────────────────────────────────────── */
|
||||
|
||||
function ResetAgentsButton({ caseNumber }: { caseNumber: string }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const reset = useResetCaseAgents(caseNumber);
|
||||
|
||||
function handleConfirm() {
|
||||
reset.mutate(undefined, {
|
||||
onSuccess: (result) => {
|
||||
setOpen(false);
|
||||
const agentNames = result.reset_agents
|
||||
.filter((a) => a.ok)
|
||||
.map((a) => a.name)
|
||||
.join(", ");
|
||||
const msg = agentNames
|
||||
? `סוכנים אופסו: ${agentNames}`
|
||||
: "אופסו בהצלחה";
|
||||
toast.success(msg);
|
||||
},
|
||||
onError: () => {
|
||||
setOpen(false);
|
||||
toast.error("שגיאה בביצוע האיפוס");
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<button
|
||||
className="text-[10px] text-ink-faint hover:text-red-600 flex items-center gap-0.5 transition-colors"
|
||||
title="אפס סוכנים תקועים"
|
||||
>
|
||||
<RotateCcw className="w-3 h-3" />
|
||||
<span>אפס</span>
|
||||
</button>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>איפוס סוכנים</DialogTitle>
|
||||
<DialogDescription>
|
||||
פעולה זו תאפס את כל הסוכנים במצב שגיאה ותחזיר issues פתוחים לניהול ידני.
|
||||
פעולה הפיכה — ניתן להפעיל את הסוכנים מחדש אחרי האיפוס.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setOpen(false)} disabled={reset.isPending}>
|
||||
ביטול
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={handleConfirm}
|
||||
disabled={reset.isPending}
|
||||
>
|
||||
{reset.isPending ? (
|
||||
<>
|
||||
<Loader2 className="w-3.5 h-3.5 ms-1.5 animate-spin" />
|
||||
מאפס...
|
||||
</>
|
||||
) : (
|
||||
"אפס סוכנים"
|
||||
)}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
/* ── Widget ───────────────────────────────────────────────────── */
|
||||
|
||||
export function AgentStatusWidget({
|
||||
@@ -54,6 +135,7 @@ export function AgentStatusWidget({
|
||||
|
||||
const agents = data.agents ?? [];
|
||||
const activeCount = agents.filter((a) => a.status === "active" || a.status === "running").length;
|
||||
const hasErrors = agents.some((a) => a.status === "error");
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
@@ -62,11 +144,14 @@ export function AgentStatusWidget({
|
||||
<Bot className="w-3.5 h-3.5" />
|
||||
<span>סוכנים</span>
|
||||
</div>
|
||||
{agents.length > 0 && (
|
||||
<span className="text-[10px] text-ink-faint">
|
||||
{activeCount} פעילים מתוך {agents.length}
|
||||
</span>
|
||||
)}
|
||||
<div className="flex items-center gap-2">
|
||||
{hasErrors && <ResetAgentsButton caseNumber={caseNumber} />}
|
||||
{agents.length > 0 && (
|
||||
<span className="text-[10px] text-ink-faint">
|
||||
{activeCount} פעילים מתוך {agents.length}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-0.5">
|
||||
|
||||
@@ -179,3 +179,25 @@ export function useSubmitInteraction(caseNumber: string | undefined) {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export type AgentResetResult = {
|
||||
ok: boolean;
|
||||
reassigned_issues: { id: string; identifier: string }[];
|
||||
reset_agents: { id: string; name: string; ok: boolean; error?: string }[];
|
||||
};
|
||||
|
||||
export function useResetCaseAgents(caseNumber: string | undefined) {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: () =>
|
||||
apiRequest<AgentResetResult>(
|
||||
`/api/cases/${caseNumber}/agents/reset`,
|
||||
{ method: "POST" },
|
||||
),
|
||||
onSuccess: () => {
|
||||
if (caseNumber) {
|
||||
qc.invalidateQueries({ queryKey: agentKeys.activity(caseNumber) });
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user