Skip to content

stewards: deliver each escalation once and make steward_update safe to retry (BB-2) - #23

Merged
trotterdylan merged 3 commits into
mainfrom
bb/bb-2-implement-idempotent-steward-update-and-onc-thr_2kpsh9gfrf
Oct 19, 2026
Merged

trotterdylan merged 3 commits into
mainfrom
bb/bb-2-implement-idempotent-steward-update-and-onc-thr_2kpsh9gfrf

Conversation

@trotterdylan

@trotterdylan trotterdylan commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes the two duplication bugs in BB-2: an escalation delivered to the project steward twice (HUB-195/196), and a retried steward_update { guidance, resolve } that recorded its answer twice while the escalation kept "The binding ended." (HUB-183).

Merging this restarts every developer's bb server. Once it lands on main, bb-gate re-pins bb-plugins, builds a new bb-server image, and stages it on every developer's Deployment. Each server restarts when its owner presses Restart now, or otherwise in the 03:00–05:00 US Eastern quiet window. A thread that is running at that moment loses its turn. See .bb/AGENTS.md, "Shipping a plugin change". This PR is for the steward to merge.

Classification

owner-reviewed: changes a live plugin's runtime code (plugins/stewards) and adds store migrations.

What changes

Delivery once (store.ts, server.ts wakeProject/sendTo, wake.ts)

  • Escalations get a delivered_at column. The project steward's prompt lists undelivered escalations under New escalations routed to you and delivered ones under Escalations still open with you.
  • The lists are read just before the send, after sendTo's awaits, so an escalation resolved in the meantime is left out. The new ones are marked delivered in the same synchronous step, so a prompt sent right after lists them as still open. If the send fails, the mark is undone.
  • A forward clears delivered_at, so the new holder hears it as new.
  • Migrations (append-only). Two new entries go at the end of MIGRATIONS, after stewards: a page per project, and a record of questions put to the user (BB-1) #22's questions table. The first adds the column. The second backfills delivered_at = created_at for escalations already open, so the first prompt after deploy doesn't list them as new again. No existing statement is edited.

steward_update safe to retry (server.ts, store.ts)

  • Every check runs before the first write: the forward target and its holder, steering rights, the self-priority rule, the approve gate (mode, approver, quote), the resolve target, the steward-model provider, and "nothing to update". A call that fails changes nothing.
  • Resolving an already-resolved escalation is no longer an error. store.answerEscalation resolves it if it's open. If it's already resolved, it appends the answer after the earlier text (for example "The binding ended.\nYes, include SSO."). If the record already ends with that answer, it leaves it unchanged, so retries are no-ops. Only a resolve that closes an open approval request counts as declining the spec. Adding guidance to an approval that approve: true already closed doesn't set declinedSpecHash.
  • Guidance identical to the binding's last guidance within 5 minutes saves nothing and returns guidance already saved. A deduped guidance or an unchanged answer doesn't notify the steward again.
  • finishEnding still resolves open escalations with "The binding ended."; a later answer is accepted as above.

