Skip to content

Frontend Real-time Integration: Global Stats & Planning #802

Closed

Description

@propr-dev

Context

To fully eliminate polling, we need to migrate the remaining components: Header Stats (global task monitoring) and Plan Generation (draft updates).

Requirements

  1. Migrate useGenerationPolling: Replace the 1-second interval polling with draft:update event listening. It should still fetch the full draft on update to get the trace details.
  2. Migrate useHeaderStats: Listen for task:update events. Since header stats are global (counts, lists), any task update should trigger a refresh of the stats.
  3. Refactor Dashboard: The Dashboard component uses useHeaderStats implicitly for some data or its own polling. Ensure it uses the new event-driven approach.

Implementation Specification

1. Generation Polling

  • In gitfix-ui/src/hooks/useGenerationPolling.ts, remove setInterval.
  • Add useEffect listening for SocketEvents.DRAFT_UPDATE.
  • When an update for the current draftId arrives, fetch the draft and update state (generationTrace, isGenerating).

2. Header Stats

  • In gitfix-ui/src/hooks/useHeaderStats.ts, remove the polling interval.
  • Add useEffect listening for SocketEvents.TASK_UPDATE and SocketEvents.QUEUE_UPDATE (if available, otherwise task updates are a good proxy).
  • Trigger fetchStats on these events.

Acceptance Criteria

  • Plan generation wizard shows progress bars updating in real-time without network tab spamming.
  • Global header counters (Active Tasks, Plans) update automatically when tasks change state.
  • No setInterval polling remains in the primary user flows.

Created by GitFix AI Planner

