Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(tasks): let agents set slug tags alongside the task summary (#107564)

Andrew Maguiredd621d3d017d
diff --git a/products/posthog_ai/frontend/logics/runStreamLogic.test.ts b/products/posthog_ai/frontend/logics/runStreamLogic.test.ts
index d69da73021cc..ed3f76d7ea1c 100644
--- a/products/posthog_ai/frontend/logics/runStreamLogic.test.ts
+++ b/products/posthog_ai/frontend/logics/runStreamLogic.test.ts
@@ -1834,6 +1834,7 @@ describe('runStreamLogic', () => {
error_message: null,
output: null,
task_summary: null,
+ task_tags: [],
artifacts: [],
state: {
pending_user_message: wrapWithPosthogContext(content, [
@@ -2624,6 +2625,7 @@ describe('runStreamLogic', () => {
error_message: null,
output: null,
task_summary: null,
+ task_tags: [],
artifacts: [],
state: { resume_from_run_id: 'run-1' },
}
@@ -2712,6 +2714,7 @@ describe('runStreamLogic', () => {
error_message: null,
output: null,
task_summary: null,
+ task_tags: [],
artifacts: [],
state: { resume_from_run_id: 'run-1' },
runtime_adapter: null,
@@ -2767,6 +2770,7 @@ describe('runStreamLogic', () => {
error_message: 'Failed to start task workflow',
output: null,
task_summary: null,
+ task_tags: [],
artifacts: [],
state: { resume_from_run_id: 'run-1' },
runtime_adapter: null,
@@ -3136,6 +3140,7 @@ describe('runStreamLogic', () => {
error_message: null,
output: null,
task_summary: null,
+ task_tags: [],
artifacts: [],
state: { resume_from_run_id: 'run-1' },
} satisfies TaskRunDetailDTOApi
@@ -3247,6 +3252,7 @@ describe('runStreamLogic', () => {
error_message: null,
output: null,
task_summary: null,
+ task_tags: [],
artifacts: [],
state: { resume_from_run_id: 'run-1' },
})
@@ -3669,6 +3675,7 @@ describe('runStreamLogic', () => {
error_message: null,
output: null,
task_summary: null,
+ task_tags: [],
artifacts: [],
state: { resume_from_run_id: 'run-0' },
})
diff --git a/products/posthog_ai/frontend/logics/taskLogic.test.ts b/products/posthog_ai/frontend/logics/taskLogic.test.ts
index 26c51dee9ba8..c8cf72001fd2 100644
--- a/products/posthog_ai/frontend/logics/taskLogic.test.ts
+++ b/products/posthog_ai/frontend/logics/taskLogic.test.ts
@@ -219,6 +219,7 @@ describe('taskLogic', () => {
error_message: null,
output: null,
task_summary: null,
+ task_tags: [],
state: {},
artifacts: [],
created_at: '2024-01-01T00:00:00Z',
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/TaskTracker.stories.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/TaskTracker.stories.tsx
index 14e9f757e0df..9b9f2fa0fb7c 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/TaskTracker.stories.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/TaskTracker.stories.tsx
@@ -49,6 +49,7 @@ function mockRun(
error_message: null,
output: null,
task_summary: null,
+ task_tags: [],
state: {},
artifacts: [],
created_at: createdAt,
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/taskDetailSceneLogic.test.ts b/products/posthog_ai/frontend/scenes/TaskTracker/taskDetailSceneLogic.test.ts
index 691f4f315b1b..b0d441866bd8 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/taskDetailSceneLogic.test.ts
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/taskDetailSceneLogic.test.ts
@@ -44,6 +44,7 @@ const createMockRun = (id: string, status: TaskRunStatus): TaskRun => ({
error_message: null,
output: null,
task_summary: null,
+ task_tags: [],
state: {},
artifacts: [],
created_at: '2024-01-01T00:00:00Z',
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic.test.ts b/products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic.test.ts
index 9cac08213cb1..d7771ee9ecb6 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic.test.ts
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic.test.ts
@@ -796,6 +796,7 @@ describe('taskTrackerSceneLogic', () => {
error_message: null,
output: null,
task_summary: null,
+ task_tags: [],
state: {},
artifacts: [],
created_at: '2026-01-01T00:00:00Z',
diff --git a/products/posthog_ai/frontend/types/wireTypes.ts b/products/posthog_ai/frontend/types/wireTypes.ts
index a5ce824b3b83..1c6b78dc200e 100644
--- a/products/posthog_ai/frontend/types/wireTypes.ts
+++ b/products/posthog_ai/frontend/types/wireTypes.ts
@@ -48,6 +48,8 @@ export interface TaskRunStateFrame {
status?: string
stage?: string | null
output?: unknown
+ task_summary?: string | null
+ task_tags?: string[]
branch?: string | null
error_message?: string | null
updated_at?: string | null
diff --git a/products/tasks/backend/facade/api.py b/products/tasks/backend/facade/api.py
index 811939ee5984..787158824d3e 100644
--- a/products/tasks/backend/facade/api.py
+++ b/products/tasks/backend/facade/api.py
@@ -126,8 +126,10 @@ from products.tasks.backend.mentions import resolve_mentioned_user_ids
from products.tasks.backend.models import (
MCP_CREDENTIAL_OWNER_STATE_KEY,
PRIOR_RUN_SUMMARY_STATE_KEY,
+ PRIOR_RUN_TAGS_STATE_KEY,
TASK_OWNERSHIP_VERSION_STATE_KEY,
TASK_RUN_SUMMARY_STATE_KEY,
+ TASK_RUN_TAGS_STATE_KEY,
Channel,
ChannelContextGeneration,
ChannelFeedMessage,
@@ -556,19 +558,20 @@ def _task_run_log_url(run: TaskRun) -> str | None:
return presigned_url
-def _task_run_summary_for_viewer(
+def _can_read_task_run_summary(
run: TaskRun,
*,
task: Task | None = None,
user_id: int | None = None,
include_agent_state: bool = False,
-) -> str | None:
+) -> bool:
if include_agent_state:
- return run.task_summary
+ return True
parent = task if task is not None else run.task
- if parent.origin_product == Task.OriginProduct.WORKFLOW and parent.created_by_id != user_id:
- return None
- return run.task_summary
+ # A missing viewer never matches, even when the creator was deleted and created_by_id is null.
+ return parent.origin_product != Task.OriginProduct.WORKFLOW or (
+ user_id is not None and parent.created_by_id == user_id
+ )
def _task_run_detail_to_dto(
@@ -590,6 +593,9 @@ def _task_run_detail_to_dto(
)
state = parse_run_state(run.state)
+ can_read_summary = _can_read_task_run_summary(
+ run, task=task, user_id=user_id, include_agent_state=include_agent_state
+ )
return contracts.TaskRunDetailDTO(
id=run.id,
task=run.task_id,
@@ -604,9 +610,8 @@ def _task_run_detail_to_dto(
log_url=_task_run_log_url(run) if include_log_url else None,
error_message=run.error_message,
output=run.output,
- task_summary=_task_run_summary_for_viewer(
- run, task=task, user_id=user_id, include_agent_state=include_agent_state
- ),
+ task_summary=run.task_summary if can_read_summary else None,
+ task_tags=run.task_tags if can_read_summary else [],
state=_public_task_run_state(run.state, include_agent_keys=include_agent_state),
artifacts=run.artifacts or [],
created_at=run.created_at,
@@ -2606,6 +2611,8 @@ _PROTECTED_RUN_STATE_KEYS = frozenset(
"warm_activated",
TASK_RUN_SUMMARY_STATE_KEY,
PRIOR_RUN_SUMMARY_STATE_KEY,
+ TASK_RUN_TAGS_STATE_KEY,
+ PRIOR_RUN_TAGS_STATE_KEY,
"sandbox_id",
# Sandbox connection state is written only by the provisioning activity. A PATCHable
# sandbox_backend/sandbox_url would let a task controller point the account-wide hogland
@@ -3156,6 +3163,7 @@ def update_task_run(
only_if_non_terminal: bool = False,
only_if_not_started: bool = False,
caller_is_agent: bool = False,
+ user_id: int | None = None,
) -> contracts.TaskRunDetailDTO | None:
"""Apply a PATCH to a run: merge output/state, set completion, then dispatch side effects.
@@ -3229,7 +3237,7 @@ def update_task_run(
if only_if_non_terminal and run.is_terminal:
if validated_data.get("status") == run.status:
transaction.on_commit(lambda: resume_workflow_step_for_run(run))
- return _task_run_detail_to_dto(run)
+ return _task_run_detail_to_dto(run, user_id=user_id)
old_status = run.status
old_pr_url = (run.output or {}).get("pr_url") if isinstance(run.output, dict) else None
old_commit_head = _commit_push_head_sha(run.output)
@@ -3366,10 +3374,12 @@ def update_task_run(
if new_status in _TERMINAL_TASK_RUN_STATUSES:
resume_workflow_step_for_run(run)
- return _task_run_detail_to_dto(run)
+ return _task_run_detail_to_dto(run, user_id=user_id)
TASK_RUN_SUMMARY_MAX_CHARS = 1500
+TASK_RUN_TAGS_MAX_COUNT = 10
+TASK_RUN_TAG_MAX_CHARS = 50
def validate_set_output(run_id: str | UUID, task_id: str | UUID, team_id: int, *, output: dict) -> str | None:
@@ -3389,7 +3399,7 @@ def validate_set_output(run_id: str | UUID, task_id: str | UUID, team_id: int, *
def set_task_run_output(
- run_id: str | UUID, task_id: str | UUID, team_id: int, *, output: dict
+ run_id: str | UUID, task_id: str | UUID, team_id: int, *, output: dict, user_id: int | None = None
) -> contracts.TaskRunDetailDTO | None:
"""Persist a run's output. Completes the run for structured-output tasks; posts Slack PR update."""
run = _get_visible_run(run_id, task_id, team_id)
@@ -3410,7 +3420,7 @@ def set_task_run_output(
_send_wizard_pr_ready_email_for_pr(run)
if merged.get("pr_url"):
post_pr_created_thread_update(run, merged["pr_url"])
- return _task_run_detail_to_dto(run)
+ return _task_run_detail_to_dto(run, user_id=user_id)
def set_task_run_summary(
@@ -3419,13 +3429,18 @@ def set_task_run_summary(
team_id: int,
*,
summary: str,
+ tags: list[str] | None = None,
include_agent_state: bool = False,
user_id: int | None = None,
) -> contracts.TaskRunDetailDTO | None:
run = _get_visible_run(run_id, task_id, team_id)
if run is None:
return None
- run.state = TaskRun.update_state_atomic(run.id, updates={TASK_RUN_SUMMARY_STATE_KEY: summary})
+ updates: dict[str, Any] = {TASK_RUN_SUMMARY_STATE_KEY: summary}
+ # Omitted tags keep the current set, so a summary-only call does not erase them.
+ if tags is not None:
+ updates[TASK_RUN_TAGS_STATE_KEY] = list(dict.fromkeys(tags))
+ run.state = TaskRun.update_state_atomic(run.id, updates=updates)
run.refresh_from_db()
run.publish_stream_state_event()
return _task_run_detail_to_dto(run, include_agent_state=include_agent_state, user_id=user_id)
@@ -6773,7 +6788,9 @@ def get_task_summaries(
summaries: list[contracts.TaskSummaryDTO] = []
for task in tasks:
raw = getattr(task, "_latest_run", None)
- can_read_summary = task.origin_product != Task.OriginProduct.WORKFLOW or task.created_by_id == user_id
+ can_read_summary = task.origin_product != Task.OriginProduct.WORKFLOW or (
+ user_id is not None and task.created_by_id == user_id
+ )
latest = _latest_run_summary(raw, getattr(task, "_latest_pr_run", None), can_read_summary=can_read_summary)
summaries.append(
contracts.TaskSummaryDTO(
@@ -8720,6 +8737,8 @@ def run_task(
extra_state = extra_state or {}
if previous_run.task_summary:
extra_state[PRIOR_RUN_SUMMARY_STATE_KEY] = previous_run.task_summary
+ if previous_run.task_tags:
+ extra_state[PRIOR_RUN_TAGS_STATE_KEY] = previous_run.task_tags
if not is_pi_task:
extra_state["resume_from_run_id"] = str(resume_from_run_id)
extra_state.update(prev_state.resume_snapshot_carry_state())
diff --git a/products/tasks/backend/facade/contracts.py b/products/tasks/backend/facade/contracts.py
index 95b80c26eddc..44fb9d0ee0df 100644
--- a/products/tasks/backend/facade/contracts.py
+++ b/products/tasks/backend/facade/contracts.py
@@ -615,6 +615,7 @@ class TaskRunDetailDTO:
task_summary: str | None
state: dict
artifacts: list = Field(default_factory=list)
+ task_tags: list[str] = Field(default_factory=list)
created_at: datetime | None = None
updated_at: datetime | None = None
completed_at: datetime | None = None
diff --git a/products/tasks/backend/models.py b/products/tasks/backend/models.py
index ac4ea1d8bd26..e8283b7c189c 100644
--- a/products/tasks/backend/models.py
+++ b/products/tasks/backend/models.py
@@ -74,6 +74,8 @@ MCP_GATEWAY_SERVER_ALLOWLIST_STATE_KEY = "mcp_gateway_server_ids"
TASK_OWNERSHIP_VERSION_STATE_KEY = "task_ownership_version"
TASK_RUN_SUMMARY_STATE_KEY = "task_summary"
PRIOR_RUN_SUMMARY_STATE_KEY = "prior_run_summary"
+TASK_RUN_TAGS_STATE_KEY = "task_tags"
+PRIOR_RUN_TAGS_STATE_KEY = "prior_run_tags"
# Stage `Task.create_run` stamps on a person-started signals run, so it resolves a mintable
# gateway product. Keyed by origin value.
@@ -849,6 +851,8 @@ class Task(DeletedMetaFields, models.Model):
raise TaskOwnershipChangedError("The resume source belongs to a previous task owner")
if resume_source.task_summary:
state.setdefault(PRIOR_RUN_SUMMARY_STATE_KEY, resume_source.task_summary)
+ if resume_source.task_tags:
+ state.setdefault(PRIOR_RUN_TAGS_STATE_KEY, resume_source.task_tags)
# Pin the stream-routing decision once so every reader/writer agrees for this run's life.
state.setdefault("use_dedicated_stream", dedicated_stream)
@@ -2509,6 +2513,16 @@ class TaskRun(models.Model):
return summary.strip()
return None
+ @property
+ def task_tags(self) -> list[str]:
+ state = self.state if isinstance(self.state, dict) else {}
+ # An explicit list on this run wins, even an empty one, so clearing tags hides inherited ones.
+ for key in (TASK_RUN_TAGS_STATE_KEY, PRIOR_RUN_TAGS_STATE_KEY):
+ tags = state.get(key)
+ if isinstance(tags, list):
+ return [tag for tag in tags if isinstance(tag, str)]
+ return []
+
@property
def mode(self) -> str:
"""Get the execution mode from state. Defaults to 'background'."""
@@ -3182,7 +3196,8 @@ class TaskRun(models.Model):
def build_stream_state_event(self) -> dict[str, Any]:
# Workflow tasks are team-readable, but their summaries can contain private trigger context.
- stream_task_summary = self.task_summary if self.task.origin_product != Task.OriginProduct.WORKFLOW else None
+ can_stream_summary = self.task.origin_product != Task.OriginProduct.WORKFLOW
+ stream_task_summary = self.task_summary if can_stream_summary else None
return {
"type": "task_run_state",
"run_id": str(self.id),
@@ -3191,6 +3206,7 @@ class TaskRun(models.Model):
"stage": self.stage,
"output": self.output,
"task_summary": stream_task_summary,
+ "task_tags": self.task_tags if can_stream_summary else [],
"branch": self.branch,
"error_message": self.error_message,
"updated_at": self.updated_at.isoformat() if self.updated_at else None,
diff --git a/products/tasks/backend/presentation/serializers.py b/products/tasks/backend/presentation/serializers.py
index eae476c1beb0..d0a5c2b7619d 100644
--- a/products/tasks/backend/presentation/serializers.py
+++ b/products/tasks/backend/presentation/serializers.py
@@ -528,6 +528,10 @@ class TaskRunDetailSerializer(DataclassSerializer):
allow_null=True,
help_text="Latest summary for this task, including a summary inherited from an earlier run.",
)
+ task_tags = serializers.ListField(
+ child=serializers.CharField(),
+ help_text="Latest slug tags for this task, including tags inherited from an earlier run.",
+ )
class Meta:
dataclass = TaskRunDetailDTO
@@ -546,6 +550,7 @@ class TaskRunDetailSerializer(DataclassSerializer):
"error_message",
"output",
"task_summary",
+ "task_tags",
"state",
"artifacts",
"created_at",
@@ -1203,6 +1208,21 @@ class TaskRunSetSummaryRequestSerializer(serializers.Serializer):
trim_whitespace=True,
help_text="Complete running summary that replaces the prior summary.",
)
+ tags = serializers.ListField(
+ child=serializers.RegexField(
+ # Python's `$` also matches before a final newline; `(?!\n)` rejects it, as JavaScript does.
+ regex=r"^[a-z0-9]+(?:-[a-z0-9]+)*$(?!\n)",
+ max_length=tasks_facade.TASK_RUN_TAG_MAX_CHARS,
+ trim_whitespace=False,
+ help_text="A lowercase kebab-case slug, for example `feature-flags` or `bug-fix`.",
+ ),
+ required=False,
+ max_length=tasks_facade.TASK_RUN_TAGS_MAX_COUNT,
+ help_text=(
+ "Complete set of slug tags that replaces the prior tags. The agent chooses the tags. "
+ "Omit the field to keep the current tags. Send an empty list to remove them."
+ ),
+ )
DESKTOP_ACCESS_REASON_CHOICES = [reason.value for reason in DesktopAccessReason]
diff --git a/products/tasks/backend/presentation/views/api.py b/products/tasks/backend/presentation/views/api.py
index fda7d73878b9..e4390e623511 100644
--- a/products/tasks/backend/presentation/views/api.py
+++ b/products/tasks/backend/presentation/views/api.py
@@ -2000,6 +2000,7 @@ class TaskRunViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
validated_data=dict(request.validated_data),
only_if_non_terminal=True,
caller_is_agent=self._is_sandbox_agent_request(task_id),
+ user_id=self._user_id(),
)
if run is None:
raise NotFound()
@@ -2031,7 +2032,7 @@ class TaskRunViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
status=status.HTTP_400_BAD_REQUEST,
)
- run = tasks_facade.set_task_run_output(pk, task_id, self.team_id, output=output_data)
+ run = tasks_facade.set_task_run_output(pk, task_id, self.team_id, output=output_data, user_id=self._user_id())
if run is None:
raise NotFound()
return Response(TaskRunDetailSerializer(run).data)
@@ -2043,7 +2044,7 @@ class TaskRunViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
404: OpenApiResponse(description="Run not found"),
},
summary="Set task run summary",
- description="Replace the running summary for a task run.",
+ description="Replace the running summary for a task run, and optionally its slug tags.",
strict_request_validation=True,
)
@action(
@@ -2059,6 +2060,7 @@ class TaskRunViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
task_id,
self.team_id,
summary=request.validated_data["summary"],
+ tags=request.validated_data.get("tags"),
include_agent_state=self._is_sandbox_agent_request(task_id),
user_id=self._user_id(),
)
diff --git a/products/tasks/backend/tests/test_api.py b/products/tasks/backend/tests/test_api.py
index adef3a18bd61..850371897d21 100644
--- a/products/tasks/backend/tests/test_api.py
+++ b/products/tasks/backend/tests/test_api.py
@@ -6350,8 +6350,9 @@ class TestTaskSummariesAPI(BaseTaskAPITest):
team=self.team,
task=task,
status=TaskRun.Status.IN_PROGRESS,
- state={"task_summary": "Private workflow context"},
+ state={"task_summary": "Private workflow context", "task_tags": ["private-tag"]},
)
+ expected_tags = ["private-tag"] if is_owner else []
summaries_response = self.post_summaries([str(task.id)])
detail_response = self.client.get(f"/api/projects/@current/tasks/{task.id}/runs/{run.id}/")
@@ -6361,6 +6362,16 @@ class TestTaskSummariesAPI(BaseTaskAPITest):
self.assertEqual(payload["latest_run"]["task_summary"], expected_summary)
self.assertEqual(detail_response.status_code, status.HTTP_200_OK)
self.assertEqual(detail_response.json()["task_summary"], expected_summary)
+ self.assertEqual(detail_response.json()["task_tags"], expected_tags)
+
+ set_output_response = self.client.patch(
+ f"/api/projects/@current/tasks/{task.id}/runs/{run.id}/set_output/",
+ {"output": {"note": "done"}},
+ format="json",
+ )
+ self.assertEqual(set_output_response.status_code, status.HTTP_200_OK)
+ self.assertEqual(set_output_response.json()["task_summary"], expected_summary)
+ self.assertEqual(set_output_response.json()["task_tags"], expected_tags)
for basic in ("true", "false"):
with self.subTest(basic=basic):
@@ -6487,21 +6498,40 @@ class TestTaskRunAPI(BaseTaskAPITest):
task=task,
team=self.team,
status=TaskRun.Status.IN_PROGRESS,
- state={"prior_run_summary": "Reading the existing code"},
+ state={"prior_run_summary": "Reading the existing code", "prior_run_tags": ["research"]},
)
client = self._sandbox_oauth_client(task.id)
initial = client.get(f"/api/projects/@current/tasks/{task.id}/runs/{run.id}/")
updated = client.patch(
f"/api/projects/@current/tasks/{task.id}/runs/{run.id}/set_summary/",
- {"summary": "Writing the fix"},
+ {"summary": "Writing the fix", "tags": ["bug-fix", "feature-flags", "bug-fix"]},
+ format="json",
+ )
+ summary_only = client.patch(
+ f"/api/projects/@current/tasks/{task.id}/runs/{run.id}/set_summary/",
+ {"summary": "Opening the PR"},
format="json",
)
self.assertEqual(initial.status_code, status.HTTP_200_OK)
self.assertEqual(initial.json()["task_summary"], "Reading the existing code")
+ self.assertEqual(initial.json()["task_tags"], ["research"])
self.assertEqual(updated.status_code, status.HTTP_200_OK)
self.assertEqual(updated.json()["task_summary"], "Writing the fix")
+ self.assertEqual(updated.json()["task_tags"], ["bug-fix", "feature-flags"])
+ self.assertEqual(summary_only.status_code, status.HTTP_200_OK)
+ self.assertEqual(summary_only.json()["task_summary"], "Opening the PR")
+ self.assertEqual(summary_only.json()["task_tags"], ["bug-fix", "feature-flags"])
+
+ cleared = client.patch(
+ f"/api/projects/@current/tasks/{task.id}/runs/{run.id}/set_summary/",
+ {"summary": "Opening the PR", "tags": []},
+ format="json",
+ )
+
+ self.assertEqual(cleared.status_code, status.HTTP_200_OK)
+ self.assertEqual(cleared.json()["task_tags"], [])
def test_unbound_sandbox_scope_does_not_bypass_task_visibility(self):
owner = self.create_organization_user("sandbox-owner")
@@ -6818,6 +6848,8 @@ class TestTaskRunAPI(BaseTaskAPITest):
"analysis_target_custom_image_name": "real-image",
"task_summary": "Current summary",
"prior_run_summary": "Prior summary",
+ "task_tags": ["current-tag"],
+ "prior_run_tags": ["prior-tag"],
"interaction_origin": "slack",
"slack_actor_user_id": self.user.id,
"run_source": "manual",
@@ -6904,6 +6936,8 @@ class TestTaskRunAPI(BaseTaskAPITest):
"analysis_target_custom_image_name": "attacker-image",
"task_summary": "Forged summary",
"prior_run_summary": "Forged prior summary",
+ "task_tags": ["forged-tag"],
+ "prior_run_tags": ["forged-prior-tag"],
"interaction_origin": "desktop",
"slack_actor_user_id": credential_target.id,
"run_source": "signal_report",
@@ -6967,6 +7001,8 @@ class TestTaskRunAPI(BaseTaskAPITest):
assert run.state["analysis_target_custom_image_name"] == "real-image"
assert run.state["task_summary"] == "Current summary"
assert run.state["prior_run_summary"] == "Prior summary"
+ assert run.state["task_tags"] == ["current-tag"]
+ assert run.state["prior_run_tags"] == ["prior-tag"]
assert run.state["interaction_origin"] == "slack"
assert run.state["slack_actor_user_id"] == self.user.id
assert run.state["run_source"] == "manual"
@@ -7018,6 +7054,8 @@ class TestTaskRunAPI(BaseTaskAPITest):
"analysis_target_custom_image_name",
"task_summary",
"prior_run_summary",
+ "task_tags",
+ "prior_run_tags",
"interaction_origin",
"slack_actor_user_id",
"run_source",
@@ -7068,6 +7106,8 @@ class TestTaskRunAPI(BaseTaskAPITest):
assert run.state["analysis_target_custom_image_name"] == "real-image"
assert run.state["task_summary"] == "Current summary"
assert run.state["prior_run_summary"] == "Prior summary"
+ assert run.state["task_tags"] == ["current-tag"]
+ assert run.state["prior_run_tags"] == ["prior-tag"]
assert run.state["interaction_origin"] == "slack"
assert run.state["slack_actor_user_id"] == self.user.id
assert run.state["run_source"] == "manual"
@@ -7537,23 +7577,32 @@ class TestTaskRunAPI(BaseTaskAPITest):
@parameterized.expand(
[
- ("over_the_cap", "x" * (tasks_facade.TASK_RUN_SUMMARY_MAX_CHARS + 1)),
- ("not_a_string", {"state": "halfway"}),
+ ("over_the_cap", {"summary": "x" * (tasks_facade.TASK_RUN_SUMMARY_MAX_CHARS + 1)}),
+ ("not_a_string", {"summary": {"state": "halfway"}}),
+ ("tag_not_a_slug", {"summary": "Reading", "tags": ["Feature Flags"]}),
+ ("tag_with_padding", {"summary": "Reading", "tags": [" bug-fix "]}),
+ ("tag_with_trailing_newline", {"summary": "Reading", "tags": ["bug-fix\n"]}),
+ ("tag_over_the_cap", {"summary": "Reading", "tags": ["x" * (tasks_facade.TASK_RUN_TAG_MAX_CHARS + 1)]}),
+ (
+ "too_many_tags",
+ {"summary": "Reading", "tags": [f"tag-{i}" for i in range(tasks_facade.TASK_RUN_TAGS_MAX_COUNT + 1)]},
+ ),
]
)
- def test_set_summary_rejects_an_unusable_summary(self, _name, summary):
+ def test_set_summary_rejects_an_unusable_summary(self, _name, payload):
task = self.create_task()
run = TaskRun.objects.create(task=task, team=self.team, status=TaskRun.Status.IN_PROGRESS)
response = self.client.patch(
f"/api/projects/@current/tasks/{task.id}/runs/{run.id}/set_summary/",
- {"summary": summary},
+ payload,
format="json",
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
run.refresh_from_db()
self.assertIsNone(run.task_summary)
+ self.assertEqual(run.task_tags, [])
@patch("products.tasks.backend.facade.api.signal_workflow_completion")
def test_task_summary_does_not_collide_with_structured_summary_output(self, mock_signal_workflow_completion):
diff --git a/products/tasks/backend/tests/test_facade.py b/products/tasks/backend/tests/test_facade.py
index 22eca881fe7c..e1f66562564d 100644
--- a/products/tasks/backend/tests/test_facade.py
+++ b/products/tasks/backend/tests/test_facade.py
@@ -258,14 +258,22 @@ class TestFacadeReadsAndMappers(TestCase):
defaults.update(kwargs)
return Task.objects.create(**defaults)
- @parameterized.expand([("the_sandbox", True), ("a_human_reader", False)])
- def test_run_detail_serves_the_boot_prompt_to_the_sandbox_only(self, _name, include_agent_state):
+ @parameterized.expand(
+ [
+ ("the_sandbox", True, True),
+ ("a_human_reader", False, True),
+ ("a_human_reader_of_a_creatorless_task", False, False),
+ ]
+ )
+ def test_run_detail_serves_the_boot_prompt_to_the_sandbox_only(self, _name, include_agent_state, has_creator):
# The agent reads initial_prompt_override off this payload to build its first
# message; dropping it strips it silently and the run falls back to
# task.description. But it embeds the triggering event wholesale (for a Slack
# trigger, a private channel's content) and workflow tasks are team-readable,
# so human readers must not receive it.
- task = self._make_task(origin_product=Task.OriginProduct.WORKFLOW)
+ task = self._make_task(
+ origin_product=Task.OriginProduct.WORKFLOW, created_by=self.user if has_creator else None
+ )
run = TaskRun.objects.create(
task=task,
team=self.team,
@@ -277,6 +285,7 @@ class TestFacadeReadsAndMappers(TestCase):
"systemPrompt": {"type": "preset", "preset": "claude_code", "append": "PostHog AI"},
"sandbox_jwt_kid": "secret",
"task_summary": "Private workflow context",
+ "task_tags": ["private-tag"],
},
)
@@ -293,6 +302,7 @@ class TestFacadeReadsAndMappers(TestCase):
assert ("systemPrompt" in detail.state) is include_agent_state
assert "sandbox_jwt_kid" not in detail.state
assert detail.task_summary == ("Private workflow context" if include_agent_state else None)
+ assert detail.task_tags == (["private-tag"] if include_agent_state else [])
def test_get_task_run_maps_all_fields(self):
task = self._make_task()
diff --git a/products/tasks/backend/tests/test_models.py b/products/tasks/backend/tests/test_models.py
index 7baa1b4c724f..71f84fd9903d 100644
--- a/products/tasks/backend/tests/test_models.py
+++ b/products/tasks/backend/tests/test_models.py
@@ -1087,6 +1087,22 @@ class TestTaskRun(TestCase):
self.assertEqual(run.state.get("prior_run_summary"), expected)
+ @parameterized.expand(
+ [
+ ("current_tags", {"task_tags": ["bug-fix"], "prior_run_tags": ["research"]}, ["bug-fix"]),
+ ("inherited_tags", {"prior_run_tags": ["research"]}, ["research"]),
+ ("no_tags", {"task_tags": []}, None),
+ ]
+ )
+ def test_create_run_carries_the_resume_source_tags(self, _name, source_state, expected):
+ previous_run = TaskRun.objects.create(
+ task=self.task, team=self.team, status=TaskRun.Status.COMPLETED, state=source_state
+ )
+
+ run = self.task.create_run(extra_state={"resume_from_run_id": str(previous_run.id)})
+
+ self.assertEqual(run.state.get("prior_run_tags"), expected)
+
@parameterized.expand(
[
("message_only", {"pending_user_message": "Look at this"}, True),
diff --git a/products/tasks/frontend/generated/api.schemas.ts b/products/tasks/frontend/generated/api.schemas.ts
index 836ecaeac270..5b04ea2e69db 100644
--- a/products/tasks/frontend/generated/api.schemas.ts
+++ b/products/tasks/frontend/generated/api.schemas.ts
@@ -1834,6 +1834,8 @@ export interface TaskRunDetailDTOApi {
* @nullable
*/
task_summary: string | null
+ /** Latest slug tags for this task, including tags inherited from an earlier run. */
+ task_tags: string[]
state: TaskRunDetailDTOApiState
readonly artifacts: readonly TaskRunArtifactResponseApi[]
/** @nullable */
@@ -4374,6 +4376,13 @@ export interface PatchedTaskRunSetSummaryRequestApi {
* @maxLength 1500
*/
summary?: string
+ /**
+ * Complete set of slug tags that replaces the prior tags. The agent chooses the tags. Omit the field to keep the current tags. Send an empty list to remove them.
+ * @maxItems 10
+ * @items.maxLength 50
+ * @items.pattern ^[a-z0-9]+(?:-[a-z0-9]+)*$(?!\n)
+ */
+ tags?: string[]
}
export interface TaskRunStartRequestApi {
diff --git a/products/tasks/frontend/generated/api.ts b/products/tasks/frontend/generated/api.ts
index 95a2fe11c14e..246fd4f85a3e 100644
--- a/products/tasks/frontend/generated/api.ts
+++ b/products/tasks/frontend/generated/api.ts
@@ -2329,7 +2329,7 @@ export const getTasksRunsSetSummaryPartialUpdateUrl = (projectId: string, taskId
}
/**
- * Replace the running summary for a task run.
+ * Replace the running summary for a task run, and optionally its slug tags.
* @summary Set task run summary
*/
export const tasksRunsSetSummaryPartialUpdate = async (
diff --git a/products/tasks/frontend/generated/api.zod.ts b/products/tasks/frontend/generated/api.zod.ts
index cfcd18bb7941..b0d3fdfb5363 100644
--- a/products/tasks/frontend/generated/api.zod.ts
+++ b/products/tasks/frontend/generated/api.zod.ts
@@ -3412,17 +3412,35 @@ export const TasksRunsSetOutputPartialUpdateBody = /* @__PURE__ */ zod.object({
})
/**
- * Replace the running summary for a task run.
+ * Replace the running summary for a task run, and optionally its slug tags.
* @summary Set task run summary
*/
export const tasksRunsSetSummaryPartialUpdateBodySummaryMax = 1500
+export const tasksRunsSetSummaryPartialUpdateBodyTagsItemMax = 50
+
+export const tasksRunsSetSummaryPartialUpdateBodyTagsItemRegExp = new RegExp('^[a-z0-9]+(?:-[a-z0-9]+)\*$(?!\\n)')
+export const tasksRunsSetSummaryPartialUpdateBodyTagsMax = 10
+
export const TasksRunsSetSummaryPartialUpdateBody = /* @__PURE__ */ zod.object({
summary: zod
.string()
.max(tasksRunsSetSummaryPartialUpdateBodySummaryMax)
.optional()
.describe('Complete running summary that replaces the prior summary.'),
+ tags: zod
+ .array(
+ zod
+ .string()
+ .max(tasksRunsSetSummaryPartialUpdateBodyTagsItemMax)
+ .regex(tasksRunsSetSummaryPartialUpdateBodyTagsItemRegExp)
+ .describe('A lowercase kebab-case slug, for example `feature-flags` or `bug-fix`.')
+ )
+ .max(tasksRunsSetSummaryPartialUpdateBodyTagsMax)
+ .optional()
+ .describe(
+ 'Complete set of slug tags that replaces the prior tags. The agent chooses the tags. Omit the field to keep the current tags. Send an empty list to remove them.'
+ ),
})
/**
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 1fa645e1d367..2b01c134f393 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -68425,6 +68425,8 @@ export namespace Schemas {
* @nullable
*/
task_summary: string | null;
+ /** Latest slug tags for this task, including tags inherited from an earlier run. */
+ task_tags: string[];
state: TaskRunDetailDTOState;
readonly artifacts: readonly TaskRunArtifactResponse[];
/** @nullable */
@@ -78396,6 +78398,13 @@ export namespace Schemas {
* @maxLength 1500
*/
summary?: string;
+ /**
+ * Complete set of slug tags that replaces the prior tags. The agent chooses the tags. Omit the field to keep the current tags. Send an empty list to remove them.
+ * @maxItems 10
+ * @items.maxLength 50
+ * @items.pattern ^[a-z0-9]+(?:-[a-z0-9]+)*$(?!\n)
+ */
+ tags?: string[];
}
/**