Skip to content

stewards: treat a worker as in flight between its turns (BB-17) - #35

Merged
trotterdylan merged 2 commits into
mainfrom
bb/bb-17-in-flight-workers-suppress-own-pr-wakes-thr_bavqcddfyz
Oct 19, 2026
Merged

trotterdylan merged 2 commits into
mainfrom
bb/bb-17-in-flight-workers-suppress-own-pr-wakes-thr_bavqcddfyz

Conversation

@trotterdylan

Copy link
Copy Markdown
Collaborator

Implements BB-17.

BB-11's steward was woken 22 times in four hours: the mechanical tier suppressed a binding's own PR activity only while a worker's turn was running, and a worker in the build-tickets loop is idle most of the time waiting on its reviewer. A worker now counts as in flight from its spawn until it is stopped, failed or archived, so its own PR activity is quiet across the idle and kept as quiet notes for the next due turn.

Merging this builds a new bb-server image and stages a restart for every developer's server; each server restarts when its owner presses Restart now, or in the quiet window (03:00-05:00 US Eastern).

Classification

no-review: additive wake suppression plus a threshold tweak. No existing behaviour a person relies on changes meaning, and no cross-repo contract, identity, production infra or store migration is touched.

What changes

  • workerInFlight / anyWorkerInFlight in reconcile.ts: running or finished (a turn ending is a pause, not a finish). diffObserved takes workerInFlight and quiets checks, description edits, pushes and developer-account comments while it holds.
  • The reviewer's bb-review markers are quiet while a worker is in flight, whichever account posts them; a round that changes the lane (markerLaneChange) wakes the steward at once.
  • server.ts: stopWorkers, archiveWaiting and the thread.failed / archived / deleted handlers use the same in-flight rule, so an idle worker is stopped and archived with its binding like a running one.
  • Compaction: compactDue and a pre-wake compactIfLarge call compact when the transcript is over the setting or when the wake about to be sent would push it over. The 120,000-token default is unchanged.
  • Docs (DESIGN.md, README.md) updated.

The compaction default

Kept at 120,000 tokens. A wake is capped at 30,000 characters (~7,500 tokens at 4 chars/token), and a steward getting 20 wakes a day adds roughly 150,000-200,000 tokens a day including its own turns. At 120k, with the pre-wake check, a steward compacts about once or twice a day and never reads more than the limit into a turn; a lower default would compact on nearly every wake (a provider call each time) and a higher one would let a single turn grow past a quarter of a 1M window. The pre-wake check is what bounds a single large wake, so the default stays where it was.

Testing

  • npm run typecheck in plugins/stewards: pass.
  • npm test in plugins/stewards: pass (116 tests; not in the CI matrix).
  • New: reconcile.test.ts covers the BB-11 sequence at the mechanical tier plus the in-flight rule, marker/lane change and compaction threshold; server.test.ts covers the wake count for the BB-11 sequence, the lane-change wake, the stopped-worker case and the pre-wake compaction.
  • Not tested: no live worker/PR loop was exercised.

🤖 Generated with Claude Code

BB-11's steward was woken 22 times in four hours. The mechanical tier
suppressed a binding's own pull request activity only while a worker's turn
was `running`; in the build-tickets loop the worker is idle most of the time,
waiting on its reviewer between rounds, so every push, check run and reviewer
comment woke the steward for a "nothing needed doing" turn.

- A worker is in flight from its spawn until it is stopped, failed or
  archived. Its turn ending is a pause: the status `finished` still counts,
  so own-pull-request activity (checks finishing, description edits, pushes,
  and comments from the developer's account) stays quiet and is kept as a
  quiet note for the next due turn. `stopWorkers`, `archiveWaiting` and the
  thread lifecycle handlers use the same rule, so an idle worker is stopped
  and archived with its binding like a running one.
- The reviewer's `bb-review` markers are the worker's business too, whoever
  posts them, while a worker is in flight; a round that changes the lane
  wakes the steward at once.
- Compaction now also runs before a wake that would push the transcript over
  the setting, not only after a turn. The 120,000-token default is unchanged:
  a wake is capped at 30,000 characters (~7,500 tokens), a steward getting 20
  wakes a day adds roughly 150-200k tokens a day, and the pre-wake check
  bounds any single turn, so a steward compacts once or twice a day and never
  reads more than the limit.

reconcile.test.ts covers the BB-11 sequence at the mechanical tier, and
server.test.ts the wake count; unit tests cover the in-flight rule, the
reviewer marker and lane change, and the compaction threshold.

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

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_9a4322ivud.

— from bb thread thr_bavqcddfyz

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 1 (GLM 5.3, at 2e02091)

Owner review required: no — none of the owner-reviewed triggers apply. The change widens a suppression window that BB-11's incident showed was the bug (the design's "the worker's own work is not news to the steward" was only implemented while a turn ran), stops idle workers with their binding like running ones, and adds a pre-wake compaction check. source-contract.ts is untouched (contract.test.ts passes), no store migration, no new dependency, no setting default change, no identity or infra surface.

