Skip to content

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

Merged
ptone merged 4 commits into
GoogleCloudPlatform:mainfrom
ptone:scion/opencode-models-prefetch
Aug 27, 2026
Merged

feat(harness): pre-fetch models.dev catalog in opencode provisioner#1308
ptone merged 4 commits into
GoogleCloudPlatform:mainfrom
ptone:scion/opencode-models-prefetch

Conversation

@ptone

@ptone ptone commented Aug 27, 2026

Copy link
Copy Markdown
Member

Summary

Adds a best-effort pre-fetch step to the opencode provisioner that downloads the latest models catalog from models.opencode.ai during provision and writes it to opencode cache location (~/.cache/opencode/models.json).

Motivation

opencode bakes a models.dev snapshot at build time. When new models are released after the image is built, opencode model validation rejects them. Pre-fetching the catalog during provision ensures fresh model data is available before opencode starts.

Changes

Single file: harnesses/opencode/provision.py

  • New function _prefetch_models_catalog(ctx): fetches https://models.opencode.ai/api.json with 10s timeout, writes to cache with atomic tmp+replace pattern
  • Best-effort: broad except Exception catches all errors, logs via ctx.info(), never fails provision
  • 10MB read cap for defense in depth
  • Called after auth resolution, before provision returns
  • Stdlib only (urllib.request), no external dependencies

Related: ptone#1283

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
@google-cla

google-cla Bot commented Aug 27, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a pre-fetching mechanism for the latest models catalog from models.opencode.ai during the provisioning step of the opencode harness, saving it to a local cache to ensure fresh model data. The review feedback suggests validating that the fetched catalog is indeed valid JSON before caching it, preventing potential crashes or parsing failures in opencode if an invalid response or error page is received.

Comment thread harnesses/opencode/provision.py Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@ptone
ptone merged commit e045b6e into GoogleCloudPlatform:main Aug 27, 2026
9 of 10 checks passed
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