Files
LangBot/src/langbot/pkg/persistence/session_summary_contract.py
T
BiFangKNT 810d053df9 fix(monitoring): persist session summaries to avoid history scans
- Maintain counts and display snapshots in source transactions with replay-safe deduplication.
- Read session lists exclusively from summaries and remove execution-only filters.
- Automatically initialize historical summaries in bounded, resumable batches during OSS startup.
- Add behavioral contracts covering accounting, retention, query cost and PostgreSQL concurrency.

Verified with the required session_summary suite and real container upgrade startup.
2026-10-20 06:12:00 +08:00

46 lines
1.2 KiB
Python

"""Payload-free contracts for interactive conversation lists."""
from dataclasses import dataclass
import datetime
from typing import Protocol
@dataclass(frozen=True, slots=True)
class SessionListFilter:
bot_ids: tuple[str, ...] = ()
pipeline_ids: tuple[str, ...] = ()
start_time: datetime.datetime | None = None
end_time: datetime.datetime | None = None
user_query: str | None = None
is_active: bool | None = None
class SessionSummaryReader(Protocol):
"""Read stored summaries without consulting or repairing historical ledgers."""
async def list_page(
self, workspace: str, filters: SessionListFilter, limit: int, offset: int
) -> tuple[list[dict], int]: ...
@dataclass(frozen=True, slots=True)
class SessionSummaryChange:
workspace: str
bot_id: str
session_id: str
source_key: str
timestamp: datetime.datetime
bot_name: str
pipeline_id: str = ''
pipeline_name: str = ''
platform: str | None = None
user_id: str | None = None
user_name: str | None = None
role: str = 'user'
event_id: str | None = None
def message_source_key(message_id: str) -> str:
"""Distinct message records remain distinct even when they share an event."""
return f'message:{message_id}'