Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: auto-clear backend health on successful conversation list fetch (#647)

Tim O'Farrell9c1ae1987841
diff --git a/src/hooks/query/use-paginated-conversations.ts b/src/hooks/query/use-paginated-conversations.ts
index 0f668ccdb0..bfcaeca5d1 100644
--- a/src/hooks/query/use-paginated-conversations.ts
+++ b/src/hooks/query/use-paginated-conversations.ts
@@ -38,5 +38,9 @@ export const usePaginatedConversations = (limit: number = 20) => {
// flips back to true on every background refetch, which would cause the
// skeleton to flicker every 10s when the list is empty.
refetchInterval: 10_000,
+ // 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.
+ meta: { backendId: active.backend.id },
});
};
diff --git a/src/query-client-config.ts b/src/query-client-config.ts
index 0f75e9269d..a4d832479e 100644
--- a/src/query-client-config.ts
+++ b/src/query-client-config.ts
@@ -4,6 +4,7 @@ import i18n from "#/i18n";
import { I18nKey } from "./i18n/declaration";
import { retrieveAxiosErrorMessage } from "./utils/retrieve-axios-error-message";
import { displayErrorToast } from "./utils/custom-toast-handlers";
+import { recordBackendSuccess } from "#/api/backend-registry/health-store";
const handle401Error = (error: AxiosError, client: QueryClient) => {
if (error?.response?.status === 401 || error?.status === 401) {
@@ -16,6 +17,13 @@ const shownErrors = new Set<string>();
export const createAgentServerQueryClient = () => {
const client = new QueryClient({
queryCache: new QueryCache({
+ onSuccess: (_data, query) => {
+ const backendId =
+ query.meta?.backendId ?? query.options.meta?.backendId;
+ if (typeof backendId === "string") {
+ recordBackendSuccess(backendId);
+ }
+ },
onError: (error, query) => {
const isAuthQuery =
query.queryKey[0] === "user" && query.queryKey[1] === "authenticated";
diff --git a/src/types/react-query.d.ts b/src/types/react-query.d.ts
index 870623edb2..e3f9dcb63f 100644
--- a/src/types/react-query.d.ts
+++ b/src/types/react-query.d.ts
@@ -3,6 +3,13 @@ import type { AxiosError } from "axios";
interface MyMeta extends Record<string, unknown> {
disableToast?: boolean;
+ /**
+ * When set on a query that targets a specific local backend, a successful
+ * fetch automatically clears that backend's failure counter in the health
+ * store β€” re-arming the status dot without requiring the user to edit the
+ * backend's config.
+ */
+ backendId?: string;
}
declare module "@tanstack/react-query" {