fix: retry premature close and connection errors in core#11794
fix: retry premature close and connection errors in core#11794
Conversation
The CLI already retries transient connection errors like "premature close", "socket hang up", etc., but the core retry logic (used by the VS Code extension) did not. This caused unrecoverable errors for users hitting transient network/stream interruptions with various providers. Add connection error patterns to both core/util/withExponentialBackoff.ts and core/llm/utils/retry.ts to match the CLI behavior. Fixes #11108, #11102, #10948, #9667, #9999
Docs ReviewNo documentation update needed for this PR. This change adds retry logic for transient connection errors (premature close, socket hang up, connection reset, etc.) in core—aligning it with the existing CLI behavior. This is an internal reliability improvement that:
Users benefit automatically without needing to know or do anything differently. 👍 |
Test Coverage GapThe changes to However, the same patterns were also added to Suggestion: Consider adding test coverage for the new connection error patterns in
These tests would verify that the exponential backoff utility correctly retries on these connection errors, similar to the tests added for |
There was a problem hiding this comment.
1 issue found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="core/util/withExponentialBackoff.ts">
<violation number="1" location="core/util/withExponentialBackoff.ts:26">
P3: The new retryable connection errors are logged as "Hit rate limit," which is inaccurate and can mislead troubleshooting. Use a generic retry message (or include the actual error type) for this shared retry branch.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| lowerMessage.includes("premature close") || | ||
| lowerMessage.includes("premature end") || | ||
| lowerMessage.includes("connection reset") || | ||
| lowerMessage.includes("socket hang up") |
There was a problem hiding this comment.
P3: The new retryable connection errors are logged as "Hit rate limit," which is inaccurate and can mislead troubleshooting. Use a generic retry message (or include the actual error type) for this shared retry branch.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At core/util/withExponentialBackoff.ts, line 26:
<comment>The new retryable connection errors are logged as "Hit rate limit," which is inaccurate and can mislead troubleshooting. Use a generic retry message (or include the actual error type) for this shared retry branch.</comment>
<file context>
@@ -19,7 +19,11 @@ const withExponentialBackoff = async <T>(
+ lowerMessage.includes("premature close") ||
+ lowerMessage.includes("premature end") ||
+ lowerMessage.includes("connection reset") ||
+ lowerMessage.includes("socket hang up")
) {
const retryAfter = (error as APIError).response?.headers.get(
</file context>
|
Actually nvm premature can happen mid-stream. |
Summary
core/util/withExponentialBackoff.tsandcore/llm/utils/retry.tsextensions/cli/src/util/exponentialBackoff.ts) but missing from core, which is used by the VS Code extensionContext
Five open issues report "premature close" errors across different providers (Ollama, OpenAI-compatible, xAI). All are from VS Code users. The CLI already retries these transient errors, but the core retry logic did not — so users saw unrecoverable "Unknown error" messages instead of automatic recovery.
Fixes #11108, #11102, #10948, #9667, #9999
Test plan
Summary by cubic
Core now retries transient connection/stream errors (“premature close”, “premature end”, “connection reset”, “socket hang up”) to match the CLI. This prevents unrecoverable “Unknown error” in the VS Code extension.
core/util/withExponentialBackoff.tsandcore/llm/utils/retry.ts.Written for commit e9fccbc. Summary will update on new commits.