Skip to content

stewards: respawn a steward whose environment is gone and add bb stewards rebind (BB-103) - #131

Merged
trotterdylan merged 2 commits into
mainfrom
bb/bb-103-respawn-thr_dmewtukbjt
Oct 28, 2026
Merged

trotterdylan merged 2 commits into
mainfrom
bb/bb-103-respawn-thr_dmewtukbjt

Conversation

@trotterdylan

Copy link
Copy Markdown
Collaborator

Implements BB-103.

A steward bound to a thread whose environment was destroyed never recovered: the wake failed with "Thread environment is unavailable" while the binding stayed awaitingReport: true. The plugin now respawns such a steward on the project steward's environment and re-points the binding, and bb stewards rebind lets an operator point a live binding at another thread by hand.

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

Classification

no-review: additive. A new recovery path for a failure that today does nothing, and a new CLI command; existing behaviour is unchanged.

What changes

  • deliverWake checks the steward thread's environment at wake time and treats a thread_environment_unavailable send error as a recoverable failure: it spawns a fresh steward through spawnSteward (the project steward's environment), re-points threadId, archives the old thread (never deletes, so thread.deleted never marks the binding manually detached), and delivers the wake as the new thread's first prompt. The binding is not counted as delivered until the new thread has the wake; the respawn is logged and noted on the binding so the next report says so.
  • bb stewards rebind <key> <thread> [--project <id>] re-points a live binding at another thread. It refuses a thread in another project, a deleted thread, or one that is already another binding's steward or a worker; clears awaitingReport; sends the binding's wake immediately; archives the previous thread through the plugin; and records the rebind in the binding's action log.

Testing

  • npm run typecheck in plugins/stewards: pass.
  • npm test in plugins/stewards: pass (758 tests; 3 new, not in the CI matrix).
  • New tests: an env-error wake respawns and re-points; a review binding's rebind refuses a thread owned by another binding; rebind sends a wake at once.
  • Not tested: the live recovery of the eight stuck bindings (done by hand after the image restarts, out of scope per the ticket).

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_eddptfiv9w.

— from bb thread thr_dmewtukbjt

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 1 (GLM 5.3, at 54366f5)

Owner review required: no — none of the owner-reviewed triggers apply. The change is additive: a new recovery path for a failure that today logs and gives up, and a new CLI command; healthy-thread behaviour, defaults and contracts are unchanged, and no bigDecisions entry's paths match plugins/stewards/server.ts (the store-migration and dependency entries name other files).

Suggestions

  1. server.ts (rebind run) — the mutation (store.patch re-point + awaitingReport: false, archive, note) happens outside the serial("b:<id>") lock that the plugin uses for every reconcile of a binding. In the narrow window where a doorbell-driven reconcile of the same binding is mid-deliverWake on the dead thread, its respawnSteward will store.patch a new threadId after yours, the rebind's own forced reconcile then wakes the respawned thread, and the command still prints "Rebound … to " while the fork is left orphaned. End state is functional (a live steward with a delivered wake) so this is not a blocker, but wrapping the whole mutation in serial("b:" + b.id, …), or re-reading the binding inside the lock and bailing if threadId moved, would close it.
  2. server.ts:1979 (deliverWake wake-time check) — the environmentGone-at-wake-time branch (criterion 1's second trigger) has no test; reverting just that branch would not fail any suite. One test setting environmentStatus: "destroyed" (no sendError) alongside the existing env-error test would pin it.
  3. server.ts:7391 (rebind steward check) — store.byThread matches ended bindings too (no ended_at filter), so rebinding to an old steward thread of a binding that has ended is refused with "already X's steward", which reads wrong for a thread nobody is using. Filtering other.endedAt === null (or wording the error to name the ended binding) would help the operator this command is for.
  4. server.ts (rebind refusals) — a thread that is the project steward's own thread is not refused (store.projectByThread is unchecked), and the success message "its wake was sent" can be untrue when the new thread is busy or the plugin is paused (the reconcile defers and keeps the wake as a "Due: requeue" note). Both are operator-confusion nits, not correctness.
  5. server.ts:4764 (session/@bb mention wake) — sendTo can now return "unavailable", and this path treats it like any failure: the mention falls back to the project steward instead of respawning, and the binding then recovers only at its next requeue/doorbell. If criterion 1's "a wake whose send fails" is meant to include mention wakes, this path needs the respawn; if the fallback is the intended design (the wake is never lost, the project steward answers), a comment saying so would spare the next reader.
  6. README.md — the plugin's README is the operator manual and documents every bb stewards command; rebind (and the auto-respawn) are undocumented there. Docs-only, can follow.

Checked

  • Ran: npm run typecheck (pass) and npm test (758/758 pass) in plugins/stewards on the head. The plugins CI matrix does include stewards and both runs are green; I ran the suite anyway.
  • Verified against bb core (BB_REF desktop-v0.47.1): include=environment has been a valid threads.get include since before v0.41, so the new parameter is safe on every server this image runs; ThreadResponse.projectId is always present, so the other-project refusal works in production and its null guard is only defensive; on the send path thread_environment_unavailable is thrown only when the environment's status is destroyed (goneThreadEnvironmentDetails) — a provisioning/not-ready environment surfaces as a different error and still lands on "failed", so a respawn cannot fire on a transient condition.
  • Verified against ticket: criterion 1 met — both triggers implemented (send error and wake-time destroyed), respawn goes through spawnSteward (project steward's environment, with its own fresh-environment fallback), the binding is re-pointed, the old thread is archived and never deleted (tests assert deletes stays empty), the wake is the new thread's first prompt, awaitingReport is written only after deliverWake returns, and the respawn is logged (bb.log.warn) and noted (store.note, after pending is cleared so the next report names it). criterion 2 met — all four refusals (other project, deleted, another binding's steward, worker), awaitingReport cleared before the forced "requeue" reconcile sends the wake, previous thread archived through the plugin, rebind recorded as a pending note that the wake carries. criterion 3 met — the three tests are present, exercise the described behaviour (not just the happy path), and each would fail if its change were reverted.
  • Scope: only plugins/stewards/server.ts and server.test.ts; source-contract.ts and other plugins untouched.
  • Failure handling: a respawn whose spawn fails returns false with no patch, so the binding keeps its requeue retry rather than looping or losing state; state survives a server restart (store rows only, no migration).

— from bb thread thr_eddptfiv9w

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 1 addressed in 63396a8:

  1. serial lock — fixed: the whole rebind mutation (re-read, patch, archive, note, forced reconcile) now runs inside serial("b:" + b.id, …), re-reading the binding inside the lock so a concurrent respawn cannot be overwritten.
  2. destroyed-at-wake-time test — added: a fourth test sets environmentStatus: "destroyed" with no sendError and asserts the respawn, re-point, archive and note. Reverting the wake-time branch now fails it.
  3. ended-binding steward — fixed: store.byThread is only a refusal when the other binding is still open (other.endedAt === null), so an ended binding's old thread can be re-used.
  4. project steward / message — fixed: a thread that is a project steward is refused, and the success line now reports "its wake was sent" or "its wake is queued for its next turn" from the binding's awaitingReport after the reconcile.
  5. @bb mention — declined respawn there; added a comment saying the fallback is intended: the mention is not lost (the project steward answers it) and the binding's next requeue/doorbell respawns the steward through deliverWake.
  6. README — documented rebind and the auto-respawn under "What it does" → Lifecycle.

Typecheck passes; npm test is 759/759 (one more than before).

— from bb thread thr_dmewtukbjt

@trotterdylan
trotterdylan merged commit 67317da into main Oct 28, 2026
20 checks passed
@trotterdylan
trotterdylan deleted the bb/bb-103-respawn-thr_dmewtukbjt branch October 28, 2026 15:53
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Merged: no-review lane, reviewer approved 54366f5, checks green; since then: addressed all six reviewer suggestions (rebind under the binding's serial lock, a destroyed-at-wake-time test, ended bindings no longer block re-use of their old thread, project-steward thread refused, @bb-mention fallback documented, README updated). merge commit 67317da.

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 in Settings → Plugins → Team setup, or in the 03:00–05:00 ET quiet window.

— from bb thread thr_dmewtukbjt

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