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
{{ message }}
This repository was archived by the owner on Aug 21, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 21, 2026. It is now read-only.
Bug: compress_research removes recent messages instead of older ones on token limit #252
I found a possible inconsistency in the token-limit recovery logic used by compress_research.
In deep_researcher.py, when token limit is exceeded, the comment says this is handled by removing older messages:
exceptExceptionase:
synthesis_attempts+=1# Handle token limit exceeded by removing older messagesifis_token_limit_exceeded(e, configurable.research_model):
researcher_messages=remove_up_to_last_ai_message(researcher_messages)
continue# For other errors, continue retryingcontinue
However, remove_up_to_last_ai_message() in utils.py seems to do the opposite:
def remove_up_to_last_ai_message(messages: list[MessageLikeRepresentation]) -> list[MessageLikeRepresentation]:
"""Truncate message history by removing up to the last AI message.
This is useful for handling token limit exceeded errors by removing recent context.
Args:
messages: List of message objects to truncate
Returns:
Truncated message list up to (but not including) the last AI message
"""
# Search backwards through messages to find the last AI message
for i in range(len(messages) - 1, -1, -1):
if isinstance(messages[i], AIMessage):
# Return everything up to (but not including) the last AI message
return messages[:i]
# No AI messages found, return original list
return messages
This removes the last AI message and everything after it, which looks like removing the most recent context, not the older history.
If the intent here is to free context space while preserving the latest research progress, then this may be trimming the wrong side of the message history.
Could you confirm whether the intended behavior is:
changed the title [-]Possible bug: compress_research removes recent messages instead of older ones on token limit[/-][+]Bug: compress_research removes recent messages instead of older ones on token limit[/+]on Mar 9, 2026
Activity
[-]Possible bug: compress_research removes recent messages instead of older ones on token limit[/-][+]Bug: compress_research removes recent messages instead of older ones on token limit[/+]fix: critical bugs in compress_research + first unit test suite (77 t…