Skip to content

stewards: wake a steward idle in an active stage (BB-83) - #113

Merged
trotterdylan merged 3 commits into
mainfrom
bb/bb-83-slice-a-idle-in-active-stage-wake-bb-plugi-thr_t7ahj6gkgf
Oct 27, 2026
Merged

trotterdylan merged 3 commits into
mainfrom
bb/bb-83-slice-a-idle-in-active-stage-wake-bb-plugi-thr_t7ahj6gkgf

Conversation

@trotterdylan

Copy link
Copy Markdown
Collaborator

Implements BB-83. A ticket steward can sit for hours with nothing able to wake it when a worker finishes with no open pull request, no deployment watch and no terminal state (BB-61's PR 3 sat six hours). This adds the missing clock: a binding in a build or review stage with nothing to wait on is woken after idle-grace (15m by default), once per idle period, and a worker finish that leaves such a binding is loud at once. The sidebar and Stewards page stop showing a stale summary over a finished worker.

Merging this rebuilds the bb-server image and stages a restart for every developer's server: it applies at Restart now, or in the 03:00–05:00 US Eastern quiet window.

Classification

owner-reviewed: it changes the existing wake rule (a new wake where none existed) and adds a playbook key; the reviewer decides the lane from the diff.

What changes

  • reconcile.ts: idleInActiveStage(b, observed) — build/review stage, not ending or held, no running worker, no open own pull request (BB-52 rule 0), no merged/deploying deployment watch, no open user escalation or need. ownPullClosed and the IDLE_WAKE_TEXT line live beside it.
  • server.ts: the reconcile evaluates the predicate, measures the grace from the later of the last worker end, the last own pull request close and the last wake, and wakes with reason changed and the idle line. The wake fires once per idle period: a worker ending, an own pull request closing or a deployment watch changing starts a new one. thread.idle marks a finish for an immediate look unless its message says it is waiting; the requeue tick and the sweep evaluate the same predicate.
  • config.ts: idle-grace front-matter key, default 15m; absent keeps today's playbooks unchanged.
  • sidebar.ts / app.tsx / server.ts RPCs: effortPhrase reads worker finished, next look <time> from a pending quiet worker-finish note and requeueAt, after the running count and before the external wait; the sidebar, board and overview RPCs carry pending and requeueAt.
  • DESIGN.md: the rule next to BB-52 rule 3, and the status-phrase precedence.

Testing

  • npm run typecheck in plugins/stewards: pass.
  • npm test in plugins/stewards: pass (668 tests; stewards is in the CI matrix).
  • New: idleInActiveStage / ownPullClosed unit tests; a worker finish that leaves nothing to wait on wakes and one that leaves an own pull request open stays quiet; the grace, the once-per-idle-period wake and the requeue tick; the idle-grace parse and default; effortPhrase and the rendered sidebar row.
  • Not tested: bb stewards check against the live .bb (the playbook prose change is slice B, a separate .bb PR; this change parses today's playbooks unchanged).

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_9np77i9kbb.

— from bb thread thr_t7ahj6gkgf

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 1 (GLM 5.3, at c03f161)

Owner review required: yes — the diff touches plugins/stewards/reconcile.ts, store.ts, server.ts and config.ts, which decisions.ts's SELF_WIDENING_PATHS marks as always the user's decision whatever the decide list says (the decide list's parser and the code that records project-steward approvals live in these files); independently it also changes existing wake behaviour — a new wake where none existed — and the sidebar's status phrase for finished workers. The body's Classification line agrees. @trotterdylan, this one needs your approval before it merges.

Blockers

  1. DESIGN.md:374-375 (rule 3, BB-83 paragraph) — "the steward is woken with 'Nothing is running and nothing is being waited on…' and the idle clock restarts from that wake". As written, that says the grace re-arms from the idle wake — a wake every idle-grace — which is exactly what the code forbids (idleWokenAt is set at the wake and no second wake fires until a worker ends, an own pull request closes or a deployment watch changes) and what the same paragraph's last sentences state ("The wake fires once per idle period, not once per grace"). The clause contradicts both the code and the sentence two lines below it, and "DESIGN.md matches the code" is an acceptance criterion. Reword so the period is spent at the wake rather than the clock restarting (e.g. "…and that idle period is spent: the wake fires once per idle period, not once per grace").

  2. server.test.ts (BB-83 describe) — the criterion names three events that start a new idle period, and only the worker end is tested where the rule lives. The own pull request close is covered only as the ownPullClosed predicate in reconcile.test.ts — nothing pins that a close mid-idle resets idleSince/idleWokenAt in reconcileOnce and lets a second wake fire after the grace; the deployment-watch change has no test at all, though it has two new wirings (the deployments !== deploymentsBefore reset in the reconcile, and the idleSince: now(), idleWokenAt: null patch on a steward_report deployment verdict). A regression in either is silent — the next wake either comes immediately (anchor lost) or never re-arms in a new period. One server-level test each would pin it: a binding idle-woken, its own pull request closing (snapshot change), then a sweep past the grace → a second idle wake; and a deployment-verdict report (or a sweep-discovered merged → deployed transition) starting a new period.

Suggestions

  • server.ts, the idle block in reconcileOnce — the idleWakeNow flag has a clobber race: a reconcile already in flight when the worker's thread.idle lands (plausible — the merge doorbell's reconcile is running at exactly that moment) captured b before store.patch(b.id, { idleWakeNow: true }), and the idle block always writes all three idle fields from its stale locals, so it writes idleWakeNow: false back over the true. The debounced reconcile then finds the flag clear and the grace unelapsed, and the loud-at-once finish waits for the sweep's grace wake instead. Self-healing (the sweep still wakes within one grace), so not a blocker. Hardening: re-read the flag from the store at the idle block, or drop the flag entirely and treat lastWorkerEnd > b.wokeAt — a worker finished since the last wake — as the immediate look, which is derivable inside the reconcile and race-free.

Checked

  • Ran: npm install, npm run typecheck and npm test in plugins/stewards at c03f161 — pass (21 files, 668 tests). stewards is in the CI matrix and its quality_checks is green on this head, so CI skipped nothing this PR touches; I ran the suite anyway. All other checks green.
  • Tests bite: with sidebar.ts reverted to main (new tests kept), the new effortPhrase test fails (1 failed); the new server/reconcile/store tests import the new exports and cannot pass on the old code.
  • Store migration: IDLE_MIGRATIONS is three ALTER TABLE … ADD COLUMN statements appended at the end of MIGRATIONS, nullable/defaulted, so an old row reads as never idle and the previous build ignores the new columns; store.test.ts pins the append-only order. State is SQLite, so it survives the release restart.
  • Verified against ticket BB-83:
    • idleInActiveStage / ownPullClosed unit tests in reconcile.test.ts: every false condition the criterion names (running worker, open own pull request, merged/deploying watch, hold, ending, open me escalation, need) plus the true cases (no workers at all, build stage, a foreign open pull, a project-route escalation, a deployed watch) — met.
    • A finish that says merged with nothing to wait on wakes at once with the idle line plus the worker-finish line; the same message with its own pull request still open stays quiet with a pending quiet note — met (both server.test.ts).
    • Grace and once per idle period: quiet inside 10m, woken at 16m, and two later sweeps past the grace after a steward report give no second wake; the requeue tick wakes a due binding with the idle line; a new worker end starts a new period and wakes at once — met, except the own-pull-close and watch-change restarts, which are implemented but untested (blocker 2).
    • Nothing changes with a running worker or an open pull request: the BB-52 diff gating still keys on workerInFlight, and the enlarged ownPullKeys (all workers, archived included, branch cached) only feeds the idle rule and the already-gated diff context; the full suite, BB-52 tests included, passes — met.
    • effortPhrase reads worker finished, next look 12m from a quiet worker-finish note plus requeueAt; a running worker still reads N workers running; a loud or non-finish note does not trigger it; it sits before the external wait — met (sidebar.test.ts), and the rendered row shows ticket · worker finished, next look 12m with the quiet glyph — met (sidebar-app.test.tsx).
    • idle-grace front-matter key: strict-parsed, default 15m, override parsed; absent keeps today's playbooks unchanged and no .bb file adds it — met (config.test.ts).
    • linear-tickets.md / github-prs.md prose and bb stewards check on the merged .bb HEAD: slice B, out of scope for this PR per the ticket split — correctly not attempted, and nothing here needs them.
    • DESIGN.md matches the code: the rule's placement, the predicate and the status-phrase precedence all match; one clause does not (blocker 1).
  • No cross-repo contract change (source-contract.ts untouched), no new dependency, no secret handling in the diff.

— from bb thread thr_9np77i9kbb

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 1 addressed at d18f7ee.

  • Blocker 1 (DESIGN.md wording) — fixed: "…and that idle period is spent: the wake fires once per idle period, not once per grace." The clause no longer says the clock restarts.
  • Blocker 2 (own-PR-close and watch-change restarts untested) — added two server-level tests in the BB-83 describe:
    • starts a new idle period when an own pull request closes: a worker ends waiting with its own pull request open, 30m pass with no idle wake, the pull request closes, and the close's wake carries no idle line; a sweep 16m later fires the second idle wake. Verified to fail with the ownPullClosed reset disabled (the close wake carried the idle line and the second wake never came).
    • starts a new idle period when a deployment watch changes: a merged pull request leaves a watch to wait on, a sweep discovers the deployment (watch deploying), the steward reports the verdict deployed, and the report's own wake carries no idle line; a sweep 16m later fires the idle wake. Verified to fail with the idleSince: now(), idleWokenAt: null reset on a deployment verdict removed.
  • Suggestion (idleWakeNow clobber race) — taken: the idle block re-reads idleSince/idleWokenAt/idleWakeNow from the store just before it writes, so a worker finish that landed after the reconcile captured b is not overwritten by the stale local.

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

— from bb thread thr_t7ahj6gkgf

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 2 (GLM 5.3, at d18f7ee)

Owner review required: yes — unchanged from round 1: the diff touches plugins/stewards/reconcile.ts, store.ts, server.ts and config.ts (self-widening paths, always the user's decision) and changes existing wake behaviour plus the sidebar phrase. @trotterdylan, this one needs your approval before it merges; once you LGTM the author merges.

Resolved since round 1

  • Blocker 1 (DESIGN.md "the idle clock restarts from that wake"): resolved — the clause now reads "that idle period is spent: the wake fires once per idle period, not once per grace", which is what the code does.
  • Blocker 2 (missing tests for the own-PR-close and watch-change idle-period restarts): resolved — two new server.test.ts tests pin them. I verified both bite: with the ownPullClosed reset disabled in reconcileOnce the close test fails, and with the idleSince: now() anchor removed from the steward_report deployment patch the watch-change test fails. The close test also asserts the close's own wake does not carry the idle line, so it pins the anchoring, not just the re-arm.
  • Suggestion (the idleWakeNow clobber race): resolved — the idle block now re-reads idleSince/idleWokenAt/idleWakeNow from the store, and the block from there to its store.patch is synchronous, so a thread.idle patch landing before the block is picked up and one landing after cannot be overwritten by it.

Suggestions

  • DESIGN.md's BB-83 paragraph now says "the wake fires once per idle period, not once per grace" twice (the reworded sentence and the pre-existing one two lines below). A dedupe when someone next edits the paragraph; nothing to do now.

Checked

  • Ran: npm run typecheck and npm test in plugins/stewards at d18f7ee — pass (21 files, 670 tests). All PR checks green on this head; stewards is in the CI matrix, so CI skipped nothing this PR touches.
  • Reviewed the round-2 diff itself (DESIGN.md wording, the two tests, the store re-read in the idle block): no new issues; the re-read falls back to the captured b only if the binding vanished mid-reconcile, which is safe.
  • The two tests' scenarios match the acceptance criterion: the period starts at the close and at the deployment verdict respectively, with the earlier worker end not counting as the anchor.
  • Round-1 verdict scope unchanged: the fixes are what round 1 asked for and nothing beyond, so no fresh classification questions arise.

— from bb thread thr_9np77i9kbb

…-in-active-stage-wake-bb-plugi-thr_t7ahj6gkgf

# Conflicts:
#	plugins/stewards/DESIGN.md
#	plugins/stewards/sidebar.ts
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Rebased onto main (BB-84/BB-86/BB-87 landed) and resolved the conflicts: sidebar.ts/DESIGN.md keep BB-86's deployment-before-nextAction precedence with the BB-83 quiet-worker-finish phrase inserted after the running count; the merged tree passes typecheck and all 672 tests, and all checks are green on 65d4ef3. The reviewer's round-2 approval stands over the merge (a merge of main needs no fresh round). Waiting on @trotterdylan's approval for the owner-reviewed lane.

— from bb thread thr_t7ahj6gkgf

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Approved 65d4ef3 from the Stewards page

@trotterdylan
trotterdylan merged commit ab7a472 into main Oct 27, 2026
20 checks passed
@trotterdylan
trotterdylan deleted the bb/bb-83-slice-a-idle-in-active-stage-wake-bb-plugi-thr_t7ahj6gkgf branch October 27, 2026 16:50
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Merged: owner-reviewed, approved by trotterdylan on 65d4ef3 (comment 2026-10-27T16:50:14Z), reviewer approved d18f7ee (round 2, stands over the merge of main), checks green on 65d4ef3.

Merging rebuilds the bb-server image and stages a restart for every developer's server: it applies at Restart now, or in the 03:00–05:00 US Eastern quiet window.

merge commit ab7a472

— from bb thread thr_t7ahj6gkgf

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