fix: system messages author=None (actor tracked in task_actions, not message author)
Some checks failed
Deploy Tracker / deploy (push) Failing after 3s

This commit is contained in:
markov 2026-02-25 12:04:19 +01:00
parent 0840e38849
commit 9bf66a88b2
3 changed files with 14 additions and 13 deletions

View File

@ -73,7 +73,7 @@ def _message_out(m: Message) -> dict:
"task_id": str(m.task_id) if m.task_id else None, "task_id": str(m.task_id) if m.task_id else None,
"parent_id": str(m.parent_id) if m.parent_id else None, "parent_id": str(m.parent_id) if m.parent_id else None,
"author_type": m.author_type, "author_type": m.author_type,
"author_id": str(m.author_id), "author_id": str(m.author_id) if m.author_id else None,
"author": {"id": str(m.author.id), "slug": m.author.slug, "name": m.author.name} if m.author else None, "author": {"id": str(m.author.id), "slug": m.author.slug, "name": m.author.name} if m.author else None,
"content": m.content, "content": m.content,
"mentions": m.mentions or [], "mentions": m.mentions or [],
@ -164,8 +164,8 @@ async def create_message(req: MessageCreate, request: Request, db: AsyncSession
msg = result2.scalar_one() msg = result2.scalar_one()
# Get author name for broadcast (already loaded via relationship) # Get author name for broadcast (already loaded via relationship)
author_name = msg.author.name if msg.author else "Unknown" author_name = msg.author.name if msg.author else "System"
author_slug = msg.author.slug if msg.author else "unknown" author_slug = msg.author.slug if msg.author else "system"
# Broadcast via WebSocket # Broadcast via WebSocket
from tracker.ws.manager import manager from tracker.ws.manager import manager

View File

@ -144,14 +144,13 @@ async def _system_message(
now = datetime.datetime.now(datetime.timezone.utc) now = datetime.datetime.now(datetime.timezone.utc)
chat_id = await _get_project_chat_id(db, task.project_id) chat_id = await _get_project_chat_id(db, task.project_id)
actor_id = actor.id if actor else None
actor_slug = actor.slug if actor else "system" actor_slug = actor.slug if actor else "system"
# 1. Task comment # 1. Task comment (author=None for system, actor tracked in task_actions)
task_msg = Message( task_msg = Message(
task_id=task.id, task_id=task.id,
author_type=AuthorType.SYSTEM, author_type=AuthorType.SYSTEM,
author_id=actor_id, author_id=None,
content=task_text, content=task_text,
mentions=[], mentions=[],
) )
@ -163,7 +162,7 @@ async def _system_message(
chat_msg = Message( chat_msg = Message(
chat_id=chat_id, chat_id=chat_id,
author_type=AuthorType.SYSTEM, author_type=AuthorType.SYSTEM,
author_id=actor_id, author_id=None,
content=chat_text, content=chat_text,
mentions=[], mentions=[],
) )
@ -177,8 +176,9 @@ async def _system_message(
"task_id": str(task.id), "task_id": str(task.id),
"task_key": key, "task_key": key,
"author_type": AuthorType.SYSTEM, "author_type": AuthorType.SYSTEM,
"author_id": str(actor_id) if actor_id else None, "author_id": None,
"author_slug": actor_slug, "author_slug": "system",
"author": None,
"content": task_text, "content": task_text,
"created_at": task_msg.created_at.isoformat() if task_msg.created_at else now.isoformat(), "created_at": task_msg.created_at.isoformat() if task_msg.created_at else now.isoformat(),
}) })
@ -189,11 +189,12 @@ async def _system_message(
"id": str(chat_msg.id), "id": str(chat_msg.id),
"chat_id": str(chat_id), "chat_id": str(chat_id),
"author_type": AuthorType.SYSTEM, "author_type": AuthorType.SYSTEM,
"author_id": str(actor_id) if actor_id else None, "author_id": None,
"author_slug": actor_slug, "author_slug": "system",
"author": None,
"content": chat_text, "content": chat_text,
"created_at": chat_msg.created_at.isoformat() if chat_msg.created_at else now.isoformat(), "created_at": chat_msg.created_at.isoformat() if chat_msg.created_at else now.isoformat(),
}, author_slug=actor_slug) }, author_slug="system")
def _task_out(t: Task, project_slug: str = "") -> dict: def _task_out(t: Task, project_slug: str = "") -> dict:

View File

@ -42,7 +42,7 @@ class Message(Base):
# Author # Author
author_type: Mapped[str] = mapped_column(String(20), nullable=False) # human | agent | system author_type: Mapped[str] = mapped_column(String(20), nullable=False) # human | agent | system
author_id: Mapped[uuid.UUID] = mapped_column(ForeignKey("members.id"), nullable=False) author_id: Mapped[uuid.UUID | None] = mapped_column(ForeignKey("members.id"), nullable=True)
# Content # Content
content: Mapped[str] = mapped_column(Text, nullable=False) content: Mapped[str] = mapped_column(Text, nullable=False)