Skip to content

fix(config): honor model.context_window as context_length alias - #15587

Open
novax635 wants to merge 1 commit into
NousResearch:mainfrom
novax635:fix/config-context-window-alias
Open

fix(config): honor model.context_window as context_length alias#15587
novax635 wants to merge 1 commit into
NousResearch:mainfrom
novax635:fix/config-context-window-alias

Conversation

@novax635

@novax635 novax635 commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

PR Description

This PR makes model.context_window work as a compatibility alias for model.context_length in explicit config override paths.

Hermes already accepts context_window in model metadata parsing, but a few manual config-reading paths only checked model.context_length. As a result, users who configured:

model:
  context_window: 1000000

could still see Hermes fall back to the detected/default context value instead of using the configured override.

This caused incorrect context behavior in agent initialization and gateway status/hygiene flows.

What was fixed

The following paths now read model.context_window when model.context_length is not set:

  • agent initialization in run_agent.py
  • gateway session hygiene context resolution in gateway/run.py
  • gateway session info/status formatting in gateway/run.py

model.context_length still takes precedence when both values are present.

Why this matters

Without this alias, users may believe they configured a larger context window, while Hermes silently ignores it in some runtime paths.

That can lead to:

  • incorrect context size shown in gateway/session info
  • premature context pressure or compression behavior
  • hygiene logic making decisions based on the wrong context limit

Behavior

Priority order is now:

model.context_length
model.context_window
detected/default context value

Invalid values continue to use the existing warning/fallback behavior.

Tests

Added regression coverage for the affected paths:

  • test_context_window_alias_works
  • test_context_window_alias
  • test_session_hygiene_honors_context_window_alias
scripts/run_tests.sh tests/run_agent/test_invalid_context_length_warning.py tests/gateway/test_session_info.py tests/gateway/test_session_hygiene.py

Result:

36 passed, 4 warnings

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery area/config Config system, migrations, profiles labels Apr 25, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #8010 — same fix: honor model.context_window as alias for context_length in config override paths.

@novax635 novax635 changed the title Title fix(config): honor model.context_window as context_length alias fix(config): honor model.context_window as context_length alias Apr 25, 2026
@novax635
novax635 marked this pull request as draft April 25, 2026 10:23
@novax635
novax635 marked this pull request as ready for review April 25, 2026 10:23
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for tracing the agent and gateway override paths.

Problems

  • The requested alias conflicts with the explicit maintainer decision on #28634: Hermes keeps model.context_length as the single canonical config key. Current main still implements that choice at agent/agent_init.py:1632 and gateway/run.py:10600, gateway/run.py:11023, and gateway/run.py:12227.
  • Independently, this patch is incomplete against current main: other top-level readers remain in tui_gateway/server.py:2909, hermes_cli/context_switch_guard.py:148, hermes_cli/web_server.py:5140, and model_tools.py:590.
  • If an alias were ever adopted, gateway hot reload would also need updating: _CACHE_BUSTING_CONFIG_KEYS contains only model.context_length at gateway/run.py:15624.

Suggested changes

  • Please retain the documented model.context_length key unless maintainers choose to change the canonical-key policy.

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) sweeper:blast-broad Sweeper blast radius: broad — a core path most sessions hit labels Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists sweeper:blast-broad Sweeper blast radius: broad — a core path most sessions hit sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants