Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ On 2026-10-09 the owner decided that each subscribed event runs, at once, the up

## Consequences

- The roadmap consumer still makes a whole round for each delivery until it gives each subscribed event to its scoped update, the second part of #1533. The live check, a real delivery of each subscribed event, waits until the Service runs again.
- The roadmap consumer gives each subscribed event to its scoped update on the lane that the table names, queueing no full round (#1533). The live check, a real delivery of each subscribed event, waits until the Service runs again.
- A delivery of `issues` `edited` about an issue that is already an Item decides nothing.
- Intake's hourly interval stays for the candidates that no delivery names.
- The delivery target of ADR 0009 stays the one seam between the router and the jobs. A move of the delivery to another engine changes only that target.
2 changes: 1 addition & 1 deletion k8s/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ kubectl -n devops logs -f job/<name>
5. `devops cloudflare tunnel routes`. If no route covers the webhook host, add one in the dashboard, not with `tunnel sync` (#794).
6. `devops cloudflare access status`, then add a Bypass application for `hooks.<domain>/webhooks/github`.
7. `devops k8s deploy-stack --stack devops` (or `--stack all`).
8. Add each repo's webhook: `https://hooks.<domain>/webhooks/github`, `application/json`, that repo's secret, and only the Issues event. The roadmap consumer takes only the Issues event, and only an issue that opens or reopens starts a round before the next poll ([ADR 0009](../docs/adr/0009-one-webhook-router-delivers-each-event-to-the-consumers-subscribed-to-it.md), #1386). The Service acknowledges an event with no subscriber, a push included, and starts no round for it, but each such delivery uses the rate limit of the route (Webhook route) and writes a log line. Check the hooks of each repository: `uv run devops gh api repos/<owner>/<name>/hooks --jq '.[]|{id,active,events,code:.last_response.code}'`. Each hook must be `active`, its `events` must be `["issues"]`, and after its first delivery its `code` must be 200 or 202. Change a hook in the repository's settings (Settings > Webhooks). `devops` has no command that changes a hook.
8. Add each repo's webhook: `https://hooks.<domain>/webhooks/github`, `application/json`, that repo's secret, and only the Issues event. The roadmap consumer takes the Issues event. An issue that opens, edits or reopens runs intake of that one issue on the model lane at once and queues no full round ([ADR 0017](../docs/adr/0017-each-subscribed-webhook-event-runs-the-update-scoped-to-it.md), #1533). The 5-minute poll reconciles board edits and lost deliveries. The Service acknowledges an event with no subscriber, a push included, and starts no round for it, but each such delivery uses the rate limit of the route (Webhook route) and writes a log line. Check the hooks of each repository: `uv run devops gh api repos/<owner>/<name>/hooks --jq '.[]|{id,active,events,code:.last_response.code}'`. Each hook must be `active`, its `events` must be `["issues"]`, and after its first delivery its `code` must be 200 or 202. Change a hook in the repository's settings (Settings > Webhooks). `devops` has no command that changes a hook.
9. To rotate a credential, update it in the keyring: `uv run devops config set service.webhook_secrets`, or, for the App, generate a new private key and run `uv run devops config set service.github_app.private_key --from-file <key.pem>`. Then run `uv run devops k8s push-secrets --only devops/devops-cli --rotate`. It restarts `roadmap-service`. Delete the old private key on the App's page after the restart.
10. Run one service per set of repos. While it runs, use `devops roadmap run --dry-run` (#981).
11. The Service keeps three files in `/home/devops/.data/roadmap/` on volume `roadmap-service-home`, beside the `schedule.json` of each repository: `service-halt.json` (GitHub refused the identity), `service-budget.json` (the GitHub requests of the last hour) and `service-failures.json` (the jobs that failed rounds in a row). A restart reads them back, so a restart does not clear a halt, the budget or a suspended job. A round that ends because the Service is stopping, for example in a rollout, does not count as a failed round: the count of its job stays as it was. The log line that suspends a job names the class of the error of each of its failed rounds in a row; the file keeps only the count, so a round that an earlier process counted reads as `unknown`. A rate limit that one request gets stops the requests of all workers until its wait ends. When GitHub refuses the identity, for example because the App's installation is suspended, the Service halts and logs `GitHub refused the identity`. To clear the halt after you fix the cause, remove the file and restart the Service: `kubectl -n devops exec deploy/roadmap-service -- rm /home/devops/.data/roadmap/service-halt.json`, then `kubectl -n devops delete pod -l app.kubernetes.io/name=roadmap-service`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-10-30
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Design

## Context

The roadmap Service runs two lanes per repository: the status lane and the model lane. Previously, any accepted webhook delivery queued a trigger on every lane worker, running full rounds of all due jobs. Issue #2009 added scoped intake updates to `src/devops_cli/roadmap/run.py`. This change connects the webhook receiver to those scoped updates through the lane workers.

## Decisions

- **Expose `issue` on `GitHubWebhookPayload`.** `GitHubWebhookPayload` reads `issue.number`. Pydantic ignores other issue fields through `extra="ignore"`.
- **Pass `payload` to `deliver`.** `_hand_to_consumers` passes `payload` to `consumer.deliver` when `deliver` accepts it. Existing consumers that only take three arguments continue to work without change.
- **Scope check in `roadmap_consumer`.** When `(event, action)` is in `SCOPED_UPDATES` and `payload.issue` is present, `roadmap_consumer` constructs `WebhookDelivery` and schedules `run_scoped_update` on the lane from `SCOPED_UPDATES` (`model` lane).
- **Run on the lane worker via `enqueue_scoped`.** `RepoWorker` gains a deque of scoped update callbacks. The worker thread executes scoped callbacks and coalesced batches sequentially, ensuring scoped updates never run concurrently with lane jobs.
- **No full round queued for scoped updates.** When a scoped update is enqueued, no trigger key is placed in `_pending_counts`. The status lane receives no trigger, and the model lane runs only the scoped update.
- **Fallback to whole-round hint.** When an event has no entry in `SCOPED_UPDATES` or lacks an issue number, `roadmap_consumer` calls `service_manager.enqueue_trigger` as before.

## Rejected Alternatives

- **Run scoped updates asynchronously outside `RepoWorker`**: rejected. Running outside `RepoWorker` would allow scoped intake to write `intake.json` while an intake job on the model lane is running.
- **Create a separate lane for scoped updates**: rejected by ADR 0017. A separate lane would race the model lane for the same repository.
- **Pass entire request or store through the router**: rejected. The router keeps clean separation from the roadmap store and jobs.

## Risks

- A slow scoped update could delay scheduled jobs on the model lane. Scoped intake only judges one issue and bounds model interaction time.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Proposal

## Why

Issue #1533, the second part after #2009: the roadmap Service treats every webhook delivery as a hint to run a full round of all due jobs across both lanes. No payload reaches any job. This wastes GraphQL budget and delays issue processing. The fix makes each subscribed webhook event run its scoped update at once on the lane that `SCOPED_UPDATES` names. The 5-minute poll reconciles board edits and lost deliveries.

## What Changes

- Add `WebhookIssue` to `src/devops_cli/models/webhooks.py` and add `issue: WebhookIssue | None = None` to `GitHubWebhookPayload`.
- Update `_hand_to_consumers` in `src/devops_cli/server/routes/webhooks.py` to pass the typed `payload` to `consumer.deliver` when accepted.
- Update `roadmap_consumer` in `src/devops_cli/server/routes/webhooks.py`:
- When the delivery has an issue number and matches an entry in `SCOPED_UPDATES`, run the scoped update on the lane that the table names through `ServiceManager.enqueue_scoped`.
- When the delivery cannot be scoped, enqueue a trigger on all lanes as a whole-round hint as before.
- Update `RepoWorker` and `ServiceManager` in `src/devops_cli/server/service.py`:
- Add `enqueue_scoped` to dispatch a scoped update callable to the lane worker.
- The lane worker executes the scoped update sequentially, records metrics and spans, and queues no full round.
- Update documentation in `k8s/README.md` and `docs/adr/0017-each-subscribed-webhook-event-runs-the-update-scoped-to-it.md` to describe the event-driven dispatch flow.

## Capabilities

### Modified Capabilities

- `roadmap-scoped-updates`: the Service hands each subscribed webhook event that carries an issue number to its scoped update on the lane the table names, queueing no full round.

## Impact

- `src/devops_cli/models/webhooks.py`
- `src/devops_cli/server/routes/webhooks.py`
- `src/devops_cli/server/service.py`
- `tests/test_server_service.py`
- `docs/adr/0017-each-subscribed-webhook-event-runs-the-update-scoped-to-it.md`
- `k8s/README.md`

## Feasibility

- On origin/main `cf9f02c2`, `run_scoped_update` and `SCOPED_UPDATES` exist in `src/devops_cli/roadmap/run.py` (added in #2009).
- `GitHubWebhookPayload` already parses webhook bodies with Pydantic v2. Adding `WebhookIssue` with `number: int` parses the issue object without breaking other webhook payloads.
- `RepoWorker` runs a single-concurrency thread per `(repo, lane)`. Adding an internal scoped task queue ensures that scoped updates and full rounds run sequentially without racing.
- Tests verify offline execution through FastAPI `TestClient` and `InMemoryRoadmapStore`.

## Existing Tool Considered

The ADR 0009 router, Pydantic v2 validation models, and ADR 0017 scoped update engine already exist. No external library covers internal lane worker dispatch of webhook payloads. The change adds small glue logic in the existing modules and deletes no existing safety checks.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## ADDED Requirements

### Requirement: The Service hands a subscribed event to its scoped update
The roadmap consumer of the Service SHALL hand each subscribed webhook event that carries an issue number and has a row in `SCOPED_UPDATES` to its scoped update, on the lane that the table names. The delivery SHALL run the scoped update on the worker of that lane and SHALL queue no full round on any lane.

#### Scenario: A subscribed issues delivery runs on the model lane
- **WHEN** a signed delivery of `issues` `opened`, `edited` or `reopened` with an issue number arrives
- **THEN** the Service runs the scoped update on the model lane worker
- **AND** the Service queues no full round on the status lane or the model lane

#### Scenario: An unscopeable event keeps a whole-round hint
- **WHEN** a signed delivery of `issues` with an action that is not in `SCOPED_UPDATES`, or without an issue number, or of another subscribed event arrives
- **THEN** the Service enqueues a trigger on each lane as a whole-round hint
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Tasks

## 1. Scoped webhook event dispatch in the Service

- [x] Add failing tests for Service-level webhook event dispatch:
- Subscribed issues events (`opened`, `edited`, `reopened`) run the scoped update on the model lane and queue no full round.
- Events that cannot be scoped (other actions, other events, or missing issue numbers) keep the whole-round hint to all lanes.
- Lost delivery is processed by the subsequent reconciling poll.
- Verification: `uv run pytest tests/test_server_service.py`
- [x] Add `WebhookIssue` to `src/devops_cli/models/webhooks.py` and `issue` field to `GitHubWebhookPayload`.
- [x] Update `RepoWorker` and `ServiceManager` in `src/devops_cli/server/service.py` with `enqueue_scoped` support.
- [x] Update `_hand_to_consumers` and `roadmap_consumer` in `src/devops_cli/server/routes/webhooks.py` to route to scoped updates.
- [x] Update documentation in `k8s/README.md` and `docs/adr/0017-each-subscribed-webhook-event-runs-the-update-scoped-to-it.md`.
- [x] Verify all tests pass: `uv run devops ci`

## 2. Archive

- [x] Archive the change
- Verification: `uv run devops openspec archive 1533-service-event-scoped-updates`
12 changes: 12 additions & 0 deletions openspec/specs/roadmap-scoped-updates/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,15 @@ Scoped intake SHALL add the issue that it decided to the intake record, SHALL ke
#### Scenario: A scoped update after a capped round
- **WHEN** a round decides five of seven candidates and leaves a fresh one, and a delivery of candidate 6 runs its scoped update
- **THEN** the record holds the entries of candidates 1 to 6 and stays due, and the next poll decides candidate 7 alone

### Requirement: The Service hands a subscribed event to its scoped update
The roadmap consumer of the Service SHALL hand each subscribed webhook event that carries an issue number and has a row in `SCOPED_UPDATES` to its scoped update, on the lane that the table names. The delivery SHALL run the scoped update on the worker of that lane and SHALL queue no full round on any lane.

#### Scenario: A subscribed issues delivery runs on the model lane
- **WHEN** a signed delivery of `issues` `opened`, `edited` or `reopened` with an issue number arrives
- **THEN** the Service runs the scoped update on the model lane worker
- **AND** the Service queues no full round on the status lane or the model lane

#### Scenario: An unscopeable event keeps a whole-round hint
- **WHEN** a signed delivery of `issues` with an action that is not in `SCOPED_UPDATES`, or without an issue number, or of another subscribed event arrives
- **THEN** the Service enqueues a trigger on each lane as a whole-round hint
9 changes: 9 additions & 0 deletions src/devops_cli/models/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ class WebhookSender(BaseModel):
login: str


class WebhookIssue(BaseModel):
"""The issue an issue event is about."""

model_config = ConfigDict(extra="ignore", frozen=True)

number: int | None = None


class GitHubWebhookPayload(BaseModel):
"""What every GitHub event carries that the Service reads. The rest of a payload differs by
event and is ignored. An event has no `action` when GitHub gives it none (a `ping`, a `push`),
Expand All @@ -31,3 +39,4 @@ class GitHubWebhookPayload(BaseModel):
action: str | None = None
repository: WebhookRepository
sender: WebhookSender | None = None
issue: WebhookIssue | None = None
55 changes: 48 additions & 7 deletions src/devops_cli/server/routes/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import hashlib
import hmac
import inspect
import logging
import threading
from collections.abc import Awaitable, Callable, Mapping, Sequence
Expand Down Expand Up @@ -118,7 +119,7 @@ class WebhookConsumer(BaseModel):
name: str
provider: WebhookProviderName
events: frozenset[str]
deliver: Callable[[str, str, str], None]
deliver: Callable[..., None]
refusal: Callable[[GitHubWebhookPayload], str | None] = _takes_every_payload


Expand All @@ -139,15 +140,46 @@ class WebhookConsumer(BaseModel):

def roadmap_consumer(service_manager: ServiceManager) -> WebhookConsumer:
"""The roadmap jobs' consumer: each event their batch keys name runs a round in every lane of
its repository, except the writes of the GitHub App's own bot. Its delivery target is
`ServiceManager.enqueue_trigger`, the one seam between the router and the lane workers."""

def deliver(repo: str, event: str, action: str) -> None:
service_manager.enqueue_trigger(repo, CONST_SERVICE_SOURCE_WEBHOOK, event, action)
its repository, except the writes of the GitHub App's own bot. A subscribed event that can be
scoped runs its scoped update on the lane that the table names; another event stays a hint
(ADR 0017)."""

def deliver(
repo: str,
event: str,
action: str,
payload: GitHubWebhookPayload | None = None,
) -> None:
GLOBAL_METRICS.increment_counter(
CONST_SERVICE_METRIC_TRIGGERS,
labels={"repo": repo, "source": CONST_SERVICE_SOURCE_WEBHOOK},
)
from devops_cli.roadmap.run import SCOPED_UPDATES, WebhookDelivery, run_scoped_update
from devops_cli.roadmap.store import get_roadmap_store

scoped = SCOPED_UPDATES.get((event, action))
if (
scoped is not None
and payload is not None
and payload.issue is not None
and payload.issue.number is not None
):
delivery = WebhookDelivery(
repo=repo,
event=event,
action=action,
number=payload.issue.number,
)

def run_scoped() -> None:
store = get_roadmap_store(repo)
data_dir = service_manager.state_dir.parent if service_manager.state_dir else None
run_scoped_update(delivery, store, data_dir=data_dir)

if service_manager.enqueue_scoped(repo, scoped.lane, run_scoped):
return

service_manager.enqueue_trigger(repo, CONST_SERVICE_SOURCE_WEBHOOK, event, action)

def refuse_own_write(payload: GitHubWebhookPayload) -> str | None:
bot, sender = service_manager.bot_login, payload.sender
Expand Down Expand Up @@ -316,7 +348,16 @@ def _hand_to_consumers(
takers = [consumer for consumer, refusal in verdicts if refusal is None]
refusals = [refusal for _consumer, refusal in verdicts if refusal is not None]
for consumer in takers:
consumer.deliver(payload.repository.full_name, delivery.event, payload.action or "")
sig = inspect.signature(consumer.deliver)
if len(sig.parameters) >= 4 or any(
p.kind in (inspect.Parameter.VAR_POSITIONAL, inspect.Parameter.VAR_KEYWORD)
for p in sig.parameters.values()
):
consumer.deliver(
payload.repository.full_name, delivery.event, payload.action or "", payload
)
else:
consumer.deliver(payload.repository.full_name, delivery.event, payload.action or "")
if takers:
return _Reply(202, {"status": "accepted"}, CONST_SERVICE_OUTCOME_ACCEPTED)
first = refusals[0]
Expand Down
Loading
Loading