Skip to content

fix(core): log background models.dev refresh failures at debug#35164

Closed
kitlangton wants to merge 1 commit into
devfrom
models-log-leak
Closed

fix(core): log background models.dev refresh failures at debug#35164
kitlangton wants to merge 1 commit into
devfrom
models-log-leak

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

Fixes #34730

Problem

ModelsDev's layer construction eagerly forks a background refresh() on a 60-minute schedule. When https://models.dev/api.json is unreachable (corporate proxy, VPN, air-gapped), each attempt logged Failed to fetch models.dev at ERROR. Two consequences:

  1. TUI corruption — if the log fires before OpenCode's file logger is installed, Effect's default logger writes to stdout, which OpenTUI owns as its frame buffer, so the error text is rendered into the terminal frame (see the bootstrap-ordering investigation in TUI corrupted by auto-fetch of models.dev error log leaks #34730 (comment)).
  2. Log spam — even with the file logger installed, a blocked network produces an ERROR on every cycle (189 entries in the reporter's log) for a best-effort refresh that has disk/bundled fallbacks.

Fix

Split failure logging by invocation kind in packages/core/src/models-dev.ts (shared with V1, so this reaches the shipped app without V1 changes):

  • The eager background scheduled refresh now logs failures at Debug. The default logger's minimum level is Info, so this can never leak to stdout regardless of logger bootstrap ordering, and the ERROR spam stops. Still diagnosable via OPENCODE_LOG_LEVEL=DEBUG.
  • The public refresh() (e.g. opencode models --refresh) keeps the ERROR log so explicit user actions still surface failures. Interface unchanged.

Disabling the auto-fetch entirely remains available via the existing documented OPENCODE_DISABLE_MODELS_FETCH flag.

Verification

  • 2 new tests in packages/core/test/models.test.ts asserting the log level for both paths via a capturing logger (11/11 pass)
  • bun typecheck clean in packages/core and packages/opencode
  • Re-ran the minimal repro from the issue comment (eager fork + failing HTTP client, no observability layer): stdout bytes went from 135 to 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI corrupted by auto-fetch of models.dev error log leaks

1 participant