Skip to content

fix(ghapp): find a queued job the status-filtered run list leaves out - #56

Merged
parsilver merged 5 commits into
mainfrom
fix/55-unlisted-queued-job
Nov 21, 2026
Merged

parsilver merged 5 commits into
mainfrom
fix/55-unlisted-queued-job

Conversation

@parsilver

@parsilver parsilver commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes #55

What changed

GitHub's runs?status=queued list can leave a queued run out. On 2026-11-21 it did so for 25 minutes, and the job never got a runner. Every cycle now also reads, for each repository, the first page of the unfiltered runs list (runs?per_page=20, read once, no paging). It then reads the jobs of each run that is not completed and was not already in a filtered list. Those jobs are served like any other and marked unlisted.

  • ghapp: repoJobs remembers which runs the filtered lists returned. A new unlistedJobs does the fallback read, and jobsOfRuns is shared by both paths. Job.Unlisted marks the jobs found only through the fallback.
  • controller: /healthz reports unlisted_jobs (the last cycle), the cycle log line carries unlisted=N, and each unlisted job is logged at warn with its repository and job id. These are counts only, since /healthz is public. No new state is kept between cycles.
  • A failed fallback read (a 5xx, a 403 rate limit, or no answer, on the unfiltered list or on an unlisted run's jobs) no longer fails the scope. QueuedJobs returns the jobs the filtered lists found together with an UnlistedReadError naming each repository and its status. The controller logs each one at warn (repository and status only), counts them on /healthz as unlisted_read_failures and on the cycle line as unlisted_read_failed, and serves the jobs. A failed filtered list still fails the scope, as before.
  • README.md, docs/deploy.md and CHANGELOG.md describe the extra read, its rate-limit cost and its limit.

I went with the fallback rather than remembering webhook job ids. It keeps GitHub as the only source of truth and works when webhooks are off or a delivery is lost. The first draft of the plan read the unfiltered page only when the filtered lists found nothing. A fresh review pointed out that this breaks "within one cycle" when the same repository has another queued job, so the page is read every cycle.

Acceptance criteria

  1. A job missing from runs?status=queued gets a runner within one cycle. TestAQueuedRunTheStatusFilterLeavesOutIsFoundThroughTheUnfilteredList uses a fake GitHub that leaves run 31 out of the filtered list and still lists a stale run. TestTheUnfilteredListIsReadEvenWhenAQueuedJobWasFound covers the case where another job was found in the same repository. TestAnUnlistedJobGetsARunnerAndIsCountedOnHealthzAndInTheLog shows the controller creates a runner for an unlisted job.
  2. A job that never shows up never creates a runner. The fallback keeps no webhook memory, so there is nothing to drop. A cancelled run (completed) is not read at all: the test asserts no jobs request goes out for it. A run that is not completed but has no queued job (waiting) returns nothing.
  3. A failed fallback costs nothing the scope had before. TestTheFallbackSkipsAVanishedRunAndKeepsTheListedJobsOnOtherErrors answers the unfiltered list, then an unlisted run's jobs, with 500 and with 403: the listed job is kept and the error names the repository and status. TestAFallbackWithNoAnswerNamesStatusZero drops the connection. TestAnOrgNamesEveryFailedFallbackAndKeepsEveryListedJob fails two repositories of an org and reads the third; TestAFailedFilteredListAfterAFailedFallbackStillFailsTheScope keeps a real read failure fatal. TestAFailedFallbackReadKeepsTheListedJobsAndIsCounted shows the controller creates the runner, does not fail the cycle, logs repo=... status=... and counts the failures on /healthz and the cycle line, then clears the count on a clean cycle. All five failed on the code before this change.
  4. The gap stays visible. /healthz unlisted_jobs, the unlisted=N field on the cycle line, and a warn line per job are all asserted in the controller tests, including when the Railway read fails in the same cycle.
  5. No runner for a run whose jobs aren't queued. The stale run in the filtered queued list returns no job, and its jobs are read exactly once (asserted by counting requests).

Commands run

$ go vet ./... && go test -race ./...
ok  	github.com/farzai/github-runner-railway/internal/config
ok  	github.com/farzai/github-runner-railway/internal/controller
ok  	github.com/farzai/github-runner-railway/internal/ghapp
ok  	github.com/farzai/github-runner-railway/internal/railway
ok  	github.com/farzai/github-runner-railway/internal/reconcile
ok  	github.com/farzai/github-runner-railway/internal/webhook

Quality gate run locally (python .quality/gate.py --base origin/main), after the review fix:

  • Format: pass, 6 changed Go files gofmt clean
  • Coverage: pass, every changed line run by a test; repo total 89.19% (baseline updated in .quality/baseline.json)
  • CRAP: pass, 10 changed functions scored; Controller.Cycle (15.0, base 15.2) and Controller.alertLate (17.0, base 17.0) are still over, no worse than base. QueuedJobs reached 10 with the change, so its repository loop moved into reposJobs.
  • Duplication: pass, 0 pairs
  • Mutation: pass, 10 killed, 0 survived on the lines changed in this round

The tests failed before the fix for the expected reasons: no job found, the fallback's errors not reported, and no unlisted_jobs on /healthz.

Risks

  • Cost: one extra GitHub read per repository per cycle. On an idle repository the page doesn't change, so it comes back as a 304 and does not count against the rate limit. A repository with recent activity pays one full call per cycle.
  • Cache size: the conditional-request cache holds 2,000 entries, and each repository now uses four run-list URLs. It fills at about 500 repositories in one controller (it was about 660). This is documented, and the cap is unchanged.
  • Runs in other statuses: a run in a status the filtered lists never ask for (waiting, requested, action_required) now has its jobs read every cycle while it stays on the first page. Only queued jobs with our labels are taken.

Limits and what I could not verify

  • The fallback never finds a missed run once 20 newer runs push it off the first page. In that case, cancel the run and re-run it (now in the README troubleshooting table).
  • This was not tested against real GitHub or the production controller. I can't reproduce GitHub's filtered-list gap on demand; the fake GitHub in the tests mirrors the responses described in the issue. After the deploy, the controller logs and unlisted_jobs will show whether the fallback fires.

…es out

GitHub's runs?status=queued left a queued run out on 2026-11-21 and
the job sat 25 minutes with no runner. These tests pin the fallback
through the unfiltered run list and the healthz and log counts. They
fail until the fallback exists.
…isses

GitHub's runs?status=queued can leave a queued run out, and its job
then never gets a runner. Every cycle now also reads the first page of
the unfiltered runs list (once, no paging) and the jobs of each run
that is not completed and was not listed; those jobs are marked
Unlisted. On an idle repository the page is a 304 through the ETag
cache. Proven by the new unlisted tests and the ghapp suite.
The gap on GitHub's side must stay visible once the fallback hides it:
/healthz reports unlisted_jobs, the cycle line carries unlisted, and
each such job is logged at warn with its repository and id. Docs list
the fourth run read and its rate-limit cost. Proven by the controller
unlisted test and the full suite.
The quality gate found two uncovered changed lines and five surviving
mutants on lines this change touched. New tests cover a Railway list
failure with an unlisted job, a failed jobs read on a listed run, and
/healthz services after a reap; the summary test now starts the call
counter above zero. Coverage baseline moves to 88.79% as the gate
asks. Gate run locally: all five checks pass.
@parsilver
parsilver marked this pull request as ready for review November 21, 2026 19:20

@parsilver parsilver left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Verdict: 1 Blocker. The fallback itself is right:

  • listed (ghapp.go:457) stops a listed run being read twice, and seen stops a job being returned twice.
  • The unfiltered page carries total_count, so it is cached and comes back as 304.
  • Only queued jobs with matching labels are taken. filter=latest handles re-runs, and completed runs are never read.
  • The 20-run limit is documented, /healthz shows only counts, and the tests count requests.

Blocker

  • internal/ghapp/ghapp.go:483: if the extra unfiltered read fails (a 5xx, or a 403 rate limit), the whole scope read fails. Before this change the scope was still served from the filtered lists. A fallback must not make the common path worse. Log the failure (warn, repo and status only), count it, and keep the jobs already found. Add a test where the unfiltered read answers 500 and then 403 while a filtered job still gets its runner.

Suggestion

  • ghapp.go:503: a run created between the filtered reads and the unfiltered read, or one in requested, is flagged Unlisted with no GitHub gap, which gives false warns. Re-check such a run's status, or don't flag runs younger than the cycle start.
  • docs/deploy.md:149-154: runs in waiting or action_required also have their jobs read every cycle. Add a worst case for a big org scope (active repos × 30 cycles/h) against the 5,000/h limit.
  • controller.go:307 (not new): seen is per scope, so an org scope and a repo scope on the same repo can count one job twice. Worth a follow-up.

Nit

  • internal/ghapp/unlisted_test.go:27: the fake says total_count:4 but lists 5 runs.

The fallback read only adds jobs, so a 5xx or a 403 rate limit on it
must not cost a scope the jobs its status-filtered lists found, which
it did before the fallback existed. QueuedJobs now returns those jobs
with an UnlistedReadError naming each repository and status; the
controller logs it at warn, counts it on /healthz and the cycle line,
and serves the jobs.
@parsilver

Copy link
Copy Markdown
Contributor Author

Fixed the Blocker from the review; ready for review again.

  • A failed read of the unfiltered run list (a 5xx, a 403 rate limit, or no answer, on the list or on an unlisted run's jobs) no longer fails the scope. The jobs the filtered lists found are still served, each failure is logged at warn with the repository and status, and it is counted on /healthz (unlisted_read_failures) and on the cycle line (unlisted_read_failed). A failed filtered list still fails the scope.
  • New tests cover 500 and 403 on the list and on the jobs read, a dropped connection, two failed repositories in an org, and the controller serving the listed job while counting the failure. All of them failed on the previous commit.
  • Fixed the nit: the fake's total_count now matches the five runs it lists.
  • Tests, vet and the quality gate pass locally and in CI (CRAP under 10 on every changed function, 0 duplicates, mutation 10 killed and 0 survived). QueuedJobs reached CRAP 10, so its repository loop moved into reposJobs.

The suggestions are not in this round: no false-warn filter for runs created mid-cycle, no worst-case rate-limit sum in the deploy doc, and no follow-up yet for the per-scope seen set. Next step: review, merge and deploy.

@parsilver parsilver left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Round 2: no Blocker. The Blocker is fixed. A failed unfiltered read (5xx or a 403 at the rate limit) now comes back as UnlistedReadError. The scope keeps its filtered jobs and runners. Each failure is logged at warn with the repo and status only, and counted as unlisted_read_failures on /healthz and unlisted_read_failed on the cycle line. TestAFailedFallbackReadKeepsTheListedJobsAndIsCounted covers 500 and 403 together, and the next clean cycle clears the count. Docs and CHANGELOG match. The remaining round-1 suggestions (false Unlisted flags for runs created mid-cycle, and seen per scope) can wait.

@parsilver
parsilver merged commit f00cdb7 into main Nov 21, 2026
15 checks passed
@parsilver
parsilver deleted the fix/55-unlisted-queued-job branch November 21, 2026 19:59
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.

Controller misses a queued job that GitHub's status=queued run list leaves out

1 participant