FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(session): cap retry attempts to prevent infinite thinking on API errors by UCASRMTG5D · Pull Request #38958 · anomalyco/opencode · GitHub

fix(session): cap retry attempts to prevent infinite thinking on API errors - #38958

Closed
UCASRMTG5D wants to merge 1 commit into
anomalyco:devfrom
UCASRMTG5D:retry-fallback-fix
Closed

fix(session): cap retry attempts to prevent infinite thinking on API errors#38958
UCASRMTG5D wants to merge 1 commit into
anomalyco:devfrom
UCASRMTG5D:retry-fallback-fix

Conversation

Copy link
Copy Markdown

Issue for this PR

Closes #38951

Type of change

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

What does this PR do?

When a provider returns a timeout error (e.g. HeaderTimeoutError from nvapi), the error is converted to an APIError with isRetryable: true. The session processor wraps the LLM stream with Effect.retry(SessionRetry.policy(...)), but since the error remains retryable indefinitely, the retry schedule never terminates — the session stays stuck in "thinking" state forever.

This PR adds RETRY_MAX_ATTEMPTS = 5 to the retry policy. After ~60 seconds of backoff (2s → 4s → 8s → 16s → 30s) the schedule gives up, the error propagates to the processor halt handler, the session transitions to idle, and a Session.Event.Error is published so configured fallback chains can take over.

How did you verify your code works?

I traced the full error propagation path through the code:

  1. MessageV2.fromError() — timeout errors are marked isRetryable: true (message-v2.ts:653-664)
  2. SessionRetry.policy() — the schedule step returns the retryable error (retry.ts:184-185)
  3. Without an attempt cap, Effect.retry loops forever — the session never exits thinking state
  4. With the cap, Cause.done propagates -> Effect.catch(halt) sets the session to idle (processor.ts:599-625)

The diff is minimal: one new constant and one guard check.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally (code trace / analysis)
  • I have not included unrelated changes in this PR

…errors

Add RETRY_MAX_ATTEMPTS = 5 so the retry schedule terminates after
~60 seconds of backoff (2+4+8+16+30s). Without this cap, errors
marked isRetryable (such as HeaderTimeoutError from nvapi) cause
Effect.retry to loop forever, keeping the session stuck in
'thinking' state indefinitely.

When the cap is reached the error propagates to the processor's halt
handler, which sets the session to idle and publishes a
Session.Event.Error so configured fallback chains can take over.

Fixes anomalyco#38951

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.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

API 404 error silently hangs session in 'thinking' state with no error recovery

1 participant


Back | FazBrowse Home | New Git URL