Activity

  1. propr-dev commented on Feb 17, 2026

    @propr-dev
    ContributorAuthor

    Suggested Implementation:

    File: gitfix-ui/src/hooks/useGenerationPolling.ts

    --- a/gitfix-ui/src/hooks/useGenerationPolling.ts
    +++ b/gitfix-ui/src/hooks/useGenerationPolling.ts
    @@ -2,2 +2,3 @@
     import { getDraft, GenerationTrace } from '../api/gitfixApi';
    +import { useSocket, SocketEvents } from '../contexts/SocketContext';
     
    @@ -16,2 +17,3 @@
       const [generationError, setGenerationError] = useState<string | null>(null);
    +  const { socket } = useSocket();
       const pollingIntervalRef = useRef<ReturnType<typeof setInterval> | null>(null);
    @@ -30,2 +32,3 @@
         setIsGenerating(true);
    +    setGenerationTrace(undefined);
         setGenerationError(null);
    @@ -33,26 +36,36 @@
    -    pollingIntervalRef.current = setInterval(async () => {
    -      try {
    -        const updatedDraft = await getDraft(draftId);
    -        if (updatedDraft.generation_trace) {
    -          setGenerationTrace(updatedDraft.generation_trace);
    -          // Check for error in generation trace
    -          const trace = updatedDraft.generation_trace as GenerationTrace & { error?: string };
    -          if (trace.error) {
    -            stopPolling();
    -            setGenerationError(trace.error);
    -            setIsGenerating(false);
    -            return;
    -          }
    -        }
    -        // Check if generation completed (status changed to 'review')
    -        if (updatedDraft.status === 'review') {
    -          stopPolling();
    -          onComplete();
    -        }
    -        // Check if generation failed (status went back to 'draft')
    -        if (updatedDraft.status === 'draft') {
    -          stopPolling();
    -          const trace = updatedDraft.generation_trace as GenerationTrace & { error?: string };
    -          setGenerationError(trace?.error || 'Plan generation failed');
    -          setIsGenerating(false);
    -        }
    -      } catch (e) {
    -        console.error('Failed to poll draft status:', e);
    +    // Initial fetch to get started
    +    fetchDraftStatus();
    +  }, []);
    +
    +  const fetchDraftStatus = useCallback(async () => {
    +    try {
    +      const updatedDraft = await getDraft(draftId);
    +      if (updatedDraft.generation_trace) {
    +        setGenerationTrace(updatedDraft.generation_trace);
    +        // Check for error
    +        const trace = updatedDraft.generation_trace as GenerationTrace & { error?: string };
    +        if (trace.error) {
    +          setGenerationError(trace.error);
    +          setIsGenerating(false);
    +          return;
    +        }
           }
    -    }, 1000);
    -  }, [draftId, onComplete, stopPolling]);
    +      if (updatedDraft.status === 'review') {
    +        setIsGenerating(false);
    +        onComplete();
    +      } else if (updatedDraft.status === 'draft' && isGenerating) {
    +        // Failed case (reverted to draft)
    +        const trace = updatedDraft.generation_trace as GenerationTrace & { error?: string };
    +        setGenerationError(trace?.error || 'Plan generation failed');
    +        setIsGenerating(false);
    +      }
    +    } catch (e) {
    +      console.error('Failed to fetch draft status:', e);
    +    }
    +  }, [draftId, onComplete, isGenerating]);
     
    -  // Cleanup on unmount
       useEffect(() => {
    -    return () => {
    -      stopPolling();
    -    };
    -  }, [stopPolling]);
    +    if (!socket || !isGenerating) return;
    +
    +    const handleUpdate = (data: { draftId: string }) => {
    +      if (data.draftId === draftId) {
    +        fetchDraftStatus();
    +      }
    +    };
    +
    +    socket.on(SocketEvents.DRAFT_UPDATE, handleUpdate);
    +    return () => { socket.off(SocketEvents.DRAFT_UPDATE, handleUpdate); };
    +  }, [socket, isGenerating, draftId, fetchDraftStatus]);
     

    File: gitfix-ui/src/hooks/useHeaderStats.ts

    --- a/gitfix-ui/src/hooks/useHeaderStats.ts
    +++ b/gitfix-ui/src/hooks/useHeaderStats.ts
    @@ -3,2 +3,3 @@
     import { getDrafts, DraftListItem } from '../api/plannerApi';
    +import { useSocket, SocketEvents } from '../contexts/SocketContext';
     
    @@ -13,5 +14,2 @@
    -const DISMISSED_TASK_TIMESTAMPS_KEY = 'dismissed_task_timestamps';
    -
    -// Polling interval in milliseconds
    -const POLLING_INTERVAL = 5000;
    +const DISMISSED_TASK_TIMESTAMPS_KEY = 'dismissed_task_timestamps';
     
    @@ -156,2 +154,3 @@
       const [error, setError] = useState<string | null>(null);
    +  const { socket } = useSocket();
     
    @@ -370,17 +369,18 @@
     
    -  // Initial load and polling setup
    +  // Initial load and socket subscription
       useEffect(() => {
         isMountedRef.current = true;
    -    
         fetchStats(true);
     
    -    // Set up polling
    -    const intervalId = setInterval(() => {
    -      fetchStats(false);
    -    }, POLLING_INTERVAL);
    +    if (socket) {
    +      const handleUpdate = () => {
    +        fetchStats(false);
    +      };
    +      
    +      socket.on(SocketEvents.TASK_UPDATE, handleUpdate);
    +      // Also listen for draft updates to refresh active plans count
    +      socket.on(SocketEvents.DRAFT_UPDATE, handleUpdate);
    +      
    +      return () => {
    +        isMountedRef.current = false;
    +        socket.off(SocketEvents.TASK_UPDATE, handleUpdate);
    +        socket.off(SocketEvents.DRAFT_UPDATE, handleUpdate);
    +      };
    +    }
     
         return () => {
           isMountedRef.current = false;
    -      clearInterval(intervalId);
         };
    -  }, [fetchStats]);
    +  }, [fetchStats, socket]);
     
  2. propr-dev commented on Feb 18, 2026

    @propr-dev
    ContributorAuthor

    🤖 AI processing has started for this issue using claude agent with claude-opus-4-5-20251101 model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: claude
    • Model: claude-opus-4-5-20251101
    • Branch: 802/claude-opus-4-5-20251101-frontend-real-time-integr-20260218-0711-wru
    • Base Branch: main
    • Worktree: issue-802-20260218-0711-claude-opus-4-5-20251101-wru

    🔍 Track Task Execution

  3. added a commit that references this issue on Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions