opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Release macro of models.dev json broken in release bundle

Open MMunier opened this issue 10 months ago • 2 comments

Description

https://github.com/anomalyco/opencode/commit/d71153eae6c3218e45c6a32ca7becd4b13ae9414 breaks the models.dev json embedded in the release executable.

The release build has the data call, defined by the macro in https://github.com/anomalyco/opencode/blob/616329ae97c975f21687f6c8c9c6d4d8018e6fd9/packages/opencode/src/provider/models-macro.ts already resolved, however only in the actual call site.

This results in the following function being embedded in the binary, with the literal sting present in the assignment to json3:

    async function get() {
      refresh();
      const file2 = Bun.file(filepath);
      const result = await file2.json().catch(() => {});
      if (result)
        return result;
      if (typeof data === "function") {
        const json3 = await '{"privatemode-ai": ...'
        return JSON.parse(json3);
      }
      const json2 = await fetch("https://models.dev/api.json").then((x) => x.text());
      return JSON.parse(json2);
    }

However, since data is now undefined this branch can never be taken and thus the binary always falls back to fetching, even if the data is present in the binray itself, and refresh is forcibly skipped by the environment variable OPENCODE_DISABLE_MODELS_FETCH.

Plugins

No response

OpenCode version

No response

Steps to reproduce

Download the release, and search for the code. I used vim and searched for either OPENCODE_DISABLE_MODELS_FETCH or models.dev respectively

Screenshot and/or share link

No response

Operating System

ubuntu 24.04

Terminal

alacritty

MMunier avatar Jan 20 '26 12:01 MMunier

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

  • #8860: loading models.dev in built artifacts

This appears to be reporting the same underlying issue caused by the same commit (d71153eae6c3218e45c6a32ca7becd4b13ae9414) that broke bun macro inlining in release builds.

Additionally, these related issues describe the symptoms and impacts of this bug:

  • #9493: Opencode quits/hangs when models.dev not responding
  • #8830: Cannot use opencode in private network
  • #4959: [FEATURE]: Add option to disable models.dev fetch for corporate proxy environments

Feel free to ignore if this addresses a different aspect of the issue.

github-actions[bot] avatar Jan 20 '26 12:01 github-actions[bot]

Whoops github actions is correct, This is a duplicate of #8860.

MMunier avatar Jan 20 '26 12:01 MMunier