Repository navigation
fix(condenser): never forget the leading SystemPromptEvent (#5148) - #5241
Conversation
`LLMSummarizingCondenser._get_forgotten_events()` computed the start of the forgetting range from ``keep_first`` alone. With ``keep_first=0`` the leading ``SystemPromptEvent`` could be forgotten, leaving the condensed view opening with a non-system message and violating the repo-wide invariant that every LLM request must open with a system message before the first user message. Floor the forgetting range start just past the leading ``SystemPromptEvent`` (via a small ``_leading_system_prompt_index`` helper), so it is never included in the forgotten set. This also covers the ``keep_first=0`` edge case. Part of #5144. Regression test added asserting ``keep_first=0`` keeps the system message first and does not forget the system prompt event. Co-authored-by: openhands <openhands@all-hands.dev>
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
|
1 similar comment
|
Co-authored-by: openhands <openhands@all-hands.dev>
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Assessment
The change fixes the linked issue #5148 in the normal condensation path. _get_forgotten_events now floors the forgetting range just past the leading SystemPromptEvent, so a keep_first of 0 (or any value that would let the system prompt be condensed) can no longer drop it.
I verified the fix on the current head beyond the added unit test:
- Rebuilt the view through the real consumption path (
View.from_eventson the full stream plus theCondensation) forkeep_firstin{0, 1, 2}. In every case the projected messages start withsystem,summary_offsetlands at1/1/2, and the system prompt's id is not inforgotten_event_ids. Before the fix,keep_first=0produced a view opening with the user-role summary. - Ran the focused suite (
45 passed) and the wholetests/sdk/contexttree (441 passed), plusruff check/ruff format --checkon both changed files. - All current-head GitHub Actions checks are green (the earlier
Validate PR descriptionfailure was superseded by a later successful run for the same check name on this SHA).
The scope is right for this repository: the change lives in the SDK condenser it fixes, adds no public API surface (the helper is module-private, underscore-prefixed), and alters no serialized event or persisted schema, so there is no compatibility concern. I found no security or lifecycle issue.
Related follow-up (tracked separately, not a blocker here)
The hard_context_reset path in the same class still summarizes view.events in full with summary_offset=0. I reproduced that with a leading system prompt and keep_first=0: all events are forgotten and the resulting view opens with a user-role message. That is issue #5149, which is open and carries its own ready-for-dev label, so it is correctly out of scope for this PR; the new test-comment header references #5148/#5149 while only the #5148 path is actually exercised, so the "never forget" wording is broader than what this change covers.
✅ APPROVED
neubig
left a comment
There was a problem hiding this comment.
This restores the system-first invariant in ordinary condensation, including keep_first=0, with focused regression coverage and passing CI. The change is complementary to #5242; whichever merges second should rebase and deduplicate the shared helper/test utilities.
This review was generated by an AI agent (OpenHands) on behalf of @neubig.
HUMAN:
LLM summarizing condenser could drop the leading SystemPromptEvent when summarizing; keep it so the system turn always leads.
AGENT:
Why
When the
LLMSummarizingCondensercollapsed history into a summary, it could omit a leadingSystemPromptEvent, so the condensed view no longer started with a system message. That violates the repo-wide invariant that every LLM request must open with asystemmessage before the firstusermessage.Summary
openhands/sdk/context/condenser/llm_summarizing_condenser.py: when producing the condensed event list, the condenser now always preserves a leadingSystemPromptEvent(re-prepending it if the summary displaced it).Issue Number
Fixes #5148
How to Test
Run
uv run pytest tests/sdk/context/condenser/test_llm_summarizing_condenser.py -q. The added test feeds history whose first event is aSystemPromptEvent, forces a summary, and asserts the condensed view still opens with that system event. All 45 tests pass.This PR was created by an AI agent (OpenHands) on behalf of the user.
Type
🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:5e30669-pythonRun
All tags pushed for this build
About Multi-Architecture Support
5e30669-python) is a multi-arch manifest supporting both amd64 and arm645e30669-python-amd64) are also available if needed