Skip to content

[Bug]: Self-hosted/custom OpenAI-compatible model discovery ignores top-level context_size/context_length field, under-reports context window (e.g. Cortecs GLM-5.2 shows 131k instead of 1M) #109367

Description

@Mohl

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:

  1. an explicit params.contextWindow override, then
  2. model.meta?.n_ctx_train (a llama.cpp-specific nested field), then
  3. 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

  1. 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).
  2. Run model discovery / onboarding for that provider (or inspect the resulting catalog entry).
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions