Skip to content

fix(settings): inherit condenser max_tokens from LLM effective_max_input_tokens - #4435

Merged
enyst merged 4 commits into
OpenHands:mainfrom
vnktadithya:fix/condenser-inherit-max-tokens-3746
Aug 9, 2026
Merged

enyst merged 4 commits into
OpenHands:mainfrom
vnktadithya:fix/condenser-inherit-max-tokens-3746

Conversation

@vnktadithya

@vnktadithya vnktadithya commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:

Resolves #3746. Traced the bug and found the root cause is in build_condenser() in model.py where the LLM's configured max_input_tokens was getting dropped instead of reaching the condenser. Fixed it, wrote tests, and verified everything locally.


AGENT:

Why

build_condenser in LLMSummarizingCondenserSettings calls
self.model_dump(..., exclude_none=True), which strips max_tokens
whenever it's left unset (default None). As a result, the condenser is
built with no token limit and only condenses based on event count
(max_size=240). A configured llm.max_input_tokens (e.g. via
agent_settings.json in headless CLI mode) never reaches the condenser,
so a single large tool/terminal output can exceed the real context window
while still counting as "1 event" — nothing triggers summarization, and
the LLM call can fail with a context-length error.

Summary

  • Inherit llm.effective_max_input_tokens into the condenser's max_tokens when it isn't explicitly configured
  • Explicit condenser max_tokens values still take priority and are never overridden
  • Added 4 tests covering inheritance, explicit-value precedence, and no-regression when neither is set

Issue Number

Closes #3746

How to Test

  1. Tests
uv run pytest tests/sdk/context/ tests/sdk/test_settings.py tests/sdk/llm/test_llm.py -q

Result: all passing.

  1. Repository checks
uv run pre-commit run --files openhands-sdk/openhands/sdk/settings/model.py tests/sdk/test_settings.py

Result: Ruff format, Ruff lint, pycodestyle, pyright, import rules, and tool registration checks all passed.

Video/Screenshots

Not applicable — this is a backend logic fix with no UI/visual surface; covered by the automated test evidence above.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

No config or API changes — this only affects the default behaviour when a condenser max_tokens isn't explicitly set.

Copilot AI lite review requested due to automatic review settings August 8, 2026 14:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a settings propagation bug in the SDK where the LLM’s configured context window (max_input_tokens / effective_max_input_tokens) was not reaching the LLM summarizing condenser unless the condenser’s own max_tokens was explicitly set, preventing token-count-based condensation in some configurations (notably headless CLI settings payloads).

Changes:

  • Inherit llm.effective_max_input_tokens into the condenser’s max_tokens when not explicitly configured.
  • Add tests validating inheritance, explicit condenser precedence, and no-regression behavior when no LLM limit is set.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
openhands-sdk/openhands/sdk/settings/model.py Updates build_condenser() to default condenser max_tokens from the agent LLM’s effective max input tokens.
tests/sdk/test_settings.py Adds unit tests covering the new inheritance behavior and precedence rules.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/sdk/test_settings.py Resolved
vnktadithya and others added 3 commits August 8, 2026 22:04
exclude_none=True in condenser_kwargs drops max_tokens whether it was
never set or explicitly set to None, making the two indistinguishable.
Checking self.model_fields_set instead correctly detects explicit None,
so a user who deliberately disables token-based condensation isn't
silently overridden by inheritance from the LLM's max_input_tokens.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@enyst enyst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@enyst
enyst merged commit be6cd3b into OpenHands:main Aug 9, 2026
29 checks passed
@vnktadithya

vnktadithya commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Thank you @enyst for the review and for merging this — really appreciate you taking the time, especially as my first Open-Source-contribution.

@vnktadithya
vnktadithya deleted the fix/condenser-inherit-max-tokens-3746 branch August 18, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

max_input_tokens in agent_settings.json does not take effect in headless CLI mode

3 participants