Open-source SEO, GEO, and marketing skills for AI agents.
fix(workspace): refresh on every in-flight poll, tighten liveness cadence
Yuting Zhong086637e89568
diff --git a/src/components/agent-task-workspace.tsx b/src/components/agent-task-workspace.tsxindex ee8e9d71..e7f9617f 100644--- a/src/components/agent-task-workspace.tsx+++ b/src/components/agent-task-workspace.tsx@@ -278,24 +278,26 @@ function SelectedTaskPanel({}) {const router = useRouter();const isInFlight = TASK_IN_FLIGHT.includes(selected.task.status);- // Each time polling returns new events we refresh the server tree so- // the status badge in this panel's header + the task list grouping- // catch up to the JSONL — the LiveTranscript handles its own rendering- // updates, this hook just rebroadcasts to the rest of the page.+ // We refresh the server tree on every in-flight poll so the status+ // badge + sidebar in-flight counters track the DB even when nothing+ // has landed in the JSONL transcript yet.//- // Double-refresh: when the agent emits its final reply (with the- // <task_status>done</task_status> block), the JSONL bytes can land- // BEFORE processOrchestrationBlocks runs the DB status flip. The- // 600ms delayed refresh catches that follow-up DB write so the badge- // updates without the user having to manually reload.+ // Why: OpenClaw doesn't flush the JSONL file until session.ended —+ // a long-running audit can spend minutes calling MCP tools (which+ // update the DB synchronously) while the JSONL stays empty. If we+ // only refresh on `newEvents > 0`, the badge stays stuck on+ // "Working" until the very end of the session even though the+ // agent already called submit_task_status seconds earlier. Polling+ // is cheap (every 800ms in-flight, 2s otherwise) and the refresh+ // is RSC-only.+ //+ // When the task is terminal AND the poll returned no new events,+ // we stop polling — the transcript is fully drained.const onPolled = useCallback(({ newEvents }: { newEvents: number; fileSize: number }) => {- if (newEvents > 0) {+ if (newEvents > 0 || isInFlight) {router.refresh();- setTimeout(() => router.refresh(), 600);}- // Return true to stop polling once the task is terminal AND the- // poll returned nothing new (transcript fully drained).if (!isInFlight && newEvents === 0) return true;return false;},diff --git a/src/components/global-liveness-poller.test.tsx b/src/components/global-liveness-poller.test.tsxindex eb9e1feb..eb88d469 100644--- a/src/components/global-liveness-poller.test.tsx+++ b/src/components/global-liveness-poller.test.tsx@@ -34,19 +34,19 @@ describe("GlobalLivenessPoller", () => {expect(refresh).not.toHaveBeenCalled();});- it("polls router.refresh() every 5 seconds while hasInFlight is true", () => {+ it("polls router.refresh() every 2 seconds while hasInFlight is true", () => {render(<GlobalLivenessPoller hasInFlight={true} />);expect(refresh).not.toHaveBeenCalled();act(() => {- vi.advanceTimersByTime(5_000);+ vi.advanceTimersByTime(2_000);});expect(refresh).toHaveBeenCalledTimes(1);act(() => {- vi.advanceTimersByTime(5_000);+ vi.advanceTimersByTime(2_000);});expect(refresh).toHaveBeenCalledTimes(2);act(() => {- vi.advanceTimersByTime(5_000);+ vi.advanceTimersByTime(2_000);});expect(refresh).toHaveBeenCalledTimes(3);});@@ -54,7 +54,7 @@ describe("GlobalLivenessPoller", () => {it("tears the interval down when hasInFlight flips to false", () => {const { rerender } = render(<GlobalLivenessPoller hasInFlight={true} />);act(() => {- vi.advanceTimersByTime(5_000);+ vi.advanceTimersByTime(2_000);});expect(refresh).toHaveBeenCalledTimes(1);rerender(<GlobalLivenessPoller hasInFlight={false} />);@@ -67,7 +67,7 @@ describe("GlobalLivenessPoller", () => {it("clears the interval on unmount so no stray refreshes fire", () => {const { unmount } = render(<GlobalLivenessPoller hasInFlight={true} />);act(() => {- vi.advanceTimersByTime(5_000);+ vi.advanceTimersByTime(2_000);});expect(refresh).toHaveBeenCalledTimes(1);unmount();@@ -85,7 +85,7 @@ describe("GlobalLivenessPoller", () => {expect(refresh).not.toHaveBeenCalled();rerender(<GlobalLivenessPoller hasInFlight={true} />);act(() => {- vi.advanceTimersByTime(5_000);+ vi.advanceTimersByTime(2_000);});expect(refresh).toHaveBeenCalledTimes(1);});diff --git a/src/components/global-liveness-poller.tsx b/src/components/global-liveness-poller.tsxindex ff9a593f..57c35e0e 100644--- a/src/components/global-liveness-poller.tsx+++ b/src/components/global-liveness-poller.tsx@@ -12,18 +12,20 @@ import { useRouter } from "next/navigation";* 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+ * Cadence: 2 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.+ * single-user local-CLI scale, 2 s polling keeps the sidebar badges+ * responsive without adding a WS server. The workspace's+ * AgentTaskWorkspace also refreshes on every in-flight transcript poll,+ * so the active task workspace itself is closer to ~800 ms.*/export function GlobalLivenessPoller({ hasInFlight }: { hasInFlight: boolean }) {const router = useRouter();useEffect(() => {if (!hasInFlight) return;- const interval = setInterval(() => router.refresh(), 5_000);+ const interval = setInterval(() => router.refresh(), 2_000);return () => clearInterval(interval);}, [hasInFlight, router]);return null;