Skip to content

Open-source SEO, GEO, and marketing skills for AI agents.

refactor(liveness): lift in-flight polling from workspace to sidebar

Yuting Zhongeea4eab73bc5
diff --git a/src/components/agent-task-workspace.tsx b/src/components/agent-task-workspace.tsx
index b226cf18..fafab4e1 100644
--- a/src/components/agent-task-workspace.tsx
+++ b/src/components/agent-task-workspace.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useCallback, useEffect, useMemo, useState, useTransition } from "react";
+import { useCallback, useMemo, useState, useTransition } from "react";
import Link from "next/link";
import { useRouter, useSearchParams } from "next/navigation";
import {
@@ -99,12 +99,10 @@ export function AgentTaskWorkspace({
return (
<div className="flex h-full min-h-0">
- {/* Background poll while ANY task on this agent is in flight. The
- LiveTranscript polls per-thread for the SELECTED task; this
- keeps the rest of the page (task list groups, sidebar count
- badge) refreshing for tasks that finish in the background —
- e.g. CMO-delegated sub-tasks the user isn't watching. */}
- <AgentLivenessPoller hasInFlight={inFlightCount > 0} />
+ {/* Background liveness polling is handled at the sidebar level
+ (GlobalLivenessPoller) so it covers every route, not just this
+ workspace. The per-thread LiveTranscript polling still handles
+ the open transcript. */}
{/* ── Left pane: task list ─────────────────────────────────────── */}
<aside className="flex w-80 shrink-0 flex-col border-r bg-muted/20">
<div className="border-b px-4 py-3">
@@ -250,24 +248,6 @@ export function AgentTaskWorkspace({
);
}
-/**
- * Tiny polling helper that fires router.refresh while any task on this
- * agent is in flight. Stops the moment the server-rendered count drops
- * to zero (the refresh that landed the 0 disables the effect). Covers
- * the gap where a sub-task the user isn't watching finishes after the
- * LiveTranscript's per-thread polling has stopped — without this the
- * sidebar badge + task list stay frozen at the last-seen counts.
- */
-function AgentLivenessPoller({ hasInFlight }: { hasInFlight: boolean }) {
- const router = useRouter();
- useEffect(() => {
- if (!hasInFlight) return;
- const interval = setInterval(() => router.refresh(), 4000);
- return () => clearInterval(interval);
- }, [hasInFlight, router]);
- return null;
-}
-
function SelectedTaskPanel({
selected,
agentSlug,
diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx
index ef1044d6..aeb2470e 100644
--- a/src/components/app-sidebar.tsx
+++ b/src/components/app-sidebar.tsx
@@ -32,6 +32,7 @@ import { ProjectSwitcher } from "./project-switcher";
import { PairedOpenclawPill } from "./paired-openclaw-pill";
import { AgentNav } from "./agent-nav";
import { CreateAgentButton } from "./create-agent-button";
+import { GlobalLivenessPoller } from "./global-liveness-poller";
import { Badge } from "@/components/ui/badge";
type NavItem = {
@@ -62,9 +63,15 @@ export async function AppSidebar() {
inFlightCounts[agentId] = count;
}
}
+ const anyInFlight = Object.values(inFlightCounts).some((n) => n > 0);
return (
<Sidebar collapsible="icon">
+ {/* Refresh the whole layout (this sidebar + the current route's
+ server components) every 5s while anything is in flight, so
+ badges + task groupings stay current no matter what page the
+ user is on. Self-disables when nothing is live. */}
+ <GlobalLivenessPoller hasInFlight={anyInFlight} />
<SidebarHeader>
{/* Project switcher + collapse toggle. Toggle stays visible in
icon-collapsed mode so the user can always re-expand the rail. */}
diff --git a/src/components/global-liveness-poller.tsx b/src/components/global-liveness-poller.tsx
new file mode 100644
index 00000000..ff9a593f
--- /dev/null
+++ b/src/components/global-liveness-poller.tsx
@@ -0,0 +1,30 @@
+"use client";
+
+import { useEffect } from "react";
+import { useRouter } from "next/navigation";
+
+/**
+ * Lives in the app sidebar (rendered on every route), so the sidebar's
+ * per-agent live-task badges + the per-page task list groups stay fresh
+ * no matter where the user is sitting — /home, /approvals, /tasks, an
+ * agent workspace, etc. — while something is in flight somewhere.
+ *
+ * Replaces the workspace-scoped AgentLivenessPoller. Same idea, just
+ * lifted to the layout level so non-workspace pages don't go stale.
+ *
+ * Cadence: 5 s while `hasInFlight` is true. The first refresh that lands
+ * a server-rendered `hasInFlight = false` flips the prop, the effect
+ * tears the interval down, and we stop spending requests on idle state.
+ * Paperclip uses 10 s + a WebSocket push for instant invalidation; at
+ * single-user local-CLI scale, 5 s polling is fine and one fewer moving
+ * part than a WS server.
+ */
+export function GlobalLivenessPoller({ hasInFlight }: { hasInFlight: boolean }) {
+ const router = useRouter();
+ useEffect(() => {
+ if (!hasInFlight) return;
+ const interval = setInterval(() => router.refresh(), 5_000);
+ return () => clearInterval(interval);
+ }, [hasInFlight, router]);
+ return null;
+}