fix(chat): audit fixes — retention, rag_project_id, cleanup scheduler, tool rounds

- cleanup_old_conversations now excludes briefing conversations (was
  silently deleting briefing history after the retention window)
- list_conversations response now includes rag_project_id, matching the
  shape returned by the single-conversation GET endpoint
- create_conversation_from_article: removed duplicate async_session import
  (_session2 was a copy of the same import); consolidated into one
- MAX_TOOL_ROUNDS fixed from 5→6 to match the actual range(6) loop;
  loop updated to range(MAX_TOOL_ROUNDS) so the constant is accurate
- Chat retention cleanup moved from per-request (every GET /conversations)
  to a daily scheduled job in event_scheduler.py; route no longer runs
  a DB write on every read

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-04 12:30:41 -04:00
parent edfed6b5bb
commit 738245af5c
4 changed files with 59 additions and 19 deletions
+2 -12
View File
@@ -11,7 +11,6 @@ from fabledassistant.config import Config
from fabledassistant.services.chat import (
add_message,
bulk_delete_conversations,
cleanup_old_conversations,
create_conversation,
delete_conversation,
get_conversation,
@@ -40,14 +39,6 @@ async def list_conversations_route():
uid = get_current_user_id()
limit, offset = parse_pagination()
conv_type = request.args.get("type", "chat")
# Apply retention policy before returning list
retention_str = await get_setting(uid, "chat_retention_days", "90")
try:
retention_days = int(retention_str)
except (ValueError, TypeError):
retention_days = 90
if retention_days > 0:
await cleanup_old_conversations(uid, retention_days)
conversations, total = await list_conversations(uid, limit=limit, offset=offset, conv_type=conv_type)
return jsonify({
"conversations": conversations,
@@ -510,6 +501,7 @@ async def create_conversation_from_article(item_id: int):
"""Create a chat conversation seeded with an RSS article's content."""
from sqlalchemy import select as _select
from fabledassistant.models import async_session as _async_session
from fabledassistant.models.conversation import Message
from fabledassistant.models.rss_feed import RssItem, RssFeed
uid = get_current_user_id()
@@ -538,9 +530,7 @@ async def create_conversation_from_article(item_id: int):
if item.url:
seeded_text += f"\n\nSource: {item.url}"
from fabledassistant.models.conversation import Message
from fabledassistant.models import async_session as _session2
async with _session2() as session:
async with _async_session() as session:
msg = Message(
conversation_id=conv.id,
role="assistant",