from __future__ import annotations

from backend.app.db.history_repository import HistoryRepository
from backend.app.db.task_repository import TaskRepository


def reconcile_persisted_incomplete_tasks(
    task_repository: TaskRepository,
    history_repository: HistoryRepository,
) -> list[str]:
    task_ids = task_repository.reconcile_incomplete_tasks()
    if task_ids:
        history_repository.reconcile_entries_failed(task_ids)
    return task_ids
