Anthropic: mid-stream connection drops are retried immediately and without notice
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
- Tech stack
- javascript, node.js, typescript
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
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
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from PierrunoYT/patch
-
enhancement platform: windows priority: low severity: low
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
PierrunoYT/patch#198 ·
Maintainers usually reply within 1 day
-
priority: medium security severity: low
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
PierrunoYT/patch#66 ·
Maintainers usually reply within 1 day
-
bug platform: macos priority: low severity: low tests
Difficulty 3/5 1-2 days Newbie friendliness 56/100
PierrunoYT/patch#218 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement priority: low security severity: low
Difficulty 4/5 3-5 days Newbie friendliness 55/100
PierrunoYT/patch#211 · 2 comments ·
Maintainers usually reply within 1 day
-
enhancement platform: windows priority: low security severity: low
Difficulty 4/5 3-5 days Newbie friendliness 55/100
PierrunoYT/patch#207 ·
Maintainers usually reply within 1 day
All issues in PierrunoYT/patch
Similar issues
-
[Bug]: Server git tests sign fixture commits with the developer's key when run from the repo rootOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
melgarafael/DeskcommCRM#2657 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
MystenLabs/MemWal#1163 · 2 comments ·
Maintainers usually reply within 1 day
-
Mondriaan
Difficulty 1/5 Under an hour Newbie friendliness 88/100
knaw-huc/textannoviz#709 ·
Maintainers usually reply within 1 day
-
billion-context-pi
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
ranxianglei/billion-context#2521 · 3 comments ·
Maintainers usually reply within 1 day