Skip to content

stewards: keep a terminal binding with an escalation open (BB-60) - #85

Merged
trotterdylan merged 2 commits into
mainfrom
bb/bb-60-three-stewards-terminal-binding-fixes-thr_my9mkxtdi4
Oct 26, 2026
Merged

trotterdylan merged 2 commits into
mainfrom
bb/bb-60-three-stewards-terminal-binding-fixes-thr_my9mkxtdi4

Conversation

@trotterdylan

Copy link
Copy Markdown
Collaborator

Implements BB-60.

A terminal binding that reported escalate without followThrough reset its
follow-through to null, so finishEnding ended it, auto-resolved the open
escalation ("The binding ended") and left the user's question unanswered. Three
narrow fixes in plugins/stewards.

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

Classification

no-review: three narrow bug fixes in the plugin's own code; no cross-repo
contract, identity/access, production-infrastructure or bigDecisions trigger.

What changes

  • steward_report on a terminal binding that carries escalate (or already
    has an open escalation) and omits followThrough keeps the binding open:
    the escalation's question becomes the follow-through and followThroughUntil
    is set as if it had been given, so the question still reaches the user and
    the binding is bounded by the follow-through deadline. The report is not
    refused.
  • The thread-idle handler for an ended binding clears archiveWhenIdle only
    when the archive actually happens, so a thread that is still busy at that
    idle is retried on the next idle instead of never being archived.
  • finishEnding resolves its open escalations without recording a resolution
    delivery (a new deliver flag on store.resolve), and flushDeliveries
    skips a delivery whose origin binding has endedAt !== null; an ended
    binding is no longer woken by "answered by plugin: The binding ended".

Testing

  • npm run typecheck in plugins/stewards: clean.
  • npm test in plugins/stewards: pass (508 tests; the plugin is in the CI
    matrix, and these ran locally).
  • New tests: a terminal report that escalates without a follow-through leaves
    the binding and escalation open; a deferred archive survives an idle that is
    still busy and archives on the next; finishEnding records no resolution
    delivery and flushDeliveries skips a manually inserted delivery for an
    ended origin, so no wake reaches the ended binding.
  • Two existing terminal-escalation tests were updated: with the new rule, an
    open escalation keeps the binding alive through the wrap-up report, so they
    now end it via the follow-through deadline before asserting the resolved
    escalation.
  • Not tested: nothing beyond the plugin's unit suite.

A terminal binding that reported escalate without followThrough reset its
follow-through to null, so finishEnding ended it, auto-resolved the open
escalation and left the user's question unanswered. Keep the binding open
on the escalation's question, with the follow-through deadline set as if
it had been given.

Also clear archiveWhenIdle only when the archive actually happens, so a
busy idle retries instead of dropping the deferred archive, and resolve a
binding's open escalations on the way out without queuing a wake it would
never read (flushDeliveries skips an ended origin too).
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_t37pje9e5b.

— from bb thread thr_my9mkxtdi4

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 1 (GLM 5.3, at 7945bcd)

Owner review required: no — none of the owner-reviewed triggers apply. Three narrow bug fixes inside plugins/stewards' own code (report/follow-through handling, the idle archive retry, delivery flushing): tweaks that make the plugin do what it was already meant to do. No source-contract.ts change, no cross-repo contract, no identity/access, no store migration, no bigDecisions, no infra files. The PR's Classification line agrees.

Suggestions

  • server.ts ~3670 (idle handler comment): the comment says a still-busy ended steward "is retried on the next idle (or the ten-minute sweep)", but nothing in sweep() retries a deferred archive — it iterates store.open(), which selects ended_at IS NULL only. If the ended thread never goes idle again, it is never archived. Soften the comment (or add a sweep retry) in a follow-up; the ticket only asks for the idle retry, which is delivered.
  • server.ts 3676: archiveWhenIdle is cleared before the threads.archive call; if the archive throws, quietly swallows it and the flag is already false, so it is never retried — slightly at odds with the "cleared only when the archive actually happens" comment. Moving the store.patch after the await would match it. Pre-existing shape, not a regression.
  • server.ts 4792: with several open escalations, openBeforeReport[0]?.question takes the first one's question as the follow-through text. Cosmetic; the deadline and liveness are right either way.

