Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Anthropic: mid-stream connection drops are retried immediately and without notice

Closed Beginner friendly
#173 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Domain
backend, testing

Research direction

Read src/main/llm/anthropic.ts around runTurn and retryDecision, then inspect lib/BetaMessageStream.js error handling. Add mock-server tests for a mid-stream socket close and invalid tool JSON; done means socket failures use the visible retry path while invalid tool JSON retains its bounded retry behavior.

Written by the indexing model from the issue text.

Description

bug priority: medium severity: medium

Found in the 2026-10-07 code review (traced through @anthropic-ai/sdk 0.129.0; not run).

Problem

runTurn (src/main/llm/anthropic.ts:202-211) is meant to retry only when tool input JSON can't be parsed. But BetaMessageStream.#handleError (lib/BetaMessageStream.js:40-58) wraps every non-Anthropic error, including a socket closing mid-stream (TypeError: terminated, cause UND_ERR_SOCKET), in a plain AnthropicError, which is not an APIError. So connection drops take the JSON-retry branch: they are re-sent at once, up to twice, with only onRestart. There is no notice and no backoff.

Impact

This breaks the AGENTS.md rule that every retry is shown in the chat (the agent loop retries visibly, with backoff). An overloaded or flaky connection is hit again immediately.

Fix

const badToolJson =
  error instanceof Anthropic.AnthropicError && /Unable to parse tool parameter JSON/.test(error.message);
if (!badToolJson || request.signal.aborted || jsonRetries++ >= MAX_JSON_RETRIES) throw error;

retryDecision already recognizes UND_ERR_SOCKET through cause. Add tests with a mock server that closes the socket mid-stream, and one that sends invalid tool JSON.

Dominant language
TypeScript
Stars
2
Forks
2
Avg merge
5h 28m
Merged PRs (30d)
24

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PierrunoYT/patch

All issues in PierrunoYT/patch

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.