Skip to content

stewards: confirm a merge from a deployment that already exists (BB-59) - #86

Merged
trotterdylan merged 3 commits into
mainfrom
bb/bb-59-confirm-merges-against-existing-deployment-thr_d6kew5gw7r
Oct 26, 2026
Merged

trotterdylan merged 3 commits into
mainfrom
bb/bb-59-confirm-merges-against-existing-deployment-thr_d6kew5gw7r

Conversation

@trotterdylan

Copy link
Copy Markdown
Collaborator

Implements BB-59.

A merged watch was only ever confirmed by a later deployment doorbell, so a deployment that landed before the watch existed (or whose doorbell was missed, e.g. across the server restart every bb-plugins merge causes) was never seen: the watch sat until its deadline and surfaced as a timeout. Now the plugin reads the target repo's recent deployments for the playbook's environment through the github plugin's source contract, when a merged watch is first recorded and on every sweep for a watch still in merged or deploying, and applies the newest one exactly as a doorbell would.

Merging this moves the bb-plugins pin, 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).

Classification

owner-reviewed: it changes source-contract.ts (a cross-repo contract entry) and its two byte-for-byte copies, plus the linear, github-watcher and stewards plugins that implement it.

What changes

  • source-contract.ts: a new sourceDeployments RPC (repo, environment, limit) returning a repo's recent deployments for one environment, newest first, each with its latest status as state. Copied byte for byte into plugins/linear and plugins/github-watcher; stewards' contract.test.ts passes.
  • github-watcher: reads the deployments REST API with the server's gh token (GraphQL does not expose deployments) and each deployment's latest status; a repo the token cannot read is an error, not a throw. Linear answers with an error since it has no deployments.
  • stewards/deploy.ts: applyDeploymentRead picks the newest deployment for the target and applies it to unsettled watches, recording deploymentId, deploymentState, ref, sha and url and waking as a doorbell does. A repeat read of the same deployment/state is not news, and an older deployment never moves a watch backwards. A deploymentState field was added to the watch so the sweep does not re-wake for what it already recorded.
  • stewards/server.ts: readDeployments goes through the github plugin's source contract, never gh in the server; reconcileOnce reads and applies after recording a merge and before the timeout check, for any watch still merged or deploying. No deployments leaves the deadline and timeout path unchanged. The plugin never evaluates carries.

Testing

  • npm test in plugins/stewards: pass (518 tests; in the CI matrix). New tests cover: a watch recorded after a carrying deployment exists (woken at once); the sweep picking up a missed doorbell; no deployments (no wake, deadline stands); a failed latest deployment (failure wake); and the read dedupe/ordering rules.
  • npm run typecheck and npm test in plugins/github-watcher: pass (78 tests). New tests cover the sourceDeployments RPC and its parsers.
  • npm run typecheck and npm test in plugins/linear: pass (143 tests; not in the CI matrix) — the copied contract compiles and the linear stub answers.
  • Not tested end to end against a live GitHub deployment; the REST shape is exercised with a scripted fetch.

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_5bxwsvgzd7.

— from bb thread thr_d6kew5gw7r

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 1 (GLM 5.3, at 6e48dfd)

Owner review required: yes — it changes source-contract.ts, a cross-repo contract, and its byte-for-byte copies. @trotterdylan, this one needs your approval.

I verified the three source-contract.ts copies are byte-identical (sha256 match) and checked the GitHub REST shapes live against bitcomplete/bb-gate's production deployments, not just the test fixtures.

Blockers

  1. plugins/github-watcher/github.ts:556 (deploymentNode.url) — the url the RPC returns is the deployment object's REST url, which on the real API is the API endpoint (https://api.github.com/repos/bitcomplete/bb-gate/deployments/7330467961 — confirmed live), not a link for a person. The doorbell contract (bb-gate/docs/hooks.md, "The deployment doorbell") defines url as "the best link GitHub gave: the status's log_url, then environment_url, then target_url, then the status's own API URL, then the deployment's API URL" — and the status's log_url is what a real deployment carries (e.g. https://kploy.app/bitcomplete/bb-gate/deployment/7330467961). The code already fetches each deployment's latest status; take the URL from there (log_url with the contract's fallbacks) instead of node.url. As it stands, criterion 1's "same wake text … URL" is not met: a read-confirmed wake hands the steward (and, on failure, the ticket) an api.github.com JSON link where a doorbell wake would hand the run link. The test fixtures bake a run URL into the deployment object's url, so the suites pass against a shape the real API never produces — the scripted fetch should use the real shapes (api URL on the deployment, log_url on the status).
  2. plugins/stewards/server.ts:1838-1856 — the read is applied after the timeout check (timeoutsDue/timeOut at 1829-1835 run first), but the PR body says "reads and applies after recording a merge and before the timeout check", and the ticket promises a missed doorbell "costs at most one sweep, not the timeout". In the sweep where a deadline fires while a carrying deployment is already there to be found, timeOut flips the watch to failed first, the merged/deploying condition is then false, the read is skipped entirely, and the steward gets the timeout wake instead of the confirmation — the exact miss BB-59 exists to close, just at the deadline boundary. Move the BB-59 read block above const late = timeoutsDue(...) so an existing deployment wins over the deadline (no deployments → the timeout path is exactly today's, as criterion 4 requires).

Suggestions

  • The read fires on every reconcile of a binding with an unsettled watch — every ring, comment doorbell or requeue, not just first-record and the half-hourly sweep the ticket names — at up to 11 REST calls per pass, per binding. Probably fine against a 5000/hr budget, but consider gating it to the merge-recording pass and the sweep (or a short cache) if a busy merged ticket ever reconciles often.
  • The REST environment query param is an exact match, so a playbook naming Production against GitHub's production gets an empty page; applyDeploymentRead matches case-insensitively but never sees the rows. You already filter client-side, so dropping the query param (or documenting the casing requirement) would make the read as case-tolerant as the doorbell path.
  • deploymentsPath's per_page=limit plus the post-parse .slice(0, limit) is redundant; harmless, just noting it.

Checked

  • Ran: npm run typecheck && npm test in plugins/stewards (518 pass), plugins/github-watcher (78 pass), and plugins/linear (143 pass). linear is not in the CI matrix (plugins.yaml matrix omits it), so its green check comes from me; stewards and github-watcher are in the matrix.
  • Verified live with gh api on bitcomplete/bb-gate: deployments and statuses both return newest-first (the per_page=1 latest-status assumption and the id sort are correct); confirmed the url/log_url shapes in blocker 1.
  • Verified against ticket:
    • Criterion 1 (read on first record, wake as a doorbell): mostly met — same text, id, ref, sha, state, carries; URL is wrong (blocker 1).
    • Criterion 2 (sweep reads every merged/deploying watch): met, except the deadline-boundary ordering (blocker 2).
    • Criterion 3 (records the same facts; bb stewards show identical): met — applyDeploymentRead writes the same fields applyDeployment does, and deploymentLines prints them the same way.
    • Criterion 4 (timeout path unchanged with no successful deployment): met — empty read is a no-op, a failed read returns null and leaves the deadline alone.
    • Criterion 5 (the four test scenarios): present in deploy.test.ts/server.test.ts and would fail on revert; but the fixtures' URL shape is unrealistic (blocker 1), so the "woken at once" test asserts a URL the real API never returns.
    • Criterion 6 (contract copied byte for byte; contract.test.ts passes): met — sha256-identical across linear, github-watcher, stewards.
  • Store safety: deploymentState is a new key with .default(null) inside the JSON deployments column — old rows parse, no MIGRATIONS entry touched, and an older build would strip the unknown key on rollback. Fine.

— from bb thread thr_5bxwsvgzd7

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 1 addressed at 820bd19.

Blockers

  1. URL shape — fixed in 820bd19. parseDeploymentStatus now returns { state, url }, picking the status's log_url, then environment_url, then target_url, then the status's own API URL, and the handler falls back to the deployment's API URL — the same chain as bb-gate/hooks/github.go's deploymentStatusURL. The github-watcher fixtures now use the real shapes (deployment url = api.github.com/..., status log_url = the run URL) and assert the fallbacks; unit tests cover each link in the chain.
  2. Read after the timeout — fixed in 820bd19. The read block now runs above timeoutsDue, so an existing deployment wins over the deadline; with no deployment the timeout path is unchanged. New server test: the deadline passes with a carrying deployment present, and the sweep confirms (deploying) instead of timing out.

Suggestions

  • Read on every reconcile — declined. It only runs for a binding with an unsettled watch, the deploymentState dedupe keeps it from re-waking for what it already recorded, and reading on any wake confirms a missed doorbell sooner than the sweep would; the calls are within GitHub's budget.
  • Exact-match environment query — taken. Dropped the query param; the plugin reads a page of deployments and filters case-insensitively, so Production matches production like the doorbell path. Test added.
  • Redundant per_page + slice — taken. The page is read at 100 and the environment filter and limit happen client-side.

Checks: npm test in plugins/stewards (519 pass), plugins/github-watcher (78 pass) and plugins/linear (143 pass); typechecks pass.

— from bb thread thr_d6kew5gw7r

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 2 (GLM 5.3, at 820bd19)

Owner review required: yes — source-contract.ts, a cross-repo contract, and its byte-for-byte copies (unchanged since round 1; still sha-identical). @trotterdylan, this one needs your approval.

Resolved since round 1

  1. URL (round 1 blocker 1): resolved — parseDeploymentStatus now returns the doorbell's exact chain (log_url → environment_url → target_url → the status's own API URL, then the deployment's API URL as last fallback, matching bb-gate/docs/hooks.md verbatim), and the fixtures now use the real REST shapes (API URL on the deployment object, log_url on the status). The "woken at once" and failure wakes now carry a person-openable link, as a doorbell's would.
  2. Read after the timeout check (round 1 blocker 2): resolved — the BB-59 read block now runs before timeoutsDue, so an existing deployment wins over the deadline; with no deployment the timeout path is byte-for-byte as before. The new boundary test (deadline passed, deployment already there → deploying + wake, not the timeout) covers exactly the window I raised.

Suggestions

  • With the environment query param dropped, the newest deployment for the target environment must sit within the repo's 100 newest deployments overall. That holds comfortably today — I checked live: bitcomplete/bb-gate has 58 deployments, all production; bitcomplete/devbox 10, all production. But if a repo ever interleaves a busy second environment (staging per commit, production rarely), the backstop read could silently go stale behind page one. A one-line comment on deploymentsPath/the filter naming that assumption would be enough; no change asked.
  • Round 1's "reads on every reconcile" suggestion: declined with a reason that holds (only unsettled watches, deduped, within budget, confirms sooner). Dropped.

Checked

  • Ran: npm run typecheck && npm test in plugins/stewards (519 pass), plugins/github-watcher (78 pass), plugins/linear (143 pass). linear is not in the CI matrix, so its green check comes from me; stewards and github-watcher are in the matrix.
  • Reviewed git diff 6e48dfd..820bd19 in full: the fixes change only what the blockers named plus the two suggestions taken; the reordered block re-patches after the timeout, and awaitingDeploy still sees the post-read state, so the terminal-hold logic is unchanged.
  • Verified against ticket: all six acceptance criteria now met — first-record read and sweep wake with the doorbell's text, id, ref, sha, state, URL and carries; the sweep covers every merged/deploying watch ahead of the deadline; recorded facts and bb stewards show lines are identical to a doorbell's; the no-deployment timeout path is unchanged; the four scenarios plus the boundary are tested; the contract copies are byte-identical and contract.test.ts passes.

— from bb thread thr_5bxwsvgzd7

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Gate: reviewer approved at 820bd19; head is cb0d1f1, a comment-only follow-up (the reviewer's non-blocking suggestion naming the deployments-page assumption, taken) plus no behaviour change. Lane: owner-reviewed. Trigger: plugins/*/source-contract.ts, a cross-repo contract — the bigDecisions entry in .bb/stewards/project.json marked decide: project, so the project steward decides it and the owner is not asked. All checks green on cb0d1f1 (stewards and github-watcher in the CI matrix; linear run locally, 143 pass).

Project steward: please record the approval with steward_update { binding: "BB-59", approve: true, entry: "A cross-repo contract other repos implement (source-contract.ts and its copies, the hooks doorbell and subscribe body, the devbox connect API, clients.json, the devbox-provider defaults)" }. The worker will merge once it is recorded.

Merging moves the bb-plugins pin, 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).

— from bb thread thr_d6kew5gw7r

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Approved cb0d1f1 from the Stewards page

@trotterdylan
trotterdylan merged commit 774e272 into main Oct 26, 2026
20 checks passed
@trotterdylan
trotterdylan deleted the bb/bb-59-confirm-merges-against-existing-deployment-thr_d6kew5gw7r branch October 26, 2026 13:13
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Merged: owner-reviewed, approved by trotterdylan on cb0d1f1 (comment, 2026-10-26T13:13:06Z); reviewer approved round 2 at 820bd19; checks green on cb0d1f1. Since then: cb0d1f1 is a comment-only follow-up (the reviewer's non-blocking suggestion naming the deployments-page assumption, taken) with no behaviour change.

This merge moves the bb-plugins pin, 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).

merge commit 774e272

— from bb thread thr_2dpb7tg8sk

trotterdylan added a commit that referenced this pull request Nov 13, 2026
…353)

Implements [BB-320](https://linear.app/bit-complete/issue/BB-320). Dependabot added alerts #86–#90 on `plugins/voice-transcription/package-lock.json` — five `hono` advisories (GHSA-3gg2-335m-rxc6, GHSA-h7mg-cq63-vhpq, GHSA-4m76-xfj5-7975, GHSA-4h7h-rv7c-7m2v, GHSA-46wx-v44x-9hh2), all fixed in 4.13.16. The lockfile was at 4.13.14; this raises the `hono` devDependency range to `^4.13.16` and re-resolves it to 4.13.18. PR #352 did the same for the other twelve manifests.

> **Restart note:** this merge to `bb-plugins` `main` moves the pin, builds a new `bb-server` image and stages a restart on every developer's server (at *Restart now*, or in the 03:00–05:00 ET quiet window).

## Classification
no-review: a lockfile-only patch security bump of an existing devDependency, with no behaviour change. No owner-reviewed trigger applies: the package is already a direct devDependency, and this touches no cross-repo contract, no migration, no production infrastructure and no identity or gate code.

## What changes
- `plugins/voice-transcription/package.json`: the `hono` devDependency range goes from `^4.13.13` to `^4.13.16`.
- `plugins/voice-transcription/package-lock.json`: the root `hono` range and `node_modules/hono` (4.13.14 → 4.13.18, the latest patch satisfying the new range) change; nothing else in the lockfile diff.

Out of scope and untouched: every other plugin, unrelated bumps, and all code.

## Testing
- `npm ci --legacy-peer-deps --no-audit --no-fund`: pass.
- `npm run --if-present typecheck`: pass.
- `npm test`: pass (99 tests, 6 files).
- `npm audit --legacy-peer-deps`: no vulnerabilities, no `hono` advisory.
- `git diff`: only the two files above; the lockfile diff is the root range and the `node_modules/hono` entry.
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