test(session): reproduce orphaned tool results from save-boundary overshoot (#4006)
This commit is contained in:
committed by
Xubin Ren
parent
30640e9e00
commit
df832a37e9
@@ -14,6 +14,7 @@ from nanobot.session.turn_continuation import (
|
||||
INTERNAL_CONTINUATION_META,
|
||||
INTERNAL_CONTINUATION_PENDING_META,
|
||||
INTERNAL_CONTINUATION_RUN_STARTED_AT_META,
|
||||
_save_skip_for_turn,
|
||||
internal_continuation_pending,
|
||||
internal_continuation_run_started_at,
|
||||
maybe_continue_turn,
|
||||
@@ -138,3 +139,35 @@ def test_internal_continuation_requires_budget_boundary_and_queue():
|
||||
pending_queue_available=True,
|
||||
session_metadata={},
|
||||
)
|
||||
|
||||
|
||||
def test_save_skip_matches_prefix_when_current_message_merged():
|
||||
# ``build_messages`` merges the current user message into a same-role
|
||||
# history tail, so the prompt prefix is ``1 + history_count`` instead of
|
||||
# ``2 + history_count``. The old boundary then cut the first new-turn
|
||||
# assistant message (carrying tool_calls) from persistence, leaving its
|
||||
# tool results orphaned in session history (#4006).
|
||||
skip = _save_skip_for_turn(
|
||||
message_metadata=None,
|
||||
initial_message_count=2, # [system, merged user]
|
||||
history_count=1,
|
||||
user_persisted_early=True,
|
||||
)
|
||||
assert skip == 2
|
||||
|
||||
|
||||
def test_save_skip_unchanged_for_standalone_current_message():
|
||||
# [system, history user, current user] — early-persisted current message.
|
||||
assert _save_skip_for_turn(
|
||||
message_metadata=None,
|
||||
initial_message_count=3,
|
||||
history_count=1,
|
||||
user_persisted_early=True,
|
||||
) == 3
|
||||
# Same prefix, current message not persisted early: re-save it.
|
||||
assert _save_skip_for_turn(
|
||||
message_metadata=None,
|
||||
initial_message_count=3,
|
||||
history_count=1,
|
||||
user_persisted_early=False,
|
||||
) == 2
|
||||
|
||||
Reference in New Issue
Block a user