Skip to content

[Bug] Condensation for 0 events #1518

Description

@xingyaoww

I got these errors:

{"kind": "Condensation", "id": "1dd50966-6311-4337-8cc8-f20f8ce3f41d", "timestamp": "2025-12-28T18:28:51.883055", "source": "environment", "forgotten_event_ids": [], "summary": "I don't see any events provided to summarize. Please share the list of events that need to be summarized, and I'll create a context-aware state summary following the format guidelines.\n\nIf you're starting a new session, please provide:\n1. The events/actions taken by the agent\n2. Any relevant context about the task being performed\n\nI'll then generate an appropriate summary tracking user context, task status, and any relevant state information.", "summary_offset": 122, "llm_response_id": "chatcmpl-8fb35e47-ca68-4f72-bd13-bc38a07d7a94"}

DM me for the covnersation event dumps

Activity

  1. changed the title [-]Condensation happens for 0 events[/-] [+][Bug]Condensation for 0 events[/+] on Dec 28, 2025
  2. changed the title [-][Bug]Condensation for 0 events[/-] [+][Bug] Condensation for 0 events[/+] on Dec 28, 2025
  3. xingyaoww commented on Dec 28, 2025

    @xingyaoww
    ContributorAuthor

    Root Cause Analysis

    After analyzing the event dump, I've identified the root cause of this bug.

    The Problem

    When a tool loop (a sequence of ActionEvent/ObservationEvent pairs starting with thinking blocks) spans almost the entire view, the manipulation_indices computed by View leave no valid range for forgetting events.

    From the event dump:

    • Total events before first condensation: 122
    • Event structure:
      • Event 0: SystemPromptEvent
      • Event 1: MessageEvent (user message)
      • Events 2-121: A continuous tool loop (60 action-observation pairs)

    The tool loop starts at index 2 (first ActionEvent with thinking blocks) and continues uninterrupted to index 121.

    Manipulation Indices

    The View.manipulation_indices property computes safe boundaries for forgetting events while preserving atomic units. For this event sequence:

    manipulation_indices = [0, 1, 2, 122]
    

    This means:

    • Index 0: Before SystemPromptEvent
    • Index 1: Before MessageEvent
    • Index 2: Start of tool loop
    • Index 122: End of tool loop (and end of view)

    Condensation Logic Failure

    When LLMSummarizingCondenser._get_forgotten_events() runs with keep_first=4:

    1. forgetting_start = find_next_manipulation_index(keep_first=4, strict=True) → Returns 122 (smallest index > 4)
    2. forgetting_end = find_next_manipulation_index(naive_end=67, strict=False) → Returns 122 (smallest index >= 67)
    3. forgotten_events = view[122:122] → Empty list!

    The condenser still generates a Condensation event with:

    • forgotten_event_ids = [] (empty)
    • summary_offset = 122

    This triggers an LLM call to summarize zero events, producing meaningless output like:

    "I don't see any events provided to summarize..."

    Impact

    From the dump, there are 53 consecutive Condensation events (indices 122-174) all with:

    • forgotten_event_ids: []
    • summary_offset: 122

    Each one represents a wasted LLM API call.

    Suggested Fix

    In LLMSummarizingCondenser.condense() or _get_forgotten_events(), check if forgetting_start >= forgetting_end (or len(forgotten_events) == 0) and return the original View instead of generating an empty Condensation.

    Test Case

    I've added a test case that reproduces this bug:

    def test_condense_tool_loop_spans_entire_view_returns_view_not_empty_condensation(mock_llm):
        """Test that when a tool loop spans the entire view, condense returns View not Condensation."""
        # Creates 60 action-observation pairs forming one continuous tool loop
        # Verifies that condenser should return View (not Condensation with empty forgotten_event_ids)

    The test currently fails, confirming the bug exists.

  4. csmith49 commented on Dec 28, 2025

    @csmith49
    Contributor

    Some idle thoughts on fixing this:

    Manipulation indices

    The manipulation indices being [0, 1, 2, 122] makes sense but is probably not 100% safe/correct. Say we condense from 2 -> 122, but the LLM is not done with the tool loop -- after we condense, is the tool loop interrupted? If so, we might be losing out on some performance (interrupting the LLM in the middle of a "thought"), and if not, we're right back to the bug the tool-loop aware fixing was trying to resolve.

    I'm guessing the answer is the former. Either way we could potentially resolve this by adjusting the tool-loop manipulation index calculation to only mark the end of a tool loop when we definitively see a non-tool-loop message. That would give manipulation indices of [0, 1, 2] here.

    Delaying condensation

    The LLM summarizing condenser has a two-step process defined by the rolling condenser base class. If we want to delay condensation we'll have to modify that interface.

    One way to do this would be to define a new NoCondensationAvailable exception that we can raise in the RollingCondenser.get_condensation abstract method. In the LLM summarizing condenser we could raise this if we end up with no forgotten events, then in RollingCondenser.condense we do a try-catch and return the original view if we see NoCondensationAvailable (EAFP-style).

    This does mean that between when a condenser is triggered and a condensation is available we'd be constantly trying to condense. If we're not doing token-counting I think the overhead will be pretty minimal though (and we have another issue open to resolve inefficiencies with the token counting (see #1502)).

  5. csmith49 commented on Dec 28, 2025

    @csmith49
    Contributor

    A quick short-term fix would be:

    • Reducing the default attribute LLMSummarizingCondenser.keep_first to 2.
    • Raising the default attribute LLMSummarizingCondenser.max_size to 240.

    That way we're much more likely to get workable manipulation indices for condensation to act on.

  6. xingyaoww commented on Dec 28, 2025

    @xingyaoww
    ContributorAuthor

    @OpenHands please help me implement the shorterm fix here in a new PR: #1518 (comment)

  7. openhands-ai commented on Dec 28, 2025

    @openhands-ai

    I'm on it! xingyaoww can track my progress at all-hands.dev

  8. openhands-ai commented on Dec 28, 2025

    @openhands-ai

    Summary

    I've successfully implemented the short-term fix for issue #1518 as suggested in the comment by @csmith49.

    Changes Made

    1. Modified LLMSummarizingCondenser default parameters (openhands-sdk/openhands/sdk/context/condenser/llm_summarizing_condenser.py):

      • Reduced keep_first from 4 to 2
      • Raised max_size from 120 to 240
    2. Added test for default values (tests/sdk/context/condenser/test_llm_summarizing_condenser.py):

      • Added test_default_values() to verify the new defaults are correctly set

    Checklist

    • ✅ Implemented the short-term fix as specified in the issue comment
    • ✅ Added appropriate test to verify the fix
    • ✅ All pre-commit hooks pass
    • ✅ All 1562 tests pass
    • ✅ Changes are minimal and focused on the fix
    • ✅ Created branch openhands/fix-condensation-defaults
    • ✅ Pushed to remote
    • ✅ Opened draft PR

    Pull Request

    PR #1523: #1523

    The PR is opened as a draft and fixes #1518. These parameter adjustments make it more likely to get workable manipulation indices for condensation to act on, preventing the bug where condensation fails when a tool loop spans almost the entire view.

    View full conversation

  9. xingyaoww commented on Dec 29, 2025

    @xingyaoww
    ContributorAuthor

    @OpenHands we should also fail hard & throw an unhandled exception when we try to condense 0 events

  10. openhands-ai commented on Dec 29, 2025

    @openhands-ai

    I'm on it! xingyaoww can track my progress at all-hands.dev

  11. added
    bug
    and removed on Dec 29, 2025
  12. added a commit that references this issue on Dec 29, 2025
    f1e9f21
  13. openhands-ai commented on Dec 29, 2025

    @openhands-ai

    Summary

    I've implemented the requested fix to fail hard and throw an unhandled exception when trying to condense 0 events.

    Changes Made

    1. openhands-sdk/openhands/sdk/context/condenser/llm_summarizing_condenser.py:

      • Added a check at the start of _generate_condensation to raise a ValueError when forgotten_events is empty
      • The error message explains the typical cause (tool loop spanning the entire view) and suggests adjusting keep_first or max_size parameters
    2. tests/sdk/context/condenser/test_llm_summarizing_condenser.py:

      • Added test_generate_condensation_raises_on_zero_events test to verify the exception is raised and the LLM is never called

    Checklist

    • ✅ Raises an unhandled exception when condensing 0 events
    • ✅ Clear error message explaining the issue and potential solutions
    • ✅ Test added to verify the behavior
    • ✅ All pre-commit hooks pass
    • ✅ All tests pass (15/15)
    • ✅ Changes are concise and focused on the requested fix

    Pull Request

    Created PR: #1541

    This PR fixes #1518 by preventing the confusing LLM response that occurs when the condenser is called with 0 events to summarize.

    View full conversation

  14. xingyaoww commented on Dec 30, 2025

    @xingyaoww
    ContributorAuthor

    This is not yet solved. We now have a way to reproduce it:

    #1551 (comment)

  15. enyst commented on Jan 3, 2026

    @enyst
    Member

    A few thoughts about this

    Point of terminology

    Agent turn is a term used out there with the meaning: uninterrupted sequence of tool calls, until the LLM yields back to the user.

    If so, what we call here “tool loop” = “agent turn”.

    In this context, please consider that max_size=120 means barely ~60 steps, and max_size=240 about 120 steps.

    How long can an agent turn be?

    1. With GPT-5.2, very long. They can be, I think, hours-long. Not sure how many steps that is, but FWIW I think that:
    • openhands can go beyond 700 events (~350 steps)
    • codex-cli can go beyond context window limit (272k tokens). I could get some numbers from my logs if needed.
    1. We expect them to be up to 500 steps, in our own benchmarks. I don’t know how many reach close to 500, but what I want to note about it is that in v1, our benchmarks runs are a single agent turn.

    2. FWIW benchmarks and reports I’ve seen seem to suggest that Opus 4.5 is capable of longer than 500 too.

    In other words, if I understand correctly, we currently try to summarize the entire agent loop in a view. In that case, it seems to me than ~120 steps is very low, so setting it to it cannot really fix it (except for special cases, shorter running tasks).

    To put it differently, the agent speaks above of this being an “edge case”, but it’s not, it’s the opposite… The special cases are short tasks.

  16. neubig commented on Jan 17, 2026

    @neubig
    Member

    I got another example of this on the cloud, it seemed to come after a normal file edit.
    https://app.all-hands.dev/conversations/7118d18d79ed49899b79b8986da5408f

    Image
  17. enyst commented on Jan 27, 2026

    @enyst
    Member

    I just got this error. I think maybe something is wrong not with the agent's turn (nor tool loop), nor with max_size, it seems it's the LLMContextWindowExceedError that got hit.

    The per-turn tokens number looks very close (193k tokens):

    Summary
    Number of Events: 187 events (event files numbered from 00000 to 00186)
    Token Usage (accumulated totals):
    
    •  Prompt tokens: 9,241,039
    •  Completion tokens: 40,458
    •  Cache read tokens: 8,554,257
    •  Cache write tokens: 686,663
    •  Reasoning tokens: 401
    •  Per-turn tokens (last turn): 193,939
    •  Context window: 128,000
    Using claude-opus-4-5 model.
    
    Latest Events:
    •  
    Event 186 (latest): A ConversationErrorEvent with code NoCondensationAvailableException - indicating the conversation hit a limit where it couldn't condense events because a tool loop spanned almost the entire view
    •  Event 185: A MessageEvent from the user
    

    Please note: NoCondensationAvailableException says a tool loop spanned the entire view, but I don't believe that is accurate. This was an interactive conversation, I asked the agent multiple times things, it did its stuff and came back to me, then repeat.

    Events at the tail:

    177 MessageEvent
    178 MessageEvent
    179 ActionEvent
    180 ObservationEvent
    181 ActionEvent
    182 ObservationEvent
    183 CondensationRequest
    184 ConversationErrorEvent
    185 MessageEvent
    186 ConversationErrorEvent
    

    According to the agent, there are only 2 places that create CondensationRequest:

    1. agent.py (line 290) - Automatic trigger on LLMContextWindowExceedError
    except LLMContextWindowExceedError as e:
        # If condenser is available and handles requests, trigger condensation
        if (
            self.condenser is not None
            and self.condenser.handles_condensation_requests()
        ):
            logger.warning(
                "LLM raised context window exceeded error, triggering condensation"
            )
            on_event(CondensationRequest())
            return
    
    1. local_conversation.py (line 853) - Manual trigger via condense() method
      (and I didn't trigger it)
  18. csmith49 commented on Feb 2, 2026

    @csmith49
    Contributor

    With the completion of #1596 this issue should be addressed.

    When we get a condensation request and there is no viable condensation we now just condense the entire view and start "fresh".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions