feat: update activity feed to include various event types and improve messaging

This commit is contained in:
Abhimanyu Saharan
2026-02-12 15:21:41 +05:30
parent 284f03f868
commit c73103d5c9
10 changed files with 1726 additions and 335 deletions

View File

@@ -30,8 +30,8 @@ from app.schemas.approvals import ApprovalCreate, ApprovalRead, ApprovalStatus,
from app.schemas.pagination import DefaultLimitOffsetPage
from app.services.activity_log import record_activity
from app.services.approval_task_links import (
lock_tasks_for_approval,
load_task_ids_by_approval,
lock_tasks_for_approval,
normalize_task_ids,
pending_approval_conflicts_by_task,
replace_approval_task_links,
@@ -408,7 +408,9 @@ async def update_approval(
if "status" in updates:
target_status = updates["status"]
if target_status == "pending" and prior_status != "pending":
task_ids_by_approval = await load_task_ids_by_approval(session, approval_ids=[approval.id])
task_ids_by_approval = await load_task_ids_by_approval(
session, approval_ids=[approval.id]
)
approval_task_ids = task_ids_by_approval.get(approval.id)
if not approval_task_ids and approval.task_id is not None:
approval_task_ids = [approval.task_id]

View File

@@ -35,6 +35,7 @@ from app.models.boards import Board
from app.models.task_dependencies import TaskDependency
from app.models.task_fingerprints import TaskFingerprint
from app.models.tasks import Task
from app.schemas.activity_events import ActivityEventRead
from app.schemas.common import OkResponse
from app.schemas.errors import BlockedTaskError
from app.schemas.pagination import DefaultLimitOffsetPage
@@ -648,7 +649,10 @@ def _task_event_payload(
deps_map: dict[UUID, list[UUID]],
dep_status: dict[UUID, str],
) -> dict[str, object]:
payload: dict[str, object] = {"type": event.event_type}
payload: dict[str, object] = {
"type": event.event_type,
"activity": ActivityEventRead.model_validate(event).model_dump(mode="json"),
}
if event.event_type == "task.comment":
payload["comment"] = _serialize_comment(event)
return payload

View File

@@ -196,10 +196,10 @@ async def pending_approval_conflicts_by_task(
legacy_statement = legacy_statement.where(col(Approval.id) != exclude_approval_id)
legacy_rows = list(await session.exec(legacy_statement))
for task_id, approval_id, _created_at in legacy_rows:
if task_id is None:
for legacy_task_id, approval_id, _created_at in legacy_rows:
if legacy_task_id is None:
continue
conflicts.setdefault(task_id, approval_id)
conflicts.setdefault(legacy_task_id, approval_id)
return conflicts

View File

@@ -35,7 +35,9 @@ async def test_agent_token_lookup_should_not_verify_more_than_once(
async def exec(self, _stmt: object) -> list[object]:
agents = []
for i in range(50):
agents.append(SimpleNamespace(agent_token_hash=f"pbkdf2_sha256$1$salt{i}$digest{i}"))
agents.append(
SimpleNamespace(agent_token_hash=f"pbkdf2_sha256$1$salt{i}$digest{i}")
)
return agents
calls = {"n": 0}

View File

@@ -5,7 +5,7 @@ from uuid import uuid4
import pytest
from app.api.tasks import _coerce_task_event_rows
from app.api.tasks import _coerce_task_event_rows, _task_event_payload
from app.models.activity_events import ActivityEvent
from app.models.tasks import Task
@@ -51,3 +51,65 @@ def test_coerce_task_event_rows_accepts_row_like_values():
def test_coerce_task_event_rows_rejects_invalid_values():
with pytest.raises(TypeError, match="Expected \\(ActivityEvent, Task \\| None\\) rows"):
_coerce_task_event_rows([("bad", "row")])
def test_task_event_payload_includes_activity_for_comment_event() -> None:
task = Task(board_id=uuid4(), title="Ship patch")
event = ActivityEvent(
event_type="task.comment",
message="Looks good.",
task_id=task.id,
agent_id=uuid4(),
)
payload = _task_event_payload(
event,
task,
deps_map={},
dep_status={},
)
assert payload["type"] == "task.comment"
assert payload["activity"] == {
"id": str(event.id),
"event_type": "task.comment",
"message": "Looks good.",
"agent_id": str(event.agent_id),
"task_id": str(task.id),
"created_at": event.created_at.isoformat(),
}
comment = payload["comment"]
assert isinstance(comment, dict)
assert comment["id"] == str(event.id)
assert comment["task_id"] == str(task.id)
assert comment["message"] == "Looks good."
def test_task_event_payload_includes_activity_for_non_comment_event() -> None:
task = Task(board_id=uuid4(), title="Wire stream events", status="in_progress")
event = ActivityEvent(
event_type="task.updated",
message="Task updated: Wire stream events.",
task_id=task.id,
)
payload = _task_event_payload(
event,
task,
deps_map={},
dep_status={},
)
assert payload["type"] == "task.updated"
assert payload["activity"] == {
"id": str(event.id),
"event_type": "task.updated",
"message": "Task updated: Wire stream events.",
"agent_id": None,
"task_id": str(task.id),
"created_at": event.created_at.isoformat(),
}
task_payload = payload["task"]
assert isinstance(task_payload, dict)
assert task_payload["id"] == str(task.id)
assert task_payload["is_blocked"] is False