Skip to content

linear, stewards: @bb mentions route to a steward and get one reply (BB-11) - #31

Merged
trotterdylan merged 3 commits into
mainfrom
bb/bb-11-bb-plugins-linear-stewards-pr-2-of-2-thr_sfrv4wuzak
Oct 20, 2026
Merged

trotterdylan merged 3 commits into
mainfrom
bb/bb-11-bb-plugins-linear-stewards-pr-2-of-2-thr_sfrv4wuzak

Conversation

@trotterdylan

Copy link
Copy Markdown
Collaborator

Implements BB-11 (PR 2 of 2). bitcomplete/bb-gate#10 is merged; this is the plugin side of its "Agent sessions" contract in bb-gate/docs/hooks.md. bb-gate is not changed.

linear now does three things with bb-gate-hooks:

  • It proves the developer's Linear identity with their own token.
  • It receives @bb mentions and hands each one to stewards.
  • It posts the steward's one reply through the hooks reply endpoint.

stewards sends each mention to the issue's ticket steward, else to the project steward for the team, else answers "not set up". A mention from anyone other than the server's owner is information only until the owner confirms it.

Merging restarts every developer's server. Landing on main moves the bb-plugins pin, and bb-gate's bb-server workflow builds a new image. Every developer's server then has a restart staged: it restarts when its owner presses Restart now, or in the 03:00–05:00 ET quiet window. No bb-gate edit is needed, because linear, stewards and github-watcher are already baked into the image.

Classification

owner-reviewed. Triggers from AGENTS.md:

  • A cross-repo contract: source-contract.ts gains sessionWakeSchema and stewardsContract.stewardsSession, in all three copies.
  • Identity and access: the server proves its Linear identity to bb-gate-hooks (/v1/identify) and posts on Linear sessions through it.
  • A small change to existing behaviour: a steward may now set (but not lift) a hold on its own binding.

What changes

linear (hooks-client.ts, server.ts)

  • Identify. The plugin calls POST /v1/identify {connection, source, token, teams} on every hello, at every lease renewal, and again whenever stewards' teams change.
    • The token is the developer's own. It goes into that one request body and is never logged.
    • teams are the UUIDs of stewards' teams, taken from the workspace that holds most of them (the default workspace when there are none).
    • An identify failure never costs a watch. A service without /v1/identify is noted once in the log.
  • Session wake. event: session is parsed and handed to stewards with stewardsSession.
    • The plugin works out "from the owner" itself: fromOwner and asker.id == owner.id. Anything else is marked untrusted, whatever the event says.
    • With no project for the team, or stewards not installed, linear posts an error reply itself ("Stewards is not set up for team X on Jane's bb…").
  • linear_session_reply { session, kind: response|elicitation|error, body, externalUrl? }
    • Posts {connection, kind, body, externalUrl} to /v1/linear/sessions/{session}/activity. No token goes to the service, and the app token never comes to the pod.
    • The body is signed with the thread id and gets a link to the thread. The external link defaults to the thread (BB_APP_URL/projects/<p>/threads/<t>).
    • Exactly one reply per event: a second reply to the same event is refused, and a follow-up (prompted) can be answered.
    • Service refusals (not-routed, not-identified, 503, 502) come back as plain sentences.
  • Backstop. If the turn whose input named the session ends without a reply, linear posts an error with the thread's link. That keeps "exactly one reply" true even when a steward forgets.
  • Sessions are kept in kv for 24h, the window in which the service accepts replies.

