perf: Replace Polling with WebSocket Events#6
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| }; | ||
| }, [missionId, fetchMissionStream]); |
There was a problem hiding this comment.
Start polling when websocket fallback is toggled
The polling fallback never actually starts (or stops) when the socket flips usePollingFallback.current after a disconnect or connect error because the polling useEffect only re-runs on missionId/fetchMissionStream (line 202). Once the socket drops, the flag is set to true in the handlers but this effect is not re-executed, so no interval is created and mission updates cease until the user changes missions; similarly, a reconnection never clears any existing interval. This leaves the app without updates whenever the websocket fails.
Useful? React with 👍 / 👎.
| return { | ||
| ...prev, | ||
| steps: [...prev.steps, step], | ||
| updatedAt: new Date(), |
There was a problem hiding this comment.
Keep mission timestamps consistent with string type
In the mission:step handler, updatedAt is set to new Date() even though Mission.updatedAt is defined as a string. TypeScript will reject this assignment and, if forced through, any consumers expecting an ISO string now receive a Date object, breaking formatting/serialization of mission updates.
Useful? React with 👍 / 👎.
Summary
This PR eliminates the inefficient 2-second polling mechanism and implements real-time WebSocket updates for mission status. Reduces network requests by 90%+ and decreases update latency from 2000ms to under 100ms while providing a graceful fallback to polling when WebSocket connection fails.
Changes
useMissionhook with WebSocket support:ConnectionStatuscomponent:mission:update- Full mission state updatesmission:step- Incremental step updatesmission:status- Status changes onlyType of Change
Performance Improvements
Testing
Connection States
Fallback Behavior
Environment Variables
Requires
VITE_API_URLfor WebSocket server:Checklist
Related Issues
Addresses Feature #4 from FEATURE_OPPORTUNITIES.md - Priority Score: 1.5
Notes