Caught before this shipped, not after it paged someone.
Without the `repo` scope, GitHub answers 404 for a PRIVATE repository —
byte for byte the same response as a deleted one. The checker would have
read that as "your repo is gone" and raised an alert for every private
project of any user whose GitHub link is sign-in-only. An alarm that
fires on healthy projects is worse than no alarm: it teaches the operator
to dismiss the surface, and the real 404 goes with it.
So ask once per user what the token is actually allowed to see —
`x-oauth-scopes`, which GitHub sets on every API response — and let that
decide what a 404 is permitted to mean. No scope, no verdict: it
downgrades to `unchecked`, which already exists and is already excluded
from auto-resolve.
Absence of the header, or a failed call, counts as "cannot see private" —
the pessimistic read is the only safe one here, because the cost of
guessing wrong is a false alarm about a repo that is fine.
Proven by mutation: trust the 404 regardless of scope → the test fails
with expected 'unchecked'.
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
`git_url` was written once, when a project was registered, and trusted
forever. Nothing ever asked GitHub whether it was still true.
Measured against production on 2026-09-22: eight of thirty-three stored
repos were wrong. Four point at repositories that no longer exist (three
are abandoned factory experiments), two at a retired personal account
that has since been renamed, two at deleted scratch repos.
That is not cosmetic. git_url is the address every agent dispatch, clone
and CI lookup starts from, so a stale one surfaces as a confusing build
error inside a run the operator already paid for, rather than as "this
project points at nothing".
THE DISTINCTION THIS IS BUILT ON
GitHub already knows the difference between a repo that MOVED and one
that is GONE, and Loki was throwing it away. A rename answers with a
redirect and the new full_name — so Loki can simply fix it, which is the
automatic repair that being connected to GitHub is supposed to buy. A 404
cannot be repaired by a machine: deleted, or made private, or renamed
away without a redirect, and the only honest response is to say so once.
moved → healed silently, logged
gone → one alert, refreshed not duplicated
unchecked → neither, and explicitly NOT counted as healthy
That third state is load-bearing. A dead token or a network blip must
never read as "all repos fine" — the auto-resolve is gated on it, so a
tick that could not look can never clear a real alert.
- src/lib/github-repo-ref.ts — parsing and one lookup, kept apart from
the route so both are testable with no network and no database
- src/app/api/crons/check-project-repos/route.ts — daily 06:20 UTC
- project_repo_missing registered in config/alert-types.ts, whose own
gate checks the producer file really raises it
scripts/test/github-repo-ref.ts covers 15 stored URL forms (ssh remotes,
trailing .git, deep links, a dot in the repo name, non-GitHub hosts) and
pins all three verdicts across 9 responses. Case alone is not a move —
GitHub is case-insensitive here, and healing on case would rewrite rows
forever without changing anything.
Proven by mutation: treat 401/403 as healthy → "HTTP 401 must be
unchecked, got ok"; stop detecting renames → the moved assertion fails.
tsc caught a real bug pre-commit: the summary's `ok` count would have
overwritten the response's boolean `ok`, so every caller checking it
would have read a number. Renamed to `healthy`.
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>