Skip to content

Error: The socket connection was closed unexpectedly. For more information, pass verbose: true in the second argument to fetch() #1692

Closed

Description

@alexeypolitov

Activity

  1. self-assigned this
    on Aug 11, 2025
  2. janderssonse commented on Sep 11, 2025

    @janderssonse

    Getting this all the time, other tools works fine in same env with constant networkscalls and lookups.

  3. me-shaon commented on Sep 17, 2025

    @me-shaon

    Facing this issue continuously and can't use OpenCode at all.

  4. jacquesbh commented on Sep 18, 2025

    @jacquesbh

    Same here.
    MacOS 14.8 (23J21)
    Opencode 0.9.11

    It's nearly impossible to work with. At the beginning it's fine, but it goes quickly to this error, over and over, sometimes just after entering a new prompt, sometimes a few seconds after, sometimes minutes after…

  5. Tonitum commented on Oct 1, 2025

    @Tonitum

    Also seeing this. on open code 0.13.5. Was working with gpt4o through OpenAI.

  6. Tonitum commented on Oct 12, 2025

    @Tonitum

    Debug Logs

    INFO  2025-10-12T01:04:30 +1ms service=tui commands={"agent_cycle":{},"agent_cycle_reverse":{},"agent_list":{},"app_exit":{},"app_help":{},"editor_open":{},"input_clear":{},"input_newline":{},"input_paste":{},"input_submit":{},"messages_copy":{},"messages_first":{},"messages_half_page_down":{},"messages_half_page_up":{},"messages_last":{},"messages_page_down":{},"messages_page_up":{},"messages_redo":{},"messages_undo":{},"model_cycle_recent":{},"model_cycle_recent_reverse":{},"model_list":{},"project_init":{},"session_child_cycle":{},"session_child_cycle_reverse":{},"session_compact":{},"session_export":{},"session_interrupt":{},"session_list":{},"session_new":{},"session_timeline":{},"theme_list":{},"thinking_blocks":{},"tool_details":{}} Loaded commands
    INFO  2025-10-12T01:04:30 +4ms service=server method=GET path=/config/providers request
    INFO  2025-10-12T01:04:30 +0ms service=server duration=0 response
    DEBUG 2025-10-12T01:04:30 +1ms service=tui model=claude-sonnet-4-20250514 provider=anthropic Selected model from config
    DEBUG 2025-10-12T01:04:30 +11ms service=tui timeTakenMs=0 messages.renderView
    DEBUG 2025-10-12T01:04:30 +5ms service=tui file=/home/.local/state/opencode/tui State saved to file
    DEBUG 2025-10-12T01:04:30 +2ms service=tui color=#1e1e2e isDark=true Background color
    DEBUG 2025-10-12T01:04:30 +6ms service=tui timeTakenMs=0 messages.renderView
    DEBUG 2025-10-12T01:04:30 +0ms service=tui file=/home.local/state/opencode/tui State saved to file
    INFO  2025-10-12T01:04:30 +1ms service=server duration=33 response
    INFO  2025-10-12T01:04:54 +24301ms service=server method=POST path=/session request
    INFO  2025-10-12T01:04:54 +4ms service=session id=ses_62a0d0748ffeoY1Lanl3RIQTQ8 version=0.14.7 projectID=79a3f1767a8362769c13882681d279cff93dd902 directory=/home/personal/tonitum title=New session - 2025-10-12T01:04:54.456Z time={"created":1760231094456,"updated":1760231094456} created
    INFO  2025-10-12T01:04:54 +1ms service=bus type=session.updated publishing
    INFO  2025-10-12T01:04:54 +2ms service=server duration=7 response
    INFO  2025-10-12T01:04:54 +7ms service=server method=POST path=/session/ses_62a0d0748ffeoY1Lanl3RIQTQ8/init request
    INFO  2025-10-12T01:04:54 +5ms service=session.prompt session=ses_62a0d0748ffeoY1Lanl3RIQTQ8 prompt
    DEBUG 2025-10-12T01:04:54 +4ms service=tui timeTakenMs=0 messages.renderView
    INFO  2025-10-12T01:04:54 +0ms service=bus type=message.updated publishing
    DEBUG 2025-10-12T01:04:54 +4ms service=tui timeTakenMs=0 messages.renderView
    INFO  2025-10-12T01:04:54 +0ms service=bus type=message.part.updated publishing
    INFO  2025-10-12T01:04:54 +1ms service=bus type=session.updated publishing
    INFO  2025-10-12T01:04:54 +0ms service=provider providerID=anthropic modelID=claude-sonnet-4-20250514 getModel
    INFO  2025-10-12T01:04:54 +1ms service=provider status=started providerID=anthropic getSDK
    DEBUG 2025-10-12T01:04:54 +0ms service=tui message=msg_9d5f2f8bc001tZqE8Wq6xM4AOo part=prt_9d5f2f8c6001JR1wuCY5XNzLep message part updated
    INFO  2025-10-12T01:04:54 +44ms service=provider status=completed duration=44 providerID=anthropic getSDK
    INFO  2025-10-12T01:04:54 +0ms service=provider providerID=anthropic modelID=claude-sonnet-4-20250514 found
    INFO  2025-10-12T01:04:54 +0ms service=session.prompt session=ses_62a0d0748ffeoY1Lanl3RIQTQ8 sessionID=ses_62a0d0748ffeoY1Lanl3RIQTQ8 locking
    DEBUG 2025-10-12T01:04:54 +1ms service=tui pending render, skipping
    DEBUG 2025-10-12T01:04:54 +1ms service=tui timeTakenMs=0 messages.renderView
    DEBUG 2025-10-12T01:04:54 +0ms service=tui timeTakenMs=0 messages.renderView
    INFO  2025-10-12T01:04:54 +11ms service=provider providerID=anthropic modelID=claude-3-5-haiku-20241022 getModel
    INFO  2025-10-12T01:04:54 +0ms service=provider status=started providerID=anthropic getSDK
    INFO  2025-10-12T01:04:54 +0ms service=provider status=completed duration=0 providerID=anthropic getSDK
    INFO  2025-10-12T01:04:54 +0ms service=bus type=message.updated publishing
    INFO  2025-10-12T01:04:54 +0ms service=provider providerID=anthropic modelID=claude-3-5-haiku-20241022 found
    INFO  2025-10-12T01:04:54 +2ms service=session.prompt session=ses_62a0d0748ffeoY1Lanl3RIQTQ8 process
    INFO  2025-10-12T01:04:54 +2ms service=session.prompt session=ses_62a0d0748ffeoY1Lanl3RIQTQ8 type=start part
    DEBUG 2025-10-12T01:04:54 +5ms service=tui timeTakenMs=0 messages.renderView
    DEBUG 2025-10-12T01:04:54 +93ms service=tui timeTakenMs=0 messages.renderView
    ERROR 2025-10-12T01:04:54 +63ms service=session.prompt session=ses_62a0d0748ffeoY1Lanl3RIQTQ8 error={"error":{"code":"ECONNRESET","path":"https://api.anthropic.com/v1/messages","errno":0}} stream error
    INFO  2025-10-12T01:04:54 +1ms service=session.prompt session=ses_62a0d0748ffeoY1Lanl3RIQTQ8 type=error part
    ERROR 2025-10-12T01:04:54 +0ms service=session.prompt session=ses_62a0d0748ffeoY1Lanl3RIQTQ8 error=The socket connection was closed unexpectedly. For more information, pass `verbose: true` in the second argument to fetch() process
    INFO  2025-10-12T01:04:54 +1ms service=bus type=session.error publishing
    INFO  2025-10-12T01:04:54 +1ms service=bus type=message.updated publishing
    INFO  2025-10-12T01:04:54 +0ms service=bus type=message.updated publishing
    INFO  2025-10-12T01:04:54 +1ms service=session.compaction pruning
    INFO  2025-10-12T01:04:54 +0ms service=session.prompt session=ses_62a0d0748ffeoY1Lanl3RIQTQ8 sessionID=ses_62a0d0748ffeoY1Lanl3RIQTQ8 unlocking
    INFO  2025-10-12T01:04:54 +0ms service=bus type=session.idle publishing
    INFO  2025-10-12T01:04:54 +0ms service=server duration=241 response
    ERROR 2025-10-12T01:04:54 +0ms service=tui message=Error: The socket connection was closed unexpectedly. For more information, pass `verbose: true` in the second argument to fetch() name=UnknownError Server error
    INFO  2025-10-12T01:04:54 +1ms service=session.compaction pruned=0 total=0 found
    DEBUG 2025-10-12T01:04:54 +4ms service=tui timeTakenMs=0 messages.renderView
    DEBUG 2025-10-12T01:04:54 +2ms service=tui pending render, skipping
    DEBUG 2025-10-12T01:04:54 +3ms service=tui timeTakenMs=0 messages.renderView
    INFO  2025-10-12T01:04:55 +990ms service=bus type=session.updated publishing
    DEBUG 2025-10-12T01:04:55 +4ms service=tui timeTakenMs=0 messages.renderView

    This was in a fresh session, running the /init command. Happened immediately.
    Currently on opencode v0.14.7

  7. rekram1-node commented on Oct 12, 2025

    @rekram1-node
    Contributor

    @Tonitum looks like anthropic had an issue and closed the connection on u prematurely, we should try ot handle more gracefully for better ux but just wanted to clarify, incase it is helpful

  8. Tonitum commented on Oct 12, 2025

    @Tonitum

    I can believe that. I have been seeing this with more than one provider though (such as gpt-4o via OpenAI, grok-code-fast via Opencode Zen). Do you think my local network could be a source of the issue, or would you think primarily on the provider side? I have a hard time thinking that all of these providers would be having the same issues.

  9. jacquesbh commented on Oct 12, 2025

    @jacquesbh

    Hi!

    To get it back to work I have to compact the context (/compact) and it comes back to normal.
    It usually reaches 60% or something, sometimes 80%, but I never go further in the context length.

    I feel there is an issue somewhere still.

    @Tonitum What's the context size when you get the error? Top right of the screen.

  10. Tonitum commented on Oct 12, 2025

    @Tonitum

    I can check that next time, but it has happened on a fresh launch and fresh session multiple times.

  11. Tonitum commented on Oct 12, 2025

    @Tonitum

    Image
    Context from most recent issue. I looked at some other sessions and it ranges from 12.7k/4% to 20.1k/7%. I feel like that's too small of a context to really need compaction.

  12. hronro commented on Oct 22, 2025

    @hronro

    Is there any way to retry the fetch?

  13. rekram1-node commented on Oct 22, 2025

    @rekram1-node
    Contributor

    Well rn this isnt retried but we could attempt to retry, im rewriting some logic so that we can have more granular retry controls

    for now if i get this i just send a follow up like “continue”

  14. towry commented on Oct 23, 2025

    @towry

    Well rn this isnt retried but we could attempt to retry, im rewriting some logic so that we can have more granular retry controls

    for now if i get this i just send a follow up like “continue”

    I have this error happened like 5 times today.

    It happens in the latest version 0.15.14, using github-copilot/cluade- model, I use the "continue" magic too.

    From the release notes of 0.15.14, it says:

    • Added retry functionality for failed parts of conversations, improving reliability

    But it didn't retry the failed parts.

  15. rekram1-node commented on Oct 23, 2025

    @rekram1-node
    Contributor

    that was a bad release note lol i should update it, it was ai generated

    we already do retries i think this error is when the server closes the connection on us which we dont automatically retry but perhaps we should, it is a little weird to retry because it could happen mid stream i think

  16. 7 remaining items

  17. 27Bslash6 commented on Nov 30, 2025

    @27Bslash6

    Yep, z.ai GLM.

  18. niderhoff commented on Dec 13, 2025

    @niderhoff

    I am observing the same error as of today. It happens on first prompt with OpenAI official API and also OpenAI-compatible custom endpoint. Google API works fine.

    Is this maybe a problem in @ai-sdk?

  19. galileor97 commented on Dec 22, 2025

    @galileor97

    Error: The socket connection was closed unexpectedly. For more information, pass verbose: true in the second argument to fetch() on antigravity auth

  20. TaterDoge commented on Dec 24, 2025

    @TaterDoge

    This problem still exists

  21. ycvk commented on Dec 24, 2025

    @ycvk

    same here, problem still exists, I'm also using MacOS with a golang project.

  22. rekram1-node commented on Dec 24, 2025

    @rekram1-node
    Contributor

    This issue is from the provider dropping connection, I added retries for this error last night

  23. jacob-8 commented on Dec 25, 2025

    @jacob-8

    I've had this issue for a couple weeks with Opus 4.5 via Copilot.

  24. rekram1-node commented on Jan 6, 2026

    @rekram1-node
    Contributor

    think this is fixed now

  25. niderhoff commented on Jan 18, 2026

    @niderhoff

    The issue appears to not always be a simple "provider is randomly dropping connections". In my case I could observe that the issue is rather a caused by broken PMTU (Path MTU Discovery) on my cellular data connection, rather than by the remote API itself.

    In my particular case I was only observing these "connection resets" when I was connected through a mobile hotspot (Wi-Fi over 5G). The same CLI and the same API endpoint work reliably over a normal Wi-Fi connection.

    In wireshark I could see some packets were silently dropped by the network path. A little test with ping utility let me confirm the results: ICMP packets above a certain size are dropped (ping -D -s 1472 fails, while ping -D -s 1360 succeeds). This indicates that packets are dropped and ICMP "packet too big" messages are not delivered back to the client.

    As a workaround, lowering the MTU on the client network interface (en0 in my case) makes the connection work reliably also via cellular. However, this is a global workaround in Mac OS and as such not preferred, but might be the only one.

    So if you want to fix this, try out ping -D -s xxxx which different values (going down from 1500) and then when it succeeds (1360 in my case), set your MTU to this value sudo networksetup -setMTU en0 1360. However, I assume you know what you are doing if you are messing with network setup on MacOS.

    The preferred way in my opinion would be that the bun network stack is more conservative in general or could adapt to flaky networks through observed bahaviour. It's definitely not bun's fault if the network I am on breaks PMTU discovery, but a lot of applications (browsers etc.) do use heuristics and retry with smaller chunks etc. However, this is definitely not opencode's fault.

    Just wanted to acknowledge this here, so whoever might have a similar setup may read this and lower their MTU to work around bun's network failing on such sketchy connections :)

  26. lukaesch commented on Jan 26, 2026

    @lukaesch

    I agree it could be a context-related problem, but I suspect it’s context size interacting with enterprise infra rather than a pure “context bug”.

    In my environment (VM inside big enterprise network → corp proxy → Azure API GW → AWS Bedrock), /compact often makes it work again, which suggests we’re crossing some threshold (longer time-to-first-token, longer stream duration, bigger request/response) that increases the chance the proxy/gateway chain closes the connection. That then surfaces as ECONNRESET / “socket connection was closed unexpectedly”.

    So my working theory is: larger context/output increases stream length and/or latency, and somewhere in the proxy/GW path (timeouts, buffering, SSE/chunked handling, HTTP2↔HTTP1.1 translation) the connection gets terminated.

    That would explain why it’s correlated with context growth but also why it can still happen in smaller/fresh sessions depending on network/gateway conditions.

  27. yu-zou commented on Mar 28, 2026

    @yu-zou

    I faced this error when upgrading opencode by opencode upgrade.

  28. chixinwang commented on Apr 15, 2026

    @chixinwang

    @yu-zou 想问下这个问题你解决了吗,我也遇到了相同的问题

  29. yu-zou commented on Apr 16, 2026

    @yu-zou

    @chixinwang 我在升级到最新版之后就很久没有再碰到过这个问题了。

  30. Tonitum commented on Jun 30, 2026

    @Tonitum

    I am still seeing this issue on the latest release of opencode. It's intermittent, but happens a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions