Skip to content

fix(ci): a PR based on any branch but main runs no unit tests, no lint and no agent suites - #2783

Closed
itomek wants to merge 6 commits into
mainfrom
issue-2767
Closed

itomek wants to merge 6 commits into
mainfrom
issue-2767

Conversation

@itomek

@itomek itomek commented Aug 4, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #2767
A PR based on anything but main ran almost no CI — no unit tests, no lint, no agent suites — and its checks page looked healthy the whole time, because pull_request.branches: [main] filters on the PR's base, not its head. Verified live just now: #2599 (merged, base a feature branch) still shows exactly 16 checks, none of them email/unit/lint; #2757 (main-based control) shows 46+ including all of them. After this change, the same class of PR gets the full suite — proven on a real throwaway PR against a non-main base, where 9+ suites that had run zero times on that base before this change all went green. A second, independent mechanism — a required checks gate — turns any future silent skip into a visible, named check instead of a checks page that simply omits rows.

Building the gate found real bugs twice over — both times by replaying real API data, not by trusting synthetic tests. Live on the throwaway PR, a bare job-name prefix ("Test") was silently cross-matching other jobs' rendered check-run names. Fixed and covered with a unit test. Then the gate itself failed on this very PR — replaying #2783's actual Checks API history through the classification logic (rather than trusting the 27 tests that existed at that point) took total failures from 55 to 1, and surfaced two more real bugs no amount of reasoning from the YAML alone would have found: GitHub keeps every historical check-run for a SHA forever, so a five-minute-old stale skip was masking a fresh, real pass sitting right next to it in the same API response; and a job with a static name plus a matrix (no ${{ }} anywhere) gets GitHub's own auto-appended (leg, values) disambiguator on every real run, which exact-matching on the bare name never catches. The one remaining "failure" after all three fixes is C++ Email Agent — a pre-existing, self-documented scaffold guard for the separate C++ email milestone (#1110), unrelated to this change.

Test plan

  • python util/lint.py --all clean
  • pytest tests/unit/ — 8842 passed, 146 skipped, 8 pre-existing failures unrelated to this change (binary-on-PATH / hub-wheel-install / VLM-extraction / a documented nested-worktree API-key artifact — none touch .github/ or the files this PR adds)
  • pytest tests/unit/test_check_required_status.py — 43 tests, all passing, proving the gate's classification logic (including every live-found bug below, and the fork-PR degrade path) by construction
  • Live evidence below, captured on real throwaway and real PRs — see the collapsed sections

What changed and why

1. Widened the PR trigger on 34 workflows. Removed branches: [main] from pull_request: only — push: branches: [main] is untouched, so main-push validation is unaffected and there's no duplicate-run risk (different event types; a feature-branch push never matched push: either way). This follows a pattern already used elsewhere in the repo (docs.yml, pypi.yml, website-ci.yml, check_doc_links.yml, …) rather than inventing an allowlist. build_tui.yml is deliberately excluded — PR #2696 already widens that one; touching it here would collide.

Audited all 34 for PR-triggered side effects before touching them: only dependency-review.yml does anything beyond test/lint, and only posts a PR comment on failure.

Intended trade-off, stated plainly: most of these 34 workflows already list their own .github/workflows/<file>.yml in their paths: filter — an existing "if you touch my CI config, re-validate me" convention, not something this PR introduced. Because this PR edits all 34 at once, essentially every one of them becomes required for this diff — confirmed by checking each one's paths:, not assumed. That's heavy by design: a workflow-config change legitimately re-validates the whole matrix. A normal single-workflow change afterward won't have this effect.

2. A required checks gate that derives what to check instead of hand-listing it. Cross-workflow needs: doesn't exist in GitHub Actions, so this can't depend on the other workflows directly — .github/scripts/check_required_status.py parses every workflow's own pull_request path filters at run time and derives what's required for a given diff, so a new workflow is covered automatically, nothing to remember to update here.

Not a false green, not noise — always runs and always decides. The gate deliberately does not carry the draft-gate if: the 34 audited workflows use. Mirroring that would reproduce this issue's own bug inside the fix: on a draft PR without ready_for_ci (this repo's default state for an open PR), the audited suites skip and the gate would skip too — nothing red, checks page still green, zero coverage. Instead the gate always runs, and reports through two channels — see the fork-PR section below for why there are two, and why only one of them is the thing to make required.

The required check is the job's own native status — Required Checks Gate — not an API-posted one, because of a fork-PR gap found on this PR itself. The original design self-posted a richer three-state (neutral/success/failure) check-run via the Checks API, needing checks: write. Confirmed live, not assumed: GitHub silently downgrades GITHUB_TOKEN to read-only for pull_request (not pull_request_target) on a fork PR regardless of what a workflow's permissions: block declares — inspected a real recent fork PR's job log (#2753's "Dependency Review", which declares pull-requests: write) and its own "Set up job" step printed GITHUB_TOKEN Permissions: Contents: read, Metadata: read, PullRequests: read. checks: write would be downgraded the identical way. A required check that can only post via a permission forks don't have would block every fork contribution to this repo — the opposite of what "required" should mean.

So the native job exit code — needs no special permissions, identical on same-repo and fork PRs — is the binding signal now, and that's what belongs in branch protection / the merge queue. neutral and success both map to exit 0 (pass): a draft PR without ready_for_ci can't be merged anyway regardless of check status — GitHub blocks merging any draft PR at the platform level — so there's nothing to protect by failing here, and reflexive red on every draft was already rejected as noise. Only a genuine failure or timeout exits 1. The neutral/success distinction isn't lost, just moved to two channels that need no elevated permissions either: the job's own Actions step summary (works identically on forks), and a second, purely informational check-run — Required Checks Gate (detail) — that the job still attempts to post wherever the token allows it (same-repo PRs). That call is wrapped so a 403 logs a warning and the job carries on; it's never what branch protection depends on.

Recency: GitHub never deletes a check-run. Every triggering event (opened, then labeled, then reopened) adds new rows alongside old ones. The gate used to give any bad match unconditional priority over good ones regardless of age. Fixed with an exact rule, not a tuned time-window — the observed gap between a stale skip and its real re-run ranged from about a minute to several minutes on real PRs in this repo, so no fixed window reliably separates "same event" from "different event." Instead: dedup by exact check-run name keeping only the newest, then discard any pre-expansion artifact older than the newest real entry for that requirement. A pre-expansion artifact is decidable two ways: a name containing literal ${{ }} (job skipped before its matrix ever expanded), or — the one caught only by replaying real data — a name with no template at all but a matrix, where GitHub auto-suffixes every real leg with (leg, values), so a real run can never produce the bare name the requirement is keyed on. A pre-expansion artifact newer than every real entry is kept, not discarded — that's a genuine re-skip (e.g. the PR went back to draft after a real pass), and the gate has a named test making sure that case still fails closed.

Exclusions are reported, not silent. Three job shapes can't be statically verified from YAML alone: continue-on-error: true (the job's own author already declared it non-blocking), an if: referencing needs.* (gated on another job's runtime output — e.g. build-electron-apps.yml's build-apps, whose matrix is also dynamically generated via fromJson(needs.discover-apps.outputs.matrix)), and an if: gated on a tag ref (startsWith(github.ref, 'refs/tags/...') — unlike needs.*, this one is statically decidable, since github.ref on a pull_request event is never a tag ref). All three are excluded from the required set, but every posted check-run summary now states the ratio and breakdown — "Enforced N/M requirements; excluded K (needs-gated: a, continue-on-error: b, ref-conditional: c): <name> (from <file>): <reason>; ..." — so a future job silently dropping out of scope is visible, not a repeat of this issue's own bug with a new mechanism.

Messaging distinguishes "did not run" from "ran and failed." The neutral and failure summaries now say label and close/reopen, not label alone — the audited suites don't listen for the labeled event (only this gate does), so the label by itself cannot re-trigger them; #2755's own text describes close/reopen alone as sufficient, but that was observed on a non-draft PR and doesn't hold for this repo's default open-PR state (measured live, companion issue #2763, PR #2782). The failure text also splits "stuck at skipped, needs a re-trigger" from "ran and genuinely failed" — different states, different advice.

Concurrency: queue instead of cancel. The gate's own workflow originally used concurrency: cancel-in-progress: true. Live on the throwaway PR, this repo's auto-labeler fired a second labeled event mid-poll and cancelled the in-progress gate run before it ever posted a check-run for that SHA — benign that time only because a later run happened to supersede it and try again. If a cancelled run is ever the last triggering event for a SHA, the check silently never posts at all: a fourth way to fail open, shipped inside the PR meant to close the other three. Fixed by queuing instead (cancel-in-progress: false) — costs some run time on a burst of events, guarantees every trigger eventually gets a real, posted verdict.

Evidence

Before — re-verified live with gh pr checks, not quoted from the issue
$ gh pr checks 2599 --repo amd/gaia   # base: tmi/2580-attention-int (not main)
16 total checks — 0 email, 0 unit, 0 lint:
Validate code examples in docs   pass
Verify external URLs             pass
Verify internal cross-references pass
build                            pass
label                            pass
auto-fix                         skipping
pr-comment                       skipping
release-notes                    skipping
validate                         pass  (x2)
Enable auto-merge...             skipping
pr-review / pr-review run        pass/skipping
pr-rereview                      skipping
issue-handler                    skipping
Mintlify Deployment              skipping

$ gh pr checks 2757 --repo amd/gaia   # base: main (control)
46+ checks, including:
Run Code Quality Checks                pass
Unit Tests (py3.10/3.11/3.12)          pass
Unit Tests (macOS smoke)               pass
Test Email Agent                       pass
Email Agent Unit Tests (py3.10/3.12)   pass
Dependency Review                      pass
...
After — throwaway PR (#2775, closed/deleted) against a non-main base

Base branch evidence/2767-fake-base (a plain, non-main branch), head touching hub/agents/email/python/** + src/gaia/agents/base/**. Two states captured:

State 1 — draft, no label. The audited suites now genuinely register (not absent, as before this fix) but correctly show skipping per their own draft-gate — this itself is new: pre-fix, a non-main-based PR wouldn't show these rows at all. The gate's self-posted check:

$ gh api repos/amd/gaia/commits/<sha>/check-runs -q '.check_runs[] | select(.name=="Required Checks Gate")'
{"conclusion":"neutral","output":{"title":"Required suites have not run yet",
 "summary":"This PR is a draft without the `ready_for_ci` label, so the suites
 this gate audits have not run... Mark ready for review, OR add ready_for_ci
 AND THEN close/reopen — the label alone is not enough."}}

State 2 — ready_for_ci label added (still draft) → suites actually run. Real gh pr checks 2775 output, non-skipped rows:

SUCCESS  Test Email Agent
SUCCESS  Email Agent Unit Tests (py3.10)
SUCCESS  Email Agent Unit Tests (py3.12)
SUCCESS  Example Agents Unit Tests
SUCCESS  Run Code Quality Checks
SUCCESS  Unit Tests (py3.10)
SUCCESS  Unit Tests (py3.11)
SUCCESS  Unit Tests (py3.12)
SUCCESS  Unit Tests (macOS smoke)
SUCCESS  Security Tests (Linux)
SUCCESS  Security Tests (Windows)
SUCCESS  Dependency Review
SUCCESS  API Tests
... (39 total, all pass)

Nine of these are the exact suites named in the issue's own table (email / unit / lint) — all ran zero times on a non-main base before this change.

Also caught live on this same throwaway PR: adding ready_for_ci while still draft (no push) correctly left the audited jobs stuck at conclusion: skipped — since labeled isn't a type they listen for — and the gate (which does listen for labeled) reported failure for exactly that reason. That's the #2755 class of bug, reproduced and caught live, not constructed.

The gate failing on its own PR (#2783), and going green — the replay evidence

Real gh api repos/amd/gaia/commits/<sha>/check-runs output for #2783's own head SHA, replayed offline through evaluate() before and after each fix (script: python -c "..." against the actual API response, not a hand-written fixture):

Before recency + exclusion-reporting fixes:
ok=44 pending=4 missing=0 failed=55   # every audited job, stuck at a stale
                                       # pre-expansion skip from the very
                                       # first (still-draft) triggering event

After recency + exclusion fixes, before the "static name + matrix" fix:
ok=44 pending=4 missing=0 failed=3
  Consolidate release bundle: skipped   # tag-ref-gated — now excluded
  C++ Email Agent: failure x2           # pre-existing #1110 guard
  Audit Dependencies: skipped           # the bug this replay caught

After the "static name + matrix" fix:
ok=45 pending=4 missing=0 failed=1
  C++ Email Agent: failure x2           # the only remaining failure —
                                         # pre-existing, unrelated to this PR

Live check on the real PR after pushing the fix — the gate's own posted verdict, matching the replay:

$ gh api repos/amd/gaia/commits/88a3fd50.../check-runs -q '.check_runs[] | select(.name=="Required Checks Gate") | .output.summary'
Ran and did not pass: C++ Email Agent (windows-latest)=failure, C++ Email Agent (ubuntu-latest)=failure
Enforced 59/72 requirement(s); excluded 13 as not statically verifiable
(continue-on-error: 1, needs-gated: 11, ref-conditional: 1): build-apps
(from build-electron-apps.yml): if references needs.*...; Consolidate
release bundle (from build_agents.yml): if gated on a tag ref...; ...

After the fork-PR fix (both check names now exist and agree, on this same-repo PR):

$ gh api repos/amd/gaia/commits/036a615c.../check-runs \
    -q '.check_runs[] | select(.name | startswith("Required Checks Gate")) | {name, conclusion}'
{"name":"Required Checks Gate (detail)","conclusion":"failure"}
{"name":"Required Checks Gate","conclusion":"failure"}

Required Checks Gate (no permissions needed, works identically on forks) is the one to add to branch protection; (detail) is the same-repo-only, richer, best-effort companion.

This PR does not go green on itself, and that is correct, not a bug. C++ Email Agent has been red on main itself for months — gh run list --workflow=build_cpp_email.yml --branch main shows failure going back to at least June 3 — a pre-existing, self-documented scaffold guard for the separate C++ email milestone (#1110), unrelated to this change. This PR touches every one of the 34 widened workflow files, including build_cpp_email.yml, so it can't avoid becoming the one PR that surfaces this genuine, already-broken check. Making the gate ignore it would mean teaching it to special-case a real failure — exactly the kind of quiet exception this issue exists to close. A gate that went green here would be a gate that lies; one real check failing, reported accurately, is the correct outcome.

itomek added 4 commits August 3, 2026 21:19
… gate

pull_request.branches:[main] on 34 workflows meant a PR based on anything
but main ran zero unit tests, lint, or agent suites while still looking
green (#2599 merged email-agent changes with 0 email tests, 0 unit tests,
0 lint). Removed that filter from the pull_request trigger only, leaving
push:[main] untouched so main-push validation runs are unaffected.

build_tui.yml is deliberately left alone here — PR #2696 already widens
that one's trigger.

Also adds a Required Checks Gate (.github/workflows/required_checks_gate.yml)
that closes the class rather than just this instance: it derives which
checks should have run for a PR's changed files directly from every other
workflow's own pull_request paths/paths-ignore filters
(.github/scripts/check_required_status.py), then polls the Checks API for
the PR's head SHA and fails if a relevant check never reports, or reports
stuck at "skipped" — the exact signature of #2755's ready_for_ci gap, since
that job's own trigger never listens for the label that would re-run it.
A job-level if: mirroring the audited jobs' own draft-gate meant the gate
skipped on exactly the PRs where it mattered most: this repo's default
draft-without-ready_for_ci state. That reproduces #2767's own bug inside
the mechanism meant to catch it — suites skip, gate skips too, checks page
reads green over zero coverage.

The gate job now always executes and self-posts a Checks API check-run
(gh api .../check-runs, checks:write) with an explicit conclusion instead
of relying on its own native job status: neutral while the PR legitimately
hasn't asked for CI yet (draft, no ready_for_ci label — named in the
check's own summary), success once the relevant suites verifiably passed,
failure otherwise. Neutral doesn't block a merge on its own, matching
GitHub's branch-protection semantics for a neutral required check, so this
is visible without being noise.

The native workflow-job check is renamed "(runner)" to make clear it only
reflects whether the script executed, not the real verdict.
Live evidence on the throwaway PR (#2775) surfaced a real bug: the bare
'Test' prefix (test_hub_agents.yml's matrix-templated job) was also
matching OTHER prefix-mode jobs' rendered names (Test Apps Build (jira),
Test MCPAgent (ubuntu-latest)) because the reserved-names guard only
covered static names, not other prefixes. The verdict came out right that
run (both were legitimately still skipped), but the failure message
misattributed which job was actually failing.

Replaces the reserved-names dict with a general most-specific-owner rule:
every check-run name belongs to whichever job's matcher matches it most
specifically (exact beats any prefix; among prefixes, the longer one
wins), computed across every job in every workflow file regardless of
exclude or trigger type.
Live evidence on the throwaway PR (#2775) showed this: the repo's
auto-labeler added labels shortly after the PR opened, firing a second
labeled event for the same SHA while the gate was still polling. With
cancel-in-progress: true, that killed the in-progress run before it ever
called post_check_run() — benign here only because a further run
happened to supersede it. If a cancelled run is ever the LAST triggering
event for a SHA, the check silently never posts at all: a fourth way to
fail open, inside the fix for the other three. Queuing costs run time on
a burst of events but guarantees every trigger eventually gets a real,
posted verdict.
@github-actions github-actions Bot added devops DevOps/infrastructure changes tests Test changes security Security-sensitive changes cpp labels Aug 4, 2026
@itomek itomek added the ready_for_ci Run CI workflows on draft PR without requesting review label Aug 4, 2026
@itomek itomek closed this Aug 4, 2026
@itomek itomek reopened this Aug 4, 2026
@itomek itomek self-assigned this Aug 4, 2026
@itomek
itomek marked this pull request as ready for review August 4, 2026 02:36
@itomek
itomek requested a review from kovtcharov-amd as a code owner August 4, 2026 02:36
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

This PR closes a real CI gap: PRs targeting non-main base branches now run the test suites (the pull_request: branches:[main] filter is dropped across ~30 workflows), and a new Required Checks Gate aggregates every PR-triggered workflow's actual check-run state so a silently-skipped or never-triggered required check turns into a visible red instead of a false green. The design is careful and unusually well-tested — the pure evaluate()/load_requirements() core is exercised against real-shaped workflow fixtures, including the nasty matrix-name-collision cases found live on #2775, and the gate deliberately fails closed (red), which is the safe direction.

One behavioral inconsistency is worth fixing before or shortly after merge, but it isn't a merge blocker because it fails closed rather than open:

  • The gate's own "add the ready_for_ci label" advice doesn't actually work for an already-open draft. The gate reacts to the labeled event and starts enforcing, but the suites it audits don't trigger on labeled — so on a draft PR they stay stuck at their initial skipped conclusion and the gate goes red instead of "requiring and verifying them" as its neutral message promises. Marking the PR ready for review works correctly; only the bare label-add path is broken. Either add labeled to the suites' triggers or reword the neutral summary.

Real-world evidence

N/A — CI-only change (workflow YAML, a helper script, and its unit tests); no runnable GAIA CLI/API/Agent-UI/MCP surface to exercise. The gate's core logic is covered by tests/unit/test_check_required_status.py; the merge-time behavior can only be fully observed on a live Actions run against a real PR, which the diff can't produce here. Verdict rests on static review plus the committed unit tests.

🔍 Technical details

🟡 Important

1. ready_for_ci label path is advertised but doesn't re-run the audited suites (required_checks_gate.yml:40, check_required_status.py:419-426)

is_gated_off() returns False once the label is present, so on a labeled event the gate switches from neutral to enforcing. But every audited suite triggers only on types: [opened, synchronize, reopened, ready_for_review] — none list labeled (confirmed across test_*.yml; only claude.yml and this gate do). Sequence for a draft PR:

  1. opened (draft, no label) → suite job if: (draft == false || contains(labels,'ready_for_ci')) is false → check-run conclusion skipped; gate posts neutral. ✓
  2. Label ready_for_ci added, no new commit → labeled fires. Suites do not re-run (head SHA unchanged, no labeled trigger) → their runs stay skipped. Gate now enforces → skipped ∈ TERMINAL_BAD_CONCLUSIONS → red.

So following the neutral summary's own instruction ("add the ready_for_ci label ... to require and verify them", check_required_status.py:419-426) produces a failing gate rather than a verified PR. It fails closed, so it's not a safety hole — but it's a confusing, self-contradicting path. Two clean fixes:

  • Add labeled to the audited suites' pull_request triggers so the label actually re-runs them (broader change, out of this diff's current scope), or
  • Narrow the neutral message to the path that works:
        summary = (
            "This PR is a draft without the `ready_for_ci` label, so the "
            "suites this gate audits have not run (by the same convention "
            "every audited workflow uses). Nothing has been verified — this "
            "is not a pass. Mark the PR ready for review to require and "
            "verify them (a new push while the `ready_for_ci` label is set "
            "works too; adding the label alone does not re-run them)."
        )

(The nuance: the label does work when it's already present at opened/synchronize time — the broken case is specifically adding it to an existing draft with no subsequent push.)

🟢 Minor

2. fnmatch vs GitHub path-filter glob semantics (check_required_status.py:251-252) — _matches_any uses fnmatch, where * matches /, but GitHub's paths/paths-ignore treat * as single-segment (** spans segments). For any filter using a bare * that needs to not cross a slash (e.g. a hypothetical src/*), the gate would compute path-relevance more permissively than GitHub actually triggers, and could then wait on a check GitHub never scheduled → timeout → false red. Impact is low today because the audited filters are almost all dir/** / exact paths, but it's a latent divergence worth a comment or a small **→segment-aware normalization.

3. Latent trap: any legitimately-skipped PR-triggered job becomes a terminal failure. The gate requires every pull_request-triggered job that isn't continue-on-error and treats skipped as terminal-bad — correct for the #2755 case. But a future job that skips for a non-draft reason (e.g. a mutually-exclusive fork-vs-same-repo split like the one in test_eval_rag.yml, which is safe today only because that workflow is workflow_dispatch-only and thus not audited) would false-fail the gate on every PR. No current instance exists among audited workflows, so nothing to change now — just a constraint worth a one-line note near TERMINAL_BAD_CONCLUSIONS so the next author who adds a conditionally-skipped PR job knows the gate will flag it.

Strengths

  • Design matches the docstring's claim. Pure evaluate() / load_requirements() split from a thin polling main(), and the unit tests prove the load-bearing behavior (stuck-skipped → failure, absent → pending-not-failure, neutral → passing) without needing a live Actions run.
  • The _most_specific_owner collision handling is genuinely thorough — driven by two real collisions (one static-name, one prefix-vs-prefix found live on THROWAWAY evidence probe for #2767 — do not merge #2775) and both encoded as regression tests against multi-file fixtures.
  • Fails loud on unrecognized conclusions (check_required_status.py:300-305) instead of defaulting an unknown state to "passing" — aligned with GAIA's no-silent-fallbacks rule.
  • The neutral third-state and the no-self-if:-skip reasoning are well thought through and clearly documented; the gate can't reproduce the silent-green bug it exists to catch.
  • continue-on-error: true jobs are correctly excluded (author already declared them non-blocking), with a test to lock it in.

The gate failed on its own PR (#2783), and replaying that PR's real
Checks API history through evaluate() (not synthetic fixtures) found the
actual causes and took total failures 55 -> 1 (the one remaining is the
pre-existing, self-documented build_cpp_email.yml scaffold guard for
#1110, unrelated to this change).

Root cause, unified: GitHub never deletes a check-run — every triggering
event (opened, then labeled, then reopened) adds new rows alongside old
ones. evaluate() collected the full history for a SHA and gave any bad
match unconditional priority over good ones, with no notion of recency.
A five-minute-old stale skip was masking a fresh, real pass sitting right
next to it in the same API response.

Fixed with an exact rule, not a tuned time-window (the observed gap
between stale and fresh ranged from about a minute to several minutes on
real data, so no fixed window reliably separates "same event" from
"different event"): dedup by exact check-run name keeping only the
newest, then discard any pre-expansion artifact older than the newest
real entry for that requirement. A pre-expansion artifact is decidable
two ways, not one — the second was found the same way, by replaying real
data: a job's name containing literal "${{ }}" (skipped before its
matrix ever expanded), OR a job whose name has no template at all but
does have a strategy.matrix, where GitHub still auto-appends "(leg,
values)" to every real rendered check-run, so a real run can never
produce the bare, un-suffixed name matching the job's declared name.

Also: a job gated on a tag ref (`startsWith(github.ref, 'refs/tags/')`)
can never run on a pull_request event at all — unlike needs.*, this is
statically decidable, not just excluded on uncertainty.

Every exclusion (continue-on-error, needs.*-gated, tag-ref-gated) is now
named in the gate's own posted summary, not silently dropped from the
required set — "enforced N/M requirements; excluded K (kind: count,
...)" with each one's reason.

Messaging: the neutral and failure summaries now say label AND
close/reopen, not label alone — the audited suites don't listen for
`labeled`, so the label by itself cannot re-trigger them. Failure text
also splits "did not run" (stuck at skipped, needs a re-trigger) from
"ran and did not pass" (a real failure), since they need different
advice.

6 new unit tests reproducing the real shapes found live: stale skip
masked by fresh pass (both artifact forms), a genuine failure not masked
by a stale skip nearby, latest-entry-still-skipped staying failed (not
silently passing), a re-skip after a real pass still reported as
current, and the exclusion-count summary itself.
@itomek
itomek marked this pull request as draft August 4, 2026 03:05
@itomek

itomek commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed the messaging gap you flagged: the neutral and failure summaries now say label AND close/reopen (not label alone) — the audited suites don't listen for the labeled event, only this gate does, so the label alone can't re-trigger them. Also found and fixed two more real bugs by replaying this PR's own Checks API history through the classifier: a five-minute-old stale skip masking a fresh pass sitting next to it in the same API response (GitHub never deletes old check-runs), and a job with a static name plus a matrix that still gets GitHub's auto-appended "(leg, values)" suffix on every real run. Total failures went from 55 to 1 — the remaining one is C++ Email Agent, a pre-existing, self-documented scaffold guard for #1110 that also fails on main itself (confirmed via gh run list --workflow=build_cpp_email.yml --branch main), unrelated to this change. Details and full replay evidence are in the PR description.

@itomek
itomek marked this pull request as ready for review August 4, 2026 05:00
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Verdict: Request changes (one concern to confirm; otherwise a strong, well-tested PR)

This adds an aggregating "Required Checks Gate" that derives what should have run from every workflow's own pull_request: path filters and then watches the Checks API for the PR's head SHA — closing the silent-green hole where a skipped or wrong-base-branch check let a PR look green with nothing behind it. It also widens every PR trigger to all base branches (removing branches: [main]), which is the root cause the gate defends against. The derivation approach, the three-state neutral/success/failure design, and the recency/most-specific-owner handling are genuinely well thought through, and the test suite is excellent.

The one thing to resolve before this becomes a required check: it needs to write check-runs, but PRs from forks get a read-only token — so on external-contributor PRs the gate will likely fail to post its verdict and error out. Please confirm the behavior against a real fork PR; if this is required in branch protection, it could block every fork contribution. See details below.

Real-world evidence

N/A — CI/infra-only change (no CLI/API/agent/UI/MCP surface), so no evidence bundle applies. The runnable surface here is GitHub Actions itself. Correctness rests on the committed unit suite (tests/unit/test_check_required_status.py, 30+ cases covering the tricky states) plus the author's documented live runs on the throwaway/real PRs (#2775, #2783) referenced throughout the code comments. The one path unit tests can't reach — the gate actually posting via gh api under a fork's token — is exactly the concern flagged above and is what to exercise on a fork PR.

🔍 Technical details

🟡 Fork PRs get a read-only GITHUB_TOKEN — post_check_run will likely 403 (required_checks_gate.yml:23, check_required_status.py:470)
The workflow is pull_request-triggered and requests checks: write, but for PRs opened from a fork GitHub grants the token read-only permissions regardless of the permissions: block. post_check_run() does a POST repos/{repo}/check-runs, and on a fork PR that call returns 403 → RuntimeError → the (runner) job goes red and no "Required Checks Gate" check-run is ever posted for that SHA. If branch protection requires this gate, external-contributor PRs would be unmergeable (either the required self-check never appears, or the runner check is red). The reads in the workflow (pulls/.../files, commits/.../check-runs) are fine — only the write is affected. This repo clearly takes fork PRs (test_eval_rag.yml even gates specifically on head.repo.full_name != github.repository), so please verify on a real fork PR before wiring this into branch protection. Options if it does 403: detect fork context and post a neutral/skip with a clear message, or handle the verdict via a separate workflow_run-triggered poster (weighing the usual pull_request_target/workflow_run security tradeoffs).

🟢 labeled-only opt-in on a draft yields a 60-min timeout before the gate reports (required_checks_gate.yml:819, check_required_status.py:599)
Adding ready_for_ci to a draft makes is_gated_off() return False so the gate starts enforcing, but the audited suites don't listen for labeled, so they were never (re)triggered — the gate then polls the full --timeout-seconds 3600 before failing. The failure summary does explain the close/reopen remedy, so this is by-design and self-documented; noting only that the verdict takes an hour to surface in that specific flow. No change required.

🟢 is_path_relevant uses fnmatch, whose glob semantics differ from GitHub's (check_required_status.py:334)
fnmatch's * crosses / and it has no **/! handling, unlike GitHub's path-filter globs. The current filters in the repo are all simple (src/**, hub/agents/<id>/**, exact files) with no negation, so they behave identically today — but a future filter using !-exclusion or a single-segment * could make the gate consider a job path-relevant that GitHub never triggered, causing a spurious timeout→failure. Worth a short comment noting the approximation, or a pathspec/wcmatch-based match if you want exact parity later.

Strengths

  • Derivation-from-source (parsing each workflow's own pull_request: filters and job continue-on-error/if:) instead of a hand-maintained list is the right call — new workflows are covered automatically, and excluded jobs are reported, not silently dropped (load_requirements / format_exclusions), which keeps the gate itself auditable.
  • Fail-loud throughout: unrecognized Checks-API conclusions become a failure rather than a silent pass (evaluate, check_required_status.py:453), and gh api errors raise with context — consistent with the repo's no-silent-fallback rule.
  • The recency / pre-expansion-artifact / most-specific-owner logic is subtle but each branch is pinned by a named test tied to a real observed collision (THROWAWAY evidence probe for #2767 — do not merge #2775/fix(ci): a PR based on any branch but main runs no unit tests, no lint and no agent suites #2783), including the static-name-with-matrix case that a naive "${{" in name check missed. That's exactly the "verify the call is valid, from the real state" discipline CLAUDE.md asks for.
  • neutral as a real third state (via a self-posted check-run, not a job-level skip) correctly avoids the gate reproducing the very silent-green bug it exists to catch.

@itomek
itomek enabled auto-merge August 4, 2026 05:10
@itomek

itomek commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

Integration-tested against the other four PRs from this run (#2774, #2782, #2784, #2788) on a combined branch — all five merged cleanly with no conflicts, and this branch's own scope (CI trigger widening + the required-checks gate) is orthogonal to the other four's email-agent code, so it carries no TUI/runtime surface of its own to re-verify here.

Integration details
  • Merged first, into integ-r2608032043 off fresh origin/main, before the other four — clean, no conflicts.
  • Combined suite: hub/agents/email/python/tests/ tests/unit/ — 10636 passed, 8 failed (all pre-existing on origin/main too, confirmed by a separate parity run), 146 skipped.
  • python util/lint.py --all — all 10 stages pass.
  • Integration branch was local-only, verified deleted after testing.

Integrated tree: 7804d3ae · this branch's merged commit: 88a3fd50

Fork PRs get a read-only GITHUB_TOKEN for `pull_request` (not
`pull_request_target`) regardless of the workflow's declared
permissions. The gate posted its verdict via a self-managed Checks API
check-run needing checks:write — a required check that can only post
via a permission forks don't have would block every fork contribution
to this repo.

Confirmed live, not assumed: inspected a real fork PR's job log (#2753,
"Dependency Review", plain pull_request trigger, declares
pull-requests: write) and it logged "GITHUB_TOKEN Permissions:
Contents: read, Metadata: read, PullRequests: read" -- write silently
dropped to read. checks:write downgrades identically.

The binding signal is now this job's own native exit code -- available
with zero special permissions, identical on same-repo and fork PRs.
neutral and success both exit 0 (a draft PR without ready_for_ci can't
be merged regardless of check status -- GitHub blocks merging any
draft PR at the platform level -- so there's nothing to protect by
failing here), only a genuine failure or timeout exits 1. The richer
three-state distinction isn't dropped: write_step_summary() puts it in
the job's own Actions summary (no permissions needed, works on forks),
and post_check_run() still attempts the richer, distinctly-colored
"Required Checks Gate (detail)" check-run wherever the token allows it
-- best-effort, catches its own failure, logs a clear warning, never
raises, never fails the job.

Renamed: the job itself is now "Required Checks Gate" (the one to add
to branch protection); the API-posted check-run is "Required Checks
Gate (detail)" (informational, same-repo only).

4 new unit tests: post_check_run() returns False (not raise) on a
simulated 403, returns True on success, and write_step_summary() both
no-ops without GITHUB_STEP_SUMMARY set and writes correctly when it is.
@itomek
itomek marked this pull request as draft August 4, 2026 05:17
auto-merge was automatically disabled August 4, 2026 05:17

Pull request was converted to draft

@itomek

itomek commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed the fork-PR gap: the gate previously bound branch protection to a self-posted Checks API check-run needing checks: write, which GitHub silently downgrades to read-only for pull_request (not pull_request_target) on fork PRs regardless of what the workflow declares — confirmed by inspecting a real recent fork PR's job log (#2753's Dependency Review, which declares pull-requests: write and still logged GITHUB_TOKEN Permissions: Contents: read, Metadata: read, PullRequests: read). A required check that can only post via a permission forks don't have would have blocked every fork contribution to this repo.

Fixed by making the job's own native exit code the binding signal (renamed to Required Checks Gate, needs no special permissions, identical on same-repo and fork PRs) and demoting the richer API-posted check-run to Required Checks Gate (detail) — informational, same-repo-only, best-effort, and its own 403 is caught and logged rather than failing the job. The neutral/success/failure nuance isn't lost on forks, just moved to the job's own Actions step summary, which needs no permissions either.

Full reasoning, including what happens to the draft-PR neutral case, is in the PR description.

@itomek

itomek commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

Closing this — the premise it was built on doesn't hold up.

The concern in #2767 was that a PR based on a branch other than main skips unit tests, lint, and the agent suites, so untested code reaches main. The first half is true. The second half isn't: that code still has to pass through an integration PR whose base is main, and that PR runs the full matrix.

The exact case #2767 cited proves it. #2599 (base tmi/2580-attention-int) ran 16 checks. The same branch's PR to main, #2604, ran 53 — including every check #2599 was accused of skipping, all passing, before any of it merged:

Check #2599 #2604
Unit Tests (py3.10 / 3.11 / 3.12 / macOS smoke) — pass
Email Agent Unit Tests (py3.10 / 3.12) — pass
Test Email Agent — pass

So branches: [main] isn't a hole, it's deferral working as designed. The real cost is feedback latency — a stacked-PR author finds out about a lint break at integration time instead of immediately. That's a genuine annoyance, and it's worth roughly a two-line change to lint.yml and test_unit.yml. It is not worth what this PR does: widening ~34 workflows so Electron builds, C++ builds, and self-hosted NPU/STX jobs fire on every PR to every branch, permanently.

The Required Checks Gate is a separate idea and a bigger one. main currently has no branch protection and no enabled ruleset — the repo has zero required status checks today. Adding a blocking gate is a real policy change that deserves its own decision, not a ride-along on a trigger fix.

If the latency is worth addressing, the proportionate version is a small PR widening only lint.yml and test_unit.yml and leaving everything self-hosted alone.

Notes for anyone picking this up
  • The check_required_status.py derivation approach (parse each workflow's own paths:/paths-ignore: rather than hand-curating a list) is sound and worth salvaging if a gate is ever wanted. Its unit tests are in tests/unit/test_check_required_status.py.
  • The C++ / STX failures on this PR are not caused by the widening. build_cpp.yml lists its own path in paths:, so any PR editing that file triggers it. Those runs are failing repo-wide right now on unrelated cpp/* branches — a broken toolchain on the Windows self-hosted runner (CMake Error: Could not find CMAKE_ROOT, plus lemonade-server missing after its own install step). Worth fixing separately; it's blocking other work.
  • Stale Unit Tests (py${{ matrix.python-version }}) — skipping rows still show up in the Checks API for old runs, since GitHub never deletes check-runs. That's the cosmetic confusion behind fix(ci): ready_for_ci label does not re-trigger skipped jobs — 'labeled' is not a PR trigger type #2755, and it's real, but it's a reporting problem rather than a coverage one.

#2767 should probably be closed or rewritten too — its acceptance criteria are built on the same premise.

@itomek itomek closed this Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cpp devops DevOps/infrastructure changes ready_for_ci Run CI workflows on draft PR without requesting review security Security-sensitive changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(ci): a PR based on any branch but main runs no unit tests, no lint and no agent suites — and looks green

1 participant