You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error: The socket connection was closed unexpectedly. For more information, pass verbose: true in the second argument to fetch() #1692
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…
@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
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.
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.
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.
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
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.
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 :)
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.
Activity
janderssonse commentedon Sep 11, 2025
Getting this all the time, other tools works fine in same env with constant networkscalls and lookups.
me-shaon commentedon Sep 17, 2025
Facing this issue continuously and can't use OpenCode at all.
jacquesbh commentedon Sep 18, 2025
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…
Tonitum commentedon Oct 1, 2025
Also seeing this. on open code 0.13.5. Was working with gpt4o through OpenAI.
Tonitum commentedon Oct 12, 2025
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.renderViewThis was in a fresh session, running the
/initcommand. Happened immediately.Currently on opencode v0.14.7
rekram1-node commentedon Oct 12, 2025
@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
Tonitum commentedon Oct 12, 2025
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.
jacquesbh commentedon Oct 12, 2025
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.
Tonitum commentedon Oct 12, 2025
I can check that next time, but it has happened on a fresh launch and fresh session multiple times.
Tonitum commentedon Oct 12, 2025
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.
hronro commentedon Oct 22, 2025
Is there any way to retry the fetch?
rekram1-node commentedon Oct 22, 2025
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”
towry commentedon Oct 23, 2025
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:
But it didn't retry the failed parts.
rekram1-node commentedon Oct 23, 2025
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
7 remaining items
27Bslash6 commentedon Nov 30, 2025
Yep, z.ai GLM.
niderhoff commentedon Dec 13, 2025
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?galileor97 commentedon Dec 22, 2025
Error: The socket connection was closed unexpectedly. For more information, pass
verbose: truein the second argument to fetch() on antigravity authTaterDoge commentedon Dec 24, 2025
This problem still exists
ycvk commentedon Dec 24, 2025
same here, problem still exists, I'm also using MacOS with a golang project.
rekram1-node commentedon Dec 24, 2025
This issue is from the provider dropping connection, I added retries for this error last night
jacob-8 commentedon Dec 25, 2025
I've had this issue for a couple weeks with Opus 4.5 via Copilot.
rekram1-node commentedon Jan 6, 2026
think this is fixed now
niderhoff commentedon Jan 18, 2026
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 1472fails, whileping -D -s 1360succeeds). 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 xxxxwhich different values (going down from 1500) and then when it succeeds (1360 in my case), set your MTU to this valuesudo 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 :)
lukaesch commentedon Jan 26, 2026
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.
yu-zou commentedon Mar 28, 2026
I faced this error when upgrading opencode by
opencode upgrade.chixinwang commentedon Apr 15, 2026
@yu-zou 想问下这个问题你解决了吗,我也遇到了相同的问题
yu-zou commentedon Apr 16, 2026
@chixinwang 我在升级到最新版之后就很久没有再碰到过这个问题了。
Tonitum commentedon Jun 30, 2026
I am still seeing this issue on the latest release of opencode. It's intermittent, but happens a lot