Skip to content

Certain tool calling frequently fails and disconnects the chat #2519

Closed

Description

@sei-dwtompkins

I've been getting a frequent error:

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

I think it's related to a failing tool call that fetches some info from the Web?

opencode — v0.6.6
macOS — v15.6.1

EDIT:
Potentially related to #2513
Same error string reported: #1692

Activity

  1. github-actions commented on Sep 9, 2025

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  2. rekram1-node commented on Sep 9, 2025

    @rekram1-node
    Contributor

    thx for raising

  3. Durandle46 commented on Oct 12, 2025

    @Durandle46

    +1 on this issue.

    Windows 11
    PowerShell 7.5.0
    OpenCode 0.15.0
    

    Interestingly, it appears to have started working again once I deleted the .idea directory that GoLand had generated.

    My bad, I'd switched to Plan mode, which worked fine. Back to agent mode, same issue.

    EDIT: The current task was trying to create an i18n file for the Lao language. I skipped that task, and the agent was able to continue. Any chance foreign characters were making the tools break?

  4. rekram1-node commented on Oct 12, 2025

    @rekram1-node
    Contributor

    if it is the socket error that is probably your provider dropping your connection unexpectedly that shouldnt have anytning to do with tools

    at least nothing comes to mind ad to why thatd be

  5. Durandle46 commented on Oct 12, 2025

    @Durandle46

    While I understand the technical reason for your point, the developer in me knows these things can often not be what they seem. What I know is when I made the agent skip whatever tooling it was trying to run and move to a different task, it immediately started working fine. That could still be the API/Provider being the issue, but could also be an internal issue triggering what looks like a timeout or connection drop. The agent came back to the whole Lao language thing and completed it eventually, just not when it originally tried to do it.

  6. rekram1-node commented on Oct 12, 2025

    @rekram1-node
    Contributor

    yeah i see, was this a toasted error for you or did you see it in the actual message history too

  7. Durandle46 commented on Oct 13, 2025

    @Durandle46

    @rekram1-node

    Toast and History

    Image

    At the very least, it'd be useful to see the tool/request/details. Maybe a new /why command that tells you about the last request, it's input, output, etc. Or a /retry-verbose that re-runs the previous request but the results are verbose displayed.

    EDIT: I can confirm this is likely my provider. I managed to replicate the issue in a different IDE. However, I'd still like to have the ability to quickly enter a request into opencode CLI to see detailed info about the exact request that was dropped and stats around it.

  8. rekram1-node commented on Oct 13, 2025

    @rekram1-node
    Contributor

    thx for sharing

  9. pjv commented on Nov 21, 2025

    @pjv

    Version 1.0.85 on macOS I'm seeing the same error happening but my provider is a lemonade server on my local LAN. still possible but lower likelihood that the local machine is dropping the connection. No other agents or web chats or other means of accessing the local provider are reporting any socket errors. Just opencode.

    here's a fresh /init in a new session in a test project:

    Image

    Since upgrading to 1.0.85 it looks to me like every tool call results in the same socket connection closed error. I know that i upgraded from 1.0.65 to 1.0.85, but unfortunately I cannot recall whether I was getting successful tool calls with 1.0.65 or if the last time I successfully used opencode was with an even earlier version than that. You guys are plowing through the version numbers pretty fast 😄 .

    All I see in the log associated with the above is this:

    INFO  2025-11-21T13:28:37 +295997ms service=bus type=* unsubscribing
    INFO  2025-11-21T13:28:37 +0ms service=server event disconnected
    

    Is there somewhere I can dig to try to debug this?

  10. rekram1-node commented on Nov 21, 2025

    @rekram1-node
    Contributor

    Maybe try opencode run <prompt> --print-logs and try to get outputs?

    can also try running opencode yourself we should add some way to get fetch call logs or something

  11. pjv commented on Nov 22, 2025

    @pjv

    @rekram1-node I've updated to opencode 1.0.98 and still seeing the same tool-calling socket error. Here is the result of your print-logs suggestion. I'm not seeing anything in here that seems helpful to my eyes. You?

    ➜ opencode run "list the files in the working directory" --print-logs
    INFO  2025-11-22T10:26:52 +758ms service=default version=1.0.98 args=["run","list the files in the working directory","--print-logs"] opencode
    INFO  2025-11-22T10:26:52 +1ms service=default directory=/Users/pjv/development/projects/test python project creating instance
    INFO  2025-11-22T10:26:52 +1ms service=project directory=/Users/pjv/development/projects/test python project fromDirectory
    INFO  2025-11-22T10:26:52 +11ms service=default directory=/Users/pjv/development/projects/test python project bootstrapping
    INFO  2025-11-22T10:26:52 +3ms service=config path=/Users/pjv/.config/opencode/config.json loading
    INFO  2025-11-22T10:26:52 +0ms service=config path=/Users/pjv/.config/opencode/opencode.json loading
    INFO  2025-11-22T10:26:52 +8ms service=config path=/Users/pjv/.config/opencode/opencode.jsonc loading
    INFO  2025-11-22T10:26:52 +3ms service=bun cmd=["/usr/local/Cellar/opencode/1.0.98/libexec/lib/node_modules/opencode-ai/node_modules/opencode-darwin-x64/bin/opencode","add","@opencode-ai/plugin@1.0.98","--exact"] cwd=/Users/pjv/.config/opencode running
    INFO  2025-11-22T10:26:52 +25ms service=bun code=0 stdout=bun add v1.3.3 (274e01c7)
    
    installed @opencode-ai/plugin@1.0.98
    
    [4.00ms] done
     stderr=Saved lockfile
     done
    INFO  2025-11-22T10:26:52 +3ms service=plugin path=opencode-copilot-auth@0.0.5 loading plugin
    INFO  2025-11-22T10:26:52 +2ms service=plugin path=opencode-anthropic-auth@0.0.2 loading plugin
    INFO  2025-11-22T10:26:52 +34ms service=bus type=* subscribing
    INFO  2025-11-22T10:26:52 +0ms service=bus type=session.updated subscribing
    INFO  2025-11-22T10:26:52 +1ms service=bus type=message.updated subscribing
    INFO  2025-11-22T10:26:52 +0ms service=bus type=message.part.updated subscribing
    INFO  2025-11-22T10:26:52 +0ms service=format init
    INFO  2025-11-22T10:26:52 +0ms service=bus type=file.edited subscribing
    INFO  2025-11-22T10:26:52 +0ms service=lsp serverIds=deno, typescript, vue, eslint, gopls, ruby-lsp, pyright, elixir-ls, zls, csharp, sourcekit-lsp, rust, clangd, svelte, astro, jdtls, yaml-ls, lua-ls, php intelephense enabled LSP servers
    INFO  2025-11-22T10:26:52 +2ms service=bus type=command.executed subscribing
    INFO  2025-11-22T10:26:52 +34ms service=server method=POST path=/session request
    INFO  2025-11-22T10:26:52 +0ms service=server status=started method=POST path=/session request
    INFO  2025-11-22T10:26:52 +2ms service=session id=ses_554e5ccb7ffe5WnxS8w1Z6L2hQ version=1.0.98 projectID=global directory=/Users/pjv/development/projects/test python project title=New session - 2025-11-22T10:26:52.360Z time={"created":1763807212360,"updated":1763807212360} created
    INFO  2025-11-22T10:26:52 +1ms service=bus type=session.created publishing
    INFO  2025-11-22T10:26:52 +0ms service=bus type=session.updated publishing
    INFO  2025-11-22T10:26:52 +1ms service=server status=completed duration=4 method=POST path=/session request
    INFO  2025-11-22T10:26:52 +4ms service=server method=GET path=/config request
    INFO  2025-11-22T10:26:52 +0ms service=server status=started method=GET path=/config request
    INFO  2025-11-22T10:26:52 +0ms service=server status=completed duration=0 method=GET path=/config request
    INFO  2025-11-22T10:26:52 +3ms service=server method=GET path=/event request
    INFO  2025-11-22T10:26:52 +0ms service=server status=started method=GET path=/event request
    INFO  2025-11-22T10:26:52 +0ms service=server event connected
    INFO  2025-11-22T10:26:52 +2ms service=bus type=* subscribing
    INFO  2025-11-22T10:26:52 +1ms service=server status=completed duration=3 method=GET path=/event request
    INFO  2025-11-22T10:26:52 +1ms service=server method=POST path=/session/ses_554e5ccb7ffe5WnxS8w1Z6L2hQ/message request
    INFO  2025-11-22T10:26:52 +0ms service=server status=started method=POST path=/session/ses_554e5ccb7ffe5WnxS8w1Z6L2hQ/message request
    INFO  2025-11-22T10:26:52 +3ms service=server status=completed duration=3 method=POST path=/session/ses_554e5ccb7ffe5WnxS8w1Z6L2hQ/message request
    INFO  2025-11-22T10:26:52 +9ms service=bus type=message.updated publishing
    INFO  2025-11-22T10:26:52 +2ms service=bus type=message.part.updated publishing
    INFO  2025-11-22T10:26:52 +1ms service=bus type=session.updated publishing
    INFO  2025-11-22T10:26:52 +1ms service=bus type=session.status publishing
    INFO  2025-11-22T10:26:52 +1ms service=session.prompt step=0 sessionID=ses_554e5ccb7ffe5WnxS8w1Z6L2hQ loop
    INFO  2025-11-22T10:26:52 +4ms service=provider status=started state
    INFO  2025-11-22T10:26:52 +1ms service=models.dev file={} refreshing
    INFO  2025-11-22T10:26:52 +4ms service=provider init
    INFO  2025-11-22T10:26:52 +5ms service=provider providerID=lemonade npm=@ai-sdk/openai-compatible found
    INFO  2025-11-22T10:26:52 +0ms service=provider providerID=opencode npm=@ai-sdk/openai-compatible found
    INFO  2025-11-22T10:26:52 +0ms service=provider status=completed duration=10 state
    INFO  2025-11-22T10:26:52 +0ms service=provider providerID=lemonade modelID=Qwen3-Coder-30B-A3B-Instruct-GGUF getModel
    INFO  2025-11-22T10:26:52 +1ms service=provider status=started providerID=lemonade getSDK
    INFO  2025-11-22T10:26:52 +0ms service=provider providerID=lemonade modelID=Qwen3-4B-Instruct-2507-GGUF getModel
    INFO  2025-11-22T10:26:52 +0ms service=provider status=started providerID=lemonade getSDK
    INFO  2025-11-22T10:26:52 +76ms service=provider status=completed duration=76 providerID=lemonade getSDK
    INFO  2025-11-22T10:26:52 +2ms service=provider providerID=lemonade modelID=Qwen3-Coder-30B-A3B-Instruct-GGUF found
    INFO  2025-11-22T10:26:52 +2ms service=bus type=message.updated publishing
    INFO  2025-11-22T10:26:52 +2ms service=provider status=completed duration=82 providerID=lemonade getSDK
    INFO  2025-11-22T10:26:52 +1ms service=provider providerID=lemonade modelID=Qwen3-4B-Instruct-2507-GGUF found
    INFO  2025-11-22T10:26:52 +16ms service=bash-tool shell=/usr/local/bin/fish bash tool using shell
    INFO  2025-11-22T10:26:52 +8ms service=session.processor process
    INFO  2025-11-22T10:26:52 +5ms service=bus type=session.status publishing
    INFO  2025-11-22T10:26:52 +7ms service=bus type=message.updated publishing
    INFO  2025-11-22T10:26:52 +1ms service=bus type=session.updated publishing
    INFO  2025-11-22T10:26:52 +1ms service=bus type=session.diff publishing
    ERROR 2025-11-22T10:26:53 +960ms service=session.prompt error=Invalid JSON response Caused by: Type validation failed: Value: {"error":{"message":"Network error: CURL error: Server returned nothing (no headers, no data)","type":"network_error"}}.
    Error message: [{"expected":"array","code":"invalid_type","path":["choices"],"message":"Invalid input: expected array, received undefined"}] model=Qwen3-4B-Instruct-2507-GGUF failed to generate title
    ERROR 2025-11-22T10:26:53 +0ms service=acp-command promise={} reason=Invalid JSON response Caused by: Type validation failed: Value: {"error":{"message":"Network error: CURL error: Server returned nothing (no headers, no data)","type":"network_error"}}.
    Error message: [{"expected":"array","code":"invalid_type","path":["choices"],"message":"Invalid input: expected array, received undefined"}] Unhandled rejection
    ERROR 2025-11-22T10:26:53 +1ms service=default e=Invalid JSON response rejection
    INFO  2025-11-22T10:27:20 +27511ms service=bus type=message.part.updated publishing
    INFO  2025-11-22T10:27:21 +63ms service=bus type=message.part.updated publishing
    INFO  2025-11-22T10:27:21 +76ms service=bus type=message.part.updated publishing
    INFO  2025-11-22T10:27:21 +449ms service=bus type=message.part.updated publishing
    INFO  2025-11-22T10:27:21 +29ms service=bus type=message.part.updated publishing
    |  List     Users/pjv/development/projects/test python project
    INFO  2025-11-22T10:27:21 +138ms service=bus type=message.part.updated publishing
    INFO  2025-11-22T10:27:21 +3ms service=bus type=message.part.updated publishing
    INFO  2025-11-22T10:27:21 +1ms service=bus type=message.updated publishing
    
    <function=list
    
    INFO  2025-11-22T10:27:21 +2ms service=bus type=message.updated publishing
    INFO  2025-11-22T10:27:21 +0ms service=bus type=session.status publishing
    INFO  2025-11-22T10:27:21 +0ms service=session.prompt step=1 sessionID=ses_554e5ccb7ffe5WnxS8w1Z6L2hQ loop
    INFO  2025-11-22T10:27:21 +2ms service=bus type=message.updated publishing
    INFO  2025-11-22T10:27:21 +0ms service=bus type=message.updated publishing
    INFO  2025-11-22T10:27:21 +1ms service=bus type=session.updated publishing
    INFO  2025-11-22T10:27:21 +1ms service=bus type=session.diff publishing
    INFO  2025-11-22T10:27:21 +1ms service=bash-tool shell=/usr/local/bin/fish bash tool using shell
    INFO  2025-11-22T10:27:21 +2ms service=session.processor process
    INFO  2025-11-22T10:27:21 +4ms service=bus type=session.status publishing
    ERROR 2025-11-22T10:27:21 +49ms service=session.prompt error={"error":{"code":"ECONNRESET","path":"http://ai.msky:8000/api/v1/chat/completions","errno":0}} stream error
    ERROR 2025-11-22T10:27:21 +1ms service=session.processor error=The socket connection was closed unexpectedly. For more information, pass `verbose: true` in the second argument to fetch() process
    INFO  2025-11-22T10:27:21 +1ms service=bus type=session.error publishing
    Error: Error: The socket connection was closed unexpectedly. For more information, pass `verbose: true` in the second argument to fetch()
    INFO  2025-11-22T10:27:21 +2ms service=bus type=message.updated publishing
    INFO  2025-11-22T10:27:21 +0ms service=session.compaction pruning
    INFO  2025-11-22T10:27:21 +1ms service=session.prompt sessionID=ses_554e5ccb7ffe5WnxS8w1Z6L2hQ cancel
    INFO  2025-11-22T10:27:21 +0ms service=bus type=session.status publishing
    INFO  2025-11-22T10:27:21 +0ms service=bus type=session.idle publishing
    
  12. rekram1-node commented on Nov 23, 2025

    @rekram1-node
    Contributor

    alr ill look into it

  13. rekram1-node commented on Nov 24, 2025

    @rekram1-node
    Contributor

    @pjv that error is coming from your provider, ECONNRESET means the server cutoff opencodes connection

  14. pjv commented on Nov 24, 2025

    @pjv

    @rekram1-node I get that that's what the error means. What I don't get is why the provider only cuts off opencode. I use the same provider with other agents and front ends that also use tool-calling like goose, zed, openwebui, and none of them throw any such error or get interrupted. only opencode.

  15. rekram1-node commented on Nov 24, 2025

    @rekram1-node
    Contributor

    Can you share your opencode.json? Looks like a custom provider right

  16. pjv commented on Nov 24, 2025

    @pjv

    Yes, it's a local lemonade server running on a different host on my LAN:

    {
      "$schema": "https://opencode.ai/config.json",
      "theme": "ayu",
      "tui": {
        "scroll_speed": 1
      },
      "provider": {
        "lemonade": {
          "npm": "@ai-sdk/openai-compatible",
          "name": "Lemonade (ai.msky)",
          "options": {
            "baseURL": "http://ai.msky:8000/api/v1"
          },
          "models": {
            "Qwen3-Coder-30B-A3B-Instruct-GGUF": {
              "name": "Qwen3-Coder-30B-A3B-Instruct-GGUF"
            },
            "Qwen3-4B-Instruct-2507-GGUF": {
              "name": "Qwen3-4B-Instruct-2507-GGUF"
            },
            "nomic-embed-text-v2-moe-GGUF": {
              "name": "nomic-embed-text-v2-moe-GGUF"
            },
            "gpt-oss-120b-mxfp-GGUF": {
              "name": "gpt-oss-120b-mxfp-GGUF"
            },
            "gpt-oss-20b-mxfp4-GGUF": {
              "name": "gpt-oss-20b-mxfp4-GGUF"
            }
          }
        }
      },
      "model": "lemonade/Qwen3-Coder-30B-A3B-Instruct-GGUF",
      "small_model": "lemonade/Qwen3-4B-Instruct-2507-GGUF",
      "permission": { "edit": "allow" }
    }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions