[PR #4370] [GUI] Report each native model's context window in /v1/models (n_ctx) #5025

Open
opened 2026-11-07 16:32:06 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4370
Author: @msalsas
Created: 10/27/2026
Status: 🔄 Open

Base: main ← Head: feat/native-models-nctx


📝 Commits (1)

  • 4b223b3 Native serving reports each loaded model's context window: /v1/models gains meta.n_ctx, the key the control server already uses, left out when unknown rather than 0 (#3931)

📊 Changes

3 files changed (+72 additions, -1 deletions)

View changed files

📝 apps/host/server/index.mjs (+2 -1)
➕ apps/host/server/native-models.mjs (+9 -0)
➕ apps/host/tests/native-models.test.mjs (+61 -0)

📄 Description

The problem

When the app serves native models, GET /v1/models lists each ready model with its id, GPUs, label and aliases, but not its context size (#3931). A client that reads the list can't tell how many tokens a model accepts. So it has to guess the size or ask the user to type it in.

What the change does

Each entry in the native /v1/models list now has meta.n_ctx, the model's context window in tokens. serve/server.py already uses this key, so clients that work with it there also work here.

The value comes from two places, in this order:

  1. The window the engine reports (metrics.engine.max_context).
  2. The configured context of the instance (context), if the engine has not reported one.

Only a positive integer counts. If neither value is known, the key is left out and not set to 0. A window of 0 makes some clients think there is no room, and then they send nothing (#351). A missing key lets them fall back to their own default. The other keys in each entry are the same as before.

The approach

The list is now built by a small pure function, nativeModelEntries in apps/host/server/native-models.mjs. index.mjs calls it in place of the inline map. The function does not change its input, so it can be tested without a running engine.

It checks the two values in the same order as index.mjs (the instance summary and contextMax) and oversize.mjs: the engine value first, then the config. All three places agree on which number is the window. One small difference: those places use ??, so a 0 would win there, while here a 0 is skipped as unknown.

Validation

Passed:

  • 8 new unit tests in apps/host/tests/native-models.test.mjs pass on Node 22 (Linux arm64). They cover the config value, the engine value winning, a fallback when the engine value is unusable, the key being left out when the value is unknown, only ready instances being listed in order, empty input, the input not being changed, and n_ctx being the only new key.

Host suite (npm test in apps/host), run on a Raspberry Pi:

  • The set of failing tests is the same on main and on this branch.
  • One timing test is flaky on the Pi.
  • Parts of the full suite were killed by the system for running out of memory on the Pi. Those parts did not run to the end on either branch.

Not run:

  • No live check with curl against /v1/models. The test machine has no native engine.

Known limits

  • The runtime path (non-native serving) is unchanged. It still reports the window as meta.context and does not add n_ctx.
  • serve/server.py reports n_ctx: 0 when the window is unknown. This change leaves the key out instead. So the two servers still differ in that one case.

Fixes #3931


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4370 **Author:** [@msalsas](https://github.com/msalsas) **Created:** 10/27/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/native-models-nctx` --- ### 📝 Commits (1) - [`4b223b3`](https://github.com/Niko1221/Strata/commit/4b223b3a61251f6f8ad2e8a7036a76db787e72ec) Native serving reports each loaded model's context window: /v1/models gains meta.n_ctx, the key the control server already uses, left out when unknown rather than 0 (#3931) ### 📊 Changes **3 files changed** (+72 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `apps/host/server/index.mjs` (+2 -1) ➕ `apps/host/server/native-models.mjs` (+9 -0) ➕ `apps/host/tests/native-models.test.mjs` (+61 -0) </details> ### 📄 Description ## The problem When the app serves native models, `GET /v1/models` lists each ready model with its id, GPUs, label and aliases, but not its context size (#3931). A client that reads the list can't tell how many tokens a model accepts. So it has to guess the size or ask the user to type it in. ## What the change does Each entry in the native `/v1/models` list now has `meta.n_ctx`, the model's context window in tokens. `serve/server.py` already uses this key, so clients that work with it there also work here. The value comes from two places, in this order: 1. The window the engine reports (`metrics.engine.max_context`). 2. The configured context of the instance (`context`), if the engine has not reported one. Only a positive integer counts. If neither value is known, the key is left out and not set to 0. A window of 0 makes some clients think there is no room, and then they send nothing (#351). A missing key lets them fall back to their own default. The other keys in each entry are the same as before. ## The approach The list is now built by a small pure function, `nativeModelEntries` in `apps/host/server/native-models.mjs`. `index.mjs` calls it in place of the inline map. The function does not change its input, so it can be tested without a running engine. It checks the two values in the same order as `index.mjs` (the instance summary and `contextMax`) and `oversize.mjs`: the engine value first, then the config. All three places agree on which number is the window. One small difference: those places use `??`, so a 0 would win there, while here a 0 is skipped as unknown. ## Validation Passed: - 8 new unit tests in `apps/host/tests/native-models.test.mjs` pass on Node 22 (Linux arm64). They cover the config value, the engine value winning, a fallback when the engine value is unusable, the key being left out when the value is unknown, only ready instances being listed in order, empty input, the input not being changed, and `n_ctx` being the only new key. Host suite (`npm test` in `apps/host`), run on a Raspberry Pi: - The set of failing tests is the same on `main` and on this branch. - One timing test is flaky on the Pi. - Parts of the full suite were killed by the system for running out of memory on the Pi. Those parts did not run to the end on either branch. Not run: - No live check with `curl` against `/v1/models`. The test machine has no native engine. ## Known limits - The runtime path (non-native serving) is unchanged. It still reports the window as `meta.context` and does not add `n_ctx`. - `serve/server.py` reports `n_ctx: 0` when the window is unknown. This change leaves the key out instead. So the two servers still differ in that one case. Fixes #3931 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5025
No description provided.