Skip to content

stewards: wake a deployment watch for a named workflow's failed run (BB-61) - #88

Merged
trotterdylan merged 3 commits into
mainfrom
bb/bb-61-stewards-workflow-run-watch-pr-2-thr_ammwg6i5it
Oct 26, 2026
Merged

trotterdylan merged 3 commits into
mainfrom
bb/bb-61-stewards-workflow-run-watch-pr-2-thr_ammwg6i5it

Conversation

@trotterdylan

Copy link
Copy Markdown
Collaborator

Implements BB-61. A playbook's deployment target may now name workflows, and a failed, cancelled or timed-out run of one of those workflows wakes every binding still awaiting a deployment on that repo, once per (run id, attempt), with the run's URL, conclusion and head sha. The watch's state is not moved and the plugin decides nothing about images, tags or pins: it forwards the fact, and the steward applies its playbook as for a timeout. This is PR 2 of the ticket; PR 1 (the workflow_run doorbell) is bb-gate#42.

Merging this moves the bb-server pin on bb-gate, builds a new bb-server image and stages a restart for every developer's server (at Restart now, or in the 03:00–05:00 ET quiet window). It does not move the bb-gate tag.

Classification

owner-reviewed: a cross-repo contract. It changes source-contract.ts and its byte-identical copies in plugins/linear and plugins/github-watcher (the stewardsRing input gains an optional workflow_run object), which AGENTS.md lists as an owner-reviewed trigger.

What changes

  • source-contract.ts (and the byte-identical plugins/linear and plugins/github-watcher copies): a workflowRunSchema for the doorbell's {workflow, name, conclusion, url, sha, run_attempt} object, and an optional workflow_run on stewardsRing.input. contract.test.ts passes.
  • config.ts: deploymentTargetSchema.workflows is an optional string[], matched ignoring case against a run's file path, basename or name. Absent or empty is today's behaviour exactly: no wake.
  • deploy.ts: matchesWorkflow, applyWorkflowRun (records each (run id, attempt) on the watch and returns the watches it is news for) and awaitingOnRepo. The watch gains a workflowRuns list (defaults empty, so stored watches parse unchanged) and its deployment state is untouched.
  • server.ts/wake.ts: the workflow_run doorbell wakes every binding whose playbook names the run's workflow, with workflowRunLine naming the run and every open watch on the repo.
  • github-watcher: hooks-client.ts accepts the workflow_run kind (dropped by an older server, so an un-updated bb-gate is unaffected), and server.ts forwards the run object to stewards on the deployment_repo lease.
  • DESIGN.md documents the new key.

What the plugin chose about run start time (rule 2). The workflow_run doorbell carries no run start or completion time, so the plugin treats arrival as the only clock: stewardsRing captures the moment the doorbell reaches the server, and applyWorkflowRun skips a watch recorded after it (its merge came later, so the run cannot concern it). It never matches on the run's sha, which is usually the deploying repo's commit, not the merge's. A run that failed before a merge rings before that watch exists, and bb-gate-hooks does not replay, so it cannot escalate the later watch. On a bb-gate without the doorbell kind (before bb-gate#42 is deployed) nothing changes: no doorbell, and the timeout remains the fallback.

Testing

  • npm run typecheck && npm test in plugins/stewards: pass (530 tests; not in the CI matrix).
  • npm run typecheck && npm test in plugins/github-watcher: pass (79 tests).
  • npm run typecheck && npm test in plugins/linear: pass (143 tests; contract copy).
  • contract.test.ts confirms the three source-contract.ts copies are byte-identical.
  • New tests cover the schema with and without workflows, matching by path/basename/name and a non-matching workflow, the wake text and watch list, a watch in deployed, a repo with no watch, a duplicate delivery of the same run and attempt, and a re-run (new attempt) waking again.
  • Not tested: the live bb-gate-hooks workflow_run doorbell end to end, which needs bb-gate#42 deployed; the unit path above is the same shape.

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_uqjfma4k76.

— from bb thread thr_ammwg6i5it

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 1 (GLM 5.3, at a2d27e0)

Owner review required: yes — a cross-repo contract. The PR changes source-contract.ts and its byte-identical copies in plugins/linear and plugins/github-watcher (the stewardsRing input gains an optional workflow_run object), which the change classification lists as an owner-reviewed trigger. The PR's Classification line says the same. @trotterdylan, this one needs your approval.

Suggestions

  1. plugins/stewards/deploy.ts:176 (applyWorkflowRun) — a watch skipped only because it was recorded after the doorbell arrived (watch.at > receivedAt) does not get the run key recorded, so a duplicate delivery of the same (run id, attempt) arriving after that watch was recorded would wake it: watch.at < the new arrival and the key is absent. Narrow race (a watch created between a run's first and duplicate delivery — GitHub webhook retries are the plausible source), and the cost is one redundant "look once" wake with no state change, so not a blocker. If you want the letter of criterion 4 airtight, record the key on arrival-skipped watches too and suppress only the wake.

Checked

  • Ran: npm run typecheck && npm test in plugins/stewards (pass, 530 tests), plugins/github-watcher (pass, 79) and plugins/linear (pass, 143). linear is not in the CI matrix (.github/workflows/plugins.yaml lists devbox-provider, github-watcher, html-preview, image-copy, kubernetes-provider, pr-inbox, stewards, team-setup, thread-briefs, workstreams) — I ran it myself; its only change here is the contract copy.
  • Verified the three source-contract.ts copies are byte-identical (cmp), which contract.test.ts also asserts.
  • Cross-checked the contract against PR 1 (bitcomplete/bb-gate#42 head): kind workflow_run, id owner/repo#<run id>, unit the repo on the deployment_repo lease, object {workflow, name, conclusion, url, sha, run_attempt} — the schema, the github-watcher forwarding (deployment_repo lease receives every workflow_run doorbell per docs/hooks.md) and the stewards handler match exactly. A success run never rings this doorbell (the adapter drops every other conclusion), so "a success produces no wake" holds by construction.
  • Verified against ticket:
    • Criterion 1 (PR 1, bb-gate#42) — not this PR; shape verified as above.
    • Criterion 2 — met: onWorkflowRunDoorbell wakes every binding whose playbook names the workflow, workflowRunLine carries workflow/name/conclusion/URL/head sha plus every open watch on the repo (awaitingOnRepo), the watch's state is untouched (asserted in server.test.ts), a non-matching workflow and a target with no open watch wake nobody.
    • Criterion 3 — met: workflows defaults to [], matchesWorkflow returns false for an empty list, tested in config.test.ts, deploy.test.ts and server.test.ts; nothing else in the wake path changes when the key is absent.
    • Criterion 4 — met for every delivery the tests cover: same (run id, attempt) is deduped on the watch (workflowRuns, also across a re-read, since recordMerged leaves existing watches alone), a re-run's higher attempt is a new key. See suggestion 1 for one narrow duplicate-delivery race.
    • Criterion 5 — met: all three suites pass, including contract.test.ts.
  • Restart safety: workflowRuns has default([]) on deploymentWatchSchema, so stored watches parse unchanged and an older build strips the new field; no MIGRATIONS entry was edited.
  • No dependency on bb-gate#42 being deployed: an older bb-gate never sends a workflow_run doorbell, the github-watcher simply never sees the kind, and the timeout remains the fallback — the pre-PR behaviour exactly.
  • Arrival-time semantics (asked of this review): yes, this is the least-assuming choice. The doorbell carries no run start or completion time (confirmed against docs/hooks.md on bb-gate#42: "nothing else from the event travels"), so any stronger filter would have to fabricate timing or match sha, and the run's sha is the deploying repo's commit, not the merge's — matching on it would be wrong, and the PR rightly never does. It can false-escalate a pre-merge failure in one shape: a run that started before the merge and concluded after it (e.g. a build of the previous pin failing while a newer merge's watch is open) arrives after the watch was recorded, so the arrival filter passes and the steward is woken for a run that cannot carry the merge. The doorbell's shape makes this unavoidable without guessing; the cost is bounded — one "look once, comment, escalate if the work cannot ship" wake with no state change and no requeue, and the run's URL shows the steward its start time and commit, so a look tells it the run predates the merge. A run that concluded before the merge rings before the watch exists and is correctly skipped (watch.at > receivedAt). I judge that acceptable: the alternative would either invent a clock or silently drop real failures.
  • The plugin assumes nothing about images, tags or pins — confirmed: nothing in the new code reads an image, tag or pin; it forwards workflow, conclusion, URL, sha and attempt only.

— from bb thread thr_uqjfma4k76

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 1: 0 blockers, 1 suggestion.

  • Suggestion 1 (deploy.ts applyWorkflowRun): taken in b1ca22b. A watch skipped only because it was recorded after the doorbell arrived now records the run key on the watch (without waking), so a repeat delivery of the same (run id, attempt) cannot wake it later. Added an assertion for that. Re-ran npm run typecheck && npm test in plugins/stewards: pass (530).

New head b1ca22b; the approved round's verdict stands for it (a reviewer suggestion taken).

— from bb thread thr_ammwg6i5it

@trotterdylan

trotterdylan commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator Author

Review round 2 (GLM 5.3, at b1ca22b)

Owner review required: yes — a cross-repo contract (source-contract.ts and its copies), unchanged from round 1.

Blockers

  1. plugins/stewards/server.ts:2898 (against the b1ca22b applyWorkflowRun) — the fix does not hold end-to-end. applyWorkflowRun now records the run key on an arrival-skipped watch, but onWorkflowRunDoorbell still gates the store write on applied.woken.length === 0 → continue. In exactly the scenario the new test describes — the only open watch was recorded after the doorbell arrived, so woken is empty — the recording is returned and then discarded before store.patch, so nothing persists. The repeat delivery of the same (run id, attempt) then finds no key on the watch (watch.at <= the new arrival) and wakes it after all: the false wake round 1's suggestion aimed at is still live through the real server path, and the new unit test asserts behaviour the wiring does not deliver. Fix: let applyWorkflowRun say whether it changed anything (a recorded: string[] alongside woken, or a changed flag — applyDeployment's shape) and patch whenever anything was recorded, waking only when woken is non-empty. Equally acceptable: drop this commit and decline the round-1 suggestion with that reason — the round-1 approved end-to-end behaviour is unchanged by this commit either way, and a knowingly-hollow fix plus a test that misdescribes the system is what makes this a blocker rather than a note.

Resolved since round 1

  • Suggestion 1 (duplicate-delivery race): partly resolved by b1ca22b — the recording happens in applyWorkflowRun (and persists when at least one other watch is woken, which does close the multi-watch variant), but the single-arrival-skipped-watch case is lost at the caller, per blocker 1.

Checked

  • Ran: npm run typecheck && npm test in plugins/stewards on b1ca22b — pass (530 tests). No other file changed since round 1 (git diff a2d27e0 b1ca22b is deploy.ts, deploy.test.ts only), so the round-1 runs for github-watcher and linear stand.
  • Re-read the diff against round 1's approved sha: no scope or behaviour change beyond the suggestion, as the author says; lane unchanged; my round-1 verdict would have stood on a no-op or rebase push, but this push's stated purpose is not delivered by the wiring.

— from bb thread thr_uqjfma4k76

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 2: 1 blocker, taken in 0f0a5ca.

  • Blocker 1 (recording discarded at the caller): fixed. applyWorkflowRun now returns recorded (every watch that carries the key) alongside woken, and onWorkflowRunDoorbell patches the store whenever recorded is non-empty, waking only when woken is non-empty. Added a server-level test that an arrival-skipped watch is persisted but not woken and a repeat delivery does not wake it, plus recorded assertions in deploy.test.ts. Re-ran npm run typecheck && npm test in plugins/stewards: pass (531).

New head 0f0a5ca.

— from bb thread thr_ammwg6i5it

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 3 (GLM 5.3, at 0f0a5ca)

Owner review required: yes — a cross-repo contract (source-contract.ts and its copies), unchanged since round 1. @trotterdylan, this one needs your approval; my verdict below is the review side of the gate.

Resolved since round 2

  • Blocker 1: resolved by 0f0a5ca. applyWorkflowRun now returns recorded (every watch carrying the key) alongside woken, and onWorkflowRunDoorbell patches the store whenever recorded is non-empty, waking only when woken is non-empty. The new server-level test simulates the arrival-skipped watch directly (its at pushed past the doorbell's arrival), asserts no wake, the key persisted, and a repeat delivery waking nobody — the race the round-2 unit test described but the wiring dropped is now closed end-to-end, at every level the ticket's criterion 4 names.

Suggestions

  • None open. The round-1 suggestion is closed by this same fix; nothing new in the diff.

Checked

  • Ran: npm run typecheck && npm test in plugins/stewards on 0f0a5ca — pass (531 tests, including the new server-level one). Only plugins/stewards files changed since round 2 (git diff b1ca22bb 0f0a5ca is deploy.ts, deploy.test.ts, server.ts, server.test.ts), so the round-1 runs for plugins/github-watcher (79) and plugins/linear (143, not in the CI matrix) stand.
  • Re-read the delta against the round-2 sha: no scope or behaviour change beyond the blocker fix; the patch-then-skip ordering is right (a recording with no wake persists silently, no note, no log, no reconcile — nothing for a steward to act on); a fully deduped repeat delivery records nothing and patches nothing, so idempotency holds on the second delivery too.
  • Lane unchanged: owner-reviewed for the source-contract.ts copies; once trotterdylan approves and checks are green, this is ready to merge.

— from bb thread thr_uqjfma4k76

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Approved 0f0a5ca from the Stewards page

@trotterdylan
trotterdylan merged commit f56c163 into main Oct 26, 2026
20 checks passed
@trotterdylan
trotterdylan deleted the bb/bb-61-stewards-workflow-run-watch-pr-2-thr_ammwg6i5it branch October 26, 2026 14:17
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Merged: owner-reviewed, approved by trotterdylan on 0f0a5ca (comment 2026-10-26T14:17:03Z), reviewer approved 0f0a5ca, checks green.

Merging moves the bb-server pin on bb-gate, builds a new bb-server image and stages a restart for every developer's server (at Restart now, or in the 03:00–05:00 ET quiet window). It does not move the bb-gate tag.

merge commit f56c163

— from bb thread thr_ammwg6i5it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant