Skip to content

Commit 6cf8e28

Browse files
authored
Fix HUD metrics "commits red on main" showing commits gray forever (#8327)
**Impact:** HUD /metrics page **Risk:** low ## What Reworks the `master_commit_red` query (/metrics page, "Commits red on main, by hour") to collapse duplicate GitHub job ids into a single per-job state before deciding whether a commit is pending, so abandoned placeholder jobs no longer keep a commit gray indefinitely. ## Why GitHub Actions sometimes emits a placeholder job id at dispatch that never gets a runner and never finalizes (`status='queued'`, empty conclusion), then creates a second id for the same job that actually runs to completion. The old query flagged a commit as pending if *any* job had an empty conclusion, so these dead "queued twins" made commits on the "commits red on main, by hour" histogram show gray forever. The fix adds a `job_identity` CTE that groups jobs by `(run_id, run_attempt, exact job name)` and classifies each into failed / resolved / pending. A job stops counting as pending once its real twin finishes, its parent `workflow_run` is `completed`, or it's been stuck longer than the 36h staleness cutoff. # Notes - The 36h staleness threshold is based on the fact that after 36h a job queued is as good as failed by a user perspective. Signed-off-by: Jean Schmidt <contato@jschmidt.me>
1 parent 9308e62 commit 6cf8e28

1 file changed

Lines changed: 44 additions & 6 deletions

File tree

  • torchci/clickhouse_queries/master_commit_red

torchci/clickhouse_queries/master_commit_red/query.sql

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ all_runs AS (
2323
workflow_run.id AS id,
2424
workflow_run.head_commit.'id' AS sha,
2525
workflow_run.name AS name,
26+
workflow_run.status AS run_status,
2627
commit.time AS time
2728
FROM
2829
workflow_run FINAL
@@ -47,9 +48,12 @@ all_jobs AS (
4748
SELECT
4849
all_runs.time AS time,
4950
all_runs.sha AS sha,
51+
all_runs.run_status AS run_status,
5052
job.run_attempt AS run_attempt,
5153
job.conclusion AS raw_conclusion,
5254
job.run_id AS run_id,
55+
job.created_at AS created_at,
56+
job.name AS exact_name,
5357
-- Normalize job name to group shards together (same as auto-revert logic)
5458
trim(
5559
replaceRegexpAll(
@@ -74,6 +78,41 @@ all_jobs AS (
7478
)
7579
),
7680

81+
-- Collapse duplicate GitHub job ids that share the same identity
82+
-- (run_id, run_attempt, exact job name) and classify the result into a single
83+
-- state. GitHub Actions sometimes creates a placeholder job id at dispatch that
84+
-- is never assigned a runner and never finalized (status='queued',
85+
-- conclusion=''), then creates a second id for the same job that actually runs
86+
-- to completion. Without collapsing, the dead placeholder's empty conclusion
87+
-- makes the commit look pending forever.
88+
-- failed - any id reached a failing conclusion, OR the job is unresolved and
89+
-- older than the staleness timeout (GitHub abandoned it)
90+
-- resolved - a terminal (non-failing) id exists, or the parent workflow_run
91+
-- already completed (nothing under it can still be pending)
92+
-- pending - genuinely still in flight and within the staleness timeout
93+
job_identity AS (
94+
SELECT
95+
time,
96+
sha,
97+
base_name,
98+
run_attempt,
99+
run_id,
100+
exact_name,
101+
multiIf(
102+
MAX(raw_conclusion IN ('failure', 'timed_out', 'cancelled')),
103+
'failed',
104+
MAX(raw_conclusion != ''),
105+
'resolved',
106+
any(run_status) = 'completed',
107+
'resolved',
108+
dateDiff('hour', MAX(created_at), now()) > 36,
109+
'failed',
110+
'pending'
111+
) AS identity_state
112+
FROM all_jobs
113+
GROUP BY time, sha, base_name, run_attempt, run_id, exact_name
114+
),
115+
77116
-- Step 1: For each (sha, base_name, run_attempt), determine if this attempt
78117
-- has any failures or is all green across all shards
79118
attempt_status AS (
@@ -83,12 +122,11 @@ attempt_status AS (
83122
base_name,
84123
run_attempt,
85124
run_id,
86-
-- Does this attempt have ANY shard with failure?
87-
MAX(raw_conclusion IN ('failure', 'timed_out', 'cancelled'))
88-
AS attempt_has_failure,
89-
-- Does this attempt have any pending jobs?
90-
MAX(raw_conclusion = '') AS attempt_has_pending
91-
FROM all_jobs
125+
-- Does this attempt have ANY shard that failed (or timed out)?
126+
MAX(identity_state = 'failed') AS attempt_has_failure,
127+
-- Does this attempt have a job still genuinely pending?
128+
MAX(identity_state = 'pending') AS attempt_has_pending
129+
FROM job_identity
92130
GROUP BY time, sha, base_name, run_attempt, run_id
93131
),
94132

0 commit comments

Comments
 (0)