← Back to Pull requests

feat: delete task history of a template #4409

Open
unknown opened this pull request with 409 lines diff across 5 files
View on GitHub
unknown unknown commented on Nov 05, 2026 07:20 UTC
Author

Closes #1101

Adds DELETE /api/project/{project_id}/templates/{template_id}/tasks, which deletes the task history of a template, and a "Delete Task History" button with a confirmation on the template page.

Behaviour


  • Deletes only finished tasks (success, error, stopped), judged by the status in the database, not by the in-memory task pool, so tasks running on another node or a remote runner in HA are never touched.

  • Also keeps finished tasks that are still needed: tasks of a workflow run that is running or waiting for approval, and build tasks referenced by a deploy task that hasn't finished.

  • Same permission rule as the single-task delete (RemoveTask): admin only, with the same deny audit record. 204 on success (also when nothing was deleted), 401 for a non-admin, 404 for an unknown template or one from another project.

  • Records one audit event of a new kind task.history/delete_all targeting the template, with the number of deleted tasks. I added a kind rather than reusing task.history/delete because the catalog keeps one metadata type per kind, as with stop / stop_all.

  • Fixes the project__template.tasks counter afterwards.
  • Deleting in batches


    Tasks are deleted in batches of 500, each in its own transaction, so a large history doesn't hold the SQLite write lock for the whole run. If a later batch fails, the earlier ones stay deleted and the audit event is marked partial.

    Stages, stage results and Ansible hosts/errors go by ON DELETE CASCADE. MySQL has no foreign key on access_key.task_id or task.build_task_id, so the task-bound access keys are deleted and build_task_id references cleared explicitly; task output is deleted explicitly too.

    Testing


  • Store tests (SQLite, also run on Postgres 15 and MySQL 8): finished tasks removed with their linked rows, unfinished kept, other templates/projects untouched, wrong ids → not found with nothing deleted, empty history, counter repaired, idempotent second call, workflow runs, build tasks, 1,007 tasks across several batches. go test ./db/sql/ -count=20 passes.

  • API tests: admin → 204 + event; non-admin → 401 + deny event, nothing deleted; another project's template → 404.

  • Web: eslint clean, vitest passes including a new spec for the button.

  • Dredd against SQLite: 112 passing, 0 failing, including DELETE (204) /api/project/1/templates/7/tasks.

  • Manually: a running task survives the deletion and finishes normally.
  • Not included: a CLI / pkg/apiclient command and translations for the new strings (other locales fall back to English).

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    New Features
    Administrators can delete a template’s finished task history from the template page. Queued and running tasks, tasks needed by unfinished work, and the newest task for build templates are retained.
    The action requires confirmation and reports success or errors. The task list refreshes after the request, including when an error occurs.
    Deletions are recorded in the audit history.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Supersedes #4407 (reopened from my main account; the review there is addressed).

    Diff: 409 lines (+306 / -103) across 5 files Reviewer: mansur-akhmadi Review duration: 37606m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 409 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.360
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #4409"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44.9% (MEDIUM) · Higher = larger blast radius
    44.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 23.9% · Safe to merge
    23.9%