Skip to content

fix(ui): add retry logic to SSE pong to improve connection resilience#519

Open
JDis03 wants to merge 1 commit into
NeuralNomadsAI:devfrom
JDis03:fix/sse-pong-retry
Open

fix(ui): add retry logic to SSE pong to improve connection resilience#519
JDis03 wants to merge 1 commit into
NeuralNomadsAI:devfrom
JDis03:fix/sse-pong-retry

Conversation

@JDis03
Copy link
Copy Markdown
Contributor

@JDis03 JDis03 commented Jun 2, 2026

Problem

When the client receives a ping from the server, it responds with a pong via HTTP POST. On unstable networks (mobile, WiFi with poor signal, network switches), this POST can fail due to transient errors:

  • Network timeouts
  • Brief disconnections
  • Server temporarily unavailable

Previously, a single pong failure would cause the server to close the SSE connection after 45s timeout, leaving message responses stuck in queue until the next message triggered a reconnection.

Solution

This fix wraps the pong POST in retryWithBackoff with exponential backoff:

  • 3 attempts maximum
  • 100ms initial delay, doubling each retry
  • 2000ms maximum delay between retries

This handles transient network issues gracefully without requiring reconnection, improving message delivery reliability for all users on imperfect networks (not just mobile).

Changes

  • packages/ui/src/lib/retry-utils.ts (new): Reusable retry utility with exponential backoff
  • packages/ui/src/lib/server-events.ts: Updated pong handler to use retry logic

Testing

  • Build passes: npm run build:ui
  • Typecheck passes for changed files
  • Manual testing required on unstable networks

Benefits

  • Improves SSE connection stability for all users
  • Reduces unnecessary reconnections
  • Reusable retry utility for future fragile HTTP operations

When the client receives a ping from the server, it responds with a
pong via HTTP POST. On unstable networks (mobile, WiFi with poor signal,
network switches), this POST can fail due to transient errors:
- Network timeouts
- Brief disconnections
- Server temporarily unavailable

Previously, a single pong failure would cause the server to close the
SSE connection after 45s timeout, leaving message responses stuck in
queue until the next message triggered a reconnection.

This fix wraps the pong POST in retryWithBackoff with exponential
backoff:
- 3 attempts maximum
- 100ms initial delay, doubling each retry
- 2000ms maximum delay between retries

This handles transient network issues gracefully without requiring
reconnection, improving message delivery reliability for all users
on imperfect networks (not just mobile).

Retry logic is extracted to a reusable retry-utils.ts module that can
be used for other fragile HTTP operations in the future.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

PR builds are available as GitHub Actions artifacts:

https://github.com/NeuralNomadsAI/CodeNomad/actions/runs/26818019424

Artifacts expire in 7 days.
Artifacts:

  • pr-519-4184d0f094a123e0c6fb1a66c248a540d415d83f-tauri-linux
  • pr-519-4184d0f094a123e0c6fb1a66c248a540d415d83f-tauri-macos
  • pr-519-4184d0f094a123e0c6fb1a66c248a540d415d83f-tauri-windows
  • pr-519-4184d0f094a123e0c6fb1a66c248a540d415d83f-tauri-macos-arm64
  • pr-519-4184d0f094a123e0c6fb1a66c248a540d415d83f-electron-macos
  • pr-519-4184d0f094a123e0c6fb1a66c248a540d415d83f-electron-windows
  • pr-519-4184d0f094a123e0c6fb1a66c248a540d415d83f-electron-linux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant