Repository navigation
Description
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.1running asopencode serve --service - OS: macOS (Apple Silicon)
- Triggering client: Hex (
3.5.2), which callsPOST /api/experimental/generatefor dictation post-processing (any client calling/api/experimental/generate/textor/api/experimental/generateafter idle eviction hits this) - Model tested:
opencode-go/claude-haiku-5-5(credential active in DB;opencode modelslists it;opencode run -m opencode-go/claude-haiku-5-5succeeds)
What happens
- A long-running
opencode serve --servicedaemon caches loaded location services (plugins, providers, models) with an idle TTL and evicts them when unused. - 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.activateis forked into the background with a100 msdebounce to load plugins — including the built-inopencode.models.devplugin that populates providers and models.server.generatedoes not wait forPlugin.awaitActivation. It immediately queries the model snapshot ~1 ms after boot, sees an empty/incomplete catalog, and returns404 Model not found.
- OpenCode boots the location (
- ~400–500 ms after the
404was already returned,opencode.models.devfinishes loading and emitsprovider.updatedandmodel.updated. - 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.generatehandlesgenerate.text(/api/experimental/generate/text),generate.textLegacy(/api/experimental/generate),generate.image,generate.decisions, andgenerate.video.createusing the base-config location.- Session-based paths (
SessionRunner,SessionGenerate.generate,SessionPrompt.prepare,SessionCommand.execute,SessionShell.start,LocationWatcher.reconcile) all wait onPlugin.awaitActivation. server.generateand@opencode/Generate(Generate.text/image/decisions/video) do not callPlugin.awaitActivationbefore resolving the model viaModelResolver/@opencode/Model.- While
/api/modelexplicitly documents"The snapshot may precede initial plugin settlement",/api/experimental/generate/textis a generation endpoint that rejects requests with404 ModelNotFoundErrorif 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.
Activity
[-]server.generate: POST /api/experimental/generate/text fails with 404 Model not found on cold location boot (missing Plugin.awaitActivation)[/-][+]generate/text returns 404 "Model not found" on cold boot before plugins load[/+]opencodejr commentedon Nov 28, 2026
Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.
Thanks for the detailed report. I reproduced this on 2.4.1, and it still happens on the latest
dev(cc0677159).Setup: a fresh
opencode servewith a custom OpenAI-compatible provider in the global config. A local mock server stood in for the provider, so this is a simulated reproduction.POST /api/experimental/generate/textfor that model as soon as the server answers returns404 {"_tag":"ModelNotFoundError",...,"message":"Model not found: acme/mock-model"}.200 {"data":{"text":"pong"}}.This happened on every run. I used a fresh server start rather than idle eviction under
--serviceon macOS, but both start the location cold. The script below reproduces it. For now, retrying the request after a short delay works around it.Reproduction script (repro.sh)
Run it:
bash repro.shtylerlaprade commentedon Nov 29, 2026
I'm hitting the same thing on 2.4.2 with Claude Agent (
claude-agent/sonnet), also from Hex.It isn't only after idle, though. Generate requests don't count as activity, so the location gets evicted on schedule even while Hex is using it. I set
location_idle_timeoutto"2 minutes"and sent a generate request every 20 seconds. The location was still evicted, and the next request got the 404. Inlocation-activity.ts, only durable session events reset a location's idle timer, and generate never creates a session. So with the default 60 minutes, Hex hits this about once an hour however often you dictate.Setting
experimental.location_idle_timeouttofalseworks around it in the meantime.Wait for a model the OpenCode service is still loading
fully-autonomous commentedon Dec 3, 2026
Confirmed on 2.4.4 with a real provider and real credentials, not a mock — and it affects
generate.decisionsas well, not onlygenerate.text.Environment: Debian 13,
opencode serveunder systemd, working directory/srv/projects, Baseten credential active.What I did:
systemctl restart opencode-web, then waited ~60 s before the first request — so this is a cold location, not a cold process.POST /api/experimental/generate/decisions:{"model":{"id":"decision-models/baseten-mammoth-27b-latest","providerID":"baseten"},"input":[{"type":"text","text":"The sky is blue."}],"questions":[{"type":"predicate","name":"sky_is_blue","instructions":"Is the statement true?"}]}→
404 {"_tag":"ModelNotFoundError","providerID":"baseten","modelID":"decision-models/baseten-mammoth-27b-latest",...}200 {"data":{"answers":[{"type":"predicate","name":"sky_is_blue","probability":0.981972997924975}],"tokens":{"input":107,"output":1},...}}.Server log for the same run:
decisionsresolves 2 ms after the location boots and ~200 ms before the provider/model snapshot for that location is published — the same window described above. A second restart reproduced it exactly.Relevant detail:
server.generatepins the location toglobal.config(handlers/generate.ts:locations.get(Location.Ref.make({ directory: AbsolutePath.make(global.config) }))), so the location that boots cold is~/.config/opencode, which is otherwise only booted on demand. Any request that boots it first — e.g.GET /api/model?location[directory]=/home/ubuntu/.config/opencode— makes the nextgenerate.decisionscall succeed, which fits the plugin-activation cause.Two notes for anyone exercising this endpoint:
model.id, notmodelID(Model.Refis{id, providerID, variant?}); sendingmodelIDfails withInvalidRequestError"Missing key at ["model"]["id"]".decision, so they never appear in/api/modelunlesstypes=decisionis passed; they cannot be used as session models.Verify: restart the server, then POST to
/api/experimental/generate/decisionstwice with no intervening request. The first returns 404, the second 200.