Skip to content

fix(condenser): Forgetting range calculation interprets keep_first correctly - #1708

Merged
csmith49 merged 6 commits into
mainfrom
fix/manual-condensation-bug
Jan 12, 2026
Merged

csmith49 merged 6 commits into
mainfrom
fix/manual-condensation-bug

Conversation

@csmith49

@csmith49 csmith49 commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Slightly modifies calculations on which range of events to forget during condensation.

The starting point of the forgetting range was previously "strict" -- this caused the condenser to look for the manipulation index greater than the keep_first value. But this produces an off-by-one error on the interpretation of keep_first, so some legit condensation ranges were being ignored.

Fixes #1701.

Checklist

  • If the PR is changing/adding functionality, are there tests to reflect this?
  • If there is an example, have you run the example to make sure that it works?
  • If there are instructions on how to run the code, have you followed the instructions and made sure that it works?
  • If the feature is significant enough to require documentation, is there a PR open on the OpenHands/docs repository with the same branch name?
  • Is the github CI passing?

Agent Server images for this PR

• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.12-nodejs22 Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:a5d6d91-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-a5d6d91-python \
  ghcr.io/openhands/agent-server:a5d6d91-python

All tags pushed for this build

ghcr.io/openhands/agent-server:a5d6d91-golang-amd64
ghcr.io/openhands/agent-server:a5d6d91-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:a5d6d91-golang-arm64
ghcr.io/openhands/agent-server:a5d6d91-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:a5d6d91-java-amd64
ghcr.io/openhands/agent-server:a5d6d91-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:a5d6d91-java-arm64
ghcr.io/openhands/agent-server:a5d6d91-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:a5d6d91-python-amd64
ghcr.io/openhands/agent-server:a5d6d91-nikolaik_s_python-nodejs_tag_python3.12-nodejs22-amd64
ghcr.io/openhands/agent-server:a5d6d91-python-arm64
ghcr.io/openhands/agent-server:a5d6d91-nikolaik_s_python-nodejs_tag_python3.12-nodejs22-arm64
ghcr.io/openhands/agent-server:a5d6d91-golang
ghcr.io/openhands/agent-server:a5d6d91-java
ghcr.io/openhands/agent-server:a5d6d91-python

About Multi-Architecture Support

  • Each variant tag (e.g., a5d6d91-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., a5d6d91-python-amd64) are also available if needed

@github-actions

github-actions Bot commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-sdk/openhands/sdk/context
   view.py225398%254, 290, 435
openhands-sdk/openhands/sdk/context/condenser
   llm_summarizing_condenser.py100397%130–132
TOTAL15095443070% 

@csmith49 csmith49 added the condenser-test Triggers a run of all condenser integration tests label Jan 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi! I started running the condenser tests on your PR. You will receive a comment with the results shortly.

Note: These are non-blocking tests that validate condenser functionality across different LLMs.

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review Summary

The fix correctly addresses the off-by-one error in the forgetting range calculation by changing strict=True to strict=False. This ensures that keep_first=N properly means "keep the first N events" (indices 0 to N-1) and start forgetting from index N.

✅ What's Good

  1. Core fix is correct: Changing from strict=True (find index > keep_first) to strict=False (find index >= keep_first) properly fixes the off-by-one error
  2. Consistency: The change makes forgetting_start consistent with forgetting_end, which already uses strict=False
  3. Test updates are accurate: All three test updates correctly reflect the new behavior with proper arithmetic
  4. Comment updates: The inline comment is correctly updated from "> keep_first" to ">= keep_first"

🟡 Minor Suggestions

  1. Documentation: Consider adding a docstring to the keep_first field (line 45) to clarify its meaning: "Number of events to keep from the start before condensation begins". This would help prevent future confusion about its interpretation.

  2. Edge case testing: While the fix should handle boundary conditions correctly (e.g., keep_first=0), consider adding explicit tests for these edge cases to increase confidence in the implementation.

Verification

I verified that:

  • The validation logic in validate_keep_first_vs_max_size() remains correct with the new interpretation
  • The formula keep_first + 1 + events_from_tail = target_size still holds
  • No other parts of the codebase use find_next_manipulation_index() that would be affected by this change
  • The arithmetic in all test comments is accurate

Overall, this is a solid bug fix that correctly addresses issue #1701. The suggestions above are optional enhancements for documentation and test coverage.

@github-actions

Copy link
Copy Markdown
Contributor

Condenser Test Results (Non-Blocking)

These tests validate condenser functionality and do not block PR merges.

🧪 Condenser Tests Results

Overall Success Rate: 71.4%
Total Cost: $0.68
Models Tested: 2
Timestamp: 2026-01-12 21:40:05 UTC

📊 Summary

Model Overall Tests Passed Skipped Total Cost Tokens
litellm_proxy_gpt_5.1_codex_max 50.0% 1/2 3 5 $0.03 18,474
litellm_proxy_anthropic_claude_opus_4_5_20251101 80.0% 4/5 0 5 $0.66 278,344

📋 Detailed Results

litellm_proxy_gpt_5.1_codex_max

  • Success Rate: 50.0% (1/2)
  • Total Cost: $0.03
  • Token Usage: prompt: 17,259, completion: 1,215, cache_read: 7,552, reasoning: 832
  • Run Suffix: litellm_proxy_gpt_5.1_codex_max_11a41d5_gpt51_condenser_run_N5_20260112_213719
  • Skipped Tests: 3

Skipped Tests:

  • c04_token_condenser: This test stresses long repetitive tool loops to trigger token-based condensation. GPT-5.1 Codex Max often declines such requests for efficiency/safety reasons.
  • c01_thinking_block_condenser: Model litellm_proxy/gpt-5.1-codex-max does not support extended thinking or reasoning effort
  • c05_size_condenser: This test stresses long repetitive tool loops to trigger size-based condensation. GPT-5.1 Codex Max often declines such requests for efficiency/safety reasons.

Failed Tests:

  • c02_hard_condensation_requirement: Expected exception when explicitly requesting condensation with no valid range (Cost: $0.0033)

litellm_proxy_anthropic_claude_opus_4_5_20251101

  • Success Rate: 80.0% (4/5)
  • Total Cost: $0.66
  • Token Usage: prompt: 265,293, completion: 13,051, cache_read: 228,858, cache_write: 28,270, reasoning: 1,989
  • Run Suffix: litellm_proxy_anthropic_claude_opus_4_5_20251101_11a41d5_opus_condenser_run_N5_20260112_213719

Failed Tests:

  • c02_hard_condensation_requirement: Expected exception when explicitly requesting condensation with no valid range (Cost: $0.0078)

# Find actual forgetting_start: smallest manipulation index >= keep_first
forgetting_start = view.find_next_manipulation_index(
self.keep_first, strict=True
self.keep_first, strict=False

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.

Just a tiny thought, this seems a bit strange to me. I expected we will fix some > into a >=, but maybe I'm missing the reason for strict?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's the reason. Instead of expecting the first manipulation index to be strictly greater than keep_first, it can now be greater than or equal to.

Although I can't quite remember why it was strict in the first place. Not sure there was ever a particular reason.

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.

It feels like maybe it was a bug to be strict, and if so, maybe we could simplify it sometime, maybe giving up strict from signature if it doesn't seem really useful.

@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.

LGTM, I have a tiny confusion but it's not important, thank you!

@csmith49 csmith49 added condenser-test Triggers a run of all condenser integration tests and removed condenser-test Triggers a run of all condenser integration tests labels Jan 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi! I started running the condenser tests on your PR. You will receive a comment with the results shortly.

Note: These are non-blocking tests that validate condenser functionality across different LLMs.

@github-actions

Copy link
Copy Markdown
Contributor

Condenser Test Results (Non-Blocking)

These tests validate condenser functionality and do not block PR merges.

🧪 Condenser Tests Results

Overall Success Rate: 100.0%
Total Cost: $0.78
Models Tested: 2
Timestamp: 2026-01-12 21:57:38 UTC

📊 Summary

Model Overall Tests Passed Skipped Total Cost Tokens
litellm_proxy_anthropic_claude_opus_4_5_20251101 100.0% 5/5 0 5 $0.77 397,470
litellm_proxy_gpt_5.1_codex_max 100.0% 2/2 3 5 $0.02 18,022

📋 Detailed Results

litellm_proxy_anthropic_claude_opus_4_5_20251101

  • Success Rate: 100.0% (5/5)
  • Total Cost: $0.77
  • Token Usage: prompt: 382,354, completion: 15,116, cache_read: 346,053, cache_write: 27,537, reasoning: 1,654
  • Run Suffix: litellm_proxy_anthropic_claude_opus_4_5_20251101_129b3b4_opus_condenser_run_N5_20260112_214857

litellm_proxy_gpt_5.1_codex_max

  • Success Rate: 100.0% (2/2)
  • Total Cost: $0.02
  • Token Usage: prompt: 16,693, completion: 1,329, cache_read: 14,976, reasoning: 1,024
  • Run Suffix: litellm_proxy_gpt_5.1_codex_max_129b3b4_gpt51_condenser_run_N5_20260112_214859
  • Skipped Tests: 3

Skipped Tests:

  • c04_token_condenser: This test stresses long repetitive tool loops to trigger token-based condensation. GPT-5.1 Codex Max often declines such requests for efficiency/safety reasons.
  • c05_size_condenser: This test stresses long repetitive tool loops to trigger size-based condensation. GPT-5.1 Codex Max often declines such requests for efficiency/safety reasons.
  • c01_thinking_block_condenser: Model litellm_proxy/gpt-5.1-codex-max does not support extended thinking or reasoning effort

@openhands-ai

openhands-ai Bot commented Jan 12, 2026

Copy link
Copy Markdown

Looks like there are a few issues preventing this PR from being merged!

  • GitHub Actions are failing:
    • Pre-commit checks

If you'd like me to help, just leave a comment, like

@OpenHands please fix the failing actions on PR #1708 at branch `fix/manual-condensation-bug`

Feel free to include any additional details that might help me get this PR into a better state.

You can manage your notification settings

@csmith49
csmith49 enabled auto-merge (squash) January 12, 2026 22:01
@csmith49
csmith49 merged commit 6959cf1 into main Jan 12, 2026
@csmith49
csmith49 deleted the fix/manual-condensation-bug branch January 12, 2026 22:01
@enyst

enyst commented Jan 12, 2026

Copy link
Copy Markdown
Member

@csmith49 Just a quick note, since I just noticed:

c01_thinking_block_condenser: Model litellm_proxy/gpt-5.1-codex-max does not support extended thinking or reasoning effort

It supports reasoning effort. Not "extended thinking" since that's Anthropic's equivalent of reasoning effort -ish (kind of), but the OpenAI reasoning effort that almost every other reasoning LLM provider supports.
image

StressTestor pushed a commit to StressTestor/software-agent-sdk that referenced this pull request Jun 1, 2026
…correctly (OpenHands#1708)

Co-authored-by: Calvin Smith <calvin@all-hands.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

condenser-test Triggers a run of all condenser integration tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

User requested condensation failed despite there's multiple user messages/agent-loop in the same conversation

3 participants