Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(frontend): reset plan-detail poller backoff after task actions (#20732)

boojack047b31d8e91c
diff --git a/frontend/src/react/pages/project/plan-detail/shell/hooks/usePlanDetailPage.ts b/frontend/src/react/pages/project/plan-detail/shell/hooks/usePlanDetailPage.ts
index 7222a8a6f3..dce3084931 100644
--- a/frontend/src/react/pages/project/plan-detail/shell/hooks/usePlanDetailPage.ts
+++ b/frontend/src/react/pages/project/plan-detail/shell/hooks/usePlanDetailPage.ts
@@ -212,7 +212,7 @@ export const usePlanDetailPage = ({
[syncDefaultActivePhases]
);
- const refreshState = useCallback(async () => {
+ const fetchState = useCallback(async () => {
try {
setIsRefreshing(true);
const current = latestSnapshotRef.current;
@@ -292,11 +292,20 @@ export const usePlanDetailPage = ({
);
}, [snapshot.rollout]);
- usePolling({
+ const { restart: restartPolling } = usePolling({
enabled: snapshot.ready && !snapshot.isCreating && !isPlanDone,
- refreshState,
+ refreshState: fetchState,
});
+ // Public refresh used by user actions (run/skip/cancel a task, edits, etc.).
+ // It fetches immediately and then resets the poll backoff so the follow-up
+ // status transition (e.g. a task moving PENDING -> RUNNING) is observed on
+ // the next ~1s tick instead of waiting out the current backoff interval.
+ const refreshState = useCallback(async () => {
+ await fetchState();
+ restartPolling();
+ }, [fetchState, restartPolling]);
+
return useDerivedPlanState({
snapshot,
isEditing,
diff --git a/frontend/src/react/pages/project/plan-detail/shell/hooks/usePolling.ts b/frontend/src/react/pages/project/plan-detail/shell/hooks/usePolling.ts
index e28710d907..4ca430951f 100644
--- a/frontend/src/react/pages/project/plan-detail/shell/hooks/usePolling.ts
+++ b/frontend/src/react/pages/project/plan-detail/shell/hooks/usePolling.ts
@@ -7,8 +7,24 @@ export interface UsePollingParams {
refreshState: () => Promise<void>;
}
-export function usePolling({ enabled, refreshState }: UsePollingParams): void {
+export interface UsePollingResult {
+ // Reset the backoff and poll again from the minimum interval. Call this
+ // after a user-triggered mutation (run/skip/cancel a task, etc.) so the UI
+ // watches closely for the resulting status transition instead of waiting out
+ // the current (possibly maxed-out) backoff interval.
+ restart: () => void;
+}
+
+export function usePolling({
+ enabled,
+ refreshState,
+}: UsePollingParams): UsePollingResult {
const pollTimerRef = useRef<number | undefined>(undefined);
+ // `active` mirrors the effect's mounted+enabled lifetime so a late-resolving
+ // refreshState (or a `restart` racing an unmount) cannot schedule a new poll.
+ const activeRef = useRef(false);
+ const refreshStateRef = useRef(refreshState);
+ refreshStateRef.current = refreshState;
const stopPolling = useCallback(() => {
if (!pollTimerRef.current) {
@@ -18,15 +34,8 @@ export function usePolling({ enabled, refreshState }: UsePollingParams): void {
pollTimerRef.current = undefined;
}, []);
- useEffect(() => {
- if (!enabled) {
- stopPolling();
- return;
- }
-
- let canceled = false;
-
- const poll = (interval: number) => {
+ const scheduleNext = useCallback(
+ (interval: number) => {
stopPolling();
const nextInterval = minmax(
interval +
@@ -37,24 +46,43 @@ export function usePolling({ enabled, refreshState }: UsePollingParams): void {
);
pollTimerRef.current = window.setTimeout(async () => {
- if (canceled) {
+ if (!activeRef.current) {
return;
}
- await refreshState().catch(() => undefined);
- if (canceled) {
+ await refreshStateRef.current().catch(() => undefined);
+ if (!activeRef.current) {
return;
}
- poll(
+ scheduleNext(
Math.min(nextInterval * POLLER_INTERVAL.growth, POLLER_INTERVAL.max)
);
}, nextInterval);
- };
+ },
+ [stopPolling]
+ );
- poll(POLLER_INTERVAL.min);
+ const restart = useCallback(() => {
+ if (!activeRef.current) {
+ return;
+ }
+ scheduleNext(POLLER_INTERVAL.min);
+ }, [scheduleNext]);
+
+ useEffect(() => {
+ if (!enabled) {
+ activeRef.current = false;
+ stopPolling();
+ return;
+ }
+
+ activeRef.current = true;
+ scheduleNext(POLLER_INTERVAL.min);
return () => {
- canceled = true;
+ activeRef.current = false;
stopPolling();
};
- }, [enabled, refreshState, stopPolling]);
+ }, [enabled, scheduleNext, stopPolling]);
+
+ return { restart };
}