truncate_messages deletes db_messages[keep_count:] (a no-op when keep_count >= the real message total) then unconditionally wrote db_session.message_count = keep_count. When keep_count exceeds the number of messages that actually exist — e.g. the manage_session AI tool defaults keep_count to 10, and the HTTP truncate endpoint passes any client value — the persisted count is set too high (10 on a 3-message session), diverging from the real row count. That column gates lazy DB-hydration in get_session (message_count > 0) and is surfaced to the history UI, so it is correctness-relevant. Clamp to min(keep_count, len(db_messages)); the in-memory slice already caps naturally.
2.3 KiB
2.3 KiB