Skip to content

fix: treat negative offset as absent in message paging - #1569

Open
doge-th wants to merge 1 commit into
anthropics:mainfrom
doge-th:fix/negative-offset-paging
Open

doge-th wants to merge 1 commit into
anthropics:mainfrom
doge-th:fix/negative-offset-paging

Conversation

@doge-th

@doge-th doge-th commented Nov 22, 2026

Copy link
Copy Markdown

Summary

Fixes #1519.

The two message-page helpers (_entries_to_session_messages, _entries_to_subagent_messages) sliced with the raw offset whenever a positive limit was given: messages[offset : offset + limit] with offset=-1 evaluated to messages[-1:4] — an empty or wrong page — while the no-limit branch treated the same negative offset as absent (if offset > 0). get_session_messages(sid, limit=5, offset=-1) on a 10-message session therefore returned [], the same negative offset meaning two different things in the two branches.

Both helpers now mirror the guards of _apply_sort_limit_offset (which the SessionStore listing path already follows, per the comment at its mirror site): a non-positive offset is treated as absent, and a positive limit takes the first entries after that offset.

Test plan

  • Regression tests in both paths: TestGetSessionMessages::test_negative_offset_with_limit_treated_as_absent (disk) and TestGetSessionMessagesFromStore::test_negative_offset_with_limit_treated_as_absent (store) — limit=2, offset=-1 now equals limit=2.
  • Verified the store-path test fails on unpatched main (asyncio + trio) and passes with the fix.
  • pytest tests/: 1758 passed, 6 skipped. ruff check, mypy src/ scripts/ all clean.

The two message-page helpers sliced with the raw offset when a positive
limit was given: messages[offset : offset + limit] with a negative
offset returned an empty/wrong page, while the no-limit branch treated
the same offset as absent. get_session_messages(sid, limit=5, offset=-1)
on a 10-message session returned [].

Mirror _apply_sort_limit_offset's guards in _entries_to_session_messages
and _entries_to_subagent_messages, which the SessionStore path already
follows: non-positive offsets are treated as absent and a positive limit
takes the first entries after the offset.

Fixes anthropics#1519

This branch has not been deployed

No deployments
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.

Negative offset with a positive limit returns an empty/wrong page from get_session_messages

1 participant