config: max_context caps only the /v1/models metadata

The routing cap was wrong: it rejected requests and hid the real model
limits.  Keep the real limits for routing; /v1/models reports at most
max_context, so a client sets a 131k context while the model may still
accept more.  j_models_limit keeps the #variant base matching.
This commit is contained in:
Konrad Lother committed 2026-11-20 07:30:38 +00:00
1 parent 24515eed3e
commit 89173a2ced
3 files changed
+10 -11

No files matched your search

-5
View File
@@ -1568,11 +1568,6 @@ int j_config_load(const char *path, j_config *cfg, char *err, size_t errlen)
}
if (!ep->kind[0]) snprintf(ep->kind, sizeof ep->kind, "remote");
}
/* max_context is a hard ceiling for every model, even one that advertises more. */
if (cfg->max_context > 0)
for (int i = 0; i < cfg->endpoint_count; i++)
if (cfg->endpoints[i].context > cfg->max_context)
cfg->endpoints[i].context = cfg->max_context;
if (cfg->ctx_fallback[0]) {
int found = 0;
for (int i = 0; i < cfg->pool_count; i++)
+3 -2
View File
@@ -370,8 +370,9 @@ typedef struct {
* Messung — deshalb steht er in der Konfiguration und nicht im Code. */
double ctx_chars_per_token;
/* Harte Obergrenze für alle Modelle, 0 = aus. Auch ein Modell, das mehr
* veröffentlicht, wird auf diesen Wert gekappt. */
/* Obergrenze fuer die /v1/models-Metadaten, 0 = aus. Die Modelle selbst
* behalten ihre echten Grenzen; der Client setzt nur 131k, weil die Liste
* nicht mehr verspricht. */
long max_context;
/* Modell-Politik. Sobald eine `models allow`-Zeile existiert, ist die Vorgabe
+7 -4
View File
@@ -155,8 +155,8 @@ int j_models_parse(j_endpoint *ep, const char *json, size_t len)
return n;
}
/* CFG.max_context is a hard ceiling: even a model that publishes more is
* treated as this small. 0 = no ceiling. */
/* CFG.max_context caps only what /v1/models publishes; the engine keeps the
* model's real limits and does not refuse a request because of it. */
static long cap_context(long lim)
{
if (lim > 0 && CFG.max_context > 0 && lim > CFG.max_context)
@@ -193,7 +193,7 @@ long j_models_limit(const j_endpoint *ep, const char *model, int which)
}
done:
pthread_mutex_unlock(&g_models_lock);
return cap_context(found);
return found;
}
/* Ein Muster gegen die volle ID und, falls vorhanden, gegen die ID ohne
@@ -377,7 +377,7 @@ static long effective_limit_for_rule(const j_rule *r, const char *model, int whi
}
}
}
return cap_context(best);
return best;
}
long j_models_rule_limit(const j_rule *r, int which)
@@ -576,6 +576,9 @@ int j_models_patch_list(const char *json, size_t len, char **out, size_t *out_le
* sichere Obergrenze — nicht die Endpoint-Zahl eines einzelnen Ziels. */
if (outlim <= 0) outlim = ctx;
if (ctx > 0 && outlim > ctx) outlim = ctx;
/* /v1/models must not promise more than the configured ceiling. */
ctx = cap_context(ctx);
outlim = cap_context(outlim);
/* nur ergänzen, wenn wir wenigstens eine Grenze kennen */
if (ctx <= 0 && outlim <= 0) continue;
int need_comma = 0;