Skip to content

Crash on startup when well-known credential endpoint is temporarily unavailable #22163

Closed as not planned

Description

@felixscherz

Description

When a wellknown credential is configured but the associated endpoint (<url>/.well-known/opencode) is unavailable, opencode will fail to start with the following message:

$ opencode
{
  "name": "UnknownError",
  "data": {
    "message": "Error: Unable to connect. Is the computer able to access the url?"
  }
}

This was already reported in #10930 but closed due to inactivity, the issue still persists. A fix was attempted in #14522 but the PR is yet to be merged.

A similar thing happens when the JSON is malformed, then opencode also won't start, reporting:

$ opencode
{
  "name": "UnknownError",
  "data": {
    "message": "SyntaxError: Failed to parse JSON"
  }
}

In any case, I believe opencode should handle both of these cases gracefully, either ignoring unavailable/malformed endpoints or falling back to cached values.

Plugins

No response

OpenCode version

1.4.3

Steps to reproduce

  1. Configure a local HTTP server that serves a minimal JSON payload, e.g. on http://127.0.0.1:8001/.well-known/opencode
{
  "auth": {
    "command": ["echo", "no-token"],
    "env": "DUMMY_ENV"
  },
  "config": {}
}
  1. login with opencode auth login http://127.0.0.1:8001/.well-known/opencode
  2. terminate the HTTP server
  3. run opencode and observe the failure to start

Screenshot and/or share link

No response

Operating System

macOS 15.7.3

Terminal

kitty

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 12, 2026
  2. anthonyhull-ford commented on Apr 27, 2026

    @anthonyhull-ford

    Description

    Unreachable well-known URL crashes app on startup

    Bug

    An unreachable .well-known/opencode URL in auth.json crashes the entire application on startup. The config loader fetches every well-known URL without any error handling, so a single network failure (server down, DNS unreachable, VPN disconnected) kills the process before the TUI even renders.

    Root cause

    packages/opencode/src/config/config.ts, inside loadInstanceState:

    for (const [key, value] of Object.entries(auth)) {
    if (value.type === "wellknown") {
    const url = key.replace(/\/+$/, "")
    process.env[value.key] = value.token
    log.debug("fetching remote config", { url: `${url}/.well-known/opencode` })
    const response = yield* Effect.promise(() => fetch(`${url}/.well-known/opencode`))
    if (!response.ok) {
    throw new Error(`failed to fetch remote config from ${url}: ${response.status}`)
    }
    const wellknown = (yield* Effect.promise(() => response.json())) as { config?: Record<string, unknown> }
    const remoteConfig = wellknown.config ?? {}
    if (!remoteConfig.$schema) remoteConfig.$schema = "https://opencode.ai/config.json"
    const source = `${url}/.well-known/opencode`
    const next = yield* loadConfig(JSON.stringify(remoteConfig), {
    dir: path.dirname(source),
    source,
    })
    yield* merge(source, next, "global")
    log.debug("loaded remote config from well-known", { url })
    }
    }

    The fetch() call inside Effect.promise() has no try/catch. When Bun's fetch can't connect, it throws:

    TypeError: Unable to connect. Is the computer able to access the url?
    

    This propagates as an unhandled rejection through the Effect runtime, crashing the config layer and therefore the entire startup.

    The HTTP non-ok case does throw intentionally, but the network-level failure (DNS, connection refused, timeout) is completely unhandled.

    Plugins

    No response

    OpenCode version

    1.14.28

    Steps to reproduce

    Manual reproduction

    1. Set up a local well-known server

    mkdir -p /tmp/wellknown-test/.well-known
    cat > /tmp/wellknown-test/.well-known/opencode <<'EOF'
    {
      "config": {
        "$schema": "https://opencode.ai/config.json",
        "instructions": ["Hello from well-known"]
      }
    }
    EOF

    Start the server:

    npx serve /tmp/wellknown-test -l 9999

    2. Add a wellknown auth entry

    Edit ~/.local/share/opencode/auth.json and add:

    {
      "http://localhost:9999": {
        "type": "wellknown",
        "key": "MY_TOKEN",
        "token": "dummy"
      }
    }

    3. Verify opencode starts (server running)

    opencode

    It should start normally, loading the remote config from http://localhost:9999/.well-known/opencode.

    4. Kill the server and restart opencode

    Stop the npx serve process (Ctrl+C), then:

    opencode

    Result: Process crashes immediately with:

    {"name":"UnknownError","data":{"message":"Error: Unable to connect. Is the computer able to access the url?"}}

    Expected: Opencode should log a warning, skip the unreachable well-known config, and start normally.

    5. Clean up

    Remove the http://localhost:9999 entry from ~/.local/share/opencode/auth.json to restore normal startup.

    Unit test reproduction

    Add to test/config/config.test.ts (follows the same pattern as the existing wellknown tests):

    test("config loads when wellknown URL is unreachable", async () => {
      const originalFetch = globalThis.fetch
      globalThis.fetch = mock((url: string | URL | Request) => {
        const urlStr = url instanceof Request ? url.url : url instanceof URL ? url.href : url
        if (urlStr.includes(".well-known/opencode")) {
          return Promise.reject(new TypeError("Unable to connect. Is the computer able to access the url?"))
        }
        return originalFetch(url)
      }) as unknown as typeof fetch
    
      const fakeAuth = Layer.mock(Auth.Service)({
        all: () =>
          Effect.succeed({
            "http://localhost:9999": new Auth.WellKnown({ type: "wellknown", key: "TEST_TOKEN", token: "test-token" }),
          }),
      })
    
      const layer = Config.layer.pipe(
        Layer.provide(testFlock),
        Layer.provide(AppFileSystem.defaultLayer),
        Layer.provide(Env.defaultLayer),
        Layer.provide(fakeAuth),
        Layer.provide(emptyAccount),
        Layer.provideMerge(infra),
        Layer.provide(Npm.defaultLayer),
      )
    
      try {
        await provideTmpdirInstance(
          () =>
            Config.Service.use((svc) =>
              Effect.gen(function* () {
                const config = yield* svc.get()
                expect(config).toBeDefined()
              }),
            ),
          { git: true },
        ).pipe(Effect.scoped, Effect.provide(layer), Effect.runPromise)
      } finally {
        globalThis.fetch = originalFetch
      }
    })

    This test fails today with TypeError: Unable to connect. Is the computer able to access the url? -- the unhandled fetch rejection crashes config loading. It should pass after the fix is applied.

    Screenshot and/or share link

    Image

    Operating System

    macOS Darwin 25.4.0

    Terminal

    iTerm2

  3. removed
    bugSomething isn't working
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  4. github-actions commented on Jul 3, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

  5. rndmcnlly commented on Sep 3, 2026

    @rndmcnlly

    I can confirm that it is still important that OpenCode be usable offline (e.g. with on-device inference) even when my configuration includes well-known credentials for online-only providers. I run a community-specific provider that gets non-technical users onboard via the well-known route, but it undermines my story about how OpenCode is going to offer them resilience when it falls apart offline. Just having the associated config go ignored when unavailable is much preferred to failing to launch.

    (I can imagine some scenarios where a remote config is somehow being used to lock down the general behavior of OpenCode, and letting it launch when the remote config is missing bypasses that lock-down. But who is actually using remote configs in that way? I'd rather a fail-open than fail-closed design for something like OpenCode that is user-centered rather than provider-centered.)

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