Skip to content

[mergebot] Put GraphQL error details in the collapsed section - #201104

Closed
izaitsevfb wants to merge 3 commits into
mainfrom
mergebot-error-format
Closed

izaitsevfb wants to merge 3 commits into
mainfrom
mergebot-error-format

Conversation

@izaitsevfb

@izaitsevfb izaitsevfb commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

✴️ iz2: When a GitHub GraphQL call fails, mergebot's "Merge failed" comment put the whole query and its variables on the Reason line, about 40 lines of query text (example: #200980).

Now Reason shows only GitHub's error message, on one line (or "(no error message)" when the errors list is empty):

Reason: GitHub GraphQL query failed: Something went wrong while executing your query on 2026-10-15T17:52:34Z. Please include 83C2:… when reporting this issue.

The variables, raw errors and query move into "Details for Dev Infra team" as fenced blocks, each size-capped to keep the comment under GitHub's 65536-char limit. The same context also stays in the job log for every gh_graphql caller: gh_graphql prints it when it raises, and GHGraphQLError adds it as an exception note on Python 3.11+ (mergebot runs on 3.10, where tracebacks don't show notes). handle_exception becomes the module-level format_failure_comment() so it can be tested. The details block now also appears when there is a failing merge rule but GH_RUN_URL is unset.

Exposure check: the comment and log contain nothing sensitive. The token is sent as an HTTP header and never reaches the exception. The query text is already in this repo. The variables are owner, repo name, PR number and opaque pagination cursors. The request ID is the one GitHub asks you to share.

Test plan: python -m unittest test_trymerge test_delete_old_branches in .github/scripts (Python 3.12): 159 pass, 2 skipped. TestFailureComment covers the short reason, empty errors, the log output and note, the collapsed details, size caps, the merge-rule case and the no-details case.

A GraphQL error used to put the whole query and its variables into the
Reason line of the Merge failed comment. Reason now carries only GitHub's
error message; the variables, raw errors and query go under Details for
Dev Infra team, each size-capped to stay under GitHub's comment limit.
@izaitsevfb
izaitsevfb requested a review from a team as a code owner October 15, 2026 19:32
@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Oct 15, 2026
@pytorch-bot

pytorch-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/201104

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 Unclassified Failure

As of commit 26149de with merge base 152bd17 (image):

🟡 GREEN LIGHT - OUTDATED (earlier commit) - PR requires human review:

  • Triviality
    • Fits no trivial class: new format_failure_comment, new GHGraphQLError.details_markdown and a reworked gh_graphql error path in mergebot
    • Changes what mergebot posts and logs on every failed merge, a behavior change rather than a no-op or a refactor
  • Socialization
    • str(GHGraphQLError) format changes, and trymerge.py writes it to the S3 merge record via save_merge_record(error=str(e))
    • The PR comment's **Reason**: line and <details> layout change shape, and tooling outside this repo may read them
  • Exposure and scope
    • GraphQL query, variables and raw errors now go into public PR comments and job logs, so a human should confirm the exposure
    • Unrelated file-mode change on .github/scripts/test_trymerge.py from 100755 to 100644
  • Review history
    • A maintainer asked for changes on the logging behavior; a human should confirm the follow-up meets that request

reason: not_trivial
Reviewed commit: de513db (NOT the current head 26149de)

Inference job

🐛 Report a wrong verdict

UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:

  • pull / linux-jammy-aarch64-py3.11-clang21 / build (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    /__w/pytorch/pytorch/aten/src/ATen/native/quantized/cpu/qembeddingbag.cpp:222:20: error: function 'embedding_neon_kernel' is not needed and will not be emitted [-Werror,-Wunneeded-internal-declaration]

    AI verdict: AI verdict: not related

    The PR only changes the mergebot Python scripts in .github/scripts (the suspect commit is just a file-mode change). The aarch64 clang build fails because the PR's stale merge base lacks trunk commit ada3fee, which added the clang job and the [[maybe_unused]] fix to qembeddingbag.cpp that the job needs.

    Full reasoning on HUD →

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@huydhn

huydhn commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

@claude Review this change

@claude

claude Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Claude finished @huydhn's task in 1m 3s —— View job


The comment change looks right, but I'd request changes for two things: the lint-urls failure caused by a test URL, and the query/variables no longer showing up in job logs for any script that raises a GraphQL error.

PR Review: #201104

Summary

The PR shortens the GraphQL error message, moves the query, variables and raw errors into the collapsed "Details for Dev Infra team" section, and pulls handle_exception out into format_failure_comment(). Two problems block it: a test fixture breaks the lint-urls job, and the error message now carries no debugging context for scripts other than trymerge.

Code Quality

  • Query and variables are gone from every log and from every other script's output. .github/scripts/github_utils.py:193: str(GHGraphQLError) used to contain the query and variables. Now it only has GitHub's message. Only trymerge.format_failure_comment calls details_markdown(). Every other path loses that context:

    • traceback.print_exc() in trymerge.handle_exception (trymerge.py:3275). The "workflow job" link in the comment points at this log, and the log now shows only the one-line message.
    • The uncaught GitHubPR(...) failure when --check-mergeability is set (trymerge.py:3279-3282). It only re-raises, so nothing records the query.
    • tryrebase.py:254: Rebase failed due to {e}.
    • trymerge.py:2892: the "Failed to fetch dependent PRs" print.
    • cherry_pick.py and any other gh_graphql caller.
    • save_merge_record(error=str(e)) (trymerge.py:3390). Dropping it here is probably fine.

    The PR body says "variables, raw errors and query move into Details". That holds only for the trymerge comment. The cheapest fix is self.add_note(self.details_markdown()) in GHGraphQLError.__init__, if the runner Python is 3.11 or newer. Notes appear in tracebacks but not in str(e), so the comment stays short and the logs keep the context. Otherwise, print e.details_markdown() in handle_exception next to traceback.print_exc().

  • Empty errors gives an empty reason. github_utils.py:183-190: if GitHub returns "errors": [] or "errors": null, messages is "" and the comment reads **Reason**: GitHub GraphQL query failed: with nothing after it. Fall back to json.dumps(rc["errors"]), or a fixed string like "(no error message)", when messages is empty.

Testing

  • The test fixture URL fails lint-urls. .github/scripts/test_trymerge.py:387: run_url = "https://github.com/pytorch/pytorch/actions/runs/1" returns 404. That is the one new CI failure (Lint / Link checks / lint-urls). Use a URL that exists, or a non-resolving placeholder such as https://example.com/run/1. The other option is the lint-urls skip marker used elsewhere in the repo.

Backward Compatibility

  • Consumers that parse the error string will see a new format. The text changes from GraphQL query ..., args ... failed: [...] to GitHub GraphQL query failed: .... Nothing in .github/scripts matches on the old string; I checked str(e) and in str( uses. HUD/test-infra tooling that reads the error field from the S3 merge record, or the **Reason**: line, would see the new format. If anything groups failures by that string, a Dev Infra owner should confirm. Dr. CI flagged the same point.

Recommendation

Request Changes: the test URL breaks a CI lint job, and the query/variables context should stay in tracebacks and logs (for example via add_note) instead of reaching only the trymerge comment.

@huydhn

huydhn commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Plz fix lint. Also, the agent review makes sense to me as I usually looks into the merge job to debug issue instead of its comment.

and the query/variables context should stay in tracebacks and logs (for example via add_note) instead of reaching only the trymerge comment

gh_graphql now prints the query, variables and errors to the job log
when it raises, and GHGraphQLError adds them as an exception note on
Python 3.11+. Mergebot runs on 3.10, where tracebacks don't show notes.
An empty errors list now reads '(no error message)'. The test's fake
run URL carries @lint-ignore so lint-urls skips it.
@izaitsevfb
izaitsevfb requested a review from huydhn October 15, 2026 23:46
@izaitsevfb

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -i

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 16, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 1 checks: pull / linux-jammy-aarch64-py3.11-clang21 / build

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

izaitsevfb added a commit to pytorch/test-infra that referenced this pull request Oct 19, 2026
…erdicts to the run they analyzed (#9139)

✴️ iz2: 

## Problem

When a failed PR job is re-run at the same commit (pytorch-bot's
auto-retry, or by hand), AI advisor suppression can never clear it.
There are two causes:

- Auto-dispatch dedups on `(head sha, job name)`, so the rerun is never
analyzed.
- The suppression gate ignores a verdict written before the job
finished, so the first run's verdict never applies to the rerun.

Together these keep the job blocking for good, and the PR needs `merge
-i`. Example: pytorch/pytorch#201104. Its
`linux-jammy-aarch64-py3.11-clang21 / build` job got `not_related` @
0.95 at 00:54:54Z, then attempt 2 finished at 01:13:57Z. In the last 7
days, 62 of 1,790 analyzed jobs had a later run that finished after the
dispatch and failed again.

The comment line and the badge also kept showing the first run's "not
related" for the rerun, which contradicts the gate. The badge image is
keyed only by sha + job and cached for a day.

## Change

- **Re-dispatch reruns.** A job whose run finished at or after the
latest live dispatch is dispatched again, reusing its budget slot. This
waits until the previous analysis has answered (a verdict newer than
that dispatch), so normally one analysis per key is in flight. drci.ts
now reads verdict rows before auto-dispatch for this, also when the
comment and suppression flags are off.
- **Bind a verdict to a run through its dispatch** (`verdictCoversRun`).
A verdict counts for a run only if the latest live dispatch was made
after the run finished and the verdict is newer than that dispatch. The
gate, the comment line and the badge all use this test. Before, the gate
only required the verdict to be newer than the job's completion. That
let an analysis of an earlier run that was still running when the rerun
finished clear the rerun, which is the "KNOWN GAP" in
`advisorSuppression.ts`. completed_at has whole-second precision, so a
dispatch only counts from the next second.
- **Dispatch row versions mark when evidence was captured.** Terminal
rows (`dispatched` / `failed`) are stamped 1ms after the pre-dispatch
row, which is written before the signal pattern is built, instead of at
confirmation time. The manual endpoint allocates its pre-dispatch
version before writing, so a write that persists but throws still sorts
below the terminal row.
- **Comment and badge.** A verdict that does not cover the run is not
shown. A live, unanswered, owed or retryable dispatch renders the
in-progress line, whose pending sentinel keeps the PR in the sweep. So
does a verdict whose key has no dispatch row while auto-dispatch is on,
since auto-dispatch will dispatch it. Any other verdict renders a new
"outdated" line. The badge URL carries `since=<completed_at>`, so each
run gets its own camo-cached image. URLs without it behave as before.
- drci.ts reads dispatch states once, after auto-dispatch, and shares
them between the line and the gate. If that read fails, the gate blocks
and the lines keep the sentinel.

Production check: all 1,838 `dr_ci_` verdicts from the last 7 days have
a live dispatch row older than the verdict, so the new gate does not
newly block existing first-run verdicts.

## Known limitations

- Verdict rows do not record which dispatch they answer. An earlier
analysis can still be counted for a later dispatch in two cases: two
renders dispatch the same key at the same moment, or GitHub accepts a
dispatch whose POST still throws, so it is recorded `failed` and
retried. Neither case is wider than main's current gap. Closing them
needs the advisor to write a dispatch id on the verdict row.
- ClickHouse ingest window: a rerun that finishes just before the first
dispatch but is not yet in `workflow_job` can still be cleared by an
earlier run's verdict. In a 2026-10-09 case, the job finished 12s before
the dispatch row and was inserted 46s after it. A follow-up PR will
record the analyzed job id on the dispatch row.
- The manual "AI Analyze" button still returns 409 for a key whose
latest row is live.

## Query performance

Both changed queries only add a column. WHERE clauses are unchanged.

| query | granules kept/total | elapsed before → after |
|---|---|---|
| `advisor_dispatch_states` (+ `max(version) AS latest_version`) | 2/6 |
0.55s → 0.71s (single run each, network-dominated) |
| `advisor_verdict_for_job` (+ `timestamp`) | 3/15 | 0.60s → 0.73s
(single run each, network-dominated) |

## Testing

`next lint`, `tsc` and `jest` pass locally. New tests cover rerun
re-dispatch and its serialization, dispatch-bound coverage in the gate,
line and badge selection (including a verdict with no dispatch row),
whole-second ordering, version stamping, and the verdict read with only
auto-dispatch on.
majing921201 pushed a commit to majing921201/pytorch that referenced this pull request Nov 16, 2026
…h#201104)

✴️ iz2: When a GitHub GraphQL call fails, mergebot's "Merge failed" comment put the whole query and its variables on the **Reason** line, about 40 lines of query text (example: pytorch#200980).

Now **Reason** shows only GitHub's error message, on one line (or "(no error message)" when the errors list is empty):

> **Reason**: GitHub GraphQL query failed: Something went wrong while executing your query on 2026-10-15T17:52:34Z. Please include `83C2:…` when reporting this issue.

The variables, raw errors and query move into "Details for Dev Infra team" as fenced blocks, each size-capped to keep the comment under GitHub's 65536-char limit. The same context also stays in the job log for every `gh_graphql` caller: `gh_graphql` prints it when it raises, and `GHGraphQLError` adds it as an exception note on Python 3.11+ (mergebot runs on 3.10, where tracebacks don't show notes). `handle_exception` becomes the module-level `format_failure_comment()` so it can be tested. The details block now also appears when there is a failing merge rule but `GH_RUN_URL` is unset.

**Exposure check:** the comment and log contain nothing sensitive. The token is sent as an HTTP header and never reaches the exception. The query text is already in this repo. The variables are owner, repo name, PR number and opaque pagination cursors. The request ID is the one GitHub asks you to share.

Test plan: `python -m unittest test_trymerge test_delete_old_branches` in `.github/scripts` (Python 3.12): 159 pass, 2 skipped. `TestFailureComment` covers the short reason, empty errors, the log output and note, the collapsed details, size caps, the merge-rule case and the no-details case.
Pull Request resolved: pytorch#201104
Approved by: https://github.com/huydhn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants