Commit Graph
7 Commits
Author SHA1 Message Date
Michael Scheiffler 04d6f0ff03 fix(server): report unavailable ttft/tps as null when the backend reports no timing (#3955)
Related to #3947, alternative for #3808.

OpenAI-compatible cloud upstreams report no timing fields, so the
extracted ttft/tps is 0.0 (indistinguishable from an absent field) and
the per-model gauges and /v1/stats sat at false zeros after every
non-streaming request.

Render the last-value timing fields as JSON null in
Telemetry::to_json() when they hold a non-positive (i.e. unmeasured)
value — the same convention cache_tokens already uses in that
function. The update logic is unchanged; the per-model gauges sample
from the JSON, so unmeasured requests emit no sample and the series
goes stale in Prometheus.

Unit tests for the to_json() null rendering in
test_telemetry_helpers.cpp; /v1/stats field notes, response-schema
descriptions and the two gauge HELP strings updated.
2026-10-24 18:00:54 +00:00
Arun Babu Neelicattu a728a91df8 test(telemetry): prevent dangling RuntimeConfig pointer and worker thread race in telemetry helpers test (#3283)
Reset the global RuntimeConfig pointer on each iteration of the Unicode bound truncation test before stack-allocated config objects go out of scope. Disable live OTLP export in telemetry test fixtures and explicitly flush and shut down telemetry workers at test completion to avoid background worker race conditions and dangling pointer segfaults.
2026-08-21 10:12:12 +00:00
Arun Babu Neelicattu 67927b4b74 feat(telemetry): configurable session ID ingestion and OpenInference tool-call capture (#3248)
* feat(telemetry): configurable and implicit session ID ingestion

Support ingesting session and client identifiers from configured headers
(telemetry.session.headers.id and telemetry.session.headers.client) and
built-in agent headers (x-opencode-session, x-session-id, mcp-session-id,
etc.) when omitted from request body. Emit standard session.id, user.id,
and gen_ai.conversation.id attributes with client namespacing.

* feat(telemetry): capture structured tool calls in LLM output messages

Extract tool calls across streaming SSE deltas and non-streaming chat
responses. Populate standard OpenInference (llm.output_messages.*.tool_calls)
span attributes, clamp attribute lengths to telemetry.max_attribute_length,
and serialize tool calls into output.value when content is empty so trace
viewers display tool invocations.
2026-08-20 23:55:21 +00:00
Ramakrishnan SivakumarandClaude Fable 5 5b22a51528 feat(telemetry): capture prefix-cache effectiveness (cache_n, cached_tokens) and route-switch counts (#2968)
* feat(telemetry): capture prefix-cache effectiveness and route-switch counts

Closes #2955.

- Record llama-server timings.cache_n and OpenAI-wire
  usage.prompt_tokens_details.cached_tokens as cache_tokens
  (latest per model + cumulative totals), on streaming and
  non-streaming paths, local and cloud.
- Count collection.router decisions and per-conversation route
  switches, keyed by a stable conversation fingerprint (hash of
  system prompt + first user message; metrics key only).
- Expose everything in GET /v1/stats and Prometheus /metrics.
- TelemetryCallback now passes StreamingProxy::TelemetryData instead
  of five scalars so backend-reported fields extend without churn.

Co-Authored-By: Claude Fable 5 <[email protected]>

* fix(telemetry): address review — stale cache gauge, cloud usage injection, Responses field

- cache_tokens latest gauge resets to unreported (JSON null) on every
  recorded request, so a request that reports nothing can no longer
  inherit the previous request's value.
- Cloud streaming injects stream_options.include_usage when the client
  did not request it and swallows the resulting usage-only frame, so
  telemetry gets provider usage while the client-visible stream is
  unchanged; client-requested usage frames pass through untouched.
- Streaming parser also reads Responses-API
  usage.input_tokens_details.cached_tokens.

Co-Authored-By: Claude Fable 5 <[email protected]>

* fix(telemetry): atomic per-request recording and non-streaming Responses capture

- Collapse the three per-request telemetry recorders into one
  record_request_telemetry_for_model() under a single lock hold, so
  concurrent requests can no longer interleave fields (one request's
  cache reset landing on another's value).
- TelemetryData carries prompt_tokens; StreamingProxy::extract_telemetry()
  parses complete response bodies (usage chat/Responses field names,
  cached-token details, llama.cpp timings), replacing the duplicated
  handler blocks.
- Non-streaming /v1/responses now records telemetry, including
  usage.input_tokens_details.cached_tokens.

Co-Authored-By: Claude Fable 5 <[email protected]>

---------

Co-authored-by: Claude Fable 5 <[email protected]>
2026-08-14 22:00:02 +00:00
Arun Babu Neelicattu 03f8c4ca2a fix: support nested schemas, alternative token keys, and client disconnects in telemetry (#2532)
- Extract text token increments when streamed under top-level delta fields and gate them on type == "response.output_text.delta".
- Parse usage metrics and timings when nested inside a response object, and support input_tokens/output_tokens key name fallbacks.
- Unify streaming usage/timing extraction and delta accumulation in StreamingProxy static helpers.
- Allow HttpClient::post_stream to return CURLE_WRITE_ERROR to the streaming layer instead of throwing.
- Classify CURLE_WRITE_ERROR as a client disconnect, recording it as an error span in telemetry without throwing C++ exceptions.
- Add comprehensive C++ unit test coverage for parsed metrics, delta accumulation gating, and client disconnects.
2026-07-04 15:04:44 +00:00
Jeremy FowersandClaude Opus 4.8 05ce2ed622 refactor(backends): self-describing WrappedServer backends (#2287) (#2320)
* refactor(backends): self-describing WrappedServer backends (#2287)

Make each inference backend describe itself with a plain-data descriptor plus
a server class, and rewrite the scattered `if (recipe == "...")` sites to read
a registry built from those descriptors. Adding a backend becomes one
LEMON_BACKENDS line plus a descriptor + factory file — no router, CLI, docs, or
support-matrix edits.

- Descriptor types (BackendDescriptor/BackendOption/SlotPolicy) + a CLI-safe
  data registry and a server-only factory registry, generated from the
  LEMON_BACKENDS list at CMake configure time.
- All 9 backends carry a descriptor (device, slot policy, options, support
  matrix, labels, binary) and a create().
- Descriptor-driven: router creation, NPU/slot eviction, device type, recipe
  options/CLI flags, config-section identity, support matrix, recipe labels,
  cloud availability.
- /system-info recipes enriched with display_name/selectable_backend/options/
  support; the app reads recipe display names from it instead of hardcoded TS.
- docs/tools/gen_backend_docs.py generates docs/dev/backends-reference.md from
  /system-info; a CI step fails on drift. Authoring guide in
  docs/dev/adding-a-backend.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(backends): move each backend into its own folder (per spec)

Restructure the self-describing backends to the layout the issue #2287 plan
specified — one folder per backend — instead of the flat file layout I used
before. This also folds the earlier _descriptor/_factory split into the spec's
cleaner shape: the descriptor is a header-only `inline const` and create() lives
with the server class.

Each backend now lives in its own folder, in namespace lemon::backends::<stem>:
  include/lemon/backends/<stem>/<stem>.h         inline const descriptor (CLI-safe data)
  include/lemon/backends/<stem>/<stem>_server.h  WrappedServer subclass + create() decl
  server/backends/<stem>/<stem>_server.cpp       implementation + create() def

Shared registry/util files stay at the top of backends/. The CMake foreach over
LEMON_BACKENDS compiles each <stem>/<stem>_server.cpp and generates the registry
headers from the folder paths. Removes the per-backend *_descriptor.{h,cpp} and
*_factory.{h,cpp} files. Behavior is unchanged (same descriptors, same create()).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* docs(backends): mechanize the README support matrix from descriptors

Make the existing curated docs generate from the backend descriptors instead of
just shipping a separate reference file — closing appendix rows 14 and 22.

- Expand the descriptor with the editorial fields the curated docs need:
  `modality`, `experimental`, `web_display_name`, and a per-support-row
  `device_summary` (RecipeBackendDef). These keep the descriptor the single
  source of truth.
- /system-info exposes them plus a registry `order` index and `slot_policy`.
- gen_backend_docs.py now targets multiple docs and renders:
    * README.md "Supported Configurations" HTML matrix (grouped by modality,
      merged rows, rowspans, experimental tag) — wrapped in GENERATED markers;
    * docs/guide/configuration/multi-model.md NPU-exclusivity list.
  The backend-docs-drift CI job's --check now covers all three docs.

The generated README matrix is also more complete than the hand-written one
(it now includes whispercpp rocm/metal, kokoro metal, sd-cpp metal). Footnotes
and prose outside the markers are preserved.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* docs(cli): mechanize the per-recipe load-options tables from descriptors

Wrap cli.md's "Recipe-Specific Options" tables in GENERATED markers and render
them from the descriptor options. This also fixes pre-existing drift: the section
documented `--steps`/`--cfg-scale`/`--width`/`--height` flags that the CLI no
longer registers, and omitted the moonshine and vllm recipes. Now covered by the
backend-docs-drift CI check.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* docs(custom-models): mechanize the --recipe value list from descriptors

Add inline-marker support to the generator and wrap the `--recipe` "Common
values" list in custom-models.md so it renders from the descriptor recipe set
(plus collection.omni). Now covered by the backend-docs-drift CI check.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* docs: mechanize config.json example and models.js recipe metadata

Close the last two cleanly-derivable doc touchpoints (appendix rows 16 and 21).

- configuration/README.md "Example config.json": generated from a fresh lemond's
  GET /internal/config (the real canonical config). This also fixes pre-existing
  drift — the hand-written block had `config_version: 1` (now 2), `prefer_system:
  false` (now true), a stray `device` key, and an invalid trailing comma. `port`
  is normalized to the documented default 13305.
- docs/assets/models.js RECIPE_PRIORITY + RECIPE_DISPLAY_NAMES: generated from
  descriptors. A new `web_priority` editorial field preserves the curated website
  ordering (so the order is descriptor-sourced, not a silent reorder); legacy
  `oga-*` recipes are dropped as agreed. Adds the correct `vllm` display name.

The generator now drives 7 docs and supports both `<!-- -->` (Markdown) and
`/* */` (JS) GENERATED markers. backend-docs-drift --check covers all of them.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(backends): finish agreed touchpoints rows 4 & 5 (registry-drive spec; drop device map)

Two agreed plan touchpoints were left incomplete; this finishes them.

Row 4 — try_get_spec_for_recipe was still a hand-written 8-branch if-ladder in
backend_utils.cpp, which also forced it to #include all 8 server headers. Each
backend now exposes a uniform `spec()` accessor (alongside create()); the
generated factory registry binds it, and `backends::spec_for(recipe)` /
try_get_spec_for_recipe iterate the registry. backend_utils.cpp now includes
ZERO server headers. Also reroute the two leaking `Server::SPEC` references
(model_manager find_flm_binary) through the registry.

Row 5 — get_device_type_from_recipe still carried the full recipe->device map,
redundant with BackendDescriptor::default_device. Reduced to a DEVICE_NONE
fallback for non-descriptor recipes (collections/unknown); the descriptor is the
single source via ModelManager::device_type_for_recipe.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(backends): add BackendOps infrastructure (Tier-2 foundation)

Introduce a stateless per-backend behavior interface for model management that
happens WITHOUT a running subprocess (checkpoint-path resolution, download,
dynamic discovery, per-model metadata, version detection, availability) — the
home for the recipe switchboards currently scattered through model_manager and
system_info.

- BackendOps base class (lemon/backends/backend_ops.h): shared default behavior;
  backends override only the policy points they need (inherit shared logic, don't
  copy it). Methods are added incrementally as switchboards migrate; each has a
  default so adding one never forces edits to backends that don't override it.
- Each backend folder exposes a uniform ops() singleton (alongside create()/spec()),
  bound into BackendRegistration; backends::ops_for(recipe) returns it.
- Purely additive: every backend uses the default base ops for now, so there is
  no behavior change yet. Migrations follow in subsequent commits.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(backends): migrate per-model metadata to ops; move GGUF/FLM readers into folders

Replace the populate_model_metadata recipe switchboard with
ops_for(recipe)->populate_metadata(). The backend-specific readers move into
their folders:

- GGUF metadata reader (read_gguf_metadata + byte parsers) -> backends/llamacpp/
  llamacpp_gguf.{h,cpp}; LlamaCppOps::populate_metadata reads arch + capability
  labels there.
- FLM model-file helpers (config.json ctx window, model-dir discovery) ->
  backends/fastflowlm/fastflowlm_models.{h,cpp}; FlmOps::populate_metadata uses it.

model_manager no longer knows how either backend stores or introspects models.
CMake now globs each backend folder's *.cpp (CONFIGURE_DEPENDS) so backend-private
helper files need no CMake edit; the backend LIST stays explicit.

Verified: GGUF context windows still populate (131072/128000/32768 for sample
models) and test_gguf_capabilities passes.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(backends): descriptor-drive ROCm channels (kill duplicated (llamacpp||sd-cpp)&&rocm)

Add a `rocm_channels` descriptor field (llamacpp {"stable","nightly"}, sd-cpp
{"stable"}) and a recipe_has_rocm_channels() registry helper. Replace the
hardcoded `(recipe=="llamacpp"||recipe=="sd-cpp") && rocm` predicate — copied
across backend_utils.cpp (3×), backend_manager.cpp (2×), and system_info.cpp —
with the descriptor check. rocm_channel_for_recipe() now clamps a requested
channel to one the backend publishes (so sd-cpp's missing "nightly" -> "stable"
falls out of the data instead of a per-recipe special case).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(backends): migrate resolve_model_path switchboard to ops (worst leak)

Replace the ~290-line recipe switchboard in ModelManager::resolve_model_path
with ops_for(recipe)->resolve_checkpoint_path(). The model manager now only does
the generic prefix (collections, local_path/local_upload, HF cache-dir
computation) and hands off to the backend.

- New BackendOps::resolve_checkpoint_path; base = the shared HF behavior
  (active-snapshot variant/aux resolution, main-repo fallback, directory
  fallback). Backends override only their artifact layout:
    * llamacpp -> GGUF resolver (sharding/folder/quant-token), moved into
      backends/llamacpp/llamacpp_gguf (resolve_gguf_path).
    * ryzenai -> genai_config.json directory; kokoro -> index.json;
      whispercpp -> first .bin; cloud -> ""; flm -> checkpoint passthrough.
- New shared backends/hf_cache_util (exists/dir_options/active_snapshot_path/
  repo_id_to_cache_dir_name) so ops reuse the same HF-cache mechanics.

model_manager.cpp -362 lines; resolve_model_path 365 -> 34. Verified all recipes
still resolve as downloaded (llamacpp variants, whisper .bin, kokoro index,
sd-cpp, ryzenai, flm) via /models.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(backends): migrate download/discovery/is_downloaded to ops; FLM cluster → folder

Dynamic discovery, download status, and downloading now flow through BackendOps
instead of recipe switchboards in model_manager:

- discover_models: build_cache loops descriptors with dynamic_models=true and
  merges ops->discover_models(). FLM (`flm list`) and cloud (per-provider) both
  implement it — the two bespoke discovery blocks collapse to one generic loop.
- is_downloaded: base = shared HF completeness (ModelManager::checkpoints_complete);
  CloudOps → true; FlmOps → installed-set membership. Replaces the flm_set/cloud/
  else branches in build_cache and add_model_to_cache.
- validate_checkpoint_file: LlamaCppOps does the GGUF-magic check (was an inline
  llamacpp branch in are_required_checkpoints_complete).
- download_model: base = shared HF engine (download_from_huggingface_engine);
  FlmOps → flm pull; CloudOps → no-op. download_registered_model just dispatches.
  invalidates_cache_after_download() replaces the recipe=="flm" cache-reset.

The whole FLM cluster (find_flm_binary, flm_installed_checkpoints, flm_discover_models,
flm_download) moves into backends/fastflowlm/fastflowlm_models. model_manager keeps
only the generic HF engine.

Verified: server_endpoints 69 pass; download status correct for every recipe.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(backends): migrate version detection to a resolve_version ops hook

get_recipe_version now reads version.txt generically and lets the backend ops
override, instead of branching on recipe. The per-backend version commands move
into their folders:

- system llama-server version (`llama-server --version` + regex) -> backends/
  llamacpp; LlamaCppOps::resolve_version returns it for the "system" backend.
- flm version (`flm version --json`) -> backends/fastflowlm (flm_version());
  FlmOps::resolve_version returns it when no version.txt is present.

Removes SystemInfo::get_system_llamacpp_version / get_flm_version and the
llamacpp-system / flm branches from system_info.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* polish(backends): drop redundant config_section (defaults to recipe)

config_section duplicated the recipe string in 8 descriptors; it defaults to the
recipe via effective_config_section(), so set those to "". Only sd-cpp ("sdcpp")
and ryzenai-llm ("ryzenai") keep an explicit section because theirs genuinely
differ from the recipe.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(backends): gate Prometheus scraping on an exposes_prometheus_metrics descriptor flag

prometheus_metrics.cpp hardcoded `recipe == "llamacpp"` to decide whether to
scrape a backend subprocess's /metrics. Replace with a descriptor flag
(exposes_prometheus_metrics; llamacpp = true) so a new backend that exposes
Prometheus metrics opts in via its descriptor, not by editing the metrics code.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(backends): move hf_load and moonshine_arch to ModelInfo::extras

These backend-specific per-model fields no longer sit on the shared ModelInfo
struct: llamacpp reads info.extra<bool>("hf_load", false) and moonshine reads
info.extra<int>("moonshine_arch", -1). Removed the typed fields, their explicit
parse sites, and their kKnownKeys entries; added parse_extras() to the two
ModelInfo-building paths that lacked it (add_model_to_cache, get_model_info_
unfiltered) so extras populate everywhere a model is built from JSON.

Verified: llamacpp models still resolve/download (hf_load path intact).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(backends): descriptor-drive the gfx1151 CWSR availability check

Replace the hardcoded (sd-cpp||llamacpp||vllm)&&rocm recipe-list in
is_recipe_installed and build_recipes_info with a rocm_requires_cwsr_fix
descriptor flag (set on those three backends). The kernel CWSR detection
(needs_gfx1151_cwsr_fix) stays in system_info as generic hardware detection;
only "which backends' rocm build needs it" is now descriptor data.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(backends): migrate install availability to a check_install ops hook

is_recipe_installed now finds the managed binary generically and asks the
backend's ops whether it's actually installed, instead of hardcoding the
llamacpp-system HIP check and the flm PATH fallback:

- check_install(backend, binary_found) ops hook; base = installed iff binary
  found. LlamaCppOps adds the ggml HIP-plugin requirement for the "system"
  build on AMD GPUs; FlmOps treats a PATH-installed flm as present.
- is_ggml_hip_plugin_available moves into backends/llamacpp; find_flm_executable
  and run_flm_validate move into backends/fastflowlm. Removed from path_utils
  (+ their orphaned decls/comments).

system_info no longer carries llamacpp/flm-specific availability knowledge.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(backends): descriptor-drive version comparison policy (Exact vs AtLeast)

The update-required check special-cased recipe=="flm" to allow an installed
version newer than the pin. Replace with a version_policy descriptor field
(Exact default; flm = AtLeast for its system-managed package). system_info no
longer names flm in the version-comparison logic.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(backends): move FLM model deletion into the fastflowlm folder

The `flm remove` subprocess orchestration moves out of ModelManager::delete_model
into backends/fastflowlm (flm_remove). model_manager keeps only the generic
HF-cache deletion path; the flm branch is now a thin call into the backend.

Verified: server_endpoints 69 pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(config): drive recipe_options() from descriptors, not per-recipe blocks

RuntimeConfig::recipe_options() had a hardcoded nested→flat translation block per
recipe (llamacpp/whispercpp/moonshine/sdcpp/vllm). Replace with a single loop
over the descriptors: each option's config.json key is derived from its name
role (*_backend → "backend", *_args → variant "<backend>_args"/"args",
*_device → "device", else the option name verbatim for sd-cpp's steps/cfg_scale/
width/height). Adding a backend no longer requires editing this function.

Verified: server_endpoints 69 pass (config/params translation unchanged).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* polish(backends): build BackendSpec from the descriptor (dedup binary across descriptor↔server.h)

The backend binary name (and recipe) were duplicated between the descriptor
(<stem>.h) and the BackendSpec literal (<stem>_server.h) — the cross-file
redundancy. Remove the static SPEC member; each backend's spec() now builds the
BackendSpec lazily from descriptor.binary (+ descriptor.recipe, or the explicit
"ryzenai-server" install id where it differs) plus the class's get_install_params
and split flag. In-class binary lookups go through spec(); server.cpp's sd upscale
uses try_get_spec_for_recipe.

Net: the binary name now lives in exactly one place (the descriptor). Lazy
function-local statics also avoid any static-init-order coupling between the
descriptor and the spec.

Verified: builds green; system-info install detection unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* polish(backends): drop redundant recipe from descriptor support rows

The recipe was repeated on every support row (6x in llamacpp.h). Introduce
a recipe-free BackendSupport struct; the owning descriptor's recipe is filled
in by recipe_defs() when flattening to RecipeBackendDef.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* polish(backends): remove dead llamacpp-special branch in version lookup

The preceding generic block already handles backend_versions[recipe] for any
recipe, so the recipe=="llamacpp" branch was unreachable duplicate code.
Removing it also drops a hardcoded backend name from shared code.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* polish(router): replace flm/cloud recipe-string checks with slot policy

find_flm_server_by_type -> find_coexisting_server_by_type matches on
SlotPolicy::CoexistByType; count_pinned_servers_by_type skips
SlotPolicy::Unmetered instead of recipe=="cloud". router.cpp now holds
zero backend-name string literals; both behaviors are unchanged (flm is the
only CoexistByType backend, cloud the only Unmetered one).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* polish(backends): descriptor flag for self-managed downloads, not recipe==flm

Add BackendDescriptor::self_manages_downloads (true only for flm) and
ModelManager::backend_self_manages_downloads(). The two load-time
auto-download guards in server.cpp/ollama_api.cpp now consult it instead of
hardcoding recipe != "flm". flm is the only backend with the flag set, so
behavior is identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* polish(backends): move local-import checkpoint scan into BackendOps

resolve_and_register_local_model() had a recipe if/else scanning the imported
directory for each backend's primary artifact (.gguf / .bin / genai_config.json
dir). Replace with BackendOps::find_imported_checkpoint(dir): default ""
registers the directory (sd-cpp/kokoro/moonshine); llamacpp reuses
resolve_gguf_path, whisper finds the .bin, ryzenai finds genai_config.json's
dir (and its resolve_checkpoint_path now reuses the same scan). server.cpp
holds no per-recipe import logic. Verified via local_import smoke tests for
llamacpp (ignores mmproj), whisper, and a default backend.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(llamacpp): parenthesize numeric_limits::max() for MSVC

On Windows the merged include chain pulls in the windows.h max() macro into
this TU, turning std::numeric_limits<T>::max() into a syntax error (C2589).
Wrap the calls as (std::numeric_limits<T>::max)() so the macro cannot expand.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(flm): mark backend dynamic_models so its models register

flm models come from flm's model_list.json at runtime (0 entries in
server_models.json), but the descriptor had dynamic_models=false, so
build_cache skipped flm's ops->discover_models() and flm models (e.g.
llama3.2-1b-FLM) never registered -> 404. The build_cache comment already
documents flm as a dynamic-discovery backend alongside cloud; align the
descriptor with that intent.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* polish(backends): move moonshine download file-selection into ops

model_manager's download path hardcoded recipe == "moonshine" to fetch a
variant directory of files. Add BackendOps::select_checkpoint_files (default
nullopt = the GGUF/direct-file defaults) and override it in MoonshineOps. The
download path no longer names a backend.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* polish(backends): move FLM unavailable-state machine into flm ops

system_info hardcoded a recipe == "flm" block to classify FLM's
supported-but-unavailable state (.deb/driver manual setup) and emit
troubleshoot links. Add BackendOps::classify_unavailable (default nullopt =
the generic installable/no-fetch path) and implement it in FlmOps. system_info
no longer names a backend in its install-state machine.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* polish(cli): drive bench backend override from descriptor, not recipe==llamacpp

bench hardcoded recipe == "llamacpp" to send the llamacpp_backend override.
Use the CLI-safe descriptor registry: any recipe with selectable_backend gets
its <config_section>_backend override (llamacpp and vllm today).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* polish(backends): move GGUF :variant registration check into llamacpp ops

model_manager hardcoded actual_recipe == "llamacpp" to require a :variant on
GGUF checkpoints at registration. Add BackendOps::validate_registration_checkpoint
(default accept) and implement the GGUF rule in LlamaCppOps. Verified: a GGUF
checkpoint without :variant is still rejected; other recipes are unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* polish(backends): make_server<T> helper + collapse redundant namespaces

DRY pass across the backend folders:
- Add backends::make_server<T>(ctx) for the standard (log_level, model_manager,
  backend_manager) construction; the 6 plain create() bodies now call it instead
  of repeating the three context fields. cloud/ryzenai keep bespoke create().
- Each *_server.h closed and re-opened namespace lemon::backends just to nest the
  per-backend namespace; nest it inline instead (8 headers). ryzenai is left as-is
  (its legacy RyzenAIServer lives in namespace lemon, not lemon::backends).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* polish(backends): make_spec<T>/single_ops<T> helpers shrink spec()/ops()

The per-backend spec()/ops() are the name-based adapter the CMake codegen binds
(<stem>::spec/ops), so the functions must exist — but their bodies were
repetitive. Add make_spec<T>(descriptor[, split]) (backend_utils.h, where
BackendSpec is complete) and single_ops<T>() (backend_registry.h, next to
make_server) so the 7 standard spec() and 7 custom ops() collapse to one line
each. ryzenai (install key != recipe) and cloud (no spec) keep bespoke spec();
sd-cpp/vllm keep default_backend_ops(). Pure refactor — registry binding,
71/71 endpoints, and all-backends-registered smoke unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* docs(nav): add Adding a Backend + Backends Reference to mkdocs nav

The two backend dev docs added by this work (dev/adding-a-backend.md and the
generated dev/backends-reference.md) were not wired into the Development nav.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* feat(config): generate defaults.json from descriptors via /internal/config/defaults

Per-recipe config defaults are now declared in each backend descriptor
(takes_args / arg_variants / bin_variants / config_extra -> config_defaults())
instead of hand-maintained blocks in defaults.json. The committed
resources/defaults.json stays fully populated (so it remains the discoverable
reference for factory defaults) but is now generated:

- New GET /internal/config/defaults emits the canonical default config
  (ConfigFile::base_defaults(): global keys + descriptor-derived per-recipe
  sections, host/deployment-independent). Documented alongside /internal/config.
- gen_backend_docs.py -> gen_backend_boilerplate.py, which mirrors that endpoint
  verbatim into resources/defaults.json (whole-file) in addition to the doc
  regions. The existing CI --check now also fails if defaults.json drifts.

config_file keeps reading defaults.json at runtime; base_defaults() re-seeds the
descriptor blocks so the descriptor stays authoritative even if the file lags.
Verified: a fresh config.json reproduces every prior default; endpoints 71/71;
generator --check clean; black clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* polish(cli): branch hf pull on repo_kind, not recipe==llamacpp

The single-installable-unit path keyed off recipe != "llamacpp"; switch it to
repo_kind != "gguf", the same server-provided classification the function
already uses for the collection branch. Behavior-equivalent (collections are
handled earlier, so by here repo_kind is gguf or onnx-ryzenai), and it drops the
last backend-name literal from hf_pull.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(backends): functional-only comments; complete, alphabetical website model list (#2320 review)

Address Geramy's review on #2320:

- Comments: sweep every backend file to functional-only, removing commentary
  that narrates self-explanatory code or references backends/flows it can't
  know about (net ~330 comment lines cut). Short purpose comments on
  declarations and genuine WHY/invariant notes are kept.
- Website model list: drop the per-backend `web_priority` descriptor field
  (a 0-default that silently dropped backends like moonshine and vllm) and
  instead list every descriptor-backed recipe, ordered alphabetically by
  display name — a new backend can no longer be accidentally excluded.
- CMakeLists: move the authoritative LEMON_BACKENDS list near the top; the
  codegen foreach stays where it was.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* docs: document descriptor generator; add defaults.json generated-marker

Add a Key Files entry for gen_backend_boilerplate.py listing the artifact
classes it regenerates, and a top-level "_generated" sentinel in
defaults.json so anyone opening the file sees it is generated.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Small moonshine fix

---------

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-29 19:35:20 +00:00
Arun Babu Neelicattu d6cdb9de0b feat(telemetry): add unified OTLP telemetry with OpenInference and OpenTelemetry GenAI support (#2330)
* feat(telemetry): add unified OTLP telemetry

Introduce a unified, lightweight, zero-dependency telemetry layer to
replace the legacy openinference namespace. Group OTLP transport
options under a nested otlp object, and replace the format string
with a semantics list (allowing multiple active tracing conventions).

This implementation:
1. Allows users to specify semantics: [openinference, otel_genai].
2. Collects and compiles trace attributes for OpenInference and
   OpenTelemetry GenAI in a single pass when both are active.
3. Integrates queue capacity, retry/backoff, and batch exporting.
4. Refactors code structure, C++ config unit tests, python integration
   tests, CLI commands, and markdown documentation.

* build: globally define NOMINMAX on Windows in CMake
2026-06-28 19:15:05 +00:00