Skip to content

Fix sensory buffer loop for oversized messages#66

Draft
taixiansen2 wants to merge 1 commit into
zjunlp:mainfrom
taixiansen2:codex/fix-sensory-buffer-oversize-loop
Draft

Fix sensory buffer loop for oversized messages#66
taixiansen2 wants to merge 1 commit into
zjunlp:mainfrom
taixiansen2:codex/fix-sensory-buffer-oversize-loop

Conversation

@taixiansen2

Copy link
Copy Markdown

Summary

Fixes an infinite loop in SenMemBufferManager.add_messages() when a single user message is larger than the sensory memory buffer's max_tokens while the current buffer is empty.

In the previous logic, this edge case called cut_with_segmenter() on an empty buffer. No segment was emitted and the oversized message was not added to processed_messages, so it was never removed from big_buffer. The outer while self.big_buffer loop then processed the same message forever.

This PR handles that edge case by emitting the oversized user turn as a singleton segment, optionally including the following assistant message, and consuming those messages from big_buffer.

Changes

  • Return early for empty messages and empty internal buffers.
  • Consume oversized single user messages when the current buffer cannot be segmented.
  • Preserve the following assistant message with the oversized user message when available.
  • Guard turn construction against incomplete or non-user/assistant pairs.
  • Fix force_segment=True cleanup to clear the whole remaining buffer with len(self.buffer) instead of len(boundaries).
  • Add a small regression test for the oversized-message case and force-segment cleanup.

Validation

  • Parsed the changed Python files with ast.parse.
  • Ran the new regression test functions directly with PYTHONPATH=src because pytest is not installed in the local Windows Python environment:
PYTHONPATH=src python - <<'PY'
from tests.test_sensory_memory import (
    test_oversized_single_user_message_is_consumed,
    test_force_segment_flushes_remaining_buffer,
)

test_oversized_single_user_message_is_consumed()
test_force_segment_flushes_remaining_buffer()
PY

In our downstream LongMemEval reproduction, this fixes a run that previously stalled at Ingest 01493427: 105/242; after the fix, the case completed successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant