Skip to content

Use workflow_dispatch return_run_details to get run ID directly#19414

Merged
pelikhan merged 6 commits intomainfrom
copilot/implement-return-run-details
Mar 3, 2026
Merged

Use workflow_dispatch return_run_details to get run ID directly#19414
pelikhan merged 6 commits intomainfrom
copilot/implement-return-run-details

Conversation

Copy link
Contributor

Copilot AI commented Mar 3, 2026

The GitHub workflow_dispatch API (Feb 2026) now supports returning the run ID immediately via return_run_details: true, eliminating the need to poll gh run list after triggering a dispatch.

dispatch_workflow.cjs

  • Pass return_run_details: true to createWorkflowDispatch()
  • Log the returned workflow_run_id and include it in the handler result
  • Fall back gracefully for older GitHub Enterprise Server deployments: if the API returns 400/422 mentioning return_run_details, retry once without the parameter so dispatch continues to work on GHES versions that don't support the Feb 2026 API
try {
  response = await githubClient.rest.actions.createWorkflowDispatch({
    ...
    return_run_details: true,
  });
} catch (dispatchError) {
  // If GHES rejects return_run_details, retry without it
  if (isValidationStatus && mentionsReturnRunDetails) {
    response = await githubClient.rest.actions.createWorkflowDispatch({ ... });
  } else {
    throw dispatchError;
  }
}
const runId = response && response.data ? response.data.workflow_run_id : undefined;

run_workflow_execution.go

  • gh workflow run (v2.87+) now prints the run URL in stdout; parse the run ID from it directly instead of polling via getLatestWorkflowRunWithRetry
  • Falls back to polling for older gh CLI versions, preserving backward compatibility
  • The run URL regex supports both public GitHub (github.com) and GitHub Enterprise Server deployments (any HTTPS host)
if parsedRunInfo := parseRunInfoFromOutput(output); parsedRunInfo != nil {
    runInfo = parsedRunInfo
} else {
    runInfo, runErr = getLatestWorkflowRunWithRetry(lockFileName, opts.RepoOverride, opts.Verbose)
}
Original prompt

Implement return_run_details to retrieve the run if when calling workflow_dispatch.

  • the "gh run" should use the new api to retrieve the workflow id
  • The dispatch_workflow should log the run id value.

See https://github.blog/changelog/2026-02-19-workflow-dispatch-api-now-returns-run-ids/#:~:text=When%20you%20trigger%20a%20workflow,to%20the%20corresponding%20workflow%20run.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.



✨ PR Review Safe Output Test - Run 22623479111

💥 [THE END] — Illustrated by Smoke Claude ·


Use workflow_dispatch return_run_details to get run ID directly

  • Update dispatch_workflow.cjs: pass return_run_details: true to createWorkflowDispatch() and log the run ID
  • Update run_workflow_execution.go: parse run ID from gh workflow run stdout output (new in v2.87+), fall back to polling for backward compatibility
  • Add parseRunInfoFromOutput helper function with generic URL regex supporting all GitHub deployments (public + enterprise)
  • Update tests for dispatch_workflow.cjs to assert return_run_details: true, verify run_id in result, test no-run-id backward compat
  • Add TestParseRunInfoFromOutput unit tests including GHES URL cases
  • Add retry fallback in dispatch_workflow.cjs: if API returns 400/422 mentioning return_run_details, retry without it for older GHES compatibility
  • Add tests for retry fallback (422 with return_run_details mention → retry; 422 for unrelated reason → no retry)
  • All tests pass, lint and build pass
Original prompt

Implement return_run_details to retrieve the run if when calling workflow_dispatch.

  • the "gh run" should use the new api to retrieve the workflow id
  • The dispatch_workflow should log the run id value.

See (github.blog/redacted),to%20the%20corresponding%20workflow%20run.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey]((gh.io/redacted)



✨ PR Review Safe Output Test - Run 22623479111

💥 [THE END] — Illustrated by Smoke Claude ·

Changeset

  • Type: patch
  • Description: Ensures workflow dispatch logs the run ID by requesting return_run_details and parsing fallback output when needed.

Generated by Changeset Generator for issue #19414 ·

Warning

⚠️ Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • github.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "github.com"

See Network Configuration for more information.

…_dispatch

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement return_run_details for workflow_dispatch Use workflow_dispatch return_run_details to get run ID directly Mar 3, 2026

// runInfoURLRegexp matches GitHub Actions run URLs of the form:
// https://github.com/{owner}/{repo}/actions/runs/{run_id}
var runInfoURLRegexp = regexp.MustCompile(`https://github\.com/[^/\s]+/[^/\s]+/actions/runs/(\d+)`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot handle enterprise deployments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the regex in parseRunInfoFromOutput to match any HTTPS host instead of hardcoding github.com, so it works for GitHub Enterprise Server deployments (e.g., https://github.mycompany.com/...) automatically. Added GHES test cases to cover this. See commit c2e1f35.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review March 3, 2026 12:48
Copilot AI review requested due to automatic review settings March 3, 2026 12:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates workflow dispatch/run tooling to capture GitHub Actions run IDs immediately (via newer APIs/CLI output) and avoid post-dispatch polling when possible.

Changes:

  • Add parsing of gh workflow run output to extract the run URL/ID directly, with polling fallback for older gh versions.
  • Update the JS dispatch_workflow handler to request workflow_run_id via return_run_details: true, log it, and return it in the handler result.
  • Add/adjust unit tests covering run-info parsing and returned run_id.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
pkg/cli/run_workflow_execution.go Parse run URL/ID from gh workflow run output; fallback to existing polling logic.
pkg/cli/run_workflow_execution_test.go Add unit tests for extracting run info from gh output.
actions/setup/js/dispatch_workflow.cjs Request run details on dispatch; log and return run_id when present.
actions/setup/js/dispatch_workflow.test.cjs Update mocks/assertions for return_run_details + add tests for run_id handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 159 to 166
const response = await githubClient.rest.actions.createWorkflowDispatch({
owner: repo.owner,
repo: repo.repo,
workflow_id: workflowFile,
ref: ref,
inputs: inputs,
return_run_details: true,
});
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return_run_details: true is always sent to the REST API. Since this repo supports GitHub Enterprise (see many handlers using GITHUB_SERVER_URL), older GHES versions that don’t implement the Feb 2026 return_run_details parameter may reject the request (e.g., 400/422), causing dispatch to fail entirely. Consider attempting the dispatch with return_run_details: true and, on a validation/unknown-parameter error, retry once without return_run_details so dispatch remains backward compatible while still taking advantage of run IDs when supported.

See below for a potential fix:

      /** @type {import('@octokit/openapi-types').components["schemas"]["workflow-run"] | any} */
      let response;
      try {
        response = await githubClient.rest.actions.createWorkflowDispatch({
          owner: repo.owner,
          repo: repo.repo,
          workflow_id: workflowFile,
          ref: ref,
          inputs: inputs,
          return_run_details: true,
        });
      } catch (dispatchError) {
        const status = dispatchError && typeof dispatchError === "object" ? dispatchError.status : undefined;
        const message =
          dispatchError &&
          typeof dispatchError === "object" &&
          dispatchError.response &&
          dispatchError.response.data &&
          typeof dispatchError.response.data.message === "string"
            ? dispatchError.response.data.message
            : String(dispatchError);

        const isValidationStatus = status === 400 || status === 422;
        const mentionsReturnRunDetails =
          typeof message === "string" && message.toLowerCase().includes("return_run_details");

        if (isValidationStatus && mentionsReturnRunDetails) {
          core.info(
            "Workflow dispatch failed due to unsupported 'return_run_details' parameter; retrying without it for GitHub Enterprise compatibility."
          );
          response = await githubClient.rest.actions.createWorkflowDispatch({
            owner: repo.owner,
            repo: repo.repo,
            workflow_id: workflowFile,
            ref: ref,
            inputs: inputs,
          });
        } else {
          throw dispatchError;
        }
      }

      const runId = response && response.data ? response.data.workflow_run_id : undefined;

Copilot uses AI. Check for mistakes.
@pelikhan
Copy link
Contributor

pelikhan commented Mar 3, 2026

@copilot review comments

…lity

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 3, 2026

@copilot review comments

Addressed both review comments in commit 329c17f:

  1. dispatch_workflow.cjs now catches 400/422 errors from createWorkflowDispatch that mention return_run_details and retries once without the parameter, keeping dispatch working on older GHES deployments.
  2. Added three new tests covering: retry on 422 mentioning return_run_details, no retry on unrelated 422, and the existing no-run-id case.

@pelikhan pelikhan added the smoke label Mar 3, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

🌑 The shadows whisper... Smoke Codex failed. The oracle requires further meditation...

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

🎬 THE ENDSmoke Claude MISSION: ACCOMPLISHED! The hero saves the day! ✨

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

📰 BREAKING: Smoke Copilot is now investigating this pull request. Sources say the story is developing...

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

Commit pushed: e71a19f

Generated by Changeset Generator

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

Agent Container Tool Check

Tool Status Version
bash 5.2.21
sh available
git 2.53.0
jq 1.7
yq 4.52.4
curl 8.5.0
gh 2.87.3
node 20.20.0
python3 3.12.3
go 1.24.13
java 21.0.10
dotnet 10.0.102

Result: 12/12 tools available ✅

Overall Status: PASS

🔧 Tool validation by Agent Container Smoke Test ·

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

#19414 – Use workflow_dispatch return_run_details to get run ID directly
#19412 – Surface Copilot inference access errors in agent failure issues/comments

Overall: PASS (11/12 — Serena MCP unavailable)
CC @pelikhan @Copilot

📰 BREAKING: Report filed by Smoke Copilot ·

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean implementation of return_run_details support with graceful GHES fallback. The JS side correctly handles the API response and propagates run_id in the result. The Go side's parseRunInfoFromOutput eliminates polling overhead for modern gh CLI users while maintaining backward compatibility. Overall a well-structured change.

📰 BREAKING: Report filed by Smoke Copilot

const isValidationStatus = status === 400 || status === 422;
const mentionsReturnRunDetails = typeof message === "string" && message.toLowerCase().includes("return_run_details");

if (isValidationStatus && mentionsReturnRunDetails) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dual condition check (isValidationStatus && mentionsReturnRunDetails) is a great defensive approach — it prevents masking other 400/422 errors while still catching GHES-specific rejection of return_run_details. The message substring check could be brittle if GitHub changes the error wording, but this is a reasonable pragmatic tradeoff for compatibility.

// output of `gh workflow run` (v2.87+), which now returns the run URL.
// Returns nil if the run URL cannot be found in the output.
func parseRunInfoFromOutput(output string) *WorkflowRunInfo {
matches := runInfoURLRegexp.FindStringSubmatch(output)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex https://[^/\s]+/[^/\s]+/[^/\s]+/actions/runs/(\d+) correctly handles both github.com and GHES URLs. Nice use of FindStringSubmatch with fallback to nil — keeps the function cleanly nil-safe and integrates well with the caller's conditional logic.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

Smoke Test Results — Run §22624132898

Overall: PARTIAL (16 passed, 1 skipped)

Core Tests

Test Status
1. GitHub MCP (last 2 merged PRs)
2. Safe Inputs GH CLI
3. Serena MCP (16 symbols found)
4. Make Build
5. Playwright (github.com)
6. Tavily Web Search
7. File Writing
8. Bash Tool
9. Discussion Interaction (#19419)
10. Agentic Workflows MCP

PR Review Tests

Test Status
11. Update PR
12. PR Review Comments
13. Submit PR Review
14. Resolve Review Thread
15. Add Reviewer
16. Push to PR Branch
17. Close PR ⚠️ skipped

💥 [THE END] — Illustrated by Smoke Claude ·

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💥 Automated smoke test review - all systems nominal!

💥 [THE END] — Illustrated by Smoke Claude

@pelikhan pelikhan merged commit a86e657 into main Mar 3, 2026
49 checks passed
@pelikhan pelikhan deleted the copilot/implement-return-run-details branch March 3, 2026 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants