Inject project_id into all WS broadcast data
Some checks failed
Deploy Tracker / deploy (push) Failing after 4s

- broadcast_message: injects project_id into message dict
- broadcast_task_event: injects project_id into task data
- chat.send handler: resolves project_id from chat or task
- _system_message: adds project_id to both task and chat broadcasts

Agents always know which project a message belongs to.
This commit is contained in:
markov 2026-02-27 14:21:36 +01:00
parent ff6b32316c
commit d953cb73ab
3 changed files with 22 additions and 3 deletions

View File

@ -157,10 +157,12 @@ async def _system_message(
created_at=task_msg.created_at.isoformat() if task_msg.created_at else now_iso, created_at=task_msg.created_at.isoformat() if task_msg.created_at else now_iso,
) )
project_id = str(task.project_id) project_id = str(task.project_id)
task_data = task_msg_out.model_dump()
task_data["project_id"] = project_id
await manager.broadcast_message( await manager.broadcast_message(
project_id, project_id,
task_msg_out.model_dump(), task_data,
author_id=None, # system has no member_id author_id=None,
) )
# Broadcast chat message # Broadcast chat message
@ -177,7 +179,9 @@ async def _system_message(
attachments=[], attachments=[],
created_at=chat_msg.created_at.isoformat() if chat_msg.created_at else now_iso, created_at=chat_msg.created_at.isoformat() if chat_msg.created_at else now_iso,
) )
await manager.broadcast_message(project_id, chat_msg_out.model_dump(), author_id=None) chat_data = chat_msg_out.model_dump()
chat_data["project_id"] = project_id
await manager.broadcast_message(project_id, chat_data, author_id=None)
async def _get_task(task_id: str, db: AsyncSession) -> Task: async def _get_task(task_id: str, db: AsyncSession) -> Task:

View File

@ -317,12 +317,22 @@ async def _handle_chat_send(session_id: str, data: dict):
msg_data = _to_message_out(msg, member).model_dump() msg_data = _to_message_out(msg, member).model_dump()
# Resolve project_id and inject into message data
project_id = None project_id = None
if chat_id: if chat_id:
chat_result = await db.execute(select(Chat).where(Chat.id == uuid.UUID(chat_id))) chat_result = await db.execute(select(Chat).where(Chat.id == uuid.UUID(chat_id)))
chat = chat_result.scalar_one_or_none() chat = chat_result.scalar_one_or_none()
if chat and chat.project_id: if chat and chat.project_id:
project_id = str(chat.project_id) project_id = str(chat.project_id)
elif task_id:
from ..models import Task as TaskModel
task_result = await db.execute(select(TaskModel).where(TaskModel.id == uuid.UUID(task_id)))
task_obj = task_result.scalar_one_or_none()
if task_obj:
project_id = str(task_obj.project_id)
if project_id:
msg_data["project_id"] = project_id
elif chat and chat.kind == ChatKind.LOBBY: elif chat and chat.kind == ChatKind.LOBBY:
await manager.broadcast_all( await manager.broadcast_all(
{"type": WSEventType.MESSAGE_NEW, "data": msg_data}, {"type": WSEventType.MESSAGE_NEW, "data": msg_data},

View File

@ -93,6 +93,9 @@ class ConnectionManager:
- If chat_listen == "mentions": only if member_id in mention IDs - If chat_listen == "mentions": only if member_id in mention IDs
- System messages: only if member_id in mention IDs - System messages: only if member_id in mention IDs
""" """
# Always inject project_id into message data
message["project_id"] = project_id
raw_mentions = message.get("mentions", []) raw_mentions = message.get("mentions", [])
# Extract member IDs from mentions (objects or strings) # Extract member IDs from mentions (objects or strings)
mention_ids: set[str] = set() mention_ids: set[str] = set()
@ -148,6 +151,8 @@ class ConnectionManager:
async def broadcast_task_event(self, project_id: str, event_type: str, data: dict): async def broadcast_task_event(self, project_id: str, event_type: str, data: dict):
"""Broadcast task events. Humans get everything, agents filtered.""" """Broadcast task events. Humans get everything, agents filtered."""
# Always inject project_id
data["project_id"] = project_id
assignee_id = data.get("assignee_id") assignee_id = data.get("assignee_id")
reviewer_id = data.get("reviewer_id") reviewer_id = data.get("reviewer_id")
watcher_ids = data.get("watcher_ids", []) watcher_ids = data.get("watcher_ids", [])