Skip to content

feat(roadmap): handle closed plan PRs from GitHub webhooks #4414

Done

Description

@dan-petty

Problem or Motivation

When a person merges or closes a staged plan pull request (Plans #<issue>), the Service does not react to the GitHub pull_request closed event. Instead, two separate polling timers delay the next step.

First, when a person merges a plan pull request at Gate G1 (merged=true), the item waits up to 7 minutes. Only then does implement_submit.py sync the label to status/planned (status_sync.py) and submit a devops-cli-runner Job.

Second, when a person closes a plan pull request unmerged (merged=false), the item waits up to 37 minutes. During that window, the issue stays Ready until stage_rejected.py runs in the next stage round.

Proposed Solution & Architectural Design

  • Subscribe to pull_request in CONST_ROADMAP_WEBHOOK_EVENTS and parse number, state, merged, and closed_at in GitHubWebhookPayload.
  • Add scoped ("pull_request", "closed") handling in src/devops_cli/server/routes/webhooks.py and src/devops_cli/roadmap/run.py.
  • When merged is True, enqueue a status lane update to fetch the clone, run sync_statuses, and call run_implement_round.
  • When merged is False, enqueue a scoped update (stage_rejected.py) to check whether an open item records stage.pr == number.
  • For a rejected plan, copy the trusted reason, delete a session-only branch, record stage.rejected, and set status/new.
  • Ignore closed pull requests that match no staged item, and keep the reconciling polls intact (ADR 0017).
  • Keep open-draft stage_ready check handling separate so this item covers only ("pull_request", "closed") merge and rejection transitions.

Target Subsystem

SDLC, Git & PR Governance

Existing Tool Considered

GitHub Actions can trigger on pull_request: [closed], and gidgethub parses webhook payloads. However, ADR 0008 and ADR 0015 keep ClusterJobs submission and roadmap records inside roadmap-service, not in GitHub-hosted workflows. Wiring ("pull_request", "closed") to implement_submit.py and stage_rejected.py costs about 120,000 tokens to build, maintain, and fix, and 3 hours of elapsed time.

Acceptance Criteria

  • A pull_request closed webhook with merged=true syncs status/planned and submits the next eligible implement Job when none runs.
  • A pull_request closed webhook with merged=false for stage.pr records stage.rejected, comments the reason, deletes a session branch, and sets status/new.
  • A closed pull request unrelated to roadmap items leaves all items unchanged and calls no LLM.
  • Offline unit tests verify both merged=true and merged=false webhook deliveries, and k8s/README.md documents the event flow.

Standards Compliance

  • I confirm this proposal aligns with AGENTS.md engineering principles (cyclomatic complexity <= 10, nesting <= 5, zero bare exceptions, tests that cover the changed lines).
  • I am willing to submit a pull request implementing this feature with accompanying tests.

Alternatives check of 2026-11-21: in-use.
The repository already uses this tool.
Tool: gidgethub/gidgethub (https://github.com/gidgethub/gidgethub), Apache-2.0, last activity 2026-11-20, maintained.
Reason: Searches found no tool that performs the roadmap transitions; gidgethub, already the project's GitHub session, parses and routes the pull_request closed delivery, but the status sync, Job submit and plan rejection remain project code.

Covers:

  • Parses and validates GitHub webhook deliveries
  • Routes an event to its per-action handler
  • Async GitHub API reads of the pull request state
  • Already the project's GitHub request session

Lacks:

  • Batch-key due rows for the stage and implement lanes
  • Label sync to status/planned and runner Job submit
  • Session branch delete, rejection comment and status/new
  • Webhook event subscription and router wiring

Proposed design

Problem statement

The roadmap Service reacts to a closed plan pull request only at its next poll. A merged plan waits up to 7 minutes for the implement Job. A plan closed with no merge waits up to 37 minutes for the stage rejection. This item adds the ("webhook", "pull_request", "closed") batch key to the stage and implement rows of DEFAULT_DUE_TABLE. Their existing rounds then run on the delivery. #4413 adds the event subscription and the trigger.

Acceptance criteria

Requirement: Closed pull request batch key

The stage and implement rows of DEFAULT_DUE_TABLE SHALL declare the batch key ("webhook", "pull_request", "closed") in their batch_keys.

Scenario: Closed pull request makes both rows due

  • WHEN a test asks each row of DEFAULT_DUE_TABLE whether it is due with the batch {("webhook", "pull_request", "closed"): 1}
  • THEN the stage and implement rows are due, and each other row is not due with that batch.

Requirement: Merged plan pull request

A pull_request closed delivery for a merged plan pull request SHALL make the implement row set status/planned and create the next runner Job.

Scenario: Merged plan pull request

  • WHEN a test runs the implement row with the closed batch for an item whose stage.pr is the closed number and whose change folder is on the default branch
  • THEN the item label is status/planned and one devops-cli-runner Job is created for the item.

Requirement: Unmerged closed plan pull request

An unmerged closed plan pull request SHALL make the stage row record stage.rejected, delete the session-only branch and set status/new.

Scenario: Rejected plan pull request

  • WHEN a test runs the stage row with the closed batch for an item whose stage.pr is the closed number and whose pull request is closed with no merge
  • THEN the item records stage.rejected, its newest comment holds the reason, the session-only branch is gone and the label is status/new.

Requirement: Unrelated closed pull request

A pull_request closed delivery for a number no open item records SHALL change no item, create no Job and make no model call.

Scenario: Closed pull request of no roadmap item

  • WHEN a test runs the stage and implement rows with the closed batch and a number that no open item records
  • THEN no item changes, no runner Job is created and no model request is recorded.

Existing Tool Considered

gidgethub (verdict in-use, https://github.com/gidgethub/gidgethub, Apache-2.0, maintained) is the existing tool. The reason is that the repository already uses gidgethub for GitHub deliveries, and no tool performs the roadmap transitions. The alternatives check in the issue body records what the tool covers and lacks. The proposal adds the ("webhook", "pull_request", "closed") batch key to the stage and implement rows. Their existing rounds do the status sync, runner Job submit, rejection comment, branch delete and status/new. The proposal builds no new parsing code.

Key questions

  • How does a pull_request closed delivery make the roadmap work start?: The consumer enqueues a trigger for the event and action when the payload holds no issue number. A row that declares ("webhook", "pull_request", "closed") in its batch_keys becomes due and runs its round. The delivery cache drops a repeated delivery id. (best practice) [sources: src/devops_cli/server/routes/webhooks.py, src/devops_cli/roadmap/run.py:1190, tests/roadmap/test_roadmap_run_webhook_keys.py]
    • Chosen: Batch key on the stage and implement rows. The router already enqueues a trigger for a subscribed event with no subject. The row's own batch_keys decide whether it runs.
    • Rejected: New status-lane handler. It duplicates the implement row and needs a clone that the handler does not have.
    • Rejected: Scoped runner that calls stage_rejected.py. The router builds a scoped delivery only when the payload holds an issue number, and a pull_request payload holds none.
  • Does the change add a payload model for the pull_request delivery?: No. GitHubWebhookPayload validates the delivery, and the router reads payload.issue only when the payload holds it. The trigger carries the event and the action. Each row reads the pull request from GitHub for the merge state, the reason and the branch. (best practice) [sources: src/devops_cli/models/webhooks.py:43, src/devops_cli/server/routes/webhooks.py]
    • Chosen: No new payload model. The batch key matches on event and action, and each row reads the pull request anyway. A model would add fields that no code reads.
    • Rejected: A WebhookPullRequest model with number, state, merged and closed_at. Nothing reads those fields. The rows read the merge state, the reason and the branch from GitHub.
    • Rejected: Flat pull request fields on GitHubWebhookPayload. It carries the same unread fields and mixes issue fields with pull request fields in one model.
  • Which row handles a merged plan pull request, and which calls run?: The implement row, on its own lane. Its round runs implement_submit.py, which syncs the status labels and creates the runner Job of the first item with no Job. (best practice) [sources: src/devops_cli/roadmap/implement/implement_submit.py, src/devops_cli/roadmap/run.py:1190, src/devops_cli/k8s/cluster_job_api.py:187]
    • Chosen: The implement row, made due by the batch key. The row owns the status sync and the Job create, runs in its own lane and needs no new clone.
    • Rejected: A new status-lane handler that fetches a clone. It duplicates the implement row and needs a clone that the handler does not have.
    • Rejected: Only the watch row's status sync. It writes the label but submits no Job, so the Job waits for the next implement interval.
  • Which row handles an unmerged closed plan pull request, and which calls run?: The stage row, on its own lane. Its round runs stage_rejected.py, which deletes the session-only branch, comments the reason, records stage.rejected and returns the item to New. The stage row already holds the clone that the branch delete needs. (best practice) [sources: src/devops_cli/roadmap/stage/stage_rejected.py, src/devops_cli/roadmap/stage/stage_submit.py, src/devops_cli/roadmap/run.py:1190]
    • Chosen: The stage row, made due by the batch key. The stage round already finds a closed unmerged plan, writes the rejection and holds the clone.
    • Rejected: A new scoped update that calls stage_rejected.py. The branch delete needs the stage row's clone, and the stage row already owns the write.
    • Rejected: The watch row. The watch row has no clone and writes no rejection. The rejection lives in the stage round.
  • What happens when a closed pull request matches no staged item?: Nothing. Each row selects by stage.pr and by the plans on the default branch. A number that no item records matches no item. No item changes, no Job is created and no model call is made. [sources: src/devops_cli/roadmap/implement/implement_submit.py, src/devops_cli/roadmap/stage/stage_rejected.py]
  • Do the reconciling polls stay after the webhook handles the closed event?: Yes. The sweep stays the source of truth, and the webhook only cuts the delay. GitHub never sends a failed delivery again. (best practice) [sources: docs/adr/0017-each-subscribed-webhook-event-runs-the-update-scoped-to-it.md, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md]
    • Chosen: Keep the polls. ADR 0017 keeps the poll as the reconciler, and ADR 0021 keeps the sweep as the source of truth.
    • Rejected: Remove the polls. A lost delivery or a label change would never be seen again.
  • Which document holds the closed plan pull request flow?: docs/CLUSTER.md. Its roadmap service section holds the webhook setup and the row triggers. The flow, the two outcomes and the new key go there. The body's k8s/README.md documents the cluster, not the service webhook flow. (best practice) [sources: docs/CLUSTER.md, CONTEXT.md]
    • Chosen: docs/CLUSTER.md. The roadmap service setup steps, the lanes and the row triggers live in this document.
    • Rejected: k8s/README.md. It documents the cluster manifests, and it holds no webhook step of the Service.
    • Rejected: docs/ROADMAP_WORKFLOW.md. It documents the workflow of an item, not the setup of the Service.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#4413

Activity

  1. added
    source/agent
    type/feature
    scope/roadmap
    status/new
    value/medium
    effort/medium
    on Nov 10, 2026
  2. dan-petty commented on Nov 10, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. It removes 7 to 37 minute delays but the polling fallback still works, so it is an improvement not a blocker.
    • Value: Medium. Users wait minutes less per plan PR transition, which speeds the roadmap pipeline but does not change correctness.
    • Effort: Medium. The body estimates about 120,000 tokens and 3 hours of work across webhook parsing, two code paths, tests, and docs.
    • Related: feat(roadmap): PR, review and check events start a scoped sweep #4413, which asks for a different change. Both subscribe to pull_request webhooks to replace polling, but #4413 triggers stage_ready on open drafts while the candidate triggers implement_submit and stage_rejected on closed PRs.
  3. added
    priority/p2-medium
    on Nov 10, 2026
  4. devops-cli-service commented on Nov 10, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 1ca0133 until a person answers the questions below. Reply in a comment or edit the body, and the next refine round looks at the item again.

    • Who adds the pull_request event to each repository's webhook? (a person decides)
  5. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Alternatives check: in-use

    Reason: gidgethub is an open, maintained Python library that parses and validates GitHub webhook deliveries and routes them by event type and action, so it covers the pull_request payload parsing and dispatch part of this item and is already the project's GitHub client (ADR 0006). It does not cover the roadmap-specific transitions (status sync and implement submission, or stage.rejected and branch deletion), which remain code in this service.

    The item already names this tool.

    Tool: gidgethub/gidgethub (https://github.com/gidgethub/gidgethub)

    • License: Apache-2.0
    • Last activity: 2026-09-25
    • Maintained: yes

    Covers:

    • Parses GitHub webhook deliveries, including pull request payload fields such as number, state, merged and closed_at.
    • Dispatches a delivery by event type and action, so a ("pull_request", "closed") delivery can be routed to a handler.
    • Validates the signature of an incoming webhook delivery.
    • It is the project's GitHub client, chosen in ADR 0006, so the parsing half of the item needs no new dependency.

    Lacks:

    • No status-lane work: it does not fetch the clone, run sync_statuses or call run_implement_round.
    • No rejection path: it does not record stage.rejected, copy the trusted reason comment, delete a session-only branch or set status/new.
    • No lane, queue or ClusterJobs submission, and no delivery cache for the roadmap consumer.
    • It cannot add the pull_request event to each repository's webhook; a person must do that after deploy.

    Tools considered:

    Searches run:

    • Python library handle GitHub pull_request closed webhook event, results: 5
    • gidgethub parse GitHub webhook events pull_request payload, results: 5
    • github webhook event router library, results: 5
    • gidgethub, results: 5
    • gidgethub routing Router add pull_request action webhook documentation, results: 5
    • gidgethub readthedocs sansio Event validate_event routing, results: 5

    Sources:

    Checked on 2026-11-11. A person decides what this means for the item. The check changes no label and closes no issue.

  6. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    Scope update from the Service step jobs plan (#5014).

    This issue folds into #4413 (pr-events). That item covers this scope with the other repeated steps. Close this issue with evidence after the pull request of that item merges. The pull request body names only its own issue after a closing keyword.

  7. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 3d6cae6 until a person answers the questions below. Reply in a comment or edit the body, and the next refine round looks at the item again.

    • Who adds the pull_request event to each managed repository's webhook? (a person decides)
  8. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor

    Owner question: See the first point of Open questions in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  9. devops-cli-service commented on Nov 21, 2026

    @devops-cli-service
    Contributor

    Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies and Watched files in the section Proposed design of the body.

  10. 15 remaining items

  11. added
    status/planned
    owner/service
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/planned
    status/in-progress
    on Nov 24, 2026
  12. devops-cli-service commented on Nov 24, 2026

    @devops-cli-service
    Contributor

    The draft pull request #6945 holds the final title and body. In mode on of roadmap.fix_checks.mode, the watch row marks it ready when its checks pass, and a fix-checks Job repairs a failed check whose name gives the class test, lint or types. In each other case the watch row stops the item: another failed check, a cancelled check, a conflict, a fix-checks Job that ended with no repair, or another mode.

    Spend: 158 model requests, 13694018 input tokens, 61538 output tokens.

  13. removed
    owner/service
    on Nov 24, 2026
  14. removed
    status/in-review
    on Nov 24, 2026
  15. devops-cli-service commented on Nov 24, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-24 13:45 UTC

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

    effort/mediumpriority/p2-mediumscope/roadmapsource/agenttype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions