Prefer the PR base SHA when available, but fall back to merge-base against origin/main when the local main branch does not exist in CI checkouts. Also add regression coverage for detached HEAD checkouts without a local main ref. Assisted-by: Codex:GPT-5.4