Skip to content

Commit 8834a2e

Browse files
committed
Fix cfbot CI status showing incorrect task counts
When cfbot retries failed tasks, it creates multiple tasks with the same `(branch_id, position)` but different `task_id` values. This caused the CI status display to show incorrect counts like "10/11" instead of "10/10". This fix changes the unique constraint from `task_id` to `(branch_id, position)` and updates the cfbot ingestion logic to replace older tasks with newer ones when retries occur. The `INSERT ... ON CONFLICT` now uses the position-based constraint to keep only the most recent task for each position.
1 parent 91d3643 commit 8834a2e

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Generated by Django 4.2.19 on 2025-08-17 16:29
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("commitfest", "0014_add_paused_cfbot_task_state"),
9+
]
10+
11+
operations = [
12+
# Remove duplicate tasks keeping the one with the latest modified time
13+
migrations.RunSQL(
14+
"""
15+
DELETE FROM commitfest_cfbottask
16+
WHERE id IN (
17+
SELECT id FROM (
18+
SELECT id,
19+
ROW_NUMBER() OVER (
20+
PARTITION BY branch_id, position
21+
ORDER BY modified DESC
22+
) as rn
23+
FROM commitfest_cfbottask
24+
) t
25+
WHERE rn > 1
26+
);
27+
""",
28+
reverse_sql="",
29+
),
30+
# Remove unique constraint from task_id field
31+
migrations.AlterField(
32+
model_name="cfbottask",
33+
name="task_id",
34+
field=models.TextField(),
35+
),
36+
# Add unique constraint on (branch_id, position)
37+
migrations.AddConstraint(
38+
model_name="cfbottask",
39+
constraint=models.UniqueConstraint(
40+
fields=["branch_id", "position"],
41+
name="commitfest_cfbottask_branch_position_unique",
42+
),
43+
),
44+
]

pgcommitfest/commitfest/models.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ class CfbotTask(models.Model):
842842
# given that we might need to change CI providers at some point, and that
843843
# CI provider might use e.g. UUIDs, we prefer to consider the format of the
844844
# ID opaque and store it as text.
845-
task_id = models.TextField(unique=True)
845+
task_id = models.TextField()
846846
task_name = models.TextField(null=False)
847847
patch = models.ForeignKey(
848848
Patch, on_delete=models.CASCADE, related_name="cfbot_tasks"
@@ -853,3 +853,11 @@ class CfbotTask(models.Model):
853853
status = models.TextField(choices=STATUS_CHOICES, null=False)
854854
created = models.DateTimeField(auto_now_add=True)
855855
modified = models.DateTimeField(auto_now=True)
856+
857+
class Meta:
858+
constraints = [
859+
models.UniqueConstraint(
860+
fields=["branch_id", "position"],
861+
name="commitfest_cfbottask_branch_position_unique",
862+
)
863+
]

pgcommitfest/commitfest/views.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,8 +1457,11 @@ def cfbot_ingest(message):
14571457
position, status,
14581458
created, modified)
14591459
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
1460-
ON CONFLICT (task_id) DO UPDATE
1461-
SET status = EXCLUDED.status,
1460+
ON CONFLICT (branch_id, position) DO UPDATE
1461+
SET task_id = EXCLUDED.task_id,
1462+
task_name = EXCLUDED.task_name,
1463+
status = EXCLUDED.status,
1464+
created = EXCLUDED.created,
14621465
modified = EXCLUDED.modified
14631466
WHERE commitfest_cfbottask.modified < EXCLUDED.modified""",
14641467
(

0 commit comments

Comments
 (0)