Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
stop double-polling the sentinel, and show "Wrapping up" on the agent card
[._.]/ Adam Eivy1ca65d50cec8
diff --git a/client/src/components/cos/tabs/AgentCard.jsx b/client/src/components/cos/tabs/AgentCard.jsxindex 8c46258654..9e642c0cdf 100644--- a/client/src/components/cos/tabs/AgentCard.jsx+++ b/client/src/components/cos/tabs/AgentCard.jsx@@ -422,9 +422,15 @@ export default function AgentCard({ agent, onPause, onKill, onDelete, onResume,{!inactive && (<span className={`px-2 py-0.5 text-xs rounded animate-pulse shrink-0 ${agent.metadata?.phase === 'initializing' ? 'bg-yellow-500/20 text-yellow-400' :+ // Hit its max runtime and was asked to write its sentinel — it has+ // minutes left before it's reaped, so say so rather than showing a+ // reassuring "Working" right up to the kill.+ agent.metadata?.phase === 'wrap-up' ? 'bg-orange-500/20 text-orange-400' :'bg-port-accent/20 text-port-accent'}`}>- {agent.metadata?.phase === 'initializing' ? 'Initializing' : 'Working'}+ {agent.metadata?.phase === 'initializing' ? 'Initializing'+ : agent.metadata?.phase === 'wrap-up' ? 'Wrapping up'+ : 'Working'}</span>)}{paused && (diff --git a/server/services/agentCompletionCleanup.js b/server/services/agentCompletionCleanup.jsindex 5203d22407..81e2a8988f 100644--- a/server/services/agentCompletionCleanup.js+++ b/server/services/agentCompletionCleanup.js@@ -355,11 +355,14 @@ export async function runAgentCompletionCleanup({ agentId, task, agent, effectiv// budget and is waiting on a human (a pointer there would be dead metadata// that `updateTask` has to strip again on the next terminal write).if (!effectiveSuccess && task?.id) {- const { getTaskById, getAgent: getAgentForBranch } = await import('./cos.js');+ const { getTaskById } = await import('./cos.js');const persisted = await getTaskById(task.id).catch(() => null);const willRetry = (persisted?.status ?? 'pending') === 'pending';- const cleanedAgent = willRetry ? await getAgentForBranch(agentId).catch(() => null) : null;- const { sourceWorkspace, worktreeBranch } = cleanedAgent?.metadata || {};+ // Reuse the `agentState` fetched at the top of this function rather than+ // re-reading the record: `getAgent` on a now-completed agent re-reads and+ // splits the whole output.txt transcript (hundreds of KB for a TUI run),+ // and both fields here are stamped once at registerAgent and never mutated.+ const { sourceWorkspace, worktreeBranch } = (willRetry && agentState?.metadata) || {};const resumeBranch = await resolveResumeBranch(sourceWorkspace, worktreeBranch).catch(err => {emitLog('warn', `Failed to resolve resume branch for ${agentId}: ${err.message}`, { agentId });return null;diff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.jsindex 576a73d422..2515dc7caa 100644--- a/server/services/agentTuiSpawning.js+++ b/server/services/agentTuiSpawning.js@@ -345,9 +345,9 @@ export async function spawnTuiAgent({// ticking), this bounds the total run so a hung provider/CLI can't run// unbounded. See DEFAULT_TUI_MAX_RUNTIME_MS for the incident.let maxRuntimeTimer = null;- // Poll driving the wrap-up grace window that the max-runtime ceiling opens- // instead of reaping immediately (see MAX_RUNTIME_WRAP_UP_GRACE_MS). Cleared- // in finish() alongside every other timer.+ // Deadline for the wrap-up grace window the max-runtime ceiling opens instead of+ // reaping immediately (see MAX_RUNTIME_WRAP_UP_GRACE_MS). Cleared in finish()+ // alongside every other timer.let wrapUpTimer = null;const streamingStrip = createStreamingAnsiStripper();@@ -405,7 +405,7 @@ export async function spawnTuiAgent({if (pasteVerifyTimer) { clearInterval(pasteVerifyTimer); pasteVerifyTimer = null; }if (submitEnterTimer) { clearInterval(submitEnterTimer); submitEnterTimer = null; }if (maxRuntimeTimer) { clearTimeout(maxRuntimeTimer); maxRuntimeTimer = null; }- if (wrapUpTimer) { clearInterval(wrapUpTimer); wrapUpTimer = null; }+ if (wrapUpTimer) { clearTimeout(wrapUpTimer); wrapUpTimer = null; }// Release the post-paste accumulator even when finalize fires mid-paste-// window. The pasteEnterTimer's own cleanup path nulls this too, but if// finalize comes from elsewhere (shell-exit, command-not-found, user@@ -782,30 +782,27 @@ export async function spawnTuiAgent({() => finalized,);- const graceStartedAt = Date.now();- wrapUpTimer = setInterval(() => {+ // A single deadline, NOT a poll: the 2s doneSentinelTimer is already watching+ // this exact path at this exact cadence and owns the success transition (and+ // finish() clears this handle), so polling here would just double the+ // existsSync syscalls for 5 minutes to learn something the other timer acts on+ // first. All this needs to do is fire once at the end of the window.+ wrapUpTimer = setTimeout(() => {try {- if (finalized) { clearInterval(wrapUpTimer); wrapUpTimer = null; return; }- // The sentinel landed — the prod worked. Let the doneSentinelTimer- // finalize it as `agent-signaled-done`; just stop the grace clock.- if (sentinelPresent()) {- clearInterval(wrapUpTimer);- wrapUpTimer = null;- appendLine(`✅ Agent wrapped up within the max-runtime grace window`);- return;- }- if (Date.now() - graceStartedAt < MAX_RUNTIME_WRAP_UP_GRACE_MS) return;- clearInterval(wrapUpTimer);wrapUpTimer = null;+ if (finalized) return;+ // The sentinel landed right at the boundary — the prod worked after all.+ // Let the sentinel path finalize it as the success it is.+ if (sentinelPresent()) return;finishMaxRuntimeFailure(`it did not wrap up within ${graceMin}min of being asked, so the provider/CLI likely hung (a stalled request keeps the working counter repainting so the idle reaper never fires);`,'max-runtime-no-wrap-up',);} catch (err) {- // setInterval callback: an uncaught throw here would crash the process.- console.error(`❌ wrapUpTimer interval callback failed: ${err.message}`);+ // setTimeout callback: an uncaught throw here would crash the process.+ console.error(`❌ wrapUpTimer callback failed: ${err.message}`);}- }, DONE_POLL_INTERVAL_MS);+ }, MAX_RUNTIME_WRAP_UP_GRACE_MS);};const sendPrompt = async (reason) => {