Skip to content

Report an offline model endpoint as 503, not model_not_found #497

Closed

Description

@barelyworkingcode

User story

As an operator, I want a model request to an offline endpoint to fail as "host unavailable" (503), so that a short network blip is not reported as a missing model.

Acceptance criteria

  • A request for a model whose endpoint is marked offline returns 503 with the endpoint name.
  • A model absent from every endpoint still returns 404 not_found.
  • The offline mark clears within the existing 15 s window.

What I'd notice

A clearer error during a brief outage.

Context

Found while working devboxWorld#38. One failed DNS lookup made relayLLM mark the endpoint offline, the catalog dropped the model key, and relay's broker answered 404 not_found for 15 s (cmd/relay/model_endpoint.go:848-851). Claude Code and eve showed "model_not_found".

Tasks

  • Keep offline models in the catalog, flagged unavailable.
  • Return 503 for them.
  • Test both paths.

Contract

Relay can't tell an offline endpoint's model from an absent one: relayLLM drops an offline endpoint's rows (and any modelMap key that targets them) from GET /v1/models. The smallest relay fix reads a new per-row flag from the host's catalog. It does not keep its own memory of past rows. Emitting the flag is relayLLM work (question 1). This PR is the relay half. It is backward compatible: with no flag, relay behaves as today.

Interfaces

Host catalog row (relayLLM -> relay, GET /v1/models on router.sock). One new optional field on a row:

{"id":"acme-lab/fake-echo","object":"model","owned_by":"acme-lab","endpoint_offline":"acme-lab"}
{"id":"acme-sonnet","object":"model","owned_by":"anthropic-map","target":"acme-lab/fake-echo","endpoint_offline":"acme-lab"}
  • endpoint_offline: the name of the endpoint whose last probe failed. Absent or "" means available. Relay reads any non-empty string as offline.
  • relayLLM sets it on each last-known model of an offline endpoint, and on a modelMap key whose target is such a row. It never sets it on managed or virtual rows (a virtual model keeps its last-resort routing).

internal/modelbroker/catalog.go

type Row struct {
    // ...existing fields...
    // OfflineEndpoint is relayLLM's endpoint_offline: the endpoint whose last
    // probe failed. "" means available.
    OfflineEndpoint string
}

// OfflineEndpoint reports whether the row with id canonical is flagged offline,
// and names its endpoint.
func OfflineEndpoint(rows []Row, canonical string) (endpoint string, offline bool)
  • Cache.Resolve(ctx, id): a hit on a row with OfflineEndpoint != "" counts as a miss for the one extra refetch, unless this call already fetched. The one-fetch-per-call bound stays. This keeps relay's 30 s TTL from holding an offline mark that relayLLM already cleared.
  • Filter(rows, grant) drops rows with OfflineEndpoint != "". /v1/models, /models and relay-sessions' list (it reads model.sock /v1/models) stay as they are today.
  • Allowed, ClassifyMessagesModel and canonicalize are unchanged.

internal/modelbroker/errors.go

// EndpointUnavailableError is the 503 for a granted model whose endpoint the
// host lists as offline.
func EndpointUnavailableError(shape Shape, endpoint string) ErrorBody // Status 503, Reason "host_unavailable"

The wire bodies are built with json.Marshal, never string concatenation:

  • OpenAI shape: {"error":{"message":"model endpoint \"<name>\" unavailable","type":"server_error","code":"endpoint_unavailable"}}
  • Anthropic shape: {"type":"error","error":{"type":"api_error","message":"model endpoint \"<name>\" unavailable"}}

cmd/relay/model_endpoint.go

  • fetchCatalog decodes endpoint_offline (json:"endpoint_offline,omitempty") into Row.OfflineEndpoint.
  • serveLocal: the new check runs after Allowed returns ok and before the body rewrite. When modelbroker.OfflineEndpoint(rows, canonical) is offline, it writes EndpointUnavailableError(route.Shape, endpoint) and audits outcome host_unavailable with requested and canonical. Nothing is forwarded.
  • The order stays: auth (401), remote project (403), grant (404, byte-identical for denied and not found), then offline (503). A caller outside the grant never sees the 503.
  • model.request ends error/unavailable with http_status 503. That mapping exists, so no change to events or audit vocabulary.

File ownership

Task Owns
T1 dev internal/modelbroker/catalog.go, internal/modelbroker/errors.go, cmd/relay/model_endpoint.go, docs/model-endpoint.md, docs/routes.md, docs/FEATURES.md
T2 test (e2e) e2e/fakes/fakemodelhost/main.go, e2e/harness/fakes.go, e2e/features/g6_offline_endpoint_test.go (new)
T3 verification no files

No file is shared.

  • T1 docs:
    • model-endpoint.md: add an endpoint_offline row to the catalog field table, the Resolve rule to Catalog cache, and the 503 to Scoping.
    • routes.md section 6: add a 503 model endpoint "<name>" unavailable row to the error table, and the same 503 to model:POST /v1/messages.
    • FEATURES.md: add this row, with the T2 test names exactly as written:

| G6.06| Offline model endpoint | A call for a granted model whose endpoint the model host lists as offline answers 503 naming the endpoint; a model in no endpoint still answers 404; the first call after the host lists it online again is served. | n/a | n/a |model:POST /v1/chat/completions model:POST /v1/messages| none |event:model.request=error/unavailable code:model:POST /v1/chat/completions#503 code:model:POST /v1/messages#503|e2e:TestModelEndpointOffline503 e2e:TestModelAbsentEverywhere404 e2e:TestModelEndpointOfflineClears |

  • T2 fake: fakemodelhost re-reads its --models file on every GET /v1/models. TestFakeModelHostServesCatalogue must stay green.
  • T2 harness: add func (i *Instance) SetFakeModelHostModels(rows []json.RawMessage). It writes i.fakePath(i.modelHost.ID + ".models.json") through a temp file in the same directory and os.Rename, and fails t on error.

Paths

  • Simple path: someone in eve or Claude Code has a short endpoint outage. The error now reads model endpoint "<name>" unavailable (503), not model_not_found. Their next call after recovery works. Nothing to choose.
  • Power path: none. Nothing is configurable. The 15 s window is relayLLM's probe TTL (proxyRegistryTTL), and it is not changed.

Acceptance mapping

Criterion Task, interface Test
Offline endpoint's model -> 503 with endpoint name T1 serveLocal + OfflineEndpoint + EndpointUnavailableError TestModelEndpointOffline503: chat completions on acme-lab/fake-echo and /v1/messages on modelMap key acme-sonnet answer 503 with "acme-lab" in the message, in the OpenAI and Anthropic shapes; the fake logs no forwarded call; a project whose allowed_models excludes the model gets the byte-identical 404; GET /v1/models does not list the offline rows
Model absent everywhere -> 404 not_found unchanged Allowed path; T1 must not regress it TestModelAbsentEverywhere404: with offline rows present, a granted (*) call for no-such-model answers 404 model_not_found, byte-equal to today's body
Offline mark clears in the existing 15 s window T1 Cache.Resolve refetch on an offline hit TestModelEndpointOfflineClears: a call answers 503; then SetFakeModelHostModels writes the same rows without endpoint_offline; the next call answers 200 (echo). The test never advances relay's clock: the refetch rule must make it pass, not TTL expiry

Test surface

  • e2e (e2e/features): all three criteria.
  • No unit tests (repo rule).
  • No Playwright pass.
  • devboxverify --phase api: a regression run only.
  • Break-and-restore target: remove the OfflineEndpoint check in serveLocal. TestModelEndpointOffline503 must go red.

Waits

  • T1: none. It adds no test; go build ./... && go vet ./... are synchronous.
  • T2:
    • Boot: harness.Start (ready.json).
    • Host: i.WaitModelHost(g6Deadline) (event model.host.register=ok).
    • Catalog swap: SetFakeModelHostModels returns after the rename (completion). The fake reads the file per request, so no further wait.
    • Reply: the HTTP response.
    • Event: i.WaitEvent(EventQuery{Key: "model.request", Trace: trace, Fields: {"http_status": 503}}, g6Deadline). Never i.Events right after an error reply: writeError answers before audit logs.
    • No audit-row assertions: the audit hook runs after the event line and has no signal.
    • No sleeps, and no relay debug clock advance.
  • T3: process exits. stack-up prints STACK up r497 <stack.json> and exits; devboxverify exits; stack-down exits.

Tasks

  • T1: flag, refetch, 503, docs and the FEATURES row (above).
  • T2: fake re-read, harness setter, three e2e tests (above).
  • T3 Verification task, no devlock, on the PR head:
    • (cd e2e && go test -race ./features/).
    • Unlock the devid keychain. Run npm ci in an eve main checkout.
    • From devboxWorld: ./stack-up.sh r497 --relay <head worktree> --eve <eve main checkout>.
    • From the head worktree: go run ./cmd/devboxverify --stack <stack.json> --phase api.
    • ./stack-down.sh r497.
    • Post Verified: <head sha> · repo-suite: <result> · devboxverify: <result> · log: <path>.
    • real-app: does not apply to this PR. No shipped model host emits endpoint_offline yet, so the real app can't show the change. The relayLLM counterpart's verification carries the real-app check, against relay main with this PR merged: take an endpoint offline, see the 503 naming it in eve, bring it back, see the next turn served.

Budget

  • T1: 6 files, about 110 lines (code about 60).
  • T2: 3 files, about 220 lines.
  • Going past either is a question for the coordinator.

Open questions

  1. BEYOND. Recommend: the coordinator files a barelyworkingcode/relayLLM issue (needs-review, from-dev, linking barelyworkingcode/relay#497). In it, relayLLM keeps an offline endpoint's last-known models, and the modelMap keys that target them, in /v1/models with endpoint_offline, and the 15 s TTL stays. Relay#497 merges first; it changes nothing until that ships. Why: issue task 1 ("keep offline models in the catalog") is relayLLM's catalog, which today clears an endpoint's models on a failed probe.
  2. INSIDE. Recommend: name the endpoint for a modelMap key too. Criterion 1 asks for the name, and the issue's own case was a modelMap key. The caller has passed auth and grant. The target id stays hidden; only its endpoint label shows. THREAT-MODEL.md makes no promise about it.
  3. INSIDE. Recommend: hide offline rows from every listing (Filter), so pickers stay as today and offer nothing that would fail.
  4. INSIDE. Recommend: reuse audit outcome host_unavailable, with no new audit or event vocabulary.
  5. INSIDE. Recommend: an offline row that is not a modelMap key, asked for on /v1/messages, stays 404 under the existing route rule.

Activity

  1. added
    enhancement
    needs-review
    from-dev
    on Oct 18, 2026
  2. barelyworkingcode commented on Oct 19, 2026

    @barelyworkingcode
    OwnerAuthor

    Coordinator approval: owner asked, 2026-10-19 (approved every waiting idea)

  3. removed
    needs-review
    on Oct 19, 2026
  4. barelyworkingcode commented on Oct 20, 2026

    @barelyworkingcode
    OwnerAuthor

    Coordinator: contract questions take the planner's recommendations (1-5). relayLLM half filed as barelyworkingcode/relayLLM#35.

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

    enhancementfrom-dev

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions