Skip to content

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

Closed
Krypto-Whitehat wants to merge 1 commit into
anomalyco:devfrom
Krypto-Whitehat:fix/renderer-fetch-timeout
Closed

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

Conversation

@Krypto-Whitehat

@Krypto-WhitehatKrypto-Whitehat commented May 21, 2026

Copy link
Copy Markdown

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-actionsgithub-actionsBot added the needs:compliance This means the issue will auto-close after 2 hours. label May 21, 2026
@Krypto-WhitehatKrypto-Whitehat changed the title fix(sdk,core): prevent unrecoverable "Failed to fetch" on long sessionsfix: prevent unrecoverable "Failed to fetch" on long sessionsMay 21, 2026
@github-actionsgithub-actionsBot 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
Fixesanomalyco#28702
Co-Authored-By: OpenClaude (GLM-5.1) <openclaude@gitlawb.com>
@Krypto-Whitehat
Krypto-Whitehatforce-pushed the fix/renderer-fetch-timeout branch from f50dfc2 to 14a6c83CompareMay 21, 2026 19:17
@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for freeto 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.

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

1 participant

@Krypto-Whitehat