Skip to content

feat(ci): devops pr update --dispatch-ci starts ci.yml on each branch it updates, and only update-prs.yml may hold actions: write #984

Closed

Description

@dan-petty

Problem Statement

Split out of #842 (owner decision Q2, 2026-10-01: "#842 keeps steps 3-5, a new dispatch item sits between #754 and #842 in v0.2.27"). Owner order D3 needs the dispatch code merged and verified live (step 3) before required checks are enabled (step 4) and the cleanup/ADR pull request lands (step 5); one pull request cannot contain a change that must already be merged. Folding it into #754 is ruled out by #754's own D3: that item lands before update-prs.yml is given any privilege, and actions: write is that privilege. This item is D3 step 2.

Pushes made with GITHUB_TOKEN are not guaranteed to start workflows. .github/workflows/update-prs.yml has no privileged token to fall back to (the repository holds 0 Actions secrets, #842's finding of 2026-10-01; update-prs.yml:72,80 resolve to GITHUB_TOKEN), so the merge commits devops pr update creates sometimes get no check runs at all (on PR #828, bot commits 8675ec1 and 700385d have 0 check runs while d259b97 got the full set). With required checks on (#842 step 4), such a head would wait on checks that never start.

What exists at HEAD 9c879ae:

  • ci.yml already has a workflow_dispatch trigger with no inputs (.github/workflows/ci.yml:16). On that event Static Analysis and Tests & Coverage run (if: github.event_name != 'schedule', ci.yml:27,73) and DevContainer Image does not (ci.yml:103, pull_request into main only). A dispatched run groups by refs/heads/<branch> with cancel-in-progress: true (ci.yml:18-20).
  • devops pr update calls the asynchronous PUT repos/{owner}/{repo}/pulls/{n}/update-branch and returns on the 202 (src/devops_cli/commands/pr.py:1885-1958: _build_update_branch_cmd :1885-1895, _parse_update_error :1898-1911, _execute_update_branch :1914-1920, _update_single_pr :1923-1958). It fetches the pull request first (_fetch_pr_details, pr.py:228-249, called at pr.py:1938), so the pre-update head SHA is already in hand. There is no dispatch, poll or wait logic anywhere in src/devops_cli (grep -rn 'actions/workflows' src/devops_cli --include='*.py' matches nothing), and pr.py imports no time module (pr.py:5-11).
  • update-prs.yml holds contents, pull-requests and issues write (update-prs.yml:45-48). No workflow has actions: write (grep -n 'actions:' .github/workflows/*.yml finds only codeql.yml:39 actions: read), and no test guards which workflows may hold it.
  • run_gh treats gh api -X POST as a mutation (src/devops_cli/github/rate_limiter.py:484-509: _is_api_mutation matches the POST method argument, _is_mutation_command routes api calls to it), so a dispatch call goes through the same pacing and retry as the update-branch call.
  • tests/test_pr_update.py already stubs run_gh (:60,68), _fetch_pr_details (:115,139,165) and _execute_update_branch (:122,150,172) with CliRunner, so the new behaviour is testable offline in the same module.

Proposed Solution

Owner decisions carried from #842 (2026-10-01), on record because they replace any matching proposed answer:

One pull request:

  1. devops pr update --dispatch-ci. A new boolean option (default off) on update_pr (pr.py:2035-2085), passed through _update_all_prs and _process_candidate_pr_row (pr.py:1990-2032) to _update_single_pr (pr.py:1923-1958). With it on, after _execute_update_branch returns success, a new helper _dispatch_ci_for_head(target_repo, number, pr, pre_sha) (kept separate so _update_single_pr stays within the repository's limits: cyclomatic complexity 10 and nesting depth 5, DEFAULT_MAX_COMPLEXITY/DEFAULT_MAX_NESTING_DEPTH at src/devops_cli/config/defaults.py:677-678, enforced by devops scan complexity (src/devops_cli/commands/scan.py:410,440) and test_no_excessive_nesting_in_src (tests/test_architectural_invariants.py:146); ruff selects no C90 rule, pyproject.toml:93):
    • polls _fetch_pr_details until head.sha differs from the pre-update SHA read from the pull request fetched at pr.py:1938, at most DEFAULT_PR_UPDATE_HEAD_POLL_ATTEMPTS (6) attempts DEFAULT_PR_UPDATE_HEAD_POLL_INTERVAL_SECONDS (5.0) apart, both new constants in src/devops_cli/config/defaults.py beside DEFAULT_PR_MONITOR_* (defaults.py:720-722), sleeping through time.sleep with a module-level import time in devops_cli.commands.pr so tests patch devops_cli.commands.pr.time.sleep (the pattern tests/test_ai_gateway_tune.py:348 uses);
    • when the SHA changed, runs gh api -X POST repos/{owner}/{repo}/actions/workflows/ci.yml/dispatches -f ref=<head ref> built by _build_dispatch_ci_cmd(owner_repo, head_ref) in the shape of _build_update_branch_cmd (pr.py:1885-1895), with the workflow file name as CONST_CI_WORKFLOW_FILE = "ci.yml" in src/devops_cli/config/constants.py (beside CONST_GH_CLI, constants.py:676); no inputs, because ci.yml:16 declares none;
    • when the SHA did not change within the bound, or the head branch lives in a fork (head.repo is null or head.repo.full_name differs from the target repository, so no ref exists to dispatch on), or the dispatch call fails, dispatches nothing and reports why.
    • --dry-run returns before any call, as today (pr.py:1942-1947); nothing is polled or dispatched.
    • Outcome reporting: the single-PR path prints the dispatch result after the existing update_branch_success line (messages.py:498-500) and exits 1 when --dispatch-ci was asked for and nothing was dispatched after a successful update, except the fork case, which is reported and exits 0 because no dispatch was ever possible; the --all path adds the dispatch outcome to the status cell of the summary table and, as today (_update_all_prs returns None, pr.py:2008-2032), never exits non-zero for one row. When --dispatch-ci is off, output and exit codes are byte-for-byte what they are today. An update-branch failure dispatches nothing, as every failure path does today.
    • New strings live in src/devops_cli/lang/en/help.py (update_dispatch_ci, beside update_expected_head_sha, help.py:730-732) and src/devops_cli/lang/en/messages.py (dispatch success, head unchanged, fork head, dispatch failed, beside update_branch_*, messages.py:498-510).
  2. update-prs.yml. The update-pull-requests job gains actions: write under its existing permissions: (update-prs.yml:45-48); the three existing permissions, the GH_TOKEN expressions (:72,80), the on: block and the job if: (:37-42, as fix(ci): only collaborators can trigger pr updates with /update or /sync comments #754 leaves them) are unchanged. Each of the four uv run devops pr update invocations (update-prs.yml:88,98,104,110, line numbers as of HEAD; fix(ci): only collaborators can trigger pr updates with /update or /sync comments #754 moves expressions to env: first) gains --dispatch-ci. No ${{ }} enters a run: block, so fix(ci): only collaborators can trigger pr updates with /update or /sync comments #754's contract test keeps passing.
  3. Workflow contract assertions in tests/test_workflow_contracts.py (created by fix(ci): only collaborators can trigger pr updates with /update or /sync comments #754, parsing update-prs.yml with PyYAML): the update-pull-requests job's permissions map equals {contents: write, pull-requests: write, issues: write, actions: write}, and every run: value that contains devops pr update also contains --dispatch-ci.
  4. The allowlist invariant in tests/test_architectural_invariants.py, next to the ci.yml and Dockerfile check (_ci_image_content_paths and test_devcontainer_image_path_filter_covers_dockerfile_sources, :416-495, which already parse ci.yml with PyYAML at :418-420), parsing every .github/workflows/*.yml:
  5. Docs and records. devops docs generate refreshes docs/commands/pr.md:276 and docs/CLI_REFERENCE.md:5820 for the new option; changelog.d/<issue>.md under ### Added; docs/agent/tasks/task-<issue>-pr-update-dispatches-ci.md written as Done in the delivering commit (docs/agent/tasks/README.md, rules 3-5).

Scope

Key Questions

All answered; the two carried from #842 are decided here with the recommendations its verdict gave.

  • Where does the dispatch live: _update_single_pr or a shell loop in update-prs.yml? Answered: _update_single_pr, through a helper. It keeps every update-prs.yml call a one-line uv run devops pr update ... (:88,98,104,110), it is testable offline where tests/test_pr_update.py already stubs run_gh and _fetch_pr_details, and a shell loop would have to re-fetch the head SHA with expressions fix(ci): only collaborators can trigger pr updates with /update or /sync comments #754 just removed from run:.
  • How does the dispatch target the new head when update-branch returns 202 before the merge commit exists? Answered: poll the pull request's head.sha until it differs from the pre-update SHA, bounded (6 attempts, 5 s apart), then dispatch on the head branch; dispatch nothing when it did not change. Dispatching immediately after the 202 would run ci.yml on the old SHA and report a green that belongs to the previous head. The head branch tip is the merge commit, so a workflow_dispatch run on refs/heads/<branch> attaches its check runs to the pull request's head SHA, which is what a required check reads.
  • Always dispatch, or behind an option? Answered: behind --dispatch-ci, default off, which update-prs.yml passes. A person running devops pr update with their own token pushes a merge commit that already starts pull_request: synchronize runs; a dispatch there would double every run (the pull_request group is refs/pull/<n>/merge and the dispatch group is refs/heads/<branch>, ci.yml:19, so neither cancels the other). Only GITHUB_TOKEN pushes need the dispatch.
  • What about pull requests from forks? Answered: no dispatch, with a message naming the fork, exit 0. workflow_dispatch takes a ref in this repository; a fork head has none. Fork pull requests get their runs from the pull_request event when the author pushes, and update-branch on a fork needs maintainer edits enabled, so this path is rare and reported rather than hidden.
  • Does the dispatched run count as the pull request's check? Answered: yes. Check runs attach to a commit SHA; the dispatched run checks out the head branch at the merge commit, which is the pull request head. chore(github): required CI checks bind merges into release and main, and ADR 0004 records the verification policy #842 step 3 confirms this live before step 4 turns the requirement on.
  • Why an invariant rather than a comment on the permission? Answered: actions: write lets a workflow create runs of any workflow in the repository. The allowlist keeps that privilege on the one job fix(ci): only collaborators can trigger pr updates with /update or /sync comments #754 gated, and a second workflow cannot gain it without changing the test and its recorded reason. It lands after refactor(ci): github ci runs the gate through devops ci from one check table #843 because it also pins the ci.yml properties the dispatch relies on (workflow_dispatch present, both pinned jobs admitting it).
  • Which complexity limit does the helper split answer? Answered: not a ruff one. pyproject.toml:93 selects no C90 rule; the limits in force are devops scan complexity (complexity 10, nesting 5, defaults.py:677-678) and the nesting invariant at tests/test_architectural_invariants.py:146. The split keeps _update_single_pr a straight line through fetch, dry-run, update and report.

Acceptance Criteria

  • uv run pytest tests/test_pr_update.py -q passes with these new tests, each with run_gh, _fetch_pr_details, _execute_update_branch and devops_cli.commands.pr.time.sleep patched and no socket opened:
    • _build_dispatch_ci_cmd("owner/repo", "feat/x") returns ["gh", "api", "-X", "POST", "repos/owner/repo/actions/workflows/ci.yml/dispatches", "-f", "ref=feat/x"].
    • update 42 --repo owner/repo --dispatch-ci, with _fetch_pr_details returning head.sha old on the first call and new on the second: exactly one run_gh call is the dispatch argv above with ref=feat/my-branch, the output names the dispatch, exit code 0.
    • the same invocation without --dispatch-ci: zero dispatch calls, no sleep, and the output is what test_update_single_pr_cli_success (tests/test_pr_update.py:110-130) asserts today.
    • head.sha never changes: sleep is called with DEFAULT_PR_UPDATE_HEAD_POLL_INTERVAL_SECONDS at most DEFAULT_PR_UPDATE_HEAD_POLL_ATTEMPTS times, no dispatch call, the output says the head did not change, exit code 1.
    • head.repo.full_name is other/repo: no poll, no dispatch, the output names the fork, exit code 0.
    • the dispatch run_gh call returns non-zero: the output carries the parsed API message (_parse_update_error, pr.py:1898-1911), exit code 1.
    • update 42 --repo owner/repo --dispatch-ci --dry-run: no poll, no sleep, no dispatch; test_update_single_pr_cli_dry_run (:133-157) still passes.
    • update --all --repo owner/repo --dispatch-ci: _update_single_pr is called with dispatch_ci=True for the non-draft row, the draft row is still skipped, and the status cell of the updated row names the dispatch outcome; test_update_all_prs_cli (:183-206) and test_process_candidate_pr_row (:78-107) pass unchanged without the option.
  • uv run pytest tests/test_workflow_contracts.py -q passes with two new assertions: the update-pull-requests job's permissions equals {contents: write, pull-requests: write, issues: write, actions: write}, and every run: value containing devops pr update also contains --dispatch-ci. fix(ci): only collaborators can trigger pr updates with /update or /sync comments #754's assertions (job if: guard, no ${{ in any run:) still pass on the edited file.
  • The allowlist invariant in tests/test_architectural_invariants.py passes on the real workflows, and the builder makes each of these edits locally, watches uv run pytest tests/test_architectural_invariants.py -k <new test name> fail, reverts it and notes the result in the pull request: actions: write added to the release.yml job; actions: write removed from update-prs.yml; workflow_dispatch removed from ci.yml's on:; the Static Analysis job's if: changed to github.event_name == 'pull_request'. The test runs under 1 s (uv run pytest --durations=5 tests/test_architectural_invariants.py).
  • grep -n 'actions:' .github/workflows/*.yml prints exactly codeql.yml actions: read and update-prs.yml actions: write; grep -c -- '--dispatch-ci' .github/workflows/update-prs.yml prints 4; grep -n '\${{' .github/workflows/update-prs.yml matches only concurrency.group and env: value lines, as fix(ci): only collaborators can trigger pr updates with /update or /sync comments #754 leaves it.
  • uv run actionlint exits 0.
  • uv run devops pr update --help lists --dispatch-ci with its help text; uv run devops docs check passes (the docs row of uv run devops ci, src/devops_cli/commands/ci.py:442-448) after docs/commands/pr.md and docs/CLI_REFERENCE.md are regenerated.
  • grep -rn '"ci.yml"' src/devops_cli --include='*.py' matches only CONST_CI_WORKFLOW_FILE in src/devops_cli/config/constants.py (it matches nothing today); rg -n 'DEFAULT_PR_UPDATE_HEAD_POLL' src/devops_cli/config/defaults.py prints the two constants; grep -n '^import time' src/devops_cli/commands/pr.py prints one line.
  • uv run devops scan complexity src/devops_cli/commands/pr.py reports within limits, as at HEAD; git diff main...HEAD -- src | grep -c 'noqa\|nosec' prints 0.
  • uv run devops ci passes offline; uv run pytest --durations=10 tests/test_pr_update.py tests/test_workflow_contracts.py shows every test under 1 s.
  • changelog.d/<issue>.md exists under ### Added, docs/agent/tasks/task-<issue>-pr-update-dispatches-ci.md passes tests/test_agent_task_files.py, and uv run devops pr check-readiness passes with no CHANGELOG.md or docs/ROADMAP.md change.

Out of Scope

Dependencies

Readiness check (2026-10-04)

Re-checked at b61e5a0 (release/v0.2.26). #843 and #741 are merged. #754 is open and earlier in v0.2.27, so tests/test_workflow_contracts.py does not exist yet, as planned. update-prs.yml is unchanged (its cited lines hold).

Corrected locations (under src/devops_cli/):

  • commands/pr.py:
    • _fetch_pr_details is at :231, called at :2007; the dry-run branch is at :2012-2017.
    • _build_update_branch_cmd :1955-1965, _parse_update_error :1968-1981, _execute_update_branch :1984-1990, _update_single_pr :1993-2027.
    • _process_candidate_pr_row :2060-2075, _update_all_prs :2078-2103, update_pr :2105-2155.
    • Imports are at :5-11, still without time.
  • Write pacing (fix(github): GraphQL mutations and implicit-POST gh api writes get the rate limiter's mutation pacing, decided from the request gh sends #1125): _is_api_mutation and _is_mutation_command (rate_limiter.py:484-509) are gone. run_gh classifies through is_write_gh_command (github/request_classifier.py:79, called at github/rate_limiter.py:1932). It parses gh api's own flags (:162-182), so the dispatch POST is still a paced write.
  • Config: DEFAULT_MAX_COMPLEXITY config/defaults.py:695, DEFAULT_MAX_NESTING_DEPTH :699, DEFAULT_PR_MONITOR_* :741-743; CONST_GH_CLI config/constants.py:884.
  • Complexity: ruff now selects C901 with max-complexity = 10 (pyproject.toml:94-97, :109-110, feat(cli): enforce the complexity cap with ruff C901 and an inline baseline that only shrinks #586). The last key question's "not a ruff one" is stale: the helper split answers ruff C901 as well as devops scan complexity and the nesting invariant (now tests/test_architectural_invariants.py:170). The no-noqa criterion covers C901.
  • tests/test_architectural_invariants.py:
  • ci.yml as refactor(ci): github ci runs the gate through devops ci from one check table #843 left it:
    • Static Analysis is at :26 and Tests & Coverage at :46; both have if: github.event_name != 'schedule' (:27, :47).
    • The DevContainer Image if: is at :71; workflow_dispatch is at :16, concurrency at :18-20.
  • The actionlint and docs rows are in get_check_specs() at commands/ci.py:438-444 and :445-452.
  • Strings:
    • help.py update_expected_head_sha is at :788.
    • messages.py update_branch_* is at :575-586; the unused already_up_to_date and conflict are at :580 and :584.
  • Other moved lines:
    • ai/mcp/server.py pr_update_branch is at :2349. It shells out to the CLI, so its test is unaffected.
    • The tests/conftest.py network guard is at :100.
    • Generated docs: docs/commands/pr.md:297 and docs/CLI_REFERENCE.md:6055 and :7117.

Rule alignment. The owner's dry-run rule (2026-10-04, #412; #886 amendment): no external request, reads included; return the ordered PlannedRequests (dry_run/requests.py).

"--dry-run returns before any call, as today" does not hold at HEAD. _update_single_pr reads the PR (_fetch_pr_details, :2007) before its dry-run return (:2012), and --all lists PRs (_fetch_open_prs, gh pr list) under a dry run. This item edits these functions, so its dry run follows the rule. The criterion that output stays byte-for-byte with --dispatch-ci off applies to real runs.

  • update 42 --repo owner/repo [--dispatch-ci] --dry-run makes no request: run_gh, _fetch_pr_details and time.sleep record zero calls, and it exits 0. It prints with render_request_plan, in order:

    • the PR read;
    • the update-branch PUT;
    • with --dispatch-ci, the head poll (repeat: up to DEFAULT_PR_UPDATE_HEAD_POLL_ATTEMPTS, DEFAULT_PR_UPDATE_HEAD_POLL_INTERVAL_SECONDS apart);
    • with --dispatch-ci, the dispatch POST (condition: the head changed and lives in this repository).

    Values a read would supply appear as <placeholders>. test_update_single_pr_cli_dry_run (tests/test_pr_update.py:133-157) also asserts zero _fetch_pr_details calls.

  • update --all --repo owner/repo [--dispatch-ci] --dry-run makes no request. It plans the gh pr list read, then the per-PR requests with repeat "each open non-draft PR". The local git branch -a in _detect_active_release_branch (pr.py:76-94) may still run.

Ready: no open question, #843 merged and #754 earlier in v0.2.27, one PR, effort Medium.

Activity

  1. added this to the v0.2.27 milestone on Oct 2, 2026
  2. added
    type/feature
    scope/github
    priority/p1-high
    scope/ci
    on Oct 2, 2026
  3. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    The Secret is now devops-cli in namespace devops, key GH_TOKEN (#741, 2026-10-03).

  4. dan-petty-bot commented on Oct 5, 2026

    @dan-petty-bot
    Collaborator

    What changed

    #1194, merged into release/v0.2.27 as 4fb18bf.

    Summary

    Resolves #984.

    This PR adds --dispatch-ci to devops pr update and devops pr update --all to poll the PR head commit SHA until it updates, and then trigger ci.yml via GitHub Actions workflow dispatch. In addition, actions: write permission is strictly limited to the update-pull-requests job in .github/workflows/update-prs.yml, guarded by architectural invariants.

    14 file(s) changed.

    How it was verified

    Check runs at 4578eb1:

    • Prune PR DevContainer Images: pass
    • CodeQL: pass
    • Service Image: skipping
    • Static Analysis: pass
    • Analyze (actions): pass
    • Analyze (python): pass
    • Tests & Coverage: pass
    • DevContainer Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-984-pr-update-dispatches-ci.md:

    • --dispatch-ci flag added to devops pr update CLI options and help text.
    • PR update polls head commit SHA up to configured attempts before dispatching ci.yml.
    • Fork head branches are excluded with informative message and exit code 0.
    • Dry-run renders request plan without making remote GitHub requests.
    • All 4 update commands in .github/workflows/update-prs.yml include --dispatch-ci.
    • update-prs.yml holds actions: write permission for update-pull-requests.
    • Architectural invariant enforces that only update-prs.yml holds actions: write and ci.yml admits workflow_dispatch.
    • Unit and workflow contract tests pass with 100% test coverage.
    • Changelog fragment changelog.d/984.md is present.
    • uv run devops ci passes with 100% green status across all quality gates.
    • Pending a person: Merged workflow execution in .github/workflows/update-prs.yml triggers ci.yml on updated pull requests.
  5. added a commit that references this issue on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p1-highscope/ciscope/githubtype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions