mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-08-09 10:39:11 +02:00
Fix truncate_messages persisting an inflated message_count (#2052)
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.
This commit is contained in:
parent
cdf31835e2
commit
db6136baa3
2 changed files with 63 additions and 1 deletions
|
|
@ -273,7 +273,10 @@ class SessionManager:
|
|||
|
||||
db_session = db.query(DbSession).filter(DbSession.id == session_id).first()
|
||||
if db_session:
|
||||
db_session.message_count = keep_count
|
||||
# keep_count can exceed the real message total (e.g. the AI tool
|
||||
# defaults to keep_count=10 on a short session); message_count must
|
||||
# track the rows that actually remain, not the requested cap.
|
||||
db_session.message_count = min(keep_count, len(db_messages))
|
||||
db_session.updated_at = datetime.now(timezone.utc)
|
||||
|
||||
db.commit()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue