-
Notifications
You must be signed in to change notification settings - Fork 928
feat: integrate retry logic Phase 3 #18699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/terminal-reconnection-phase2
Are you sure you want to change the base?
feat: integrate retry logic Phase 3 #18699
Conversation
- Integrate useRetry hook into TerminalPage component - Add automatic retry trigger on disconnection - Implement terminal content preservation during reconnection - Update WebSocket connection logic to support retry mechanism - Pass retry props to TerminalAlerts component for UI display - Maintain existing terminal event handlers for data and resize - Use exponential backoff with 1s initial delay, 30s max, 10 attempts Completes Phase 3 of terminal reconnection feature as outlined in: coder/internal#659 Co-authored-by: BrunoQuaresma <[email protected]>
- Add WEBSOCKET_CLOSE_NORMAL constant (1000) for normal closure - Replace magic number 1000 with descriptive constant name - Improves code readability and maintainability Co-authored-by: BrunoQuaresma <[email protected]>
…Retry - Add enabled prop to useRetry hook interface - Remove startRetrying and stopRetrying methods from hook return - Update TerminalPage to use enabled prop based on connection status - Simplify retry logic with declarative enabled state - Update tests to use enabled prop instead of manual start/stop calls - Fix WebSocket close magic number with named constant This makes the retry behavior more React-like and easier to reason about. The hook now automatically starts/stops retrying based on the enabled prop. Co-authored-by: BrunoQuaresma <[email protected]>
The issue was that when a retry succeeded, the state was reset to initial state (attemptCount: 0), which triggered the useEffect to start retrying again, creating an infinite loop. Fixed by adding a hasStartedRef to track whether we've already started the initial retry, preventing the hook from restarting after success. Also removed onRetryEvent from performRetry dependency array since it's created with useEffectEvent and should be stable. Fixes the timeout in the 'should reset state when retry succeeds' test. Co-authored-by: BrunoQuaresma <[email protected]>
The onRetryEvent is created with useEffectEvent and is stable across renders, so it doesn't need to be in the dependency array. Added a suppression comment to explain this to the linter. Co-authored-by: BrunoQuaresma <[email protected]>
… comment Since onRetryEvent is created with useEffectEvent, it's stable across renders and can be safely included in the dependency array without causing issues. This is cleaner than using a linter suppression comment. Co-authored-by: BrunoQuaresma <[email protected]>
- Remove unnecessary startTimeRef and simplify timer management - Consolidate reducer return statements for cleaner code - Split complex useEffect into separate focused effects - Remove redundant comments and simplify countdown logic - Maintain same API and behavior while improving readability Co-authored-by: BrunoQuaresma <[email protected]>
@code-asher I also would appreciate a QA on this. |
🧪 QA Testing Guide: Terminal Reconnection FeatureThis guide will help you test the new terminal reconnection functionality with automatic retry logic. 🎯 What to TestThe terminal should now automatically attempt to reconnect when the WebSocket connection is lost, with exponential backoff retry logic and preserved terminal content. 🔧 Test Setup
📋 Test Scenarios✅ Scenario 1: Network Interruption SimulationSteps:
Expected Behavior:
✅ Scenario 2: Workspace Agent RestartSteps:
Expected Behavior:
✅ Scenario 3: Manual Retry TestingSteps:
Expected Behavior:
✅ Scenario 4: Retry ExhaustionSteps:
Expected Behavior:
✅ Scenario 5: Successful Mid-Retry ReconnectionSteps:
Expected Behavior:
🔍 What to Look For✅ UI Indicators
✅ Terminal Behavior
✅ Retry Logic
🐛 Common Issues to Watch For
🌐 Browser TestingTest across different browsers:
📱 Network ConditionsTest with various network conditions:
🎉 Success Criteria✅ The feature is working correctly if:
Questions or Issues? Please comment below with:
Happy testing! 🚀 |
useRetry Hook Improvements
startTimeRef
and used local variablesCompletes Phase 3 of terminal reconnection feature as outlined in: coder/internal#659