Skip to content

History.truncate() hides retained current-session entries #1785

Closed

Description

@tridev-tej

On current main (e9c64db568404a6ec384f156656768d77a026c04), truncating old history leaves session_start_index unchanged. Retained current-session entries then disappear from span(), string search and regex search.

Reproduced on macOS 26.3.2 arm64 with Python 3.11.15:

from cmd2.history import History, HistoryItem
from cmd2.parsing import Statement

history = History([
    HistoryItem(Statement("", raw="old-1")),
    HistoryItem(Statement("", raw="old-2")),
    HistoryItem(Statement("", raw="old-3")),
])
history.start_session()
history.append(HistoryItem(Statement("", raw="new-1")))
history.append(HistoryItem(Statement("", raw="new-2")))
history.truncate(3)
print([entry.raw for entry in history.span(":").values()])

Expected: ["new-1", "new-2"]. Actual: []. Both entries remain in the history; the session boundary stays at 3 instead of shifting to 1.

Activity

  1. tridev-tej commented on Oct 25, 2026

    @tridev-tej
    Author

    I'm working on a fix for the session boundary in History.truncate().

  2. tleonhardt commented on Oct 25, 2026

    @tleonhardt
    Member

    @tridev-tej Can you please check to see if the history changes in PR #1778 happen to fix this issue? I think they are orthogonal to this, but it is worth checking.

  3. tleonhardt commented on Oct 28, 2026

    @tleonhardt
    Member

    @tridev-tej I have a fix for this up under PR #1787. Could you please verify that this fixes the issue you were encountering?

  4. added a commit that references this issue on Oct 29, 2026
    57c3a66
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions