You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{"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"}
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:
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:
deftest_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.
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)).
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.
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?
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.
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.
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.
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.
According to the agent, there are only 2 places that create CondensationRequest:
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
local_conversation.py (line 853) - Manual trigger via condense() method
(and I didn't trigger it)
Activity
[-]Condensation happens for 0 events[/-][+][Bug]Condensation for 0 events[/+][-][Bug]Condensation for 0 events[/-][+][Bug] Condensation for 0 events[/+]Fix infinite loop when condensation cannot forget events
xingyaoww commentedon Dec 28, 2025
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_indicescomputed byViewleave no valid range for forgetting events.From the event dump:
SystemPromptEventMessageEvent(user message)The tool loop starts at index 2 (first
ActionEventwith thinking blocks) and continues uninterrupted to index 121.Manipulation Indices
The
View.manipulation_indicesproperty computes safe boundaries for forgetting events while preserving atomic units. For this event sequence:This means:
Condensation Logic Failure
When
LLMSummarizingCondenser._get_forgotten_events()runs withkeep_first=4:forgetting_start = find_next_manipulation_index(keep_first=4, strict=True)→ Returns122(smallest index > 4)forgetting_end = find_next_manipulation_index(naive_end=67, strict=False)→ Returns122(smallest index >= 67)forgotten_events = view[122:122]→ Empty list!The condenser still generates a
Condensationevent with:forgotten_event_ids = [](empty)summary_offset = 122This triggers an LLM call to summarize zero events, producing meaningless output like:
Impact
From the dump, there are 53 consecutive Condensation events (indices 122-174) all with:
forgotten_event_ids: []summary_offset: 122Each one represents a wasted LLM API call.
Suggested Fix
In
LLMSummarizingCondenser.condense()or_get_forgotten_events(), check ifforgetting_start >= forgetting_end(orlen(forgotten_events) == 0) and return the originalViewinstead of generating an emptyCondensation.Test Case
I've added a test case that reproduces this bug:
The test currently fails, confirming the bug exists.
csmith49 commentedon Dec 28, 2025
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 from2 -> 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
NoCondensationAvailableexception that we can raise in theRollingCondenser.get_condensationabstract method. In the LLM summarizing condenser we could raise this if we end up with no forgotten events, then inRollingCondenser.condensewe do a try-catch and return the original view if we seeNoCondensationAvailable(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)).
csmith49 commentedon Dec 28, 2025
A quick short-term fix would be:
LLMSummarizingCondenser.keep_firstto2.LLMSummarizingCondenser.max_sizeto240.That way we're much more likely to get workable manipulation indices for condensation to act on.
xingyaoww commentedon Dec 28, 2025
@OpenHands please help me implement the shorterm fix here in a new PR: #1518 (comment)
openhands-ai commentedon Dec 28, 2025
I'm on it! xingyaoww can track my progress at all-hands.dev
Fix condensation for 0 events by adjusting default parameters
openhands-ai commentedon Dec 28, 2025
Summary
I've successfully implemented the short-term fix for issue #1518 as suggested in the comment by @csmith49.
Changes Made
Modified
LLMSummarizingCondenserdefault parameters (openhands-sdk/openhands/sdk/context/condenser/llm_summarizing_condenser.py):keep_firstfrom4to2max_sizefrom120to240Added test for default values (
tests/sdk/context/condenser/test_llm_summarizing_condenser.py):test_default_values()to verify the new defaults are correctly setChecklist
openhands/fix-condensation-defaultsPull 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
xingyaoww commentedon Dec 29, 2025
@OpenHands we should also fail hard & throw an unhandled exception when we try to condense 0 events
openhands-ai commentedon Dec 29, 2025
I'm on it! xingyaoww can track my progress at all-hands.dev
Raise ValueError when condensing 0 events
openhands-ai commentedon Dec 29, 2025
Summary
I've implemented the requested fix to fail hard and throw an unhandled exception when trying to condense 0 events.
Changes Made
openhands-sdk/openhands/sdk/context/condenser/llm_summarizing_condenser.py:_generate_condensationto raise aValueErrorwhenforgotten_eventsis emptykeep_firstormax_sizeparameterstests/sdk/context/condenser/test_llm_summarizing_condenser.py:test_generate_condensation_raises_on_zero_eventstest to verify the exception is raised and the LLM is never calledChecklist
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
xingyaoww commentedon Dec 30, 2025
This is not yet solved. We now have a way to reproduce it:
#1551 (comment)
enyst commentedon Jan 3, 2026
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=120means barely ~60 steps, andmax_size=240about 120 steps.How long can an agent turn be?
openhandscan go beyond 700 events (~350 steps)codex-clican go beyond context window limit (272k tokens). I could get some numbers from my logs if needed.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.
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.
neubig commentedon Jan 17, 2026
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
enyst commentedon Jan 27, 2026
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 theLLMContextWindowExceedErrorthat got hit.The
per-turn tokensnumber looks very close (193k tokens):Please note:
NoCondensationAvailableExceptionsays 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:
According to the agent, there are only 2 places that create
CondensationRequest:LLMContextWindowExceedErrorcondense()method(and I didn't trigger it)
csmith49 commentedon Feb 2, 2026
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".