π OpenHands: AI-Driven Development
fix: bound automation run-history fan-out and pause sidebar polling (#16867)
Hiep Lea3652270f632
diff --git a/__tests__/hooks/query/concurrency-limiter.test.ts b/__tests__/hooks/query/concurrency-limiter.test.tsnew file mode 100644index 0000000000..70e3b0dea2--- /dev/null+++ b/__tests__/hooks/query/concurrency-limiter.test.ts@@ -0,0 +1,93 @@+import { describe, expect, it } from "vitest";+import { ConcurrencyLimiter } from "#/hooks/query/concurrency-limiter";++/** A task whose completion the test controls. */+function deferred<T>() {+ let resolve!: (value: T) => void;+ let reject!: (reason: unknown) => void;+ const promise = new Promise<T>((res, rej) => {+ resolve = res;+ reject = rej;+ });+ return { promise, resolve, reject };+}++async function flushMicrotasks() {+ await Promise.resolve();+ await Promise.resolve();+}++describe("ConcurrencyLimiter", () => {+ it("runs at most `limit` tasks at once and starts queued tasks in FIFO order as slots free", async () => {+ // Arrange β five controllable tasks behind a limit of two.+ const limiter = new ConcurrencyLimiter(2);+ const started: number[] = [];+ const gates = [0, 1, 2, 3, 4].map(() => deferred<void>());+ const runs = gates.map((gate, index) =>+ limiter.run(() => {+ started.push(index);+ return gate.promise;+ }),+ );++ // Act & Assert β only the first two start; each completion admits the+ // next waiter in arrival order.+ await flushMicrotasks();+ expect(started).toEqual([0, 1]);++ gates[0].resolve();+ await flushMicrotasks();+ expect(started).toEqual([0, 1, 2]);++ gates[1].resolve();+ gates[2].resolve();+ await flushMicrotasks();+ expect(started).toEqual([0, 1, 2, 3, 4]);++ gates[3].resolve();+ gates[4].resolve();+ await expect(Promise.all(runs)).resolves.toBeDefined();+ });++ it("releases a slot when a task rejects, so later tasks still run", async () => {+ // Arrange β a single slot occupied by a failing task.+ const limiter = new ConcurrencyLimiter(1);++ // Act+ const failing = limiter.run(() => Promise.reject(new Error("boom")));++ // Assert β the failure propagates and the slot is free for the next task.+ await expect(failing).rejects.toThrow("boom");+ await expect(limiter.run(() => Promise.resolve("next"))).resolves.toBe(+ "next",+ );+ });++ it("rejects a task whose signal aborted while queued, without running it", async () => {+ // Arrange β one slot held open so the second task queues, then gets+ // aborted before a slot frees (a query unmounting while it waits).+ const limiter = new ConcurrencyLimiter(1);+ const gate = deferred<void>();+ const first = limiter.run(() => gate.promise);+ const controller = new AbortController();+ let queuedTaskRan = false;+ const queued = limiter.run(() => {+ queuedTaskRan = true;+ return Promise.resolve("ran");+ }, controller.signal);+ queued.catch(() => {}); // observed below; avoid an unhandled rejection++ // Act+ controller.abort();+ gate.resolve();++ // Assert β the aborted task rejects without executing, and its slot is+ // handed on to later work.+ await expect(queued).rejects.toThrow();+ expect(queuedTaskRan).toBe(false);+ await expect(limiter.run(() => Promise.resolve("after"))).resolves.toBe(+ "after",+ );+ await first;+ });+});diff --git a/__tests__/hooks/query/use-automation-run-summaries.test.tsx b/__tests__/hooks/query/use-automation-run-summaries.test.tsxindex ee356456bb..6387d6f9f4 100644--- a/__tests__/hooks/query/use-automation-run-summaries.test.tsx+++ b/__tests__/hooks/query/use-automation-run-summaries.test.tsx@@ -1,12 +1,14 @@-import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";-import { renderHook, waitFor } from "@testing-library/react";-import { QueryClientProvider, QueryClient } from "@tanstack/react-query";-import { useAutomationRunSummaries } from "#/hooks/query/use-automation-run-summaries";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import React from "react";+import { act, renderHook, waitFor } from "@testing-library/react";+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";import AutomationService from "#/api/automation-service/automation-service.api";+import { useAutomationRunSummaries } from "#/hooks/query/use-automation-run-summaries";import {AutomationRunStatus,type Automation,type AutomationRun,+ type AutomationRunsResponse,} from "#/types/automation";vi.mock("#/api/automation-service/automation-service.api", () => ({@@ -39,10 +41,26 @@ function makeRun(status: AutomationRunStatus): AutomationRun {};}+function makeAutomation(id: string): Automation {+ return {+ id,+ name: `Automation ${id}`,+ prompt: "p",+ trigger: { type: "schedule", schedule_human: "Daily" },+ enabled: true,+ repository: "acme/repo",+ model: "daily-profile",+ created_at: "2026-01-01T00:00:00Z",+ updated_at: "2026-01-01T00:00:00Z",+ };+}++const emptyRuns: AutomationRunsResponse = { runs: [], total: 0 };+function createWrapper() {- const queryClient = new QueryClient({- defaultOptions: { queries: { retry: false } },- });+ // No retry default override here: the hook's own `retry: false` is under+ // test, and a global override would mask a regression.+ const queryClient = new QueryClient();return ({ children }: { children: React.ReactNode }) => (<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>);@@ -128,3 +146,77 @@ describe("useAutomationRunSummaries β keeping an in-flight card current", () =expect(AutomationService.getAutomationRuns).toHaveBeenCalledTimes(1);});});++describe("useAutomationRunSummaries", () => {+ beforeEach(() => {+ vi.mocked(AutomationService.getAutomationRuns).mockReset();+ });++ it("keeps at most three runs requests in flight and starts the rest as responses arrive", async () => {+ // Arrange β five automations, each runs request held open by the test.+ const pending: Array<(response: AutomationRunsResponse) => void> = [];+ vi.mocked(AutomationService.getAutomationRuns).mockImplementation(+ () =>+ new Promise<AutomationRunsResponse>((resolve) => {+ pending.push(resolve);+ }),+ );+ const fanOut = ["a-1", "a-2", "a-3", "a-4", "a-5"].map(makeAutomation);++ // Act+ const { result } = renderHook(() => useAutomationRunSummaries(fanOut), {+ wrapper: createWrapper(),+ });++ // Assert β only three requests start despite five queries mounting.+ await waitFor(() => {+ expect(AutomationService.getAutomationRuns).toHaveBeenCalledTimes(3);+ });+ expect(AutomationService.getAutomationRuns).toHaveBeenCalledTimes(3);++ // One response frees a slot for exactly one queued request.+ await act(async () => {+ pending.shift()!(emptyRuns);+ });+ await waitFor(() => {+ expect(AutomationService.getAutomationRuns).toHaveBeenCalledTimes(4);+ });++ // Draining the rest completes the whole fan-out.+ await act(async () => {+ pending.splice(0).forEach((resolve) => resolve(emptyRuns));+ });+ await waitFor(() => {+ expect(AutomationService.getAutomationRuns).toHaveBeenCalledTimes(5);+ });+ await act(async () => {+ pending.splice(0).forEach((resolve) => resolve(emptyRuns));+ });+ await waitFor(() => {+ fanOut.forEach((automation) => {+ expect(result.current.get(automation.id)?.isLoading).toBe(false);+ });+ });+ });++ it("settles a failed summary into the error state without retrying", async () => {+ // Arrange β the runs request fails outright.+ vi.mocked(AutomationService.getAutomationRuns).mockRejectedValue(+ new Error("automation service unavailable"),+ );++ // Act+ const { result } = renderHook(+ () => useAutomationRunSummaries([makeAutomation("a-1")]),+ { wrapper: createWrapper() },+ );++ // Assert β the entry reports the error promptly (retries would keep it+ // loading for seconds) and the service was asked exactly once.+ await waitFor(() => {+ expect(result.current.get("a-1")?.isError).toBe(true);+ });+ expect(AutomationService.getAutomationRuns).toHaveBeenCalledTimes(1);+ expect(result.current.get("a-1")?.summary).toBeNull();+ });+});diff --git a/__tests__/hooks/query/use-automations-backend-switch.test.tsx b/__tests__/hooks/query/use-automations-backend-switch.test.tsxindex c2a711ec1e..585e60083f 100644--- a/__tests__/hooks/query/use-automations-backend-switch.test.tsx+++ b/__tests__/hooks/query/use-automations-backend-switch.test.tsx@@ -12,6 +12,7 @@ import {import { ActiveBackendProvider } from "#/contexts/active-backend-context";import {useAutomations,+ useCancelAutomationRun,useDispatchAutomation,useDeleteAutomation,useToggleAutomation,@@ -37,6 +38,7 @@ vi.mock("#/api/automation-service/automation-service.api", () => ({getAutomation: vi.fn(),getAutomationRuns: vi.fn(),dispatchAutomation: vi.fn(),+ cancelAutomationRun: vi.fn(),deleteAutomation: vi.fn(),updateAutomation: vi.fn(),toggleAutomation: vi.fn(),@@ -116,6 +118,10 @@ beforeEach(() => {vi.mocked(AutomationService.dispatchAutomation).mockResolvedValue(automationRun,);+ vi.mocked(AutomationService.cancelAutomationRun).mockReset();+ vi.mocked(AutomationService.cancelAutomationRun).mockResolvedValue(+ automationRun,+ );vi.mocked(AutomationService.deleteAutomation).mockReset();vi.mocked(AutomationService.updateAutomation).mockReset();vi.mocked(AutomationService.toggleAutomation).mockReset();@@ -252,6 +258,74 @@ describe("useAutomationRuns β polling", () => {);});+describe("run mutations β sidebar conversation refresh", () => {+ // The sidebar's conversation poll is paused on automation routes, so these+ // mutations are what keep the sidebar list current for a run's conversation.+ function makeClientWrapper() {+ const queryClient = new QueryClient({+ defaultOptions: { queries: { retry: false } },+ });+ function Wrapper({ children }: { children: React.ReactNode }) {+ return (+ <QueryClientProvider client={queryClient}>+ <ActiveBackendProvider>{children}</ActiveBackendProvider>+ </QueryClientProvider>+ );+ }+ return { queryClient, Wrapper };+ }++ const conversationsKey = [+ "user",+ "conversations",+ "paginated",+ 20,+ "local-1",+ null,+ ];++ it("invalidates the cached conversation list after a successful dispatch", async () => {+ // Arrange β a sidebar list already sits in the cache.+ const { queryClient, Wrapper } = makeClientWrapper();+ queryClient.setQueryData(conversationsKey, { pages: [], pageParams: [] });+ const { result } = renderHook(() => useDispatchAutomation(), {+ wrapper: Wrapper,+ });++ // Act+ await act(async () => {+ await result.current.mutateAsync("auto-1");+ });++ // Assert+ expect(queryClient.getQueryState(conversationsKey)?.isInvalidated).toBe(+ true,+ );+ });++ it("invalidates the cached conversation list after a successful cancel", async () => {+ // Arrange+ const { queryClient, Wrapper } = makeClientWrapper();+ queryClient.setQueryData(conversationsKey, { pages: [], pageParams: [] });+ const { result } = renderHook(() => useCancelAutomationRun(), {+ wrapper: Wrapper,+ });++ // Act+ await act(async () => {+ await result.current.mutateAsync({+ automationId: "auto-1",+ runId: "run-1",+ });+ });++ // Assert+ expect(queryClient.getQueryState(conversationsKey)?.isInvalidated).toBe(+ true,+ );+ });+});+describe("automation mutation hooks β analytics tracking", () => {it("captures automation_executed after a successful dispatch", async () => {const { result } = renderHook(() => useDispatchAutomation(), {diff --git a/__tests__/hooks/query/use-latest-automation-runs.test.tsx b/__tests__/hooks/query/use-latest-automation-runs.test.tsxnew file mode 100644index 0000000000..2315b30e1e--- /dev/null+++ b/__tests__/hooks/query/use-latest-automation-runs.test.tsx@@ -0,0 +1,90 @@+import { beforeEach, describe, expect, it, vi } from "vitest";+import React from "react";+import { act, renderHook, waitFor } from "@testing-library/react";+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import AutomationService from "#/api/automation-service/automation-service.api";+import { useLatestAutomationRuns } from "#/hooks/query/use-latest-automation-runs";+import type { Automation, AutomationRunsResponse } from "#/types/automation";++vi.mock("#/api/automation-service/automation-service.api", () => ({+ default: {+ getAutomationRuns: vi.fn(),+ },+}));++vi.mock("#/contexts/active-backend-context", () => ({+ useActiveBackend: () => ({+ backend: { id: "test-backend", kind: "local" },+ orgId: null,+ }),+}));++function makeAutomation(id: string): Automation {+ return {+ id,+ name: `Automation ${id}`,+ prompt: "p",+ trigger: { type: "schedule", schedule_human: "Daily" },+ enabled: true,+ repository: "acme/repo",+ model: "daily-profile",+ created_at: "2026-01-01T00:00:00Z",+ updated_at: "2026-01-01T00:00:00Z",+ };+}++const emptyRuns: AutomationRunsResponse = { runs: [], total: 0 };++function createWrapper() {+ const queryClient = new QueryClient({+ defaultOptions: { queries: { retry: false } },+ });+ return ({ children }: { children: React.ReactNode }) => (+ <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>+ );+}++describe("useLatestAutomationRuns", () => {+ beforeEach(() => {+ vi.mocked(AutomationService.getAutomationRuns).mockReset();+ });++ it("keeps at most three runs requests in flight across the home fan-out", async () => {+ // Arrange β five automations, each runs request held open by the test.+ const pending: Array<(response: AutomationRunsResponse) => void> = [];+ vi.mocked(AutomationService.getAutomationRuns).mockImplementation(+ () =>+ new Promise<AutomationRunsResponse>((resolve) => {+ pending.push(resolve);+ }),+ );+ const automations = ["a-1", "a-2", "a-3", "a-4", "a-5"].map(makeAutomation);++ // Act+ const { result } = renderHook(() => useLatestAutomationRuns(automations), {+ wrapper: createWrapper(),+ });++ // Assert β only three requests start; the rest follow as responses free+ // slots, until every automation's state settles.+ await waitFor(() => {+ expect(AutomationService.getAutomationRuns).toHaveBeenCalledTimes(3);+ });+ expect(AutomationService.getAutomationRuns).toHaveBeenCalledTimes(3);++ await act(async () => {+ pending.splice(0).forEach((resolve) => resolve(emptyRuns));+ });+ await waitFor(() => {+ expect(AutomationService.getAutomationRuns).toHaveBeenCalledTimes(5);+ });+ await act(async () => {+ pending.splice(0).forEach((resolve) => resolve(emptyRuns));+ });+ await waitFor(() => {+ automations.forEach((automation) => {+ expect(result.current.get(automation.id)?.isLoading).toBe(false);+ });+ });+ });+});diff --git a/__tests__/hooks/query/use-paginated-conversations.test.tsx b/__tests__/hooks/query/use-paginated-conversations.test.tsxnew file mode 100644index 0000000000..518e519bec--- /dev/null+++ b/__tests__/hooks/query/use-paginated-conversations.test.tsx@@ -0,0 +1,101 @@+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import React from "react";+import { act, renderHook } from "@testing-library/react";+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import AgentServerConversationService from "#/api/conversation-service/agent-server-conversation-service.api";+import { NavigationProvider } from "#/context/navigation-context";+import { usePaginatedConversations } from "#/hooks/query/use-paginated-conversations";+import type { AppConversationPage } from "#/api/conversation-service/agent-server-conversation-service.types";++vi.mock(+ "#/api/conversation-service/agent-server-conversation-service.api",+ () => ({+ default: {+ searchConversations: vi.fn(),+ },+ }),+);++vi.mock("#/contexts/active-backend-context", () => ({+ useActiveBackend: () => ({+ backend: { id: "test-backend", kind: "local" },+ orgId: null,+ }),+}));++const emptyPage: AppConversationPage = { items: [], next_page_id: null };++function createWrapper(currentPath: string) {+ const queryClient = new QueryClient({+ defaultOptions: { queries: { retry: false } },+ });+ const navigation = {+ currentPath,+ conversationId: null,+ isNavigating: false,+ navigate: () => {},+ };+ return ({ children }: { children: React.ReactNode }) => (+ <QueryClientProvider client={queryClient}>+ <NavigationProvider value={navigation}>{children}</NavigationProvider>+ </QueryClientProvider>+ );+}++/** Flush timers and the promise work they unblock inside act. */+async function flushAsync(ms = 0) {+ await act(async () => {+ await vi.advanceTimersByTimeAsync(ms);+ });+}++describe("usePaginatedConversations β interval polling", () => {+ beforeEach(() => {+ vi.useFakeTimers();+ vi.mocked(AgentServerConversationService.searchConversations).mockReset();+ vi.mocked(+ AgentServerConversationService.searchConversations,+ ).mockResolvedValue(emptyPage);+ });++ afterEach(() => {+ vi.useRealTimers();+ });++ it("fetches once but does not interval-poll while an automations route is open", async () => {+ // Arrange & Act β mount the sidebar list on the automations route.+ renderHook(() => usePaginatedConversations(), {+ wrapper: createWrapper("/automations"),+ });+ await flushAsync();+ await flushAsync();++ // Assert β the initial fetch happened, and a full poll window later no+ // further request has fired.+ expect(+ AgentServerConversationService.searchConversations,+ ).toHaveBeenCalledTimes(1);+ await flushAsync(31_000);+ expect(+ AgentServerConversationService.searchConversations,+ ).toHaveBeenCalledTimes(1);+ });++ it("keeps the 30s poll on routes outside the automation surface", async () => {+ // Arrange & Act+ renderHook(() => usePaginatedConversations(), {+ wrapper: createWrapper("/"),+ });+ await flushAsync();+ await flushAsync();+ expect(+ AgentServerConversationService.searchConversations,+ ).toHaveBeenCalledTimes(1);++ // Assert β one poll window later the list refreshed.+ await flushAsync(31_000);+ expect(+ AgentServerConversationService.searchConversations,+ ).toHaveBeenCalledTimes(2);+ });+});diff --git a/__tests__/manifests/automation-interface.test.ts b/__tests__/manifests/automation-interface.test.tsindex 385dfaff4d..ade56a4924 100644--- a/__tests__/manifests/automation-interface.test.ts+++ b/__tests__/manifests/automation-interface.test.ts@@ -48,6 +48,29 @@ describe("the automation interface seam", () => {});});+ it("classifies pathnames inside and outside the automation surface", async () => {+ // Arrange β routes are the host's own registrations, so the matcher+ // answers with or without an admitted manifest.+ const seam = await loadSeam(undefined);++ // Act & Assert+ expect({+ list: seam.isAutomationsRoute("/automations"),+ detail: seam.isAutomationsRoute("/automations/abc-123"),+ templates: seam.isAutomationsRoute("/automations/templates"),+ home: seam.isAutomationsRoute("/"),+ conversation: seam.isAutomationsRoute("/conversations/abc-123"),+ lookalike: seam.isAutomationsRoute("/automations-foo"),+ }).toEqual({+ list: true,+ detail: true,+ templates: true,+ home: false,+ conversation: false,+ lookalike: false,+ });+ });+it("serves an admitted manifest's data", async () => {// Arrangeconst seam = await loadSeam(createInterfaceManifest());diff --git a/src/hooks/query/concurrency-limiter.ts b/src/hooks/query/concurrency-limiter.tsnew file mode 100644index 0000000000..d5091ae444--- /dev/null+++ b/src/hooks/query/concurrency-limiter.ts@@ -0,0 +1,55 @@+/**+ * A FIFO promise semaphore: at most `limit` wrapped tasks run at once; the+ * rest wait in arrival order. Wrap a queryFn's work in `run` to bound how many+ * of a query family's requests are in flight simultaneously.+ */+export class ConcurrencyLimiter {+ private active = 0;++ private readonly queue: Array<() => void> = [];++ constructor(private readonly limit: number) {}++ async run<T>(task: () => Promise<T>, signal?: AbortSignal): Promise<T> {+ await this.acquire();+ try {+ // A query cancelled while queued (e.g. its last observer unmounted)+ // frees its slot without ever hitting the network.+ if (signal?.aborted) {+ throw signal.reason ?? new DOMException("Aborted", "AbortError");+ }+ return await task();+ } finally {+ this.release();+ }+ }++ private acquire(): Promise<void> {+ if (this.active < this.limit) {+ this.active += 1;+ return Promise.resolve();+ }+ return new Promise((resolve) => {+ this.queue.push(resolve);+ });+ }++ private release(): void {+ const next = this.queue.shift();+ if (next) {+ // The waiter inherits the released slot directly, so `active` stays put.+ next();+ } else {+ this.active -= 1;+ }+ }+}++/**+ * Shared by every per-automation runs query: the dashboard and home page each+ * fan out one GET .../runs request per automation, which can exhaust the+ * automation service's DB connection pool (~15 connections) and stall every+ * request for the pool's 30s acquisition timeout. Three in flight keeps the+ * surfaces responsive without saturating the pool.+ */+export const automationRunRequestsLimiter = new ConcurrencyLimiter(3);diff --git a/src/hooks/query/use-automation-run-summaries.ts b/src/hooks/query/use-automation-run-summaries.tsindex 0465362040..92070faab3 100644--- a/src/hooks/query/use-automation-run-summaries.ts+++ b/src/hooks/query/use-automation-run-summaries.ts@@ -1,6 +1,7 @@import { useQueries } from "@tanstack/react-query";import AutomationService from "#/api/automation-service/automation-service.api";import { useActiveBackend } from "#/contexts/active-backend-context";+import { automationRunRequestsLimiter } from "#/hooks/query/concurrency-limiter";import { AUTOMATION_RUNS_QUERY_KEY } from "#/hooks/query/use-automation-detail";import {summarizeAutomationRuns,@@ -58,13 +59,25 @@ export function useAutomationRunSummaries(active.backend.id,active.orgId,],- queryFn: () =>- AutomationService.getAutomationRuns(- automation.id,- RECENT_RUN_SAMPLE_SIZE,- 0,+ queryFn: ({ signal }: { signal: AbortSignal }) =>+ automationRunRequestsLimiter.run(+ () =>+ AutomationService.getAutomationRuns(+ automation.id,+ RECENT_RUN_SAMPLE_SIZE,+ 0,+ ),+ signal,),staleTime: 60 * 1000,+ // No retries and no focus refetch: a failed summary settles into the+ // dashboard's degraded "unknown" health state instead of hammering an+ // unhealthy automation service (mirrors useLatestAutomationRuns).+ retry: false,+ refetchOnWindowFocus: false,+ // isError already renders as the degraded indicator; a failing fan-out+ // must not raise one global error toast per automation.+ meta: { disableToast: true },enabled: enabled && !!automation.id,refetchInterval: (query: {state: { data?: AutomationRunsResponse };diff --git a/src/hooks/query/use-automations.ts b/src/hooks/query/use-automations.tsindex 60b5000738..f4ac927583 100644--- a/src/hooks/query/use-automations.ts+++ b/src/hooks/query/use-automations.ts@@ -103,6 +103,10 @@ export function useDispatchAutomation() {queryClient.invalidateQueries({queryKey: [...AUTOMATION_RUNS_QUERY_KEY, id],});+ // Runs carry a conversation_id surfaced in the sidebar, and the+ // conversation poll is paused on automation routes, so refresh the list+ // explicitly (same prefix all conversation mutations invalidate).+ queryClient.invalidateQueries({ queryKey: ["user", "conversations"] });trackAutomationExecuted({ backendKind: active.backend.kind });},});@@ -119,6 +123,9 @@ export function useCancelAutomationRun() {queryClient.invalidateQueries({queryKey: [...AUTOMATION_RUNS_QUERY_KEY, automationId],});+ // Same staleness hole as dispatch: the cancelled run's conversation+ // shows in the sidebar while the poll is paused on automation routes.+ queryClient.invalidateQueries({ queryKey: ["user", "conversations"] });},});}diff --git a/src/hooks/query/use-latest-automation-runs.ts b/src/hooks/query/use-latest-automation-runs.tsindex f67718bf1e..e0c922ddcc 100644--- a/src/hooks/query/use-latest-automation-runs.ts+++ b/src/hooks/query/use-latest-automation-runs.ts@@ -1,6 +1,7 @@import { useQueries } from "@tanstack/react-query";import AutomationService from "#/api/automation-service/automation-service.api";import { useActiveBackend } from "#/contexts/active-backend-context";+import { automationRunRequestsLimiter } from "#/hooks/query/concurrency-limiter";import {AutomationRunStatus,type Automation,@@ -53,11 +54,15 @@ export function useLatestAutomationRuns(active.backend.id,active.orgId,],- queryFn: () =>- AutomationService.getAutomationRuns(- automation.id,- AUTOMATION_RUN_ACTIVITY_LIMIT,- 0,+ queryFn: ({ signal }: { signal: AbortSignal }) =>+ automationRunRequestsLimiter.run(+ () =>+ AutomationService.getAutomationRuns(+ automation.id,+ AUTOMATION_RUN_ACTIVITY_LIMIT,+ 0,+ ),+ signal,),staleTime: 60 * 1000,// No retries: the home section settles into its degraded "unknown"diff --git a/src/hooks/query/use-paginated-conversations.ts b/src/hooks/query/use-paginated-conversations.tsindex 50f087ed67..460dfdb463 100644--- a/src/hooks/query/use-paginated-conversations.ts+++ b/src/hooks/query/use-paginated-conversations.ts@@ -2,12 +2,15 @@ import { useInfiniteQuery } from "@tanstack/react-query";import AgentServerConversationService from "#/api/conversation-service/agent-server-conversation-service.api";import { useIsAuthed } from "./use-is-authed";import { isNoBackend } from "#/api/backend-registry/active-store";+import { useNavigation } from "#/context/navigation-context";import { useActiveBackend } from "#/contexts/active-backend-context";+import { isAutomationsRoute } from "#/manifests/automation-interface";import { AppConversationPage } from "#/api/conversation-service/agent-server-conversation-service.types";export const usePaginatedConversations = (limit: number = 20) => {const { data: userIsAuthenticated } = useIsAuthed();const active = useActiveBackend();+ const { currentPath } = useNavigation();const hasBackend = !isNoBackend(active.backend);return useInfiniteQuery({@@ -42,7 +45,14 @@ export const usePaginatedConversations = (limit: number = 20) => {// skeletons) on `isLoading`, not `isFetching` β `isFetching` flips back to// true on every background refetch, which would cause the skeleton to// flicker on each poll when the list is empty.- refetchInterval: 30_000,+ //+ // The interval is paused on automation routes: the dashboard there already+ // fans out one runs request per automation, and the sidebar list is not+ // the focus. Only the poll pauses β the initial fetch still happens β and+ // mutations that create or cancel runs invalidate ["user", "conversations"]+ // so the sidebar stays correct while paused.+ refetchInterval: isAutomationsRoute(currentPath) ? false : 30_000,+ refetchIntervalInBackground: false,// A successful fetch proves the backend is reachable. The global// QueryCache onSuccess handler reads this to clear any persisted// failure state, re-arming the status dot without user intervention.diff --git a/src/manifests/automation-interface.ts b/src/manifests/automation-interface.tsindex cce175f13f..18b04ab70e 100644--- a/src/manifests/automation-interface.ts+++ b/src/manifests/automation-interface.ts@@ -125,6 +125,17 @@ export function automationTemplatesPath(): string {return MOUNTED_ROUTES.templates;}+/**+ * Whether `path` (a location pathname) is inside the automation surface: the+ * list route itself or anything nested under it (detail, setup, templates,+ * git-sync). Prefix-safe: "/automations-foo" does not match.+ */+export function isAutomationsRoute(path: string): boolean {+ return (+ path === MOUNTED_ROUTES.list || path.startsWith(`${MOUNTED_ROUTES.list}/`)+ );+}+/*** A declared endpoint path. Empty for one the manifest may omit - the two a* bundle needs were added after the block shipped - so a caller that needs one