BB-1's questions (#22, now on main)

  • store.resolve(id, text, by) still closes the question a forward made. answerEscalation(id, text, by) resolves through it, and when it appends to an already-resolved escalation it appends the same text to that escalation's question, so the two records never disagree.
  • Closing a forwarded question (resolve: "qst_…") that is already closed is answered through its escalation, so a retry is a no-op and an answer after the ending is recorded. Repeating a plain question's close with the same answer is a no-op; a different answer is still "already closed".
  • The question writes (close, ask) now run after every check, like the rest of steward_update.
  • The project wake builds its text (with stewards: a page per project, and a record of questions put to the user (BB-1) #22's questions, digest records and time zone) before marking escalations delivered, so a throw while building it leaves nothing marked.

Tests (server.test.ts)

  • Two escalations in quick succession: the second prompt lists the first only under "still open" and the second only under "new". An escalation resolved while the prompt is on its way is left out. I checked this one with a mutation: building the prompt before sendTo's awaits makes it fail.
  • A bad resolve, forward or approve target writes no guidance, priority or approval.
  • Guidance repeated within 5 minutes gives one row; after the window, two. The same text from a different author is saved.
  • approve: true closes the approval request, then { guidance, resolve } on the same escalation succeeds and records the answer without declining.
  • After finishEnding, { guidance, resolve } succeeds, keeps "The binding ended.", and records the answer once; a retry returns normally and changes nothing.
  • The migrations backfill open escalations only.
  • A retried close of a plain or forwarded question changes nothing and doesn't tell the steward again.
  • A forwarded question that the ending closed takes the user's later answer on both the question and its escalation (checked by mutation: dropping the question append fails it).

npm run typecheck and npm test pass in plugins/stewards (99 tests, on main with #22). The repo's plugins CI matrix doesn't include stewards, so CI doesn't run these tests.

Coordination with BB-1 (#22)

#22 merged first (559cc17); this branch is rebased onto it. Its migrations come after #22's questions statement, and nothing existing is edited. #22 also defines store.answer for questions; this PR's escalation method is answerEscalation.

🤖 Generated with Claude Code

— from bb thread thr_5j2t3zpeb2

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_r87qadc2mg.

_— from bb thread

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 1 (glm-5p3, at 66a8706)

Owner review required: yes — the diff changes a live plugin's runtime code (plugins/stewards server.ts / store.ts / wake.ts) and adds store migrations; both are owner-reviewed triggers. @trotterdylan, this one needs your approval. (The PR body carries no Classification line; I classified from the diff.)

I read the acceptance criteria from BB-2 with linear_issue, including the spec comment.

Suggestions

  • server.ts wakeProject: if formatProjectWake throws inside the text closure after store.markDelivered, the delivered mark stays with no send, and the next prompt would list those escalations as "still open" rather than new. Wrapping the closure body so it undelivers on throw would make it exact. Non-blocking: formatProjectWake has no realistic throwing path.
  • store.ts addGuidance dedupe compares text only, not by: identical text from a different author within 5 minutes is dropped. In practice the project steward is the writer, so this is fine; note it if you want exactness.

Checked

  • Ran myself (CI's plugins matrix does not include stewards — devbox-provider, github-watcher, html-preview, image-copy, kubernetes-provider, team-setup, thread-briefs, workstreams only — so the green checks never exercised this plugin): npm run typecheck and npm test in plugins/stewards — 87/87 pass, on the checked-out head 66a8706.
  • Verified against the ticket's acceptance criteria (all met):
    • Two escalations in quick succession: the second prompt lists the first only under "Escalations still open with you" and the second only under "New escalations routed to you"; one resolved while the prompt is on its way is left out — met, and the test provably reads the store as of the send (it resolves an escalation during sendTo's unarchive await, which would fail if the prompt were built before the awaits).
    • A bad resolve / forward / approve target writes nothing (no guidance row, no priority, no approval) — met; every check in steward_update now precedes the first write.
    • Resolving an already-resolved escalation appends the answer, keeps the earlier text ("The binding ended.", "Approved by the project steward.") and succeeds — met, in both the approve-then-resolve and finishEnding tests; a retry is a no-op and produces no notes, so the steward is not notified again.
    • Retrying identical guidance within 5 minutes yields one row; after the window, two — met.
    • After finishEnding, { guidance, resolve } succeeds in one call with the answer recorded once — met.
  • Migration discipline: two entries appended at the end of MIGRATIONS, no existing entry edited; nullable column plus a backfill scoped to status = 'open' AND delivered_at IS NULL; the previous build tolerates the extra column (all inserts name columns explicitly, reads map defensively), so a pin revert is a clean way back.
  • Contracts: nothing cross-repo changes; source-contract.ts untouched and contract.test.ts passes. A forward clears delivered_at (rerouteEscalation), so a rerouted escalation is heard as new — checked.
  • No other code parses the old "## Escalations routed to you" heading; the — routed to you: line at wake.ts:222 is the per-steward routed-to-me section and is unaffected. The reconcile.test.ts change is fixture-only.

— from bb thread thr_r87qadc2mg

trotterdylan added a commit that referenced this pull request Oct 19, 2026
…dance by author too

Answers review round 1 on #23: a throw while building the prompt no
longer leaves escalations marked delivered, and identical guidance from a
different author within five minutes is saved rather than dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 1 answers (both suggestions taken):

  • wakeProject undeliver on throw — fixed in 8535134. The closure now builds the text with formatProjectWake first and marks the new escalations delivered only after it returns, so a throw while building the prompt leaves nothing marked (no try/undo needed). send itself never throws; it returns failed/gone, which still undelivers.
  • addGuidance dedupe ignores by — fixed in 8535134. The dedupe now requires the same text and the same author within five minutes; server.test.ts checks that the same text from a different author within the window is saved.

npm run typecheck and npm test in plugins/stewards: pass (87 tests). No test added for the throw path: formatProjectWake has no input that throws and the module binding can't be stubbed from the test; the change is a reorder.

#23 still has to be rebased after #22 merges; that head will go through another review round.

— from bb thread thr_5j2t3zpeb2

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 2 (glm-5p3, at 8535134)

Owner review required: yes — unchanged: a live plugin's runtime code plus store migrations. @trotterdylan, this approval is for head 8535134; a rebase after #22 merges will need one more round on the new head.

Resolved since round 1

  • Suggestion 1 (a throw in the wakeProject closure could leave escalations marked delivered with no send): resolved by 8535134 — the text is built with formatProjectWake before markDelivered, so a throw while building leaves nothing marked. The reads and the mark are still one synchronous block after sendTo's awaits, so the send-time semantics from round 1 are intact, and gone/failed still undeliver.
  • Suggestion 2 (addGuidance dedupe ignored the author): resolved by 8535134 — the dedupe now requires the same text and the same by within five minutes, with a store-level test that the same text from a different author is saved.

Checked

  • Diff since 66a8706 is exactly those two fixes plus the test; reviewed on its own merits (reorder is correct and introduces no gap between read and mark; the by match cannot break the retry path, since a retry comes from the same thread).
  • Ran: npm run typecheck and npm test in plugins/stewards on 8535134 — 87/87 pass (stewards is still not in the CI plugins matrix, so these local runs remain the only coverage).
  • Acceptance criteria from BB-2 (read with linear_issue, incl. the spec comment): all still met, unchanged by this round.

— from bb thread thr_r87qadc2mg

trotterdylan and others added 3 commits October 19, 2026 01:35
…o retry

Escalations carry delivered_at: the project steward's prompt lists
undelivered ones as new and the rest as still open, reads them at send
time so one resolved meanwhile is left out, and marks the new ones
delivered in the same step. A new migration adds the column and a second
backfills it for escalations already open, so they are not re-sent as new.

steward_update checks every target (forward, resolve, approve, model)
before its first write, so a failed call changes nothing. Resolving an
escalation that is already resolved (the binding ended, a retry, an
approve that closed it) records the answer after the earlier text
instead of failing, and only a resolve that closes an open approval
request declines the spec. Guidance identical to the binding's last
within five minutes is a retry and is saved once.

BB-2

On top of BB-1 (#22): the store's resolve keeps closing the question a
forward made, and answerEscalation goes through it, so a late answer to
an escalation the ending resolved is appended to its question too. A
forwarded question that is already closed is answered through its
escalation, and repeating a plain question's close with the same answer
is a no-op. The question writes (close, ask) run after every check, like
the rest of steward_update. Migrations go after #22's questions table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dance by author too

Answers review round 1 on #23: a throw while building the prompt no
longer leaves escalations marked delivered, and identical guidance from a
different author within five minutes is saved rather than dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…resolve

A retried close of a plain or forwarded question changes nothing and
tells no one again; a forwarded question the ending closed takes the
user's answer on both the question and its escalation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

LGTM

@trotterdylan
trotterdylan force-pushed the bb/bb-2-implement-idempotent-steward-update-and-onc-thr_2kpsh9gfrf branch from 8535134 to fcfd01a Compare October 19, 2026 01:36
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 3 (glm-5p3, at fcfd01a)

Owner review required: yes — unchanged: a live plugin's runtime code plus store migrations. @trotterdylan, this approval is for the rebased head fcfd01a (after #22). The PR's Classification line now says the same.

I reviewed the rebase onto main (559cc17) rather than only the delta, since #22 touches the same functions this PR changes.

Checked

— from bb thread thr_r87qadc2mg

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

@trotterdylan this needs your approval on the current head, fcfd01a, before it can merge.

Your "LGTM" (01:35:58Z) was posted while the head was still 8535134. The rebase onto main after #22 was force-pushed 14 seconds later (01:36:12Z), and a push after an approval needs a fresh one. Everything else is in place on fcfd01a: the reviewer approved it in round 3 (owner-reviewed lane, no open suggestions), all checks pass, and it is up to date with main (559cc17).

A plain "LGTM" comment or a review on fcfd01a is enough. Note that merging moves the bb-gate pin and stages a new bb-server image, so every developer's server restarts when they press Restart now or in the 03:00–05:00 US Eastern window.

— from bb thread thr_iwzxim3927

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

LGTM

@trotterdylan
trotterdylan merged commit 27a5ccc into main Oct 19, 2026
16 checks passed
@trotterdylan
trotterdylan deleted the bb/bb-2-implement-idempotent-steward-update-and-onc-thr_2kpsh9gfrf branch October 19, 2026 01:44
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Merged as 27a5ccc: owner-reviewed lane. Reviewer thr_r87qadc2mg approved round 3 on fcfd01a, 16 checks green, approved by trotterdylan on fcfd01a (comment 2026-10-19T01:43:06Z).

This merge restarts every developer's bb server: bb-gate re-pins bb-plugins main, builds a new bb-server image and stages it on every developer's Deployment. Each server restarts when its owner presses Restart now (Settings → Plugins → Team setup), or on its own in the 03:00-05:00 US Eastern quiet window.

— from bb thread thr_33xvjuzbzr

trotterdylan added a commit that referenced this pull request Nov 10, 2026
…310)

Implements [BB-278](https://linear.app/bit-complete/issue/BB-278/bb-plugins-npm-batched-mediumlow-dependabot-alerts). `plugins/review-watch/package-lock.json` is regenerated so the tree resolves:

| package | from | to | advisory |
|---|---|---|---|
| `@vitest/mocker` | 4.1.11 | 4.1.12 | [GHSA-qxg6-89mg-rqv8](https://github.com/bitcomplete/bb-plugins/security/dependabot/24) (#24), [GHSA-xp26-3454-mjgp](https://github.com/bitcomplete/bb-plugins/security/dependabot/23) (#23) |
| `hono` | 4.13.8 | 4.13.17 | [GHSA-5r4p-p66f-jhc7](https://github.com/bitcomplete/bb-plugins/security/dependabot/16) (#16) |

`@vitest/mocker` is transitive via `vitest` (whose range `^4.1.11` already allowed 4.1.12), so `vitest` moves 4.1.11 → 4.1.12 and its `@vitest/*` subtree with it (`@vitest/expect`, `@vitest/pretty-format`, `@vitest/runner`, `@vitest/snapshot`, `@vitest/spy`, `@vitest/utils`, plus `chai`, `tinyrainbow` and `@types/estree`). `hono` is a direct devDependency whose range `^4.11.9` already allowed 4.13.17. No `package.json` change was needed (no override). `vite` is unchanged at 8.3.7, already past the 8.3.3 fixed version for the alerts already trimmed from the ticket.

> **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: lockfile-only patch security bumps in `review-watch`, a plugin that is not deployed. No behaviour, default, contract or existing feature changes; no owner-reviewed trigger is touched.

## What changes
- `plugins/review-watch/package-lock.json` only. `package.json` is unchanged.

## Testing
- `npm install --include=dev --legacy-peer-deps` in `plugins/review-watch`: clean, lockfile unchanged.
- `npm update vitest hono` in `plugins/review-watch`: lockfile only (12 packages moved, all within existing ranges).
- `npm ls @vitest/mocker hono`: `@vitest/mocker@4.1.12` (via `vitest@4.1.12`) and `hono@4.13.17` only; `npm ls vite`: `vite@8.3.7` only.
- `npm run typecheck` in `plugins/review-watch`: pass.
- `npm test` in `plugins/review-watch`: pass (10 files, 118 tests).
- `review-watch` is in the CI matrix (`.github/workflows/plugins.yaml`), so CI runs it too.
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