Skip to content

refactor(ci): extract run-fetching into reusable script with time-window filtering - #1302

Merged
max-sixty merged 4 commits into
mainfrom
hourly/review-22748945565
Mar 6, 2026
Merged

max-sixty merged 4 commits into
mainfrom
hourly/review-22748945565

Conversation

@worktrunk-bot

@worktrunk-bot worktrunk-bot commented Mar 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Extracts run-fetching logic into a reusable .github/scripts/list-recent-runs.sh script
  • Dynamically discovers claude-* workflows instead of maintaining a hardcoded list
  • Uses a two-step time filter: fetches runs started in the past 3 hours, then keeps only completed runs whose updatedAt is within the past hour (see hourly-review: sleep-polling still-running jobs wastes 14+ minutes of compute #1301 for why)
  • Simplifies the hourly review workflow prompt to just reference the script

Fixes #1301

Test plan

  • Next hourly review run should skip any in-progress jobs without polling

🤖 Generated with Claude Code

The hourly review bot was entering 2-minute sleep-poll loops waiting for
still-running CI jobs to complete, wasting 14+ minutes of compute per
occurrence. The prompt now explicitly instructs the bot to skip
in-progress runs at both the discovery (Step 1) and download (Step 2)
stages.

Fixes #1301

Co-Authored-By: Claude Opus 4.6 <[email protected]>

Some runs may not have artifacts (e.g., skipped runs). That's fine — skip them.

**IMPORTANT: If a run is still in progress (empty conclusion), skip it entirely. Do NOT poll, sleep-wait, or retry — only analyze runs that have already completed. Waiting for in-progress runs wastes significant compute time.**

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems duplicative

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed — removed this in c0d2dbb. The filtering is now consolidated in Step 1.

```

If no Claude CI runs occurred in the past hour, report "no runs to review" and exit.
Filter out runs that are still in progress (empty `conclusion`) — only include completed runs. If no completed Claude CI runs occurred in the past hour, report "no runs to review" and exit.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when we collect runs to look at, are we filtering by their ending time.

this change is good, but conditional on that

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question — the answer is no. The --created flag filters by creation time, not completion time. So a run created 2+ hours ago that only recently finished would be missed by the 1-hour window.

gh run list doesn't offer an end-time filter — --created is the only date option. A workaround would be to widen the creation window (e.g., 4 hours) and then post-filter the JSON by updatedAt to only analyze runs that completed in the last hour. But that's a separate improvement from what this PR does.

This PR's change (skip in-progress runs) is still correct regardless — it prevents the sleep-polling waste. The creation-time vs end-time gap is a pre-existing issue. Want me to file a follow-up issue for the windowing improvement?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's do them both in this issue: pull anything that started in the past (3?) hours and then filter for whether it finished in the last hour; add comments explaining why + linking to this logic

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Updated in c0d2dbb:

  • Widened the --created window to 3 hours
  • Added updatedAt to the JSON fields
  • Added two-step filtering: drop in-progress, then keep only runs whose updatedAt is within the past hour
  • Added a "Why" paragraph explaining the start-time vs end-time gap, linking to hourly-review: sleep-polling still-running jobs wastes 14+ minutes of compute #1301
  • Removed the duplicative "skip in-progress" instruction from Step 2 (addresses the other comment too)

`gh run list --created` filters by start time, not end time. A 1-hour
creation window misses runs that started earlier but finished recently.

- Fetch runs created in the past 3 hours (wide net)
- Post-filter: drop in-progress runs, keep only those completed in the
  last hour
- Add `updatedAt` to JSON fields for completion-time filtering
- Remove duplicative "skip in-progress" instruction from Step 2
- Add explanatory comments linking to #1301

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Filter out runs that are still in progress (empty `conclusion`) — only include completed runs. If no completed Claude CI runs occurred in the past hour, report "no runs to review" and exit.
Then apply two filters:
1. **Drop in-progress runs** — skip any run with an empty `conclusion`.
2. **Keep only recently finished runs** — from the completed runs, only include those whose `updatedAt` timestamp is within the past hour.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is updatedAt the correct field?

can we just supply a script that does this filtering? then these changes can much terser

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updatedAt is the best available — gh run list doesn't expose a completedAt field. The available time fields are createdAt, startedAt, and updatedAt. For completed runs, updatedAt tracks completion closely (verified on recent runs — typically within a second of the check run's completedAt).

Good idea on the script. I'll extract the fetch + filter logic into a script (e.g., .github/scripts/list-recent-runs.sh) so the prompt just says "run the script" instead of explaining the filtering in prose.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you do this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No — I said I would but didn't follow through. Let me do that now: extract the fetch + filter logic into a .github/scripts/list-recent-runs.sh script so the prompt can just reference the script instead of explaining the filtering inline.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do this!

For the hourly reviewer — please work out what's going on, ty

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 704e139. Extracted the fetch + filter logic into .github/scripts/list-recent-runs.sh — the prompt now just says "run the script" instead of explaining the filtering inline. The script has comments explaining the 3h window + 1h completion filter rationale.

Move the fetch + filter logic (3h creation window, drop in-progress,
keep recently finished) from inline prompt prose into
`.github/scripts/list-recent-runs.sh`. The workflow prompt now just
references the script, making it much terser.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Comment thread .github/scripts/list-recent-runs.sh Outdated

set -euo pipefail

WORKFLOWS=(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we get all workflows and then filter by claude.*?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea — done in 0a48468. Replaced the hardcoded list with dynamic discovery via gh workflow list --json name --jq '.[].name | select(startswith("claude-"))'. No more maintenance when workflows are added or removed.

Replace hardcoded workflow list with `gh workflow list` filtered by
the `claude-` prefix. This avoids needing to update the script when
workflows are added or removed.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@worktrunk-bot worktrunk-bot changed the title fix(ci): prevent hourly review from sleep-polling in-progress runs refactor(ci): extract run-fetching into reusable script with time-window filtering Mar 6, 2026
@max-sixty
max-sixty merged commit 4ea395e into main Mar 6, 2026
23 checks passed
@max-sixty
max-sixty deleted the hourly/review-22748945565 branch March 6, 2026 18:31
max-sixty pushed a commit that referenced this pull request Sep 22, 2026
…ion (#4231)

`.github/scripts/list-recent-runs.sh` has had no caller since March. It
was extracted in #1302 to feed the `review-reviewers` skill ("Run
`.github/scripts/list-recent-runs.sh` for recently completed Claude CI
runs"), and #1676 moved that skill to the tend repo while replacing the
hand-written Claude workflows with generated ones. The script survived
the move; its only reference didn't.

Nothing references it today — neither the repo (`git grep
list-recent-runs` returns nothing outside the file itself) nor tend's
bundled skills, which is where the calling skill now lives. The deletion
empties `.github/scripts/`, so the directory goes with it.

No test accompanies this: the change removes an unreferenced file and
alters no behavior to regress.

Co-authored-by: worktrunk-bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hourly-review: sleep-polling still-running jobs wastes 14+ minutes of compute

2 participants