Repository navigation
fix(settings): inherit condenser max_tokens from LLM effective_max_input_tokens - #4435
Merged
enyst merged 4 commits intoAug 9, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
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_tokensinto the condenser’smax_tokenswhen 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.
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>
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. |
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HUMAN:
Resolves #3746. Traced the bug and found the root cause is in
build_condenser()inmodel.pywhere the LLM's configuredmax_input_tokenswas getting dropped instead of reaching the condenser. Fixed it, wrote tests, and verified everything locally.AGENT:
Why
build_condenserinLLMSummarizingCondenserSettingscallsself.model_dump(..., exclude_none=True), which stripsmax_tokenswhenever it's left unset (default
None). As a result, the condenser isbuilt with no token limit and only condenses based on event count
(
max_size=240). A configuredllm.max_input_tokens(e.g. viaagent_settings.jsonin 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
llm.effective_max_input_tokensinto the condenser'smax_tokenswhen it isn't explicitly configuredmax_tokensvalues still take priority and are never overriddenIssue Number
Closes #3746
How to Test
Result: all passing.
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
Notes
No config or API changes — this only affects the default behaviour when a condenser
max_tokensisn't explicitly set.