Add message store validation and session logging - #7
Conversation
There was a problem hiding this comment.
Reviewed the full diff against the surrounding module and all call sites (voice/twilio_webhook.py, security.py). The change is purely additive logging plus a defensive type guard: no return values, control flow, or stored state change on any existing path, and the new RuntimeError is only reachable if a non-list messages is injected through ConversationStore.create(**kwargs). Message content is not logged (only counts), and the caller phone number in create() duplicates a line already emitted at voice/twilio_webhook.py:101, so there's no new PII exposure. Scope matches the title/description — one file, nothing unrelated.
Non-blocking follow-ups:
store/conversations.py:7— every other module uses an explicit"pdagent.*"logger name (security.py:15,voice/twilio_webhook.py:20);__name__givesstore.conversations, which a"pdagent"-scoped handler would silently drop.store/conversations.py:99— the WARNING on removing a missing session can fire on a normal call, since/status(twilio_webhook.py:242) and the media-streamfinally(twilio_webhook.py:193) race to remove the samecall_sid./statuslogs that same condition at debug as "already cleaned up", so this level is inconsistent.- The
isinstance(self.messages, list)guard is duplicated verbatim in bothadd_*_messagemethods;__post_init__already validates the other fields and is the natural home.
Note: I was unable to run pytest in the review environment, so this is a read-only review; CI gates the merge.
What
Add validation checks and logging to detect message store corruption and track session state transitions.
Why
Prevents silent data corruption by validating message list integrity before appends and logs key lifecycle events for debugging session issues.