A task that already has sub_tasks refuses re-distribution 🟩

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-07-07 12:04:34 +00:00
parent dade7a3a5f
commit cfedb8e9cf

View file

@ -12,7 +12,7 @@ from collections.abc import Callable, Iterator
from typing import Any, cast
import boto3
from fastapi import APIRouter, Depends
from fastapi import APIRouter, Depends, HTTPException
from sqlmodel import Session
from backend.app.config import get_settings
@ -70,6 +70,16 @@ async def trigger_run(
session: Session = Depends(get_session),
send_messages: MessageSender = Depends(get_message_sender),
) -> dict[str, str]:
subtask_repo = SubTaskPostgresRepository(session)
if subtask_repo.list_by_task(body.task_id):
raise HTTPException(
status_code=409,
detail=(
f"Task {body.task_id} already has sub_tasks — it has been "
"distributed. Check its progress instead of re-triggering."
),
)
properties: list[FilteredProperty] = resolve_filtered_property_ids(
session, body.portfolio_id, body.filters
)
@ -78,7 +88,6 @@ async def trigger_run(
# Pre-create one sub_task per (scenario, batch) message under the
# app-owned task, each holding its exact message payload — the fixed
# progress denominator and the batch's re-run recipe (ADR-0055).
subtask_repo = SubTaskPostgresRepository(session)
subtasks: list[SubTask] = []
payloads: list[dict[str, Any]] = []
for scenario_id in body.scenario_ids: