fix(assemble): check task status immediately on mount to handle fast completions

When using Groq (very low latency), tasks complete before the 3s polling
interval fires. Now checkAll() runs immediately on effect mount.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jonas Pacheco 2026-03-27 17:12:25 -03:00
parent 3ca659ca0c
commit 31914956ef
1 changed files with 7 additions and 4 deletions

View File

@ -220,12 +220,12 @@ function AgentFactoryTabs() {
}); });
const defs = defsData?.data || []; const defs = defsData?.data || [];
// Poll task status for assembling defs // Poll task status for assembling defs — verifica imediatamente e depois a cada 3s
useEffect(() => { useEffect(() => {
const assembling = defs.filter(d => d.status === "assembling" && d.lastTaskId); const assembling = defs.filter(d => d.status === "assembling" && d.lastTaskId);
if (assembling.length === 0) return; if (assembling.length === 0) return;
const interval = setInterval(async () => { async function checkAll() {
for (const def of assembling) { for (const def of assembling) {
if (!def.lastTaskId) continue; if (!def.lastTaskId) continue;
try { try {
@ -233,7 +233,6 @@ function AgentFactoryTabs() {
const data = await res.json(); const data = await res.json();
const taskStatus = data?.task?.status; const taskStatus = data?.task?.status;
if (taskStatus === "completed" || taskStatus === "failed") { if (taskStatus === "completed" || taskStatus === "failed") {
// Mark agent as ready or draft
await fetch(`/api/agent-defs/${def.id}`, { await fetch(`/api/agent-defs/${def.id}`, {
method: "PATCH", method: "PATCH",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
@ -245,7 +244,11 @@ function AgentFactoryTabs() {
setAssembleTaskStatus(prev => ({ ...prev, [def.id]: taskStatus || "unknown" })); setAssembleTaskStatus(prev => ({ ...prev, [def.id]: taskStatus || "unknown" }));
} catch { /* ignore */ } } catch { /* ignore */ }
} }
}, 3000); }
// Verifica imediatamente (cobre tasks que já completaram antes do polling iniciar)
checkAll();
const interval = setInterval(checkAll, 3000);
return () => clearInterval(interval); return () => clearInterval(interval);
}, [defs, queryClient]); }, [defs, queryClient]);