Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

Summary

  • centralize initial-load attempt/timeout handling in a shared hook
  • refactor project/workspace contexts to use the shared load coordinator
  • surface initial-load errors + retry actions in AppLoader/LoadingScreen

Background

  • Web clients could hang on the loading screen after intermittent WebSocket drops because in-flight loads never retried or surfaced errors.

Implementation

  • add useInitialLoadState with attempt guards, timeout support, and retry helpers
  • wire contexts to the shared hook and propagate load errors
  • extend loader UI to show errors, connection status, and retry affordances

Validation

  • make static-check

Risks

  • Low: changes only affect initial loading state and error UI; steady-state behavior is unchanged.

Generated with mux • Model: openai:gpt-5.2-codex • Thinking: high • Cost: $9.61

Replace the custom useInitialLoadState hook and Result-type ceremony
with a simpler approach:

1. Add connectionEpoch to API.tsx - increments on successful reconnect
2. Contexts re-run initial load when epoch changes (automatic recovery)
3. Inline timeouts using Promise.race (3 lines vs separate utility)
4. Keep simple loading/loadError state (no new abstractions)

Deleted:
- src/browser/hooks/useInitialLoadState.ts (72 LoC)
- src/browser/hooks/useInitialLoadState.test.ts (61 LoC)
- src/common/utils/withTimeout.ts (21 LoC)
- src/constants/initialLoad.ts (1 LoC)

Net: -218 LoC while maintaining all functionality:
- Timeouts on initial load (15s)
- Error display + retry button in AppLoader
- Automatic retry on reconnect (new behavior via epoch)

The key insight: API provider already detects disconnects and
reconnects. Contexts just needed to re-run their load when
the connection comes back.
1. Instant first reconnect attempt (0ms delay), then exponential backoff
   - First retry: instant
   - Subsequent: 100ms, 200ms, 400ms... up to 10s

2. ConnectionStatusBanner shows reconnection/degraded status
   - Appears at top of app when connection is unstable
   - Shows attempt count during reconnection
   - Warns about degraded connections (pings failing)

3. AppLoader re-syncs stores on connectionEpoch change
   - Ensures stores get fresh client on reconnect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant