This is an automated email from the ASF dual-hosted git repository. potiuk pushed a commit to branch fork-ci-note-error-text in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 624e14d5b7b6c40e6af1737739cb48b2016f6d70 Author: Jarek Potiuk <[email protected]> AuthorDate: Mon Nov 16 03:24:25 2026 +0900 Say why a fork CI monitor call failed in its Slack note Notes such as "reporting `CI run started` for project CI failed" named only the exception type, so a failure seen three times in the pilot could not be diagnosed from Slack. Generated-by: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01NyQq9U7i5HhjDgrQ9qd3gq --- .../doc/ci/08_fork_ci_for_external_contributors.md | 6 ++++- .../src/airflow_breeze/utils/fork_ci_reconcile.py | 28 ++++++++++++++++---- dev/breeze/tests/test_fork_ci_reconcile.py | 30 +++++++++++++++++++--- 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/dev/breeze/doc/ci/08_fork_ci_for_external_contributors.md b/dev/breeze/doc/ci/08_fork_ci_for_external_contributors.md index a1d932971a5..39c166c6cc7 100644 --- a/dev/breeze/doc/ci/08_fork_ci_for_external_contributors.md +++ b/dev/breeze/doc/ci/08_fork_ci_for_external_contributors.md @@ -1226,7 +1226,11 @@ Unknown means any of: - A state comment whose marker cannot be parsed. Expected states never alert. The message lists the pull request numbers and the reason for -each, with a link to the workflow run, so a maintainer can act. The run itself still ends +each, with a link to the workflow run, so a maintainer can act. An item or note about a failed +call names the exception and the first line of its message, shortened to 200 characters; a failed +`gh` call's arguments, which for GraphQL hold the whole query, are left out, and the run log has +the error in full. A failure that persists gives the same text on every run, so it is still posted +once. The run itself still ends green unless the reconciler could not talk to GitHub at all. ### Budget diff --git a/dev/breeze/src/airflow_breeze/utils/fork_ci_reconcile.py b/dev/breeze/src/airflow_breeze/utils/fork_ci_reconcile.py index 61a30366219..f499fc2e25d 100644 --- a/dev/breeze/src/airflow_breeze/utils/fork_ci_reconcile.py +++ b/dev/breeze/src/airflow_breeze/utils/fork_ci_reconcile.py @@ -190,6 +190,8 @@ COMPARE_FILES_CAP = 300 SLACK_SECTION_LIMIT = 3000 SLACK_MAX_BLOCKS = 50 SLACK_ITEM_LIMIT = 500 +# The error text a Slack item quotes; the full error is in the run log. +ERROR_TEXT_LIMIT = 200 # Events whose runs use the workflow files of the pull request's merge commit, so a pull request # can change what they run. pull_request_target and issue_comment use the base branch's files. MERGE_REF_EVENTS = ("pull_request", "pull_request_review", "pull_request_review_comment") @@ -569,6 +571,22 @@ def changed_paths(entries: Iterable[dict[str, Any]]) -> list[str]: return paths +def describe_error(e: Exception) -> str: + """ + The exception type and the first line of its message, for a Slack item. + + A failed `gh` call's message starts with its arguments, which for GraphQL hold the whole query, + so only what `gh` reported is kept. A failure that persists gets the same text on every run, so + its item is still posted once. + """ + message = str(e).strip() + if message.startswith("gh ") and " failed: " in message: + message = message.split(" failed: ", 1)[1] + first_line = message.splitlines()[0].strip() if message else "" + text = f"{type(e).__name__}: {first_line}" if first_line else type(e).__name__ + return text if len(text) <= ERROR_TEXT_LIMIT else f"{text[: ERROR_TEXT_LIMIT - 1]}…" + + def changes_ci_definition(files: Sequence[str], *, file_count: int | None = None) -> bool: """ Whether a pull request's changed files can alter what its fork CI runs. @@ -1519,7 +1537,7 @@ def report_project_ci_passed( successes += change[0] == "success" except Exception as e: console_print(f"[error]#{node['number']}: `{CI_PASSED_CONTEXT}` not updated: {e}[/]") - attention.append((node["number"], f"`{CI_PASSED_CONTEXT}` not updated: {type(e).__name__}")) + attention.append((node["number"], f"`{CI_PASSED_CONTEXT}` not updated: {describe_error(e)}")) return written @@ -1703,7 +1721,7 @@ def discover( except Exception as e: console_print(f"[error]#{node['number']}: `{CI_PASSED_CONTEXT}` not updated: {e}[/]") if unknown is not None: - unknown.append((node["number"], f"`{CI_PASSED_CONTEXT}` not updated: {type(e).__name__}")) + unknown.append((node["number"], f"`{CI_PASSED_CONTEXT}` not updated: {describe_error(e)}")) for search_query in queries: for node in _search(client, DISCOVERY_QUERY % {"context": CI_PASSED_CONTEXT}, search_query): @@ -2887,7 +2905,7 @@ def run_reconcile( # Writes made before the failure are not known, so the whole allowance is charged. ci_run_started_writes = MAX_CI_RUN_STARTED_PER_RUN ci_run_started_note = ( - f"reporting `{CI_RUN_STARTED_CONTEXT}` for project CI failed: {type(e).__name__}" + f"reporting `{CI_RUN_STARTED_CONTEXT}` for project CI failed: {describe_error(e)}" ) # Commit statuses belong to a commit, so a fork `success` posted for any pull request on one of # these would also let a pull request with `use project ci` merge. None when they could not be @@ -2902,7 +2920,7 @@ def run_reconcile( project_ci_heads = None ci_passed_reserved = MAX_PROJECT_CI_PASSED_PER_RUN ci_passed_notes.append( - f"listing the pull requests with `{LABEL_USE_PROJECT_CI}` failed: {type(e).__name__}" + f"listing the pull requests with `{LABEL_USE_PROJECT_CI}` failed: {describe_error(e)}" ) read_jobs: ReadJobs = {} job_reporter = JobStatusReporter( @@ -3005,7 +3023,7 @@ def run_reconcile( except Exception as e: console_print(f"[error]Reporting `{CI_PASSED_CONTEXT}` for `{LABEL_USE_PROJECT_CI}` failed: {e}[/]") ci_passed_notes.append( - f"reporting `{CI_PASSED_CONTEXT}` for `{LABEL_USE_PROJECT_CI}` failed: {type(e).__name__}" + f"reporting `{CI_PASSED_CONTEXT}` for `{LABEL_USE_PROJECT_CI}` failed: {describe_error(e)}" ) attention.extend(bypass_finder.ambiguous) attention.extend(job_reporter.delayed) diff --git a/dev/breeze/tests/test_fork_ci_reconcile.py b/dev/breeze/tests/test_fork_ci_reconcile.py index 4e2ddd2bf90..6b89c8d124a 100644 --- a/dev/breeze/tests/test_fork_ci_reconcile.py +++ b/dev/breeze/tests/test_fork_ci_reconcile.py @@ -78,6 +78,7 @@ from airflow_breeze.utils.fork_ci_reconcile import ( classify, compare_with_base, compute_projection, + describe_error, discover, drop_reported, fetch_fork_observations, @@ -2298,7 +2299,7 @@ def test_discover_keeps_going_when_the_project_ci_lookup_of_one_pull_request_fai discover(client, configs, repo=REPO, now=NOW, unknown=unknown, ci_passed_written=[]) - assert unknown == [(1, "`CI passed` not updated: GitHubError")] + assert unknown == [(1, "`CI passed` not updated: GitHubError: HTTP 502")] assert client.rest_get.call_count == 2 @@ -4040,7 +4041,7 @@ def test_run_reconcile_marks_older_pilot_pull_requests_and_reports_project_ci_ru mock_reporter.assert_called_once_with(client, repo=REPO, budget=job_status_budget, now=NOW, read_jobs={}) assert has_alerts is fails if fails: - assert "reporting `CI run started` for project CI failed: GitHubError" in output.read_text() + assert "reporting `CI run started` for project CI failed: GitHubError: HTTP 502" in output.read_text() @pytest.mark.parametrize( @@ -4518,7 +4519,7 @@ def test_report_project_ci_passed_keeps_going_after_an_error(client): attention: list[tuple[int, str]] = [] assert report_project_ci_passed(client, repo=REPO, attention=attention) == [2] - assert attention == [(1, "`CI passed` not updated: GitHubError")] + assert attention == [(1, "`CI passed` not updated: GitHubError: HTTP 502")] def _rest_for_project_ci_passed(runs, checks): @@ -4854,7 +4855,8 @@ def test_run_reconcile_reports_project_ci_passed_failure(mock_report_project_ci_ assert has_alerts is True assert ( - "reporting `CI passed` for `use project ci` failed: GitHubError" in (tmp_path / "s.json").read_text() + "reporting `CI passed` for `use project ci` failed: GitHubError: HTTP 502" + in (tmp_path / "s.json").read_text() ) @@ -5038,3 +5040,23 @@ def test_monitor_interval_is_the_monitor_workflow_cadence(): crons = [entry["cron"] for entry in workflow[True]["schedule"]] assert crons == [f"*/{MONITOR_INTERVAL // timedelta(minutes=1)} * * * *"] + + [email protected]( + ("error", "expected"), + [ + pytest.param( + GitHubError("gh api graphql -f query=query { long } failed: HTTP 502: Bad Gateway\nmore"), + "GitHubError: HTTP 502: Bad Gateway", + id="gh-arguments-left-out", + ), + pytest.param( + GitHubError("GraphQL errors: [x]"), "GitHubError: GraphQL errors: [x]", id="other-message" + ), + pytest.param(KeyError("sha"), "KeyError: 'sha'", id="other-exception"), + pytest.param(RuntimeError(), "RuntimeError", id="no-message"), + pytest.param(GitHubError("x" * 300), "GitHubError: " + "x" * 186 + "…", id="shortened"), + ], +) +def test_describe_error(error, expected): + assert describe_error(error) == expected
