Skip to content

fix(agents): clamp OpenAI WS maxRetries to >=1 to prevent off-by-one zero-retry bug - #4

Open
echoVic wants to merge 1 commit into
mainfrom
fix/issue-36055-websocket-reconnect-attempts
Open

echoVic wants to merge 1 commit into
mainfrom
fix/issue-36055-websocket-reconnect-attempts

Conversation

@echoVic

@echoVic echoVic commented Mar 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • Clamp maxRetries to a minimum of 1 in OpenAIWebSocketManager constructor to prevent the off-by-one bug where maxRetries=0 causes retryCount(0) >= maxRetries(0) to be true immediately, firing the max-retries-exceeded error before any reconnect attempt is made
  • Add a comment explaining the edge case

Test plan

  • Set maxRetries: 0 and verify the manager now attempts at least one reconnect instead of failing immediately with "max reconnect retries (0) exceeded"
  • Verify normal reconnect behavior still works for maxRetries >= 1
  • Verify code 1006 (abnormal closure) reconnect attempts proceed correctly

Fixes openclaw#36055

…zero-retry bug

When maxRetries is 0 (either explicitly or via misconfiguration), the check
`retryCount (0) >= maxRetries (0)` fires immediately on the first disconnect,
emitting "max reconnect retries (0) exceeded" before ever attempting to reconnect.
This matches the reported "Max reconnect attempts (0) reached after code 1006".

Clamp maxRetries to a minimum of 1 in the constructor so that even if a caller
passes maxRetries: 0, at least one reconnect attempt is made. The default of 5
remains unchanged for normal usage.

Fixes openclaw#36055
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.

[Bug]: Uncaught exception: Error: Max reconnect attempts (0) reached after code 1006 at GatewayPlugin.handleReconnectionAttempt

1 participant