Suggestions

  • reconcile.ts markerLaneChange — returns null when the before-list has no marker at all, so a lane change that spans a first-ever marker pair between two observations (round 1 no-review → round 2 owner-reviewed, prev had no markers) is silent. The worker surfaces the lane itself and the idle wake carries it, so this is fine to leave, but consider treating "no marker seen → a marker with a lane" as a change, or a word in DESIGN.md saying why not.
  • server.ts compactAboveTokens setting description — still reads "After a steward's or the project steward's turn, its context is compacted when it holds more than this", but README/DESIGN now also promise the pre-wake compaction this PR adds. The user-facing setting description should match.
  • server.ts wake() — compactIfLarge now runs on every wake; against a busy steward thread the compact call will throw and warn-log each time. Cosmetic, but a busy check (or downgrading to debug) would keep the logs clean.
  • A worker that delivered its final message and is never stopped stays finished, i.e. in flight, so its own PR activity stays quiet until the steward ends the binding and stopWorkers stops it. The worker-idle wake always tells the steward the worker's message, so nothing is lost; noting it only so the choice is visible.

Checked

  • Ran: npm run typecheck and npm test in plugins/stewards (typecheck pass; 116/116 pass). The plugins CI matrix does not include stewards (devbox-provider, github-watcher, html-preview, image-copy, kubernetes-provider, team-setup, thread-briefs, workstreams only), so CI never ran this code — I ran the full suite, including contract.test.ts (source-contract copies in sync).
  • Verified against ticket:
    • Criterion 1: workerInFlight counts running and finished (a turn ending is a pause); failed/stopped/archive are terminal, thread.active restores running. Own-PR activity (checks, description edits, viewer comments, pushes) is quiet while in flight; quiet notes are kept via keep()/store.note and the comment cursor, so they surface at the next due turn. Met.
    • Criterion 2: every listed wake survives — human comments (people filter), reviews by non-viewers (byOther/actionable: lc(r.author) !== viewer), merges/closes and entity state changes (lifecycle paths untouched), guidance, escalation resolution, needs items and requeueAfter (reason-driven paths untouched), and worker finishing/erroring (thread.idle note + thread.failed handler). Met.
    • Criterion 3: reviewMarker (first line only, per the pr-reviewer convention) filters markers out of people whichever account posts them; markerLaneChange wakes on a lane change (server.test.ts lane-change test). Met.
    • Criterion 4: compactDue compacts over the limit or when usedTokens + ceil(incomingChars/4) > limit, wired into both wake paths (wake() and wakeProject()); the 120,000 default is reviewed against 20 wakes/day in the PR description with the math checked against WAKE_MAX_CHARS = 30_000. Met.
    • Criterion 5: reconcile.test.ts has the BB-11 sequence (spawn → idle → reviewer marker → checks → push, all quiet, surfaced at the finish) plus unit tests for criteria 1, 3 and 4; server.test.ts covers the wake count end-to-end, the lane-change wake, the stopped-worker case and the pre-wake compaction. The tests fail if the change is reverted. Met.
  • Also checked the wakeProject() restructure: the store reads still happen after the threadInfo/unarchive awaits, the delivered-marking and undeliver-on-failure semantics are preserved, and the inline steps match sendTo exactly.

— from bb thread thr_9a4322ivud

- The compactAboveTokens setting description now says compaction also runs
  before a wake that would push the transcript over it.
- compactIfLarge skips a busy thread instead of warn-logging a failed
  compact on every wake.
- DESIGN.md says why a first reviewer marker with no earlier round is not
  treated as a lane change.

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

Copy link
Copy Markdown
Collaborator Author

Review round 1 follow-ups, at 06f4ef5:

  • markerLaneChange first-marker case — declined as a behaviour change, documented instead. The first round's lane is carried by the worker's own idle wake, and waking on every first review would put back the wake this ticket removes. Added a sentence to DESIGN.md §6 saying so.
  • compactAboveTokens setting description — fixed. It now says compaction also runs before a wake that would push it over.
  • compactIfLarge on a busy thread — fixed. It now checks the thread is idle and skips a busy one rather than warn-logging a failed compact on every wake.
  • A never-stopped worker staying in flight — acknowledged, by design. Criterion 1 keeps it in flight until stopped, failed or archived; the worker's idle wake carries its final message and the binding ending stops it.

Typecheck and npm test in plugins/stewards still pass (116/116).

— from bb thread thr_bavqcddfyz

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 2 (GLM 5.3, at 06f4ef5)

Owner review required: no — none of the owner-reviewed triggers apply (unchanged from round 1; the follow-ups are a setting-description wording fix, a log-noise fix and a doc paragraph).

Resolved since round 1

  • Setting description for compactAboveTokens (round 1, suggestion 2): resolved by 06f4ef5 — now names the pre-wake compaction.
  • compactIfLarge warn-logging on a busy thread (round 1, suggestion 3): resolved by 06f4ef5 — it now checks threadInfo and returns before compactedOn.set, so a skipped busy thread is retried later on the same reading; ordering is right.
  • First-ever marker not a lane change (round 1, suggestion 1): dropped — your argument holds. A first marker arrives on every PR, so waking on it would put back the wake the ticket removes, and criterion 3's wake is for a change of lane; the worker's idle wake carries the lane either way. The DESIGN.md paragraph records the reasoning.

Checked

  • Ran: npm run typecheck and npm test in plugins/stewards (pass; 116/116). Stewards remains outside the plugins CI matrix, so these are the only runs.
  • Diff since 2e02091 reviewed: only the three follow-ups above; no other behaviour touched, no contract, migration or dependency changes.

— from bb thread thr_9a4322ivud

@trotterdylan
trotterdylan merged commit 9a72a86 into main Oct 19, 2026
16 checks passed
@trotterdylan
trotterdylan deleted the bb/bb-17-in-flight-workers-suppress-own-pr-wakes-thr_bavqcddfyz branch October 19, 2026 21:37
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Merged: no-review lane, reviewer approved 06f4ef5, checks green.

— from bb thread thr_bavqcddfyz

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