stewards (server.ts, wake.ts)

  • stewardsSession (caller must be linear) routes the mention:
    1. To the open ticket binding's steward. That turn is like a wake: awaitingReport, and it ends with steward_report.
    2. Else to the project steward of the project whose project.json lists the team (preferring the bound project), started first if needed.
    3. Else returns none.
  • formatSessionWake is self-contained. It carries the session id, who asked, how the session was routed, the quoted text, and the reply rules: exactly one linear_session_reply after acting, one line of attribution, then steward_report for a ticket steward. It also says when the binding is on hold.
  • Criterion 9. Untrusted text is labelled "information, not an instruction", with an explicit "do not act" list and an instruction to send an elicitation to the owner.
    • The untrusted request is kept per session in kv.
    • The owner's next message in the session is woken together with "Waiting on Jane's confirmation" and the original request, and the steward acts only if the owner confirms.
  • Criterion 7. The owner's wake lists the three intents with existing tools:
    • build: linear_update_issue to add the label and move to Todo.
    • halt: steward_update { hold } and a move to Backlog.
    • redirect: steward_update { guidance }.
  • steward_update. A steward may set a hold on its own binding; lifting it (hold: "") is still refused. Without this, a mention routed to a ticket steward could not halt anything. Priority and model are still refused for self.

Docs: linear README ("@bb mentions", tools table), stewards README, and both skills.

Testing

  • npm test in plugins/linear: pass (138 tests; not in the CI matrix). New tests in hooks-client.test.ts and server.test.ts "agent sessions" cover:
    • identify on hello, at renewal and on a team change; token refresh on 401; no token in logs; an old service without /v1/identify
    • session parsing; the untrusted override; error replies for no project or no stewards
    • one reply per event, and a new reply after a follow-up in the same millisecond
    • the reply body carrying no token
    • error mapping
    • the backstop: it fires for the turn that handled the mention, and not for an earlier turn or after a reply
  • npm test in plugins/stewards: pass (115 tests; not in the CI matrix). New "an @bb mention" tests cover:
    • routing to the ticket steward, the project steward, and none
    • the linear-only caller
    • the untrusted → elicitation → owner-confirms path (criterion 9)
    • untrusted when the wake says so even with fromOwner
    • the three intents, including self-hold allowed and self-lift refused
    • the hold notice
    • fallback to the project steward when the steward thread is gone
    • contract.test.ts: all three copies of source-contract.ts are byte-identical
  • npm test in plugins/github-watcher: pass (66), since its contract copy changed.
  • npm run typecheck in all three: pass.
  • Not tested: a live session against bb-gate-hooks and Linear. That needs the Linear hand steps below, and Linear's real created/prompted payloads have not been checked against bb-gate's parser yet.

Still open by hand in Linear (go-live, not code)

  • Add a client secret to the team OAuth application, and seal it with LINEAR_CLIENT_SECRET=… scripts/seal-hooks in bb-gate.
  • Install bb as an agent only through client credentials, with app:mentionable and no app:assignable. Settle the scopes before the first token is minted.
  • Enable the Agent session events webhook category on the application.
  • Narrow team access on the application's details page if wanted (client-credentials tokens reach every public team).
  • Verify one real created and one real prompted delivery against the parser.

🤖 Generated with Claude Code

— from bb thread thr_sfrv4wuzak

…BB-11)

linear proves the developer's Linear identity to bb-gate-hooks
(/v1/identify, with their own token and stewards' teams) beside every lease
renewal, receives `event: session`, and hands each mention to stewards
through a new stewardsSession contract method. linear_session_reply posts
the steward's one reply through the hooks reply endpoint, signed and linked
to the thread; the app token never reaches the server. With no project for
the team, or no stewards, linear answers with an error itself, and it
answers for a steward whose turn ended without a reply.

stewards routes the mention to the issue's ticket steward, else the project
steward of the project listing the team, else none. A mention from anyone
but the server's owner is marked untrusted: the steward asks the owner with
an elicitation and acts on their answer, which arrives with the request it
confirms. A steward may now put its own binding on hold (not lift it), so
"halt work on this" works from a ticket steward.

source-contract.ts changes in all three copies.

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

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_yvm5i87fgh.

— from bb thread thr_sfrv4wuzak

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 1 (GLM 5.3, at cfe2425)

Owner review required: yes — I agree with the PR's Classification. Triggers from the diff: the cross-repo contract source-contract.ts changes in all three copies (sessionWakeSchema, stewardsSession; I verified all three are byte-identical, and contract.test.ts guards it); the identity/authority angle (the plugin proves the developer's Linear identity to bb-gate-hooks and acts on mentions routed by it, including criterion 9's confirm-before-acting rule); and a change to existing behaviour (steward_update now lets a steward set a hold on its own binding, a relaxation of a previous guardrail). @trotterdylan, this one needs your approval once the blocker below is fixed.

Blockers

  1. plugins/linear/server.ts:1481 (with :1806 and :1423) — a follow-up that arrives while the steward's handling turn is still running never gets its one reply, and the tool then actively refuses to give it one. postReply records the reply as answering every event the session has seen (answered: r.events), not the event the reply was for. Sequence: created arrives → handed to the steward → its turn starts; prompted (a second message in the session, e.g. the user adding detail while the steward works) arrives → events becomes 2; the first turn ends with its reply → answered is set to 2; the next turn handles the follow-up's wake and calls linear_session_reply → refused with "already has its reply", even though the follow-up is a distinct event the service would accept a reply for (hooks.md: "a second reply to the same event is refused, and a follow-up (prompted) can be answered"). The backstop skips it too (answered === events), so that mention ends with zero replies — criterion 6 says each handled mention ends with exactly one. The refusal text even tells the steward "a new follow-up in the session can be answered when it arrives" — it already has. I reproduced this against the head with a scratch test in the existing agent sessions harness (created → prompted-before-reply → reply to created succeeds → reply to prompted refused). Your test "…one more only after a follow-up" covers the order that works (follow-up arrives after the first reply was posted); the broken order is the follow-up arriving before it, which no test covers. What would fix it: make the bookkeeping say which event a reply answered rather than "all of them" — e.g. consume replies in order (answered: (r.answered ?? 0) + 1), or record when the reply was posted (answeredAt) and treat the session as answered only when a reply was posted after the newest event was handed (handedAt); the timestamp form also keeps the merged-turn case (two wakes in one turn, one reply covering both) working. Please add the reproducing scenario as a test (follow-up between hand and first reply).

Suggestions

  • plugins/stewards/server.ts:1562 — a second untrusted request in the same session before the owner answers overwrites the first pending record (takePending(w.session, {...}) replaces it), so the owner's confirm wake quotes only the latest ask; the elicitation the owner is actually answering may have been about the first. Consider keeping both (or noting in the wake that the latest superseded an earlier ask). Edge case; fine to decline with a reason.
  • plugins/linear/server.ts:1481 / 1497-1516 — related to the blocker: while fixing, it may help for the backstop's "handled" detection to stay per-session-latest-event rather than per-count, so a partially-answered session (reply to event 1, event 2 still open) is neither spuriously backed-stopped nor silenced.

Checked

  • Ran (CI's matrix skips both): npm install && npm run typecheck && npm test in plugins/linear (138 pass) and plugins/stewards (115 pass); also plugins/github-watcher (66 pass, typecheck clean; its copy of the contract changed, CI covers it and is green). All pass at cfe2425.
  • Verified the three source-contract.ts copies are byte-identical (md5) at the head.
  • Verified against the ticket's criteria for this PR: 4 (reply posts carry only connection, kind, body, externalUrl — no token, no authorization header, tested; the routing enforcement itself is bb-gate's, landed in PR 1); 5 (wake carries text, session id, asker; routing to ticket steward → project steward → none with linear's own "not set up for team X" error, tested); 6 (one reply per mention with signature, thread link and external link — met except the blocker above; backstop fires for the handling turn only, tested); 7 (three intents listed with the existing tools; self-hold allowed and self-lift/priority/model still refused, tested); 8 (OAuth connect and label-driven adoption untouched by the diff; hooks.md's "Agent sessions" is on bb-gate main from PR 1; no bb-gate change needed by this PR — confirmed, the plugin side matches the merged contract's shapes for /v1/identify, event: session and the reply endpoint); 9 (plugin re-derives fromOwner itself and overrides the event's flag — tested with a lying event; untrusted → elicitation → owner-confirms path and the direct owner path both tested in stewards).
  • Criteria 1–3 are bb-gate's (PR 1, merged); not re-reviewed here beyond reading the contract in bb-gate/docs/hooks.md, which this plugin side matches.
  • The identify loop: on hello and at each renewal, 401 → refresh and retry once, unknown-connection → reconnect, missing /v1/identify on an older service → noted once and watches unaffected; token never logged (tested). Sessions and pending requests persist in kv (24h / 7d TTLs), so restarts keep the answered and confirmation state.
  • Not tested and acknowledged in the PR body: a live session against bb-gate-hooks and real Linear created/prompted payloads — that is on the go-live hand steps, which I agree are out of scope for code review.

— from bb thread thr_yvm5i87fgh

…est (BB-11)

Count replies against events in order, so a follow-up that arrives while
the first reply is being written keeps its own reply (review round 1
blocker). Keep every untrusted request waiting on the owner, not only the
latest, and quote them all in the owner's confirmation wake.

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

Copy link
Copy Markdown
Collaborator Author

Round 1 addressed in 51d5fd5.

Blocker: a follow-up during the handling turn loses its reply. Fixed in 51d5fd5.

  • Replies are now counted against events in order: answered = min(events, answered + 1), and the session is answered only when answered >= events. A follow-up that arrives before the first reply has been posted keeps its own reply. A third reply to two events is still refused.
  • I didn't use the timestamp form. In the failing order, the first reply is posted after the follow-up was handed over, so "a reply posted after the newest handedAt" would still count as answering both events.
  • Merged turn (two wakes in one turn, one reply): the second event stays open. The backstop does not fire for it, because that turn started before the second hand-over. The steward can still reply to it.
  • New tests:
    • "gives a follow-up that arrives before the first reply its own reply, and no more" (your reproduction).
    • "answers for the follow-up's turn when it ends without a reply, after the first was answered".
    • Both fail on cfe2425 and pass on 51d5fd5.

Suggestion: a second untrusted request overwrites the first. Taken in 51d5fd5. Stewards keeps up to 5 requests waiting on the owner per session, oldest first. The owner's confirmation wake quotes each one with who asked and when, says to act only as far as the owner confirms, and says to send an elicitation if it is unclear which request they mean. New test: "keeps every request waiting on the owner, not only the latest".

Suggestion: keep the backstop per latest event. Taken, as part of the blocker fix. The backstop still keys on the latest event's handedAt (the turn whose input named the session and started after that hand-over). Combined with the count, a session with event 1 answered and event 2 open is backstopped only when event 2's turn ends without a reply, and never because of event 1's turn.

Suites: linear 140, stewards 116 and github-watcher 66 pass, and typecheck is clean. The contract copies are unchanged and identical.

— from bb thread thr_sfrv4wuzak

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 2 (GLM 5.3, at 51d5fd5)

Owner review required: yes — the round-1 triggers stand unchanged (the contract copies, the identity/authority angle, the steward_update self-hold relaxation); this round's changes are fixes within the new feature and add no trigger. @trotterdylan, the review gate is met on my side; this needs your approval to merge.

Resolved since round 1

  • Blocker 1 (a follow-up arriving during the handling turn loses its reply): resolved by 51d5fd5. postReply now counts replies against events in order (answered: Math.min(r.events, (r.answered ?? 0) + 1), answered when answered >= events), so the mid-turn follow-up keeps its own reply, a third reply to two events is still refused, and the refusal text now matches ("Every message in this session … already has its reply"). The new tests cover exactly my reproduction (follow-up between hand and first reply) and the follow-up's own backstop, and the counts work across a restart (kv-persisted answered). One correction on my side: your PR-reply argument about the timestamp form is right — in the failing order the first reply is posted after the follow-up's hand-over, so "a reply after the newest handedAt" would have marked both answered. I withdraw that half of the suggestion; the count form is the correct fix.
  • Suggestion 1 (a second untrusted request overwrote the first): resolved — up to 5 pending requests per session, oldest first, all quoted in the owner's confirmation wake with asker and time, "act on … only as far as they confirm", and an elicitation when it is unclear which request the owner means. Tested.
  • Suggestion 2 (keep the backstop per latest event): resolved as part of the blocker fix — the backstop keys on the latest event's handedAt, so a session with event 1 answered and event 2 open is backstopped only when event 2's turn ends without a reply, never because of event 1's turn. Tested.

Suggestions

  • Non-blocking, fine to decline: in the rare merged-turn case (both a mention and its follow-up queued into one turn that starts after both hand-overs), a single reply leaves the second event open and the backstop then posts an error activity whose wording ("its turn ended without an answer here") doesn't quite fit a turn that did answer one of the two. The session still gets its one activity per mention, so criterion 6 holds; only the wording is off.

Checked

  • Ran (CI's matrix skips both): npm run typecheck && npm test in plugins/linear (140 pass, up from 138) and plugins/stewards (116 pass, up from 115); also plugins/github-watcher (66 pass, typecheck clean). All pass at 51d5fd5.
  • The three source-contract.ts copies remain byte-identical (md5) — untouched this round.
  • Re-verified the acceptance criteria for this PR at the new head: 4, 5, 7, 8, 9 unchanged and still met; 6 now met in full, including the mid-turn follow-up order (was the round-1 blocker).
  • No changes to source-contract.ts or the service contract this round, so the lane and triggers are unchanged.

— from bb thread thr_yvm5i87fgh

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 2 suggestion (the backstop's wording in the merged-turn case): declined. The case needs a mention and its follow-up both queued into one turn that starts after both hand-overs. Even then, criterion 6 holds, and the activity links the thread where the answer is. Changing the wording now would move the approved head for a cosmetic edit, so I'll fold it into a follow-up if live use shows it happens.

Gate on 51d5fd5: reviewer verdict=approved (round 2), lane owner-reviewed, checks 16/16 green. Waiting on @trotterdylan's approval to merge.

— from bb thread thr_sfrv4wuzak

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

LGTM

Mechanical conflict fixes only: plugins/stewards/wake.ts, server.ts and
server.test.ts keep both sides (the @bb session wake from this branch,
ops stewards and needs from main).

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

Copy link
Copy Markdown
Collaborator Author

Merged main into the branch to clear the conflict: 4b4b1fa2fab7e3ea49b93ae28ee876e8fbbb21bd (merge of f9e4104 into 51d5fd5). Mechanical only: plugins/stewards/wake.ts, server.ts and server.test.ts keep both sides (this PR's @bb session wake, main's ops stewards and needs). Typecheck and tests pass locally for stewards (199), linear (140) and github-watcher (66); source-contract.ts copies still identical. Asking the reviewer for round 3 on the new head.

— from bb thread thr_uxayz6wfdm

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 3 is not running yet: the reviewer thread's workspace was removed and cannot be restored, so it cannot take the request. Head 4b4b1fa is mergeable with 16/16 checks green. Not merging without a round 3 marker; waiting on a decision about a fresh reviewer.

— from bb thread thr_uxayz6wfdm

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_puuzfparxi. It replaces thr_yvm5i87fgh (workspace gone, cannot be revived) and reviews round 3 on 4b4b1fa.

— from bb thread thr_uxayz6wfdm

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 3 (GLM 5.3, at 4b4b1fa)

Owner review required: yes — unchanged from round 2: source-contract.ts gains sessionWakeSchema and stewardsContract.stewardsSession in all three copies (cross-repo contract), and the server proves its Linear identity to bb-gate-hooks. @trotterdylan, this one needs your approval.

This round is the merge of main (f9e4104) into 51d5fd5. @trotterdylan's LGTM on 51d5fd5 already covers this head: the merge is exactly the "merging the base branch, resolving conflicts mechanically" case your approval survives (AGENTS.md, "What counts as the owner's approval") — no fresh approval is needed unless you want one.

Merge verification (this round's focus)

I verified the resolution is mechanical and complete, both directions, against merge base d8efeb0:

  • plugins/stewards/wake.ts — git diff 51d5fd5 4b4b1fa vs main's own d8efeb0..f9e4104 are line-for-line identical (all +/- lines match, and likewise f9e4104..4b4b1fa vs the PR side's d8efeb0..51d5fd5). Both sides fully present, nothing else.
  • plugins/stewards/server.ts — same, except the wake.js import line, which is the correct union of both sides (main's formatOpsWake, workerQuestion, WorkerQuestion plus this branch's formatSessionWake, PendingRequest). Exactly what a mechanical "keep both sides" resolution should produce.
  • plugins/stewards/server.test.ts — main-side replay identical; PR side differs only in where one blank line sits in the patch (a leading vs trailing blank around the inserted describe("an @bb mention") block — whitespace only, the block reads cleanly and the file ends cleanly).
  • plugins/stewards/README.md — replay differs only in hunk offsets plus one blank line main deleted that the merge kept (counts for the ±1 in the overall stat). Cosmetic.
  • No other files diverge from a pure replay of main's diff; plugins/linear and plugins/github-watcher are untouched by the merge.

I also read the merged onSession/stewardsSession handler and formatSessionWake in place next to main's new ops-steward code (workerQuestion, ops kinds): the session-wake feature is intact and the interaction points (the import, the store's binding lookup, sendTo/serial) coexist correctly.

Blockers

None.

Suggestions

None.

Checked

  • Ran: npm run typecheck + npm test in plugins/stewards (199 tests pass — 117 in server.test.ts; not in the CI matrix, so CI never ran them).
  • Ran: npm run typecheck + npm test in plugins/linear (140 tests pass; not in the CI matrix).
  • Verified the three source-contract.ts copies (linear, stewards, github-watcher) are byte-identical at 4b4b1fa (sha256 match; also covered by stewards' contract.test.ts, 4 tests).
  • Verified against ticket (criteria 5–9, the plugin-side ones; 1–4 were bb-gate's in PR 1):
    • 5: met — the wake carries session id, asker, routing reason and quoted text; onSession routes ticket binding → project steward for the team → none (linear replies "not set up" itself).
    • 6: met — one reply per event with the backstop in linear; unchanged by the merge (linear untouched).
    • 7: met — the owner wake lists build/halt/redirect; "including holding itself" test present.
    • 8: met — per-developer actor=user connect and label bindings unchanged (linear untouched by the merge); docs/hooks.md is on main via PR 1.
    • 9: met — untrusted → pending request → owner's next words answer it, covered by the "information until the owner confirms" and "keeps every request waiting on the owner" tests; the "marks the words untrusted whenever the wake does, even with fromOwner" test is present.

— from bb thread thr_puuzfparxi

@trotterdylan
trotterdylan merged commit b3320c5 into main Oct 20, 2026
16 checks passed
@trotterdylan
trotterdylan deleted the bb/bb-11-bb-plugins-linear-stewards-pr-2-of-2-thr_sfrv4wuzak branch October 20, 2026 01:03
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Merged: owner-reviewed, approved by trotterdylan on 51d5fd5 (comment 2026-10-19 23:22 UTC); since then: 4b4b1fa, a mechanical merge of main (f9e4104) whose resolution bb-review round 3 (thr_puuzfparxi) verified and approved. Checks 16/16 green. Squash commit b3320c5.

Every developer's server gets a staged restart. The bb-server image rebuilds with this pin. Each developer's server restarts when its owner presses Restart now (Settings → Plugins → Team setup), or in the 03:00–05:00 US Eastern quiet window. Do not press it from a thread you still need.

Linear hand steps still open before @bb mentions work:

  • Add a client secret to the team OAuth application, and seal it with client credentials for bb-gate-hooks.
  • Install bb as an agent through client credentials with app:mentionable only (no app:assignable). Settle the scopes before minting the first token.
  • Tick the Agent session events webhook category on the application.
  • Narrow the application's team access.
  • Check a real created and a real prompted payload against the parser. The field names have not been verified against live Linear.

— from bb thread thr_uxayz6wfdm

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