generate/text returns 404 "Model not found" on cold boot before plugins load

Đang mở
#67,008 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
api, backend

Hướng nghiên cứu

Start with server.generate and compare its model-resolution path with SessionGenerate.generate, which already waits for Plugin.awaitActivation. Verify the change in the @opencode/Generate paths as well if the fix is placed at that layer. Done means a cold or freshly booted base-config location waits for plugin activation before resolving the model, so a valid authenticated model returns a generation response rather than 404 Model not found.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

area/sdk-api inference/go platform/macos status/repro-simulated type/bug version/v2
TL;DR

Calling POST /api/experimental/generate/text (or its deprecated alias POST /api/experimental/generate) after OpenCode's base-config location has been evicted — or on a fresh server — intermittently fails with 404 Model not found even for valid, authenticated models.

The handler boots the location and tries to resolve the model ~1 ms later, while PluginSupervisor is still loading opencode.models.dev in a background fiber (~400 ms later). Unlike session endpoints, server.generate never awaits Plugin.awaitActivation.


Environment
  • OpenCode: 2.4.1 running as opencode serve --service
  • OS: macOS (Apple Silicon)
  • Triggering client: Hex (3.5.2), which calls POST /api/experimental/generate for dictation post-processing (any client calling /api/experimental/generate/text or /api/experimental/generate after idle eviction hits this)
  • Model tested: opencode-go/claude-haiku-5-5 (credential active in DB; opencode models lists it; opencode run -m opencode-go/claude-haiku-5-5 succeeds)

What happens
  1. A long-running opencode serve --service daemon caches loaded location services (plugins, providers, models) with an idle TTL and evicts them when unused.
  2. When a stateless request hits POST /api/experimental/generate (or /api/experimental/generate/text) after that base-config location was evicted:
    • OpenCode boots the location (location services booted).
    • PluginSupervisor.activate is forked into the background with a 100 ms debounce to load plugins — including the built-in opencode.models.dev plugin that populates providers and models.
    • server.generate does not wait for Plugin.awaitActivation. It immediately queries the model snapshot ~1 ms after boot, sees an empty/incomplete catalog, and returns 404 Model not found.
  3. ~400–500 ms after the 404 was already returned, opencode.models.dev finishes loading and emits provider.updated and model.updated.
  4. Because that failed request warmed up the location, the very next request a few seconds or minutes later succeeds — until the location goes idle, gets evicted again, and the next request fails again.

Log evidence

Every single 404 in ~/.local/share/opencode/log/opencode.log (18 occurrences over 4 days) follows the exact same millisecond sequence:

# Base-config location was previously evicted after idle timeout:
2026-11-28T16:02:48.083Z level=INFO run=5b4fd86e message="watcher stopped" path=~/.config/oc-v1/opencode type=directory

# Next POST /api/experimental/generate arrives -> boots location -> immediately 404s (1 ms later):
2026-11-28T16:38:23.501Z level=INFO run=5b4fd86e message="location services booted" directory=~/.config/oc-v1/opencode durationMs=31
2026-11-28T16:38:23.502Z level=INFO run=5b4fd86e message="Sent HTTP response" http.method=POST http.url=/api/experimental/generate http.status=404

# Built-in plugins finish loading ~425 ms AFTER the 404 was already sent:
2026-11-28T16:38:23.926Z level=INFO run=5b4fd86e message=event event.type=provider.updated event.location.directory=~/.config/oc-v1/opencode
2026-11-28T16:38:23.932Z level=INFO run=5b4fd86e message=event event.type=model.updated event.location.directory=~/.config/oc-v1/opencode

(Successful 200 responses don't appear in opencode.log because the response middleware suppresses status < 400, but subsequent requests succeed once the location is warm — e.g. failing at 14:54:42Z and succeeding at 14:58:35Z without any restart.)


Root cause in OpenCode (2.4.1)
  • server.generate handles generate.text (/api/experimental/generate/text), generate.textLegacy (/api/experimental/generate), generate.image, generate.decisions, and generate.video.create using the base-config location.
  • Session-based paths (SessionRunner, SessionGenerate.generate, SessionPrompt.prepare, SessionCommand.execute, SessionShell.start, LocationWatcher.reconcile) all wait on Plugin.awaitActivation.
  • server.generate and @opencode/Generate (Generate.text / image / decisions / video) do not call Plugin.awaitActivation before resolving the model via ModelResolver / @opencode/Model.
  • While /api/model explicitly documents "The snapshot may precede initial plugin settlement", /api/experimental/generate/text is a generation endpoint that rejects requests with 404 ModelNotFoundError if plugins haven't settled yet.

Suggested fix

Await Plugin.awaitActivation inside server.generate (or inside @opencode/Generate before calling ModelResolver.resolve*) when booting/using the base-config location, matching what SessionGenerate.generate already does.

Ngôn ngữ chính
TypeScript
Star
230k
Fork
31.3k
Merge trung bình
5 giờ 32 phút
Pull request đã merge (30 ngày)
453

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của anomalyco/opencode

Tất cả issue của anomalyco/opencode

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.