Fix Phase 5 review issues: mark_all_read, datetime, WS payload, logging

Review fixes:
- mark_all_read now filters status IN (sent, delivered), preventing
  pending notifications from being incorrectly marked as read
- schedule_notification tool: force UTC on naive datetimes, reject
  past dates (send immediately instead)
- WebSocket notification payload now includes all fields matching
  NotificationResponse (user_id, channel, status, scheduled_at, etc.)
- Centralized _serialize_notification helper in notification_sender
- notification_sender: per-notification error handling with rollback
- health_review: moved import json to module top level

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-19 14:14:08 +03:00
parent ada7e82961
commit 04e3ae8319
4 changed files with 44 additions and 29 deletions

View File

@@ -129,10 +129,14 @@ async def _execute_tool(
return json.dumps({"entries": items, "count": len(items)})
elif tool_name == "schedule_notification":
from datetime import datetime
from datetime import datetime, timezone as tz
scheduled_at = None
if tool_input.get("scheduled_at"):
scheduled_at = datetime.fromisoformat(tool_input["scheduled_at"])
if scheduled_at.tzinfo is None:
scheduled_at = scheduled_at.replace(tzinfo=tz.utc)
if scheduled_at <= datetime.now(tz.utc):
scheduled_at = None # Past date → send immediately
notif = await create_notification(
db, user_id,
@@ -145,15 +149,10 @@ async def _execute_tool(
# Push immediately if not scheduled
if not scheduled_at:
from app.workers.notification_sender import _serialize_notification
await manager.send_to_user(user_id, {
"type": "new_notification",
"notification": {
"id": str(notif.id),
"title": notif.title,
"body": notif.body,
"type": notif.type,
"created_at": notif.created_at.isoformat(),
},
"notification": _serialize_notification(notif),
})
return json.dumps({