Skip to content

feat(harness): pre-fetch models.dev catalog in opencode provisioner - #1283

Open
ptone wants to merge 4 commits into
mainfrom
scion/opencode-models-prefetch
Open

feat(harness): pre-fetch models.dev catalog in opencode provisioner#1283
ptone wants to merge 4 commits into
mainfrom
scion/opencode-models-prefetch

Conversation

@ptone

@ptone ptone commented Aug 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds a best-effort pre-fetch step to harnesses/opencode/provision.py that downloads the latest models catalog from https://models.opencode.ai/api.json during provision
  • Writes the catalog to ~/.cache/opencode/models.json (opencode's primary cache location) so fresh model data is available when opencode starts
  • Uses stdlib-only urllib.request with a 10-second timeout; logs success/failure via ctx.info() but never fails provision on fetch errors

Motivation

opencode bakes a models.dev snapshot at build time. When new models are released after the image is built, opencode's model validation rejects them. While opencode does a background re-fetch, the v1 Provider system doesn't refresh from it at startup. Pre-fetching the catalog during provision ensures the data is fresh before opencode reads it.

Test plan

  • Python syntax validation passes: python3 -c "import py_compile; py_compile.compile('harnesses/opencode/provision.py', doraise=True)"
  • Manual test: provision an opencode container and verify ~/.cache/opencode/models.json exists with fresh catalog data
  • Verify opencode accepts newly released models after provisioning

Scion Agent (oc-dev) added 3 commits August 27, 2026 00:17
opencode bakes a models.dev snapshot at build time; when new models
are released after the image is built, its validation rejects them.

Add a best-effort pre-fetch step that downloads the latest catalog
from models.opencode.ai during provision and writes it to the
opencode cache location (~/.cache/opencode/models.json). This
ensures fresh model data is available when opencode starts, without
failing provision if the fetch errors out.
R1: Broaden except clause to catch Exception for best-effort code
O1: Add 10MB size cap to resp.read() for defense in depth
O2: Use temp file + os.replace for atomic write
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant