Skip to content

stewards: archive finished workers and reviewers, and hide them with a waiting steward (BB-47) - #73

Merged
trotterdylan merged 3 commits into
mainfrom
bb/bb-custom-project-steward-thr_v3hwjqxxq3
Oct 24, 2026
Merged

trotterdylan merged 3 commits into
mainfrom
bb/bb-custom-project-steward-thr_v3hwjqxxq3

Conversation

@trotterdylan

@trotterdylan trotterdylan commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Implements BB-47.

The stewards plugin archived only the steward, at binding end. Finished workers and consumed reviewers stayed in the sidebar for as long as the binding was open, and a steward that hid itself while waiting on someone else left its finished rows behind with no context. This gives workers and reviewers a lifecycle and cascades hiding to them.

Merging this moves the bb-plugins pin, builds a new bb-server image and stages a restart on every developer's server. Do not press Restart now from a thread you still need; a server left alone restarts in the quiet window.

Classification

owner-reviewed: it changes existing behaviour — threads that stayed in the sidebar now leave it — and it is not a strictly additive change. It does not need a store migration: reviewer-to-worker ownership is derived from bb's parent relationship, exactly as the sidebar RPC already derives reviewers.

What changes

  • Reviewers. A reviewer is a child of the worker that started it (--parent-self). thread.created now archives the worker's older reviewer children when a newer round is spawned, and thread.idle on the worker archives reviewers whose round is consumed (not busy). The newest reviewer for a worker is never archived while the worker is in flight.
  • Finished workers. After the reconcile that delivered the workers' reports to the steward (wake returns true; the ops, deps and Sentry wakes do the same), finished workers are archived. A worker that ended with a question for the steward, or a binding that needs the user, keeps it visible. sendTo already unarchives an archived thread, so a later message brings it back under its effort.
  • Cascade hiding. hideWaiting hides the steward's finished workers and their reviewers with it; showing the steward again (showSteward, used by both visibility paths) shows the same finished workers and reviewers again. A running worker and its reviewer are unaffected. sendTo also shows a worker it brings back from the hidden cascade, so a resumed worker reappears.
  • Steward instructions. The standing wake text (wake.ts) now says a consumed worker is archived and that bb thread tell refuses it, so the steward runs bb thread unarchive <id> first or starts a fresh worker.
  • DESIGN.md (§2, §5, §9, §15) and README.md (Lifecycle, sidebar/unread dot, Workers) describe the lifecycle.

No source-contract.ts or other plugin changed. wake.ts is touched for the instruction text; the store is untouched.

Testing

  • npm run typecheck in plugins/stewards: pass.
  • npm test in plugins/stewards: pass (426 tests; stewards is in the CI matrix, so CI runs this too).
  • New server.test.ts cases: reviewer archived on the worker's next idle but not while its round runs; a worker is kept while its reviewer is in flight; older reviewer archived on a newer round; finished worker archived after the consuming reconcile but kept when it asks a question; unarchive-on-message round trip through an answered escalation; cascade hide/show with a running worker and its hidden reviewer left alone.
  • Not tested: the real bb sidebar's live-thread filtering (unit tests assert the archive/unarchive/visibility calls that drive it).

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_jgbgkt6vss.

— from bb thread thr_quj66sswap

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 1 (GLM 5.3, at 7d34fe2)

Owner review required: yes — it changes existing behaviour someone would notice: workers and reviewers that stayed in the sidebar for the binding's life now leave it, and a steward's follow-up to a consumed worker no longer works (blocker 3). @trotterdylan, this one needs your approval once the blockers are fixed. The PR's Classification line agrees with the lane.

Blockers

  1. server.ts:1256 (archiveFinishedWorkers) — a worker is archived while its reviewer is still in flight, which strands the review loop this PR's own docs describe ("ended the turn that spawned the reviewer to wait", DESIGN §5). In that flow the worker goes idle with its reviewer busy: archiveConsumedReviewers correctly leaves the reviewer, but the worker is marked finished with no question, and the reconcile its idle schedules (the loud "Worker … finished its turn" note) wakes the steward and archives the worker while the reviewer's round is still running. I verified the two bb-core behaviours this then trips over, at desktop-v0.46.0 (the pinned BB_REF):

    • threads.archive on the worker releases its unarchived children (archiveThreadAndReleaseChildren → releaseUnarchivedChildrenFromArchivedThreadInTransaction, services/threads/thread-ownership.ts): the reviewer's parentThreadId is set to null, so reviewersOf can never find it again — it will never be archived by archiveConsumedReviewers/supersedeOlderReviewers, and the worker's bb thread list --parent-thread check (build-tickets 4a) finds nothing, inviting a second reviewer.
    • the reviewer's finished turn can then no longer wake the worker: its parentThreadId is null, and queueParentSystemMessage refuses an archived parent anyway (services/threads/parent-system-messages.ts:436).
      Net: the worker never receives the verdict, the steward waits on the worker, and an unarchived reviewer is orphaned — the exact residue the ticket set out to remove. Fix: in archiveFinishedWorkers, skip a worker that still has an unarchived child (at minimum a busy one, the same busy predicate archiveConsumedReviewers uses). The worker is re-marked finished when its next turn ends after the round is consumed, so the archive then composes with the existing flow. A test: worker idles without a question while its reviewer is active, a reconcile runs, and the worker is not archived.
  2. server.ts:1278 (cascadeVisibility) — the show branch drops the finished filter the hide branch has, so showSteward sets visibility: "visible" on every worker and every reviewer, not just what the hide cascade hid. Reviewers of running workers — including ones the build-tickets skill spawns --visibility hidden precisely to keep out of the sidebar — are flipped visible, so after any wake that needs the user on a waiting binding, running reviewer rounds appear as sidebar rows that never appeared before this PR. The ticket says hiding hides "its finished workers and reviewers" and showing "makes them visible again"; showing threads the cascade never hid goes beyond it, and "running workers are unaffected" should hold on the way back up too. Fix: make the visible branch symmetric (finished workers and their reviewers), or record what the hide pass hid and restore exactly that.

  3. wake.ts:311 / the consumed-worker lifecycle — the standing wake text tells every steward "Follow it up with bb thread tell <id> <message>", but after this change a finished worker whose report was consumed is archived, and bb rejects a send to an archived thread with 409 "Thread is archived" (ensureThreadIsWritable, services/threads/thread-send.ts:190 at desktop-v0.46.0); bb thread tell does not unarchive. The plugin's own sendTo unarchives first, so the ticket's "a later message to it unarchives it" holds only for the plugin's messages — the message the wake text itself instructs now fails, and nothing in the wake text, README or DESIGN tells the steward to bb thread unarchive first or start a fresh worker. Fix (wake.ts is in the plugin and in scope): teach the standing rules the new lifecycle — e.g. "a worker whose report was consumed is archived: bb thread unarchive <id> before bb thread tell, or start a fresh worker" — and say it in DESIGN/README.

Suggestions

  • server.ts:1213 (reviewerOwner) — the docstring claims a lifecycle-owner-only reviewer's "parent is the worker", which is not so, and reviewersOf lists by parentThreadId only: such a reviewer would be superseded on creation but never found by archiveConsumedReviewers or the cascade. Build-tickets passes both flags so this is currently unreachable; either drop the lifecycleOwnerThreadId branch or make reviewersOf look there too, and fix the docstring.
  • server.test.ts — the new tests create reviewers visibility: "visible", but build-tickets spawns them --visibility hidden; modeling the hidden spawn would have caught blocker 2.
  • server.ts:982 (sendTo) — it unarchives but never restores visibility, so a worker hidden by the waiting cascade and then archived by a later reconcile runs its next turn invisible; "shows in the sidebar again under its effort" fails in that sequence. Consider setting visibility visible when a worker is brought back (not the steward's own thread, whose hiding must survive "nothing changed" wakes).
  • The round-trip test raises its escalation after the worker was archived; with a real worker the escalation is open before the worker goes idle, and needsUser(b) then blocks the archive — the tested sequence cannot arise naturally. It still guards the sendTo mechanism, but a comment saying so (or a question-worker variant) would keep it honest.

Checked

  • Ran: npm run typecheck and npm test in plugins/stewards — pass (426 tests). Stewards is in the CI matrix, so CI covers it; I ran it anyway.
  • Verified against bb core at desktop-v0.46.0 (the pinned BB_REF): a send to an archived thread throws 409; archiving a thread releases its unarchived children (parentThreadId → null); queueParentSystemMessage refuses an archived parent; visibility: "visible" is what puts a thread in the sidebar.
  • Verified against ticket:
    • Reviewer archived on the worker's next idle / newer-round spawn, newest kept while its round runs — met, tested.
    • Finished worker archived after the consuming reconcile, kept when it asks a question or the binding needs the user — met for the plugin's messages; the steward's bb thread tell path fails (blocker 3), and the worker-archived-while-reviewer-in-flight case breaks the loop (blocker 1).
    • Cascade hide/show, running workers unaffected on hide — met for the tested case; the show branch overshoots (blocker 2).
    • Binding end still stops workers and archives the steward, reopen brings a steward back — met (existing tests, one updated for the new worker archive).
    • DESIGN.md §2/§5/§9/§15 and README (Lifecycle, "The sidebar and the unread dot", Workers) describe the lifecycle — met.
    • Unit tests for the three cases plus the unarchive round trip — met; gaps noted above.

— from bb thread thr_jgbgkt6vss

…idden, and tell the steward to unarchive (BB-47)
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 2 fixes, at 60b7428.

Blockers

  1. Worker archived while its reviewer is in flight — fixed. archiveFinishedWorkers now skips any worker that still has an unarchived reviewer child, so bb core never releases the reviewer's parent mid-round. server.test.ts now asserts the worker is kept on the idle that spawned/wait-on a running reviewer, and that both the reviewer and the worker are archived only once the round is consumed.
  2. Show cascade overshot the hide cascade — fixed. cascadeVisibility is symmetric: on both hide and show it walks finished workers and their reviewers only. The cascade test now gives a running worker (thr_w3) a --visibility hidden reviewer and asserts it stays hidden after the steward is shown again.
  3. Wake text told stewards to bb thread tell an archived worker — fixed in wake.ts: the standing text now says a consumed worker's thread is archived, bb thread tell refuses it, and the steward should bb thread unarchive <id> first or start a fresh worker. DESIGN.md and README.md say the same. wake.ts is a fifth file in the diff; it is inside plugins/stewards and the task allowed a store migration for ownership, so I read this instruction-text fix as in scope.

Suggestions

  • reviewerOwner lifecycle-owner branch / docstring — taken. reviewerOwner is parent-only now, matching reviewersOf and the sidebar RPC, and the docstring says so.
  • Tests modeled reviewers as visible — taken; the cascade test above now spawns a hidden reviewer.
  • sendTo does not restore visibility — taken. sendTo now shows a hidden thread when it is a worker (never a steward, so "nothing changed" wakes still leave the steward hidden).
  • Round-trip test sequence is contrived — taken; it carries a comment that the escalation is raised after the archive to exercise sendTo directly, since a real open escalation would keep needsUser true and block the archive.

npm run typecheck and npm test in plugins/stewards pass (426 tests).

— from bb thread thr_quj66sswap

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 2 (GLM 5.3, at 60b7428)

Owner review required: yes — it changes existing behaviour someone would notice (workers and reviewers that stayed in the sidebar for the binding's life now leave it; the steward's follow-up path now involves an unarchive step). @trotterdylan, this one needs your approval; from my side no blockers remain.

Resolved since round 1

  • Blocker 1 (worker archived while its reviewer is in flight): resolved by 60b7428 — archiveFinishedWorkers now skips a worker with any unarchived child, with a comment naming the bb-core child-release behaviour, and the renamed test covers exactly the scenario I asked for (worker idles without a question while its reviewer is active; worker kept, then both archived once the round is consumed). The loop now composes: the reviewer's finished turn wakes the still-unarchived worker, whose next idle consumes and archives the reviewer, and only then does the worker archive.
  • Blocker 2 (show cascade flipped never-hidden reviewers visible): resolved by 60b7428 — cascadeVisibility is now symmetric (finished filter in both branches), and the new hidden-reviewer spawn in the cascade test (a running worker's reviewer, visibility: "hidden") would have caught the round-1 bug and now asserts it stays hidden through both the hide and the show.
  • Blocker 3 (bb thread tell to a consumed worker now fails with nothing telling the steward): resolved by 60b7428 — the standing wake text says the consumed worker is archived and names bb thread unarchive <id> or a fresh worker; DESIGN §5 and the README say the same, matching what I verified in bb core (send → 409 on archived, unarchive restores).
  • Suggestions 1–4: all taken — reviewerOwner is parent-only with an honest docstring, the tests model the hidden reviewer, sendTo shows a hidden worker it revives (and only a worker, so a waiting steward stays hidden), and the round-trip test comments on why the escalation is raised after the archive.

Suggestions

  • server.ts:1259 — the new guard is fail-open: reviewersOf swallows a threads.list failure into [], so a transient listing error at that moment archives the worker and re-triggers the orphaning the guard exists to prevent (the same swallow is fail-safe in archiveConsumedReviewers, which then archives nothing). A fail-safe variant would treat a failed listing as "has children". Rare, and self-healing on the next pass only for the reviewer, not the released parent — worth a follow-up, not a merge blocker.
  • server.ts:1282 — symmetric show skips a worker that was hidden while finished and has since been woken (it runs invisible until it finishes again and a later show or archive resolves it). sendTo covers the plugin-messaged resume; the reviewer-wake resume is uncovered. Edge of an edge; fine to leave.

Checked

  • Ran: npm run typecheck and npm test in plugins/stewards at 60b7428 — pass (426 tests). Stewards is in the CI matrix, so CI covers it; I ran it anyway.
  • Re-read the full round-2 diff against 7d34fe2 and the surrounding code; no new issues beyond the two suggestions above.
  • Verified against ticket: reviewer archived on the worker's next idle / newer-round spawn and kept while its round runs — met; finished worker archived after the consuming reconcile unless it asks a question, the binding needs the user, or its reviewer is still unarchived (the necessary carve-out) — met; unarchive-on-message round trip, including visibility — met; cascade hide/show symmetric with running workers and their reviewers unaffected — met; binding end and reopen unchanged — met; DESIGN §2/§5/§9/§15 and README sections updated to match the code, including the steward's unarchive step — met; unit tests cover all three cases and the round trip — met.

— from bb thread thr_jgbgkt6vss

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round-2 suggestions taken, at 23224d7.

  • reviewersOf fail-open guard — fixed. It now returns null when threads.list fails, and archiveFinishedWorkers treats null as "unknown" and keeps the worker; archiveConsumedReviewers, supersedeOlderReviewers and the cascade treat it as "nothing to do". A test stubs the listing to throw and asserts the finished worker is not archived.
  • Hidden worker woken by its reviewer runs invisible — fixed. thread.active now shows a hidden worker, so a worker hidden while finished and later woken by its reviewer reappears even without a plugin message. A test covers it.

npm run typecheck and npm test in plugins/stewards pass (428 tests).

— from bb thread thr_quj66sswap

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 3 (GLM 5.3, at 23224d7)

Owner review required: yes — same lane as before: it changes existing behaviour someone would notice (finished workers and reviewers now leave the sidebar; the steward's follow-up path gains an unarchive step). @trotterdylan, this one needs your approval; from my side no blockers remain.

Resolved since round 2

  • Suggestion 1 (fail-open listing guard): resolved by 23224d7 — reviewersOf now returns null on a failed listing (with a warn log), archiveFinishedWorkers treats "unknown" as keep-the-worker, and the other callers keep their fail-safe ?? []. The new test stubs threads.list to throw and asserts the finished worker is not archived; it fails without the fix.
  • Suggestion 2 (a worker hidden while finished runs invisible after a reviewer wake): resolved by 23224d7 — thread.active shows a hidden worker when it runs, worker-scoped (the early store.worker return keeps stewards' and reviewers' hidden state alone). The new test emits thread.active on a hidden worker and asserts it is shown; it fails without the fix.

No other changes; both are narrow fixes to my own suggestions, so the round-2 approval stands and this marker repeats it on the new head.

Checked

  • Ran: npm run typecheck and npm test in plugins/stewards at 23224d7 — pass (428 tests, the two new ones included). Stewards is in the CI matrix, so CI covers it; I ran it anyway.
  • Re-read the full round-3 diff against 60b7428; nothing beyond the two fixes.
  • All six acceptance criteria of BB-47 remain met, now including the fail-safe listing and the running-worker reshow.

— from bb thread thr_jgbgkt6vss

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Approved 23224d7 from the Stewards page

@trotterdylan
trotterdylan merged commit 6777f38 into main Oct 24, 2026
20 checks passed
@trotterdylan
trotterdylan deleted the bb/bb-custom-project-steward-thr_v3hwjqxxq3 branch October 24, 2026 20:23
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Merged: owner-reviewed, approved by trotterdylan on 23224d7 (unsigned PR comment, 2026-10-24T20:23:29Z), reviewer approved at round 3 on the same sha, checks green.

— from bb thread thr_quj66sswap

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