Bug Report
Version
OpenClaw 2026.7.1 (2d2ddc4)
Environment
- OS: Linux (Debian-based), self-hosted Gateway install
- Provider: Cortecs.ai, configured as a self-hosted/custom OpenAI-compatible provider (
cortecs/glm-5.2)
Expected behavior
openclaw capability model inspect --model cortecs/glm-5.2 should report the real context window Cortecs advertises for GLM-5.2.
Cortecs' own /v1/models endpoint returns this for the model row:
{
"id": "glm-5.2",
"context_size": 1048576,
...
}
(1,048,576 = 1M tokens — matches Z.ai's own published spec for GLM-5.2.)
Actual behavior
openclaw capability model inspect --model cortecs/glm-5.2 reports:
{
"id": "glm-5.2",
"contextWindow": 131000,
...
}
This under-reports the real context window by ~8x.
Root cause
discoverOpenAICompatibleLocalModels in src/plugins/provider-self-hosted-setup.ts builds each discovered model's contextWindow from:
- an explicit
params.contextWindow override, then
model.meta?.n_ctx_train (a llama.cpp-specific nested field), then
- a hardcoded fallback:
SELF_HOSTED_DEFAULT_CONTEXT_WINDOW (128,000).
It never reads a top-level context-length field directly off the /v1/models row. Cortecs (and other non-llama.cpp OpenAI-compatible catalogs) advertise the model's context window as a top-level field (context_size in Cortecs' case), which this discovery path silently ignores, falling back to the wrong hardcoded 128k default (observed as ~131k after downstream reserve-token adjustments).
Impact
Because the catalog under-reports the true context window, sessions on this model hit context-overflow-precheck and trigger auto-compaction far earlier than necessary — even when the real model has 8x more headroom. In our case this caused a large (149k-token) session to fail with:
Auto-compaction could not recover this turn ... Compaction timed out
twice in a row (both the automatic overflow-recovery attempt and a manual /compact retry hit the 180s compaction timeout), because it tried to summarize a huge session that didn't actually need to be compacted at all — the real 1M-token model would have accepted it directly.
Technical Reproduction
- Configure a self-hosted/custom OpenAI-compatible provider whose
/v1/models response advertises context length via a top-level field (e.g. context_size) rather than nesting it under meta.n_ctx_train (the only field the discovery code currently reads).
- Run model discovery / onboarding for that provider (or inspect the resulting catalog entry).
- Observe the discovered
contextWindow falls back to 128,000 instead of the provider-advertised value.
Remediation Advice
Read the commonly-used top-level field name variants (context_length, context_window, context_size) directly off the /v1/models row, in addition to the existing meta.n_ctx_train llama.cpp-specific lookup, before falling back to the hardcoded default. A PR implementing this is attached/linked.
Bug Report
Version
OpenClaw 2026.7.1 (2d2ddc4)
Environment
cortecs/glm-5.2)Expected behavior
openclaw capability model inspect --model cortecs/glm-5.2should report the real context window Cortecs advertises for GLM-5.2.Cortecs' own
/v1/modelsendpoint returns this for the model row:{ "id": "glm-5.2", "context_size": 1048576, ... }(1,048,576 = 1M tokens — matches Z.ai's own published spec for GLM-5.2.)
Actual behavior
openclaw capability model inspect --model cortecs/glm-5.2reports:{ "id": "glm-5.2", "contextWindow": 131000, ... }This under-reports the real context window by ~8x.
Root cause
discoverOpenAICompatibleLocalModelsinsrc/plugins/provider-self-hosted-setup.tsbuilds each discovered model'scontextWindowfrom:params.contextWindowoverride, thenmodel.meta?.n_ctx_train(a llama.cpp-specific nested field), thenSELF_HOSTED_DEFAULT_CONTEXT_WINDOW(128,000).It never reads a top-level context-length field directly off the
/v1/modelsrow. Cortecs (and other non-llama.cpp OpenAI-compatible catalogs) advertise the model's context window as a top-level field (context_sizein Cortecs' case), which this discovery path silently ignores, falling back to the wrong hardcoded 128k default (observed as ~131k after downstream reserve-token adjustments).Impact
Because the catalog under-reports the true context window, sessions on this model hit
context-overflow-precheckand trigger auto-compaction far earlier than necessary — even when the real model has 8x more headroom. In our case this caused a large (149k-token) session to fail with:twice in a row (both the automatic overflow-recovery attempt and a manual
/compactretry hit the 180s compaction timeout), because it tried to summarize a huge session that didn't actually need to be compacted at all — the real 1M-token model would have accepted it directly.Technical Reproduction
/v1/modelsresponse advertises context length via a top-level field (e.g.context_size) rather than nesting it undermeta.n_ctx_train(the only field the discovery code currently reads).contextWindowfalls back to 128,000 instead of the provider-advertised value.Remediation Advice
Read the commonly-used top-level field name variants (
context_length,context_window,context_size) directly off the/v1/modelsrow, in addition to the existingmeta.n_ctx_trainllama.cpp-specific lookup, before falling back to the hardcoded default. A PR implementing this is attached/linked.