Skip to content

fix: prevent unrecoverable "Failed to fetch" on long sessions#28707

Open
emco1234 wants to merge 1 commit into
anomalyco:devfrom
emco1234:fix/renderer-fetch-timeout
Open

fix: prevent unrecoverable "Failed to fetch" on long sessions#28707
emco1234 wants to merge 1 commit into
anomalyco:devfrom
emco1234:fix/renderer-fetch-timeout

Conversation

@emco1234
Copy link
Copy Markdown

@emco1234 emco1234 commented May 21, 2026

Issue for this PR

Closes #28702

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The TypeError: Failed to fetch error permanently freezes the TUI display during long sessions. The display goes blank while the loading bar keeps spinning — the backend continues working but the renderer can't fetch messages anymore.

The root cause is that the SDK client sets req.timeout = false, disabling request timeouts entirely. When the Go backend is temporarily unresponsive (GC pause, heavy snapshot, DB operation), the renderer's fetchMessages hangs forever. The retry utility only tries 3 times with a 10s max delay, which is insufficient.

The fix is straightforward:

  • packages/sdk/js/src/client.ts and packages/sdk/js/src/v2/client.ts: Set req.timeout = 300_000 (5 min) instead of false. This lets the fetch fail after 5 minutes so the retry mechanism can recover.
  • packages/core/src/util/retry.ts: Increase default attempts from 3 to 5, delay from 500ms to 1000ms, and maxDelay from 10s to 30s. This gives ~31 seconds of exponential backoff retries — enough to ride out transient backend pauses.

How did you verify your code works?

Tested on Windows 11 with OpenCode v1.15.7. Before patching, the TUI froze within 10-20 minutes of active agent usage (Prometheus). After applying the req.timeout patch locally, the renderer recovers from transient backend pauses instead of permanently hanging.

Screenshots / recordings

N/A — no UI changes, only fetch/retry behavior.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions
Copy link
Copy Markdown
Contributor

Hey! Your PR title fix(sdk,core): prevent unrecoverable "Failed to fetch" on long sessions doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label May 21, 2026
@emco1234 emco1234 changed the title fix(sdk,core): prevent unrecoverable "Failed to fetch" on long sessions fix: prevent unrecoverable "Failed to fetch" on long sessions May 21, 2026
@github-actions github-actions Bot removed needs:title needs:compliance This means the issue will auto-close after 2 hours. labels May 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

The SDK client disabled request timeouts entirely (`req.timeout = false`),
causing fetch to hang forever when the Go backend becomes unresponsive.
Combined with only 3 retry attempts at 10s max delay, the renderer's
fetchMessages call would permanently fail with TypeError: Failed to fetch,
freezing the TUI display while the backend continued working in the background.

Changes:
- Set SDK fetch timeout to 5 minutes (300_000ms) instead of disabled
- Increase retry defaults: 5 attempts (was 3), 1s initial delay (was 500ms),
  30s max delay (was 10s) for better transient error recovery

Fixes anomalyco#28702

Co-Authored-By: OpenClaude (GLM-5.1) <openclaude@gitlawb.com>
@emco1234 emco1234 force-pushed the fix/renderer-fetch-timeout branch from f50dfc2 to 14a6c83 Compare May 21, 2026 19:17
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.

OpenCode Windows App is laging and Having issue it is Stopping While Running

1 participant