Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: refetch list on revisit so agent-created automations appear (#805)

Hiep Lec34aa03273ce
diff --git a/__tests__/routes/automations-list.test.tsx b/__tests__/routes/automations-list.test.tsx
index d1dd6214a1..c052d83a62 100644
--- a/__tests__/routes/automations-list.test.tsx
+++ b/__tests__/routes/automations-list.test.tsx
@@ -71,12 +71,14 @@ const listResponse: AutomationsResponse = {
total: 1,
};
-function renderList() {
- const queryClient = new QueryClient({
- defaultOptions: { queries: { retry: false }, mutations: { retry: false } },
- });
+function renderList(queryClient?: QueryClient) {
+ const client =
+ queryClient ??
+ new QueryClient({
+ defaultOptions: { queries: { retry: false }, mutations: { retry: false } },
+ });
return render(
- <QueryClientProvider client={queryClient}>
+ <QueryClientProvider client={client}>
<ActiveBackendProvider>
<MemoryRouter initialEntries={["/automations"]}>
<AutomationsList />
@@ -314,3 +316,40 @@ describe("AutomationsList β€” Run now toasts", () => {
expect(displaySuccessToast).not.toHaveBeenCalled();
});
});
+
+describe("AutomationsList β€” list freshness on remount", () => {
+ it("surfaces automations created since the last visit without a manual refresh", async () => {
+ // Arrange β€” share a QueryClient across two mounts to simulate the user
+ // navigating away from /automations and back. Between the two mounts an
+ // agent has created a new automation, so the service starts returning
+ // it on the next call. Previously, the cached list was treated as fresh
+ // for 5 minutes and the second mount would have re-rendered the stale
+ // list without refetching.
+ const newAutomation: Automation = {
+ ...automation,
+ id: "auto-2",
+ name: "Hello World",
+ };
+ vi.mocked(AutomationService.getAutomations)
+ .mockReset()
+ .mockResolvedValueOnce(listResponse)
+ .mockResolvedValueOnce({
+ automations: [automation, newAutomation],
+ total: 2,
+ });
+ const queryClient = new QueryClient({
+ defaultOptions: { queries: { retry: false }, mutations: { retry: false } },
+ });
+
+ // Act β€” first mount lands on the original list, then unmount and remount
+ // against the same QueryClient (the cache the bug used to serve stale).
+ const first = renderList(queryClient);
+ await screen.findByText(automation.name);
+ first.unmount();
+ renderList(queryClient);
+
+ // Assert β€” the remount refetched and surfaced the newly created
+ // automation, which is the user-observable behavior the bug blocked.
+ await screen.findByText(newAutomation.name);
+ });
+});
diff --git a/src/hooks/query/use-automations.ts b/src/hooks/query/use-automations.ts
index 712323a71d..3d84670a19 100644
--- a/src/hooks/query/use-automations.ts
+++ b/src/hooks/query/use-automations.ts
@@ -26,7 +26,7 @@ export function useAutomations(options: UseAutomationsOptions = {}) {
active.orgId,
],
queryFn: () => AutomationService.getAutomations(limit, offset),
- staleTime: 5 * 60 * 1000,
+ staleTime: 0,
enabled,
});
}