Checked

  • Ran: npm install + npm run typecheck (clean) and npm test in plugins/stewards — 508 tests, 18 files, all pass. Stewards is in the CI plugins matrix, so CI covers it too; I ran it regardless since the latest run was still in progress.
  • Verified against ticket:
    • Criterion 1: met. steward_report on a terminal binding now derives followThrough from input.escalate?.question ?? openBeforeReport[0]?.question and anchors followThroughUntil as if given; the idle handler's followingThrough branch keeps the binding and escalation open. New test asserts binding open, escalation open, followThrough = the question, followThroughUntil non-null; the already-open-escalation side is exercised by the two updated tests.
    • Criterion 2: met. The idle handler clears archiveWhenIdle only when the archive actually happens; the new test stubs the thread busy through two idles (flag asserted true both times, no archive) and then archives on the third with the flag cleared.
    • Criterion 3: met. finishEnding passes the new deliver: false to store.resolve (no delivery row recorded — verified recordResolutionDelivery gates insertDelivery on it), and flushDeliveries skips deliveries whose origin binding has endedAt !== null while keeping the origin-less thread delivery path. The new test asserts no pending delivery after the deadline end and that a manually inserted delivery for the ended origin produces no wake and is marked done.
    • Criterion 4: met. Full plugins/stewards suite including contract.test.ts passes; typecheck clean.
  • Cross-checked the deliver=false cascade: resolve follows the forwarded_from chain, but a forward requires the escalation to belong to the target binding (server.ts 5220) and the question row is filed on that same binding, so a mechanical end never suppresses a wake owed to a different, still-open binding.
  • Restart safety: no schema or MIGRATIONS change; all new state is in existing columns.

— from bb thread thr_t37pje9e5b

Address review round 1: the idle handler now clears the flag after a
successful archive (a failed one is logged and retried), and the comment
no longer claims a sweep retries it, since sweep() only iterates open
bindings.
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Addressed review round 1:

  • Idle-handler comment (server.ts ~3670): fixed in 9a1a30d — removed the "(or the ten-minute sweep)" claim; sweep() iterates store.open() (ended_at IS NULL) and does not retry a deferred archive, so the comment no longer says it does.
  • archiveWhenIdle cleared before the archive (server.ts ~3676): fixed in 9a1a30d — the flag is now cleared only after bb.sdk.threads.archive resolves; a failed archive is logged and the flag survives to retry on the next idle. (Moving the store.patch after quietly() would not have helped: quietly() swallows the error, so the handler now catches directly.)
  • openBeforeReport[0]?.question with several open escalations (server.ts ~4792): declined — the follow-through is only the binding's deadline, each escalation keeps its own question on the board, and the first open question is a representative label. Naming all of them would not change liveness.

npm run typecheck clean and npm test 508/508 pass on 9a1a30d.

— from bb thread thr_my9mkxtdi4

@trotterdylan

trotterdylan commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator Author

Review round 2 (GLM 5.3, at 9a1a30d)

Owner review required: no — none of the owner-reviewed triggers apply (unchanged from round 1; the new commit is a comment fix and a flag-ordering fix inside plugins/stewards' own code).

Resolved since round 1

  • Suggestion 1 (comment claiming a ten-minute sweep retry): resolved by 9a1a30d — the comment now says only the next idle retries, which matches the code.
  • Suggestion 2 (flag cleared before the archive call): resolved by 9a1a30d — the archive now runs in a try/catch, the flag is cleared only on success, and a failure logs and leaves the flag for the next idle. Semantically the retry-on-failure this round asked for; an archive that keeps failing retries once per idle event with a warn line, not a hot loop.
  • Suggestion 3 (openBeforeReport[0] question as the follow-through label): dropped — the author's dispute holds. With several open escalations the binding's liveness and deadline are identical either way; only the label differs, and any of the open questions bounds the binding.

Checked

  • Ran: npm run typecheck (clean) and npm test in plugins/stewards at 9a1a30d — 508 tests, 18 files, all pass.
  • Reviewed the new diff itself: the only behavioural change is the flag-ordering fix, and it cannot regress the busy-idle path (the busy guard is unchanged). Ticket criteria 1–4 remain met as verified in round 1; nothing else moved.

— from bb thread thr_t37pje9e5b

@trotterdylan
trotterdylan merged commit 15654c7 into main Oct 26, 2026
20 checks passed
@trotterdylan
trotterdylan deleted the bb/bb-60-three-stewards-terminal-binding-fixes-thr_my9mkxtdi4 branch October 26, 2026 12:44
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Merged: no-review lane, reviewer approved 9a1a30d, checks green.

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

merge commit 15654c7

— from bb thread thr_my9mkxtdi4

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