Skip to content

Commit fdc947a

Browse files
tend-agentclaude
andcommitted
fix(list-recent-runs): anchor completion window to intended cron tick
Replaces the 2h widening with an intended-tick anchor: when the script runs under a scheduled workflow with a simple hourly cron (`MM * * * *`), read the cron from $GITHUB_EVENT_PATH and anchor the window to the most recent matching tick instead of `now`. Consecutive cycles tile exactly ([intended-1h, intended]) regardless of GHA scheduler delay, with no overlap. Non-schedule events and non-hourly crons fall back to the original now-anchored 1h window. Per maintainer feedback on PR #526 — strictly cleaner than the 2h widening it replaces. Co-Authored-By: Claude Opus 4.7 <[email protected]>
1 parent 89b09e6 commit fdc947a

1 file changed

Lines changed: 35 additions & 13 deletions

File tree

‎plugins/tend-ci-runner/scripts/list-recent-runs.sh‎

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
# Lists recently completed tend CI runs.
33
#
44
# Fetches runs started in the past 3 hours, then filters to only those that
5-
# are completed and whose updatedAt is within the past 2 hours. This
6-
# two-step approach is needed because `gh run list --created` filters by
7-
# *start* time, not *end* time — a run started 2h ago may have just
5+
# are completed and whose updatedAt falls within a 1-hour completion window.
6+
# This two-step approach is needed because `gh run list --created` filters
7+
# by *start* time, not *end* time — a run started 2h ago may have just
88
# finished, and a run started 50min ago may still be running.
99
#
10-
# The 2h completion window absorbs GitHub Actions cron delay. Hourly
11-
# review-reviewers runs (cron `47 * * * *`) routinely fire 20–40 min late
12-
# during peak hours, producing gaps of 80–100 min between consecutive
13-
# cycles. A tighter 1h cutoff drops everything older than the previous
14-
# cycle's expected start, silently hiding runs that landed in the delay
15-
# slack. The 2h cutoff covers all observed gaps with margin; the small
16-
# re-analysis overlap between cycles is cheap because gist entries are
17-
# keyed by run ID.
10+
# Window anchor: when invoked under a scheduled workflow with a simple
11+
# hourly cron (`MM * * * *`), the completion window is anchored to the most
12+
# recent intended cron tick instead of `now`. Consecutive cycles then tile
13+
# exactly: [intended-1h, intended], then [intended, intended+1h]. Without
14+
# this, GHA scheduler delay (20-40 min during peak hours) shifts each
15+
# cycle's window relative to actual start time and drops runs that finished
16+
# in the slack between consecutive actual starts. For non-schedule events
17+
# or non-hourly crons, falls back to a now-anchored 1h window.
1818
#
1919
# Environment variables:
2020
# TARGET_REPO - Query a different repo (default: current repo)
@@ -45,8 +45,30 @@ for prefix in "${PREFIXES[@]}"; do
4545
WORKFLOWS+=("${matches[@]}")
4646
done
4747

48-
CREATED_SINCE=$(date -d '3 hours ago' +%Y-%m-%dT%H:%M:%S)
49-
COMPLETED_AFTER=$(date -d '2 hours ago' +%s)
48+
# Detect a simple hourly cron (e.g. "47 * * * *") from the workflow event
49+
# payload so we can anchor the window to the most recent intended tick.
50+
cron_minute=""
51+
if [ -f "${GITHUB_EVENT_PATH:-}" ]; then
52+
schedule=$(jq -r '.schedule // empty' "$GITHUB_EVENT_PATH" 2>/dev/null || true)
53+
if [[ "$schedule" =~ ^([0-9]+)\ \*\ \*\ \*\ \*$ ]]; then
54+
cron_minute="${BASH_REMATCH[1]}"
55+
fi
56+
fi
57+
58+
if [ -n "$cron_minute" ]; then
59+
this_hour_tick=$(date -u -d "$(date -u +%Y-%m-%dT%H:00:00) $cron_minute minutes" +%s)
60+
now_ts=$(date -u +%s)
61+
if [ "$now_ts" -lt "$this_hour_tick" ]; then
62+
intended=$((this_hour_tick - 3600))
63+
else
64+
intended=$this_hour_tick
65+
fi
66+
COMPLETED_AFTER=$((intended - 3600))
67+
CREATED_SINCE=$(date -u -d "@$((intended - 10800))" +%Y-%m-%dT%H:%M:%S)
68+
else
69+
CREATED_SINCE=$(date -d '3 hours ago' +%Y-%m-%dT%H:%M:%S)
70+
COMPLETED_AFTER=$(date -d '1 hour ago' +%s)
71+
fi
5072

5173
all_runs="[]"
5274

0 commit comments

Comments
 (0)