Repository navigation
test(sdk): pin events_to_messages boundaries + fix responses_reasoning_item batch drop - #4526
Conversation
_combine_action_events reconstructs the original LLM response from the first event's fields but omitted responses_reasoning_item, so the OpenAI Responses-API reasoning item survived as a singleton action yet vanished the moment the response carried parallel tool calls. Mirror the adjacent reasoning_content/thinking_blocks lines, with a parity regression test.
Characterization tests for the projection's documented-but-unpinned edges: trailing parallel batches at end of stream (exact tool-call order), interleaved response ids not re-batching, user-message merge cascading across 3+ events with mixed text/image order preserved, projection purity w.r.t. input events (the deepcopy defense), and the condensation-summary fusion with adjacent user turns. Addresses the long-standing TODO on events_to_messages.
|
Hi! I started running the integration tests on your PR. You will receive a comment with the results shortly. |
|
👋 This PR needs a couple of things fixed before OpenHands can review it:
Push an update once this is addressed and this check re-runs automatically. This is an automated check - no AI was used to generate this comment. |
enyst
left a comment
There was a problem hiding this comment.
🟡 Acceptable — The production fix is minimal and correct, but the test expansion is broader than the regression and live eval evidence is still pending.
[IMPROVEMENT OPPORTUNITIES]
- [
tests/sdk/event/test_events_to_messages.py, line 193] Scope: The input-immutability test characterizes existing deep-copy behavior rather than theresponses_reasoning_itembatch-drop fix. Removing it would keep this PR focused. - [
tests/sdk/event/test_events_to_messages.py, line 473] Regression assertion: Compare the whole preservedresponses_reasoning_itemwith the first event's item, not only its ID. That directly states the contract and catches future field loss. - [
tests/sdk/event/test_events_to_messages.py, line 537] Duplicate coverage: The trailing-batch test overlaps the existing three-call parallel test. Add an exact order assertion to the existing test instead. - [
tests/sdk/event/test_events_to_messages.py, line 584] Unrealistic case: Interleaved reuse of one LLM response ID is not produced by the SDK and does not exercise this fix. It can be dropped.
[TESTING]
- The focused event-conversion suite passes locally: 23 passed.
- The new reasoning-item regression test fails against
origin/mainbecause the combined message hasresponses_reasoning_item=None, confirming it catches the bug. - GitHub's integration workflow did not execute:
actions/checkout@v7refused fork code in thepull_request_targetjob. Per repository policy, this review remains COMMENT pending a lightweight live eval and human maintainer confirmation.
[RISK ASSESSMENT]
- [Overall PR]
⚠️ Risk Assessment: 🟡 MEDIUM
The code change is only two field assignments and preserves existing batching order and tool calls, but it changes replayed OpenAI Responses history in core LLM message construction. That is agent/eval-sensitive behavior and warrants the requested live integration run before merge.
VERDICT:
✅ Worth merging after live eval confirmation: The core fix is sound; the test cleanup suggestions are nonblocking.
KEY INSIGHT:
The first action already owns the response-level reasoning metadata, so copying that metadata onto the single recombined assistant message restores the original LLM response without adding a new batching rule.
Improve this review? If any feedback above seems incorrect or irrelevant to this repository, you can teach the reviewer to do better:
- Add a
.agents/skills/custom-codereview-guide.mdfile to your branch (or edit it if one already exists) with the/codereviewtrigger and the context the reviewer is missing (e.g., "Security concerns about X do not apply here because Y"). See the customization docs for the required frontmatter format.- Re-request a review - the reviewer reads guidelines from the PR branch, so your changes take effect immediately.
- When your PR is merged, the guideline file goes through normal code review by repository maintainers.
Resolve with AI? Install the iterate skill in your agent and run
/iterateto automatically drive this PR through CI, review, and QA until it's merge-ready.Was this review helpful? React with 👍 or 👎 to give feedback.
AI-generated review posted by OpenHands on behalf of the user.
Co-authored-by: openhands <openhands@all-hands.dev>
|
📁 PR Artifacts Notice This PR contains a |
- drop test_trailing_parallel_batch_at_end_of_stream — redundant with test_parallel_function_calling_same_response_id, which already places a 3-call batch at end of stream - drop test_interleaved_response_ids_do_not_batch — a response id cannot recur non-adjacently in a real log (ids are per-response hashes), so the scenario is unreachable - cascade test: drop the isinstance filter; the merged message holds only TextContent by construction (matches the file's type: ignore idiom) - events_to_messages(): docstring now states the read-only projection contract (events are immutable once appended to the log), so the invariant lives in the repo; the no-mutation test stays as its regression pin - remove the 'add extensive tests' TODO — this branch is those tests
- restore the isinstance filter in the cascade test — the review resolved that nit as keep (runtime narrowing, clearer failure); rewriting it was churn - drop test_events_to_messages_does_not_mutate_input_events — the repo-wide event immutability contract should be documented and tested separately; the events_to_messages() docstring carries the read-only note here - fold an exact tool-call order assertion into test_parallel_function_calling_same_response_id (replacing membership checks) — keeps the deleted trailing-batch test's one useful extra check without duplicating its scenario - strengthen the responses_reasoning_item regression to whole-item equality, so future field loss fails the test
|
Thanks. Current head
|
|
🚦 CI is currently failing on this PR's latest commit. Please fix the failing checks before OpenHands reviews it - this is re-checked automatically once you push a new commit. (A maintainer can also request This is an automated check - no AI was used to generate this comment. |
HUMAN:
All tests pass human validation.
I think the tests are correct in design and execution.
AGENT:
Why
LLMConvertibleEvent.events_to_messages(event/base.py:108) is the projection that turns the persisted event log into themessages[]the LLM actually sees — it re-batches parallel tool calls byllm_response_idand coalesces adjacent plain user messages for strict role alternation. It has carried# TODO: We should add extensive tests for thissince the function was written, and the existing suite (15 tests) covers the happy paths but none of the boundaries.While writing characterization tests for those boundaries, one of them failed and exposed a real bug:
_combine_action_eventsreconstructs a multi-tool-call response from the first event's fields but never passesresponses_reasoning_item— so the OpenAI Responses-API reasoning item survives when an action converts as a singleton (action.py:143passes it) and silently disappears the moment the same response carries parallel tool calls.response_dispatch.py:169-174stamps reasoning state on the first batch event only (by design), so the first event holding the field and the combiner dropping it is a live inconsistency, not a theoretical one.Summary
test(sdk): characterization tests pinning documented-but-unpinned boundary behavior, retiring the TODO: user-message merge cascading across 3+ events, mixed text/image merge order, parallel batches preserving first-event reasoning state (reasoning_content/thinking_blocks), and the condensation-summary/user-message fusion.fix(sdk)(found by one of those tests):_combine_action_eventsnow passesresponses_reasoning_item=events[0].responses_reasoning_item, mirroring the adjacentreasoning_content/thinking_blockslines; the parity test that exposed the drop is its regression test, asserting whole-item equality so future field loss fails it.docs(sdk): theevents_to_messages()docstring now states the read-only projection contract (events are immutable once appended to the log; merges build new content lists rather than mutating the events' own messages), and the retired TODO is removed.Issue Number
Fixes #4525
How to Test
Full-suite result on this branch: 5974 passed, 0 failed (7 skipped, 10 xfailed), run by the human author on Linux, Python 3.13. A full-repo run (
tests/) passed 9391 with 27 failures, all host-environment artifacts unrelated to the change (stock shell-integration escape codes in pty-spawned terminal tests, environment-variable leakage into live-server tests, and one order-dependent OpenAPI test that passes in isolation on both base and this head); thebrowser_usee2e suite was excluded locally becauseBrowserToolExecutorteardown deadlocks off-CI. Pre-commit suite (ruff format/lint, pycodestyle, pyright, import rules, tool registration) clean.Two notes for reviewers:
test_parallel_batch_preserves_responses_reasoning_item— it fails withresponses_reasoning_item=Noneon the combined message despite the first event carrying the item. The fix flips it green. It was also validated live against GPT-5-nano on the real Responses API: a recombined parallel batch kept its reasoning item, and the regression test fails onmainas expected — results recorded in.pr/gpt-5-nano-integration-results.mdon this branch.CondensationSummaryEvent.to_llm_message()produces a plain user message, so a condensation summary adjacent to a userMessageEventin the view is fused with it into a single user turn (the summarizing condenser inserts the summary atforgetting_start, and the kept suffix may legally begin with a user message).test_condensation_summary_merges_with_adjacent_user_messagepins the current behavior — API-valid and content-complete, with the summary's structural boundary erased in the projection. Raised here as a design question; confirmed by the maintainer as intended behavior (a normal consequence of the plain-user merge for strict role alternation), so the pin stays as documentation.Video/Screenshots
Type
Notes
The change is a one-line production fix (
_combine_action_events) plus a docstring, and 5 test functions; the tests are the bulk of the diff by design — they close the long-standingevents_to_messagesTODO.Design Doc
N/A — one-line production change plus tests.