Skip to content

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

Backlog

Description

@Majidalee1

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.

Activity

  1. changed the title [-]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[/+] on Nov 28, 2026
  2. added
    area/sdk-api
    inference/go
    type/bug
    version/v2
    on Nov 28, 2026
  3. opencodejr commented on Nov 28, 2026

    @opencodejr
    Contributor

    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 serve with a custom OpenAI-compatible provider in the global config. A local mock server stood in for the provider, so this is a simulated reproduction.

    • Sending POST /api/experimental/generate/text for that model as soon as the server answers returns 404 {"_tag":"ModelNotFoundError",...,"message":"Model not found: acme/mock-model"}.
    • The same request 3 seconds later returns 200 {"data":{"text":"pong"}}.

    This happened on every run. I used a fresh server start rather than idle eviction under --service on 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)
    #!/usr/bin/env bash
    # Repro for #67008: POST /api/experimental/generate/text returns 404 "Model not found"
    # on a cold server, then works for the same model a moment later.
    # Needs bun. Starts an OpenAI-compatible mock (mock.ts, next to this script) that answers "pong".
    # OC: command to run opencode (default: opencode from PATH).
    set -u
    DIR=$(cd "$(dirname "$0")" && pwd)
    OC=${OC:-opencode}
    PORT=${PORT:-4199}; MOCK_PORT=${MOCK_PORT:-4299}
    mkdir -p /tmp/opencode
    export HOME=$(mktemp -d /tmp/opencode/home-XXXX)
    export XDG_DATA_HOME=$HOME/.local/share XDG_CONFIG_HOME=$HOME/.config XDG_STATE_HOME=$HOME/.local/state XDG_CACHE_HOME=$HOME/.cache
    export OPENCODE_PASSWORD=repro-pass ACME_API_KEY=sk-fake
    mkdir -p "$HOME/project" "$XDG_CONFIG_HOME/opencode"
    cat > "$XDG_CONFIG_HOME/opencode/opencode.jsonc" <<JSON
    {
      "providers": {
        "acme": {
          "name": "Acme",
          "env": ["ACME_API_KEY"],
          "package": "@opencode/ai/providers/openai-compatible",
          "settings": { "baseURL": "http://127.0.0.1:$MOCK_PORT/v1" },
          "models": { "mock-model": { "name": "Mock" } }
        }
      }
    }
    JSON
    MOCK_PORT=$MOCK_PORT bun "$DIR/mock.ts" > "$HOME/mock.log" 2>&1 & MOCK=$!
    cd "$HOME/project"
    echo "== version: $($OC --version)"
    $OC serve --port $PORT --hostname 127.0.0.1 > "$HOME/serve.log" 2>&1 & SERVER=$!
    trap 'kill $SERVER $MOCK 2>/dev/null' EXIT
    # wait until the HTTP API answers something other than 503 service_starting
    until code=$(curl -s -o /dev/null -w "%{http_code}" -u opencode:repro-pass "http://127.0.0.1:$PORT/api/experimental/generate/text" -X POST -H "content-type: application/json" -d "{}") && [ "$code" != 000 ] && [ "$code" != 503 ]; do sleep 0.05; done
    post() { curl -s -u opencode:repro-pass -w '  [HTTP %{http_code}]\n' -X POST \
      "http://127.0.0.1:$PORT/api/experimental/generate/text" -H 'content-type: application/json' \
      -d '{"prompt":"ping","model":{"providerID":"acme","id":"mock-model"}}'; }
    echo "== 1st request, right after the server is up"; post
    sleep 3
    echo "== same request 3s later"; post

    Run it: bash repro.sh

  4. added
    status/repro-simulated
    on Nov 28, 2026
  5. tylerlaprade commented on Nov 29, 2026

    @tylerlaprade

    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_timeout to "2 minutes" and sent a generate request every 20 seconds. The location was still evicted, and the next request got the 404. In location-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_timeout to false works around it in the meantime.

  6. fully-autonomous commented on Dec 3, 2026

    @fully-autonomous

    Confirmed on 2.4.4 with a real provider and real credentials, not a mock — and it affects generate.decisions as well, not only generate.text.

    Environment: Debian 13, opencode serve under systemd, working directory /srv/projects, Baseten credential active.

    What I did:

    1. systemctl restart opencode-web, then waited ~60 s before the first request — so this is a cold location, not a cold process.
    2. First request, 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",...}
    3. The identical request immediately after → 200 {"data":{"answers":[{"type":"predicate","name":"sky_is_blue","probability":0.981972997924975}],"tokens":{"input":107,"output":1},...}}.

    Server log for the same run:

    location services booted directory=/home/ubuntu/.config/opencode durationMs=44
    Sent HTTP response http.method=POST http.url=/api/experimental/generate/decisions http.status=404
    event.type=provider.updated event.location.directory=/home/ubuntu/.config/opencode   (+197 ms)
    

    decisions resolves 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.generate pins the location to global.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 next generate.decisions call succeed, which fits the plugin-activation cause.

    Two notes for anyone exercising this endpoint:

    • the payload uses model.id, not modelID (Model.Ref is {id, providerID, variant?}); sending modelID fails with InvalidRequestError "Missing key at ["model"]["id"]".
    • the models are type decision, so they never appear in /api/model unless types=decision is passed; they cannot be used as session models.

    Verify: restart the server, then POST to /api/experimental/generate/decisions twice with no intervening request. The first returns 404, the second 200.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/sdk-apiinference/goplatform/macosstatus/repro-simulatedtype/bugversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions