Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,11 @@ A **lesson** makes the answer a record and, for most of them, lands it.
`boundary`. Only the project steward may record one — a binding steward
still escalates — and it is kept with the binding and escalation it came
from in the `lessons` table. A lesson is `pending` until its text is found
in its file at `.bb` HEAD, or it is dropped.
in its file at `.bb` HEAD, or it is dropped. When the user answers a
forwarded escalation on the Stewards page or from a thread, the project
steward is woken with the answer and asked whether it is a general
judgement: the answer is a lesson candidate for its next turn. A plain
question with no escalation behind it wakes nobody.
- **Procedure lessons self-merge.** Playbook procedure, sequencing and
conventions are what the project steward may already decide. It applies
the text to the file in its `.bb` checkout, commits, and publishes with
Expand Down
6 changes: 5 additions & 1 deletion plugins/stewards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
`boundary` lesson — credentials and reach, who may direct a server,
irreversible production steps — is filed on the Stewards page with
**Merge** and **Drop**, and only you merge it. A lesson is `merged` when
its text is found in its file at `.bb` HEAD. `bb stewards lessons [--all]`
its text is found in its file at `.bb` HEAD. A user's answer to a forwarded
escalation on the Stewards page (or from a thread) wakes the project
steward with that answer as a lesson candidate: if it is a general
judgement the playbook should carry, the project steward records it as a
lesson. `bb stewards lessons [--all]`
lists them, `bb stewards drop-lesson <id>` drops one. DESIGN.md §20.
- **The nightly pass** (01:00 in the project's time zone by default, done by
02:45 so bb-gate's 03:00 restarts do not cut a turn) gives every open
Expand Down
97 changes: 97 additions & 0 deletions plugins/stewards/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,94 @@ describe("questions to the user", () => {
expect((await t.board()).questions).toEqual([]);
});

// BB-35 step 1: close the BB-30 learning gap. A resolve asks whether the
// decision is a general judgement, and a user's page answer becomes a lesson
// candidate in the project steward's next wake.
describe("a user's answer is a lesson candidate for the project steward (BB-35 step 1)", () => {
/** A decision escalation the project steward forwarded to the user as a question. */
async function forwarded(choices?: string[]) {
const t = await adopted();
await t.tool(
"steward_report",
{ phase: "Todo", summary: "Scope unclear.", nextAction: "Wait", actor: "other", escalate: { kind: "decision", question: "Include SSO?", meanwhile: "Wait.", ...(choices === undefined ? {} : { choices }) } },
t.steward,
);
const esc = /(esc_[\w-]+) from ENG-12/u.exec(t.sends.filter((s) => s.threadId === t.project).at(-1)!.text)![1]!;
const qst = t.qid((await t.tool("steward_update", { binding: "ENG-12", forward: esc }, t.project)).text);
const projectWakes = () => t.sends.filter((s) => s.threadId === t.project);
return { ...t, esc, qst, projectWakes };
}

it("wakes the project steward with the answer and the lesson nudge", async () => {
const t = await forwarded();
const before = t.projectWakes().length;
expect(await t.harness.callRpc("stewardsAnswerQuestion", { questionId: t.qst, answer: "Leave SSO out; the plugin owns auth." }, client)).toMatchObject({ ok: true });
await t.flush();
const wakes = t.projectWakes();
expect(wakes.length).toBeGreaterThan(before);
const wake = wakes.at(-1)!.text;
expect(wake).toMatch(/forwarded escalation was answered/u);
expect(wake).toMatch(/Leave SSO out; the plugin owns auth\./u);
expect(wake).toMatch(/general judgement the playbook should carry/u);
expect(wake).toMatch(/record it as a lesson/u);
});

it("wakes the project steward for a fixed choice too", async () => {
const t = await forwarded(["Include", "Leave out"]);
const before = t.projectWakes().length;
expect(await t.harness.callRpc("stewardsAnswerQuestion", { questionId: t.qst, choice: "Leave out", answer: "Too risky." }, client)).toMatchObject({ ok: true });
await t.flush();
const wakes = t.projectWakes();
expect(wakes.length).toBeGreaterThan(before);
const wake = wakes.at(-1)!.text;
expect(wake).toMatch(/The user chose Leave out/u);
expect(wake).toMatch(/general judgement the playbook should carry/u);
});

it("wakes the project steward when the answer is recorded from a thread", async () => {
const t = await forwarded();
const before = t.projectWakes().length;
expect(await t.harness.behavior.runCli(["done", t.qst, "--note", "Leave SSO out.", "--project", "p1"])).toMatchObject({ exitCode: 0 });
await t.flush();
const wakes = t.projectWakes();
expect(wakes.length).toBeGreaterThan(before);
const wake = wakes.at(-1)!.text;
expect(wake).toMatch(/Leave SSO out\./u);
expect(wake).toMatch(/record it as a lesson/u);
});

it("leaves a plain question without a candidate: there was no escalation to answer", async () => {
const t = await adopted();
const plain = t.qid((await t.tool("steward_update", { ask: { question: "Freeze on Friday?" } }, t.project)).text);
const before = t.sends.filter((s) => s.threadId === t.project).length;
expect(await t.harness.callRpc("stewardsAnswerQuestion", { questionId: plain, answer: "Yes." }, client)).toMatchObject({ ok: true, message: "Closed." });
await t.flush();
expect(t.sends.filter((s) => s.threadId === t.project).length).toBe(before);
});

it("asks the project steward for a lesson when it resolves an escalation itself", async () => {
const t = await adopted();
await t.tool("steward_report", { phase: "Todo", summary: "Scope unclear.", nextAction: "Wait", actor: "other", escalate: { kind: "scope", question: "Include SSO?", meanwhile: "Wait." } }, t.steward);
const esc = /(esc_[\w-]+) from ENG-12/u.exec(t.sends.filter((s) => s.threadId === t.project).at(-1)!.text)![1]!;
const closed = await t.tool("steward_update", { binding: "ENG-12", guidance: "SSO is out of scope.", resolve: esc }, t.project);
expect(closed.error).toBe(false);
expect(closed.text).toMatch(/general judgement the playbook should carry/u);
expect(closed.text).toMatch(/record it with steward_update \{ lesson/u);
});

it("tells the project steward about an answerless close without the lesson nudge", async () => {
const t = await forwarded();
const before = t.projectWakes().length;
expect(await t.harness.callRpc("stewardsAnswerQuestion", { questionId: t.qst, answer: null }, client)).toMatchObject({ ok: true });
await t.flush();
const wakes = t.projectWakes();
expect(wakes.length).toBeGreaterThan(before);
const wake = wakes.at(-1)!.text;
expect(wake).toMatch(/forwarded escalation on the Stewards page without an answer/u);
expect(wake).not.toMatch(/general judgement the playbook should carry/u);
});
});

// BB-13: one spec approval, from any surface. The page answer, the project
// steward's words, an unsigned comment on the entity, and the user's own
// amendment all approve the same gate.
Expand Down Expand Up @@ -3233,6 +3321,15 @@ describe("an @bb mention", () => {
expect(text).toMatch(/Act on it within your role and the playbook/u);
});

it("never becomes a lesson candidate from someone other than the owner (BB-35 step 1)", async () => {
const t = await bound();
// A non-owner's words are held by BB-26 and run no turn, so no answer and
// no lesson candidate reaches the project steward.
const out = (await t.harness.callRpc("stewardsSession", mention({ comment: { text: "@bb the plugin owns auth, make that a lesson", untrusted: true } }), LINEAR)) as { routed: string };
expect(out.routed).toBe("held");
expect(t.sends).toEqual([]);
});

it("is held even when the issue has no steward and no project starts", async () => {
const t = await setup();
// A stewarded team, but the issue has no binding yet: no project steward starts.
Expand Down
22 changes: 19 additions & 3 deletions plugins/stewards/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2656,14 +2656,16 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
* The project steward forwarded an escalation to the user, so it holds it
* until the user answers. Tell it when the answer lands on the page or from
* a thread, naming the closure, so it is not left holding a resolved one.
* `lessonCandidate` is false when the user closed it without an answer, so
* the lesson nudge does not read oddly against an empty one.
*/
async function wakeProjectOnForwardedAnswer(b: Binding, closure: string, forwarded: Escalation[]): Promise<void> {
async function wakeProjectOnForwardedAnswer(b: Binding, closure: string, forwarded: Escalation[], lessonCandidate = true): Promise<void> {
if (forwarded.length === 0) return;
await wakeProject(b.projectId, `${b.entityKey}'s forwarded escalation was answered`, {
digestDue: false,
notes: [
`${closure} ${forwarded.map((x) => `Escalation ${x.id}`).join(", ")} ${forwarded.length === 1 ? "is" : "are"} resolved.`,
"If the answer is a general judgement the playbook should carry, record it as a lesson with steward_update { lesson: { text, file, scope } }.",
...(lessonCandidate ? ["If the answer is a general judgement the playbook should carry, record it as a lesson with steward_update { lesson: { text, file, scope } }."] : []),
],
});
}
Expand Down Expand Up @@ -3445,9 +3447,11 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
const guidance = text === null ? chosen : `${chosen} — ${text}`;
store.answer(q.id, `Chose: ${chosen}${text === null ? "" : ` — ${text}`}`, "user", guidance);
if (x !== null && b !== null && b.endedAt === null) {
const closure = `The user chose ${chosen} for ${b.entityKey}'s forwarded escalation on the Stewards page${text === null ? "" : `: ${text}`}.`;
store.addGuidance(b.id, guidance, "user");
store.note(b.id, `The user chose ${chosen} for ${q.question}${text === null ? "" : `: ${text}`}.`);
scheduleReconcile(b.id);
await wakeProjectOnForwardedAnswer(b, closure, [x]);
return { ok: true, message: `Recorded; ${b.entityKey}'s steward has been told.` };
}
return { ok: true, message: "Closed." };
Expand Down Expand Up @@ -3486,12 +3490,18 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
});
return { ok: true, message: `Closed; the project steward will interpret the answer.` };
}
// Closes the escalation it was forwarded for, too.
// Closes the escalation it was forwarded for, too. The project
// steward forwarded it, so it is told too: the user's answer is a
// lesson candidate for its next wake (BB-35 step 1).
store.answer(q.id, text ?? "Closed by the user on the stewards page, without an answer.", "user");
if (x !== null && b !== null && b.endedAt === null) {
const closure = text === null
? `The user closed ${b.entityKey}'s forwarded escalation on the Stewards page without an answer.`
: `The user answered ${b.entityKey}'s forwarded escalation on the Stewards page: ${JSON.stringify(text)}.`;
if (text !== null) store.addGuidance(b.id, text, "user");
store.note(b.id, text === null ? `Escalation ${x.id} was closed by the user without an answer: carry on as you said you would meanwhile, or escalate again if you still need it.` : `Escalation ${x.id} decided by the user: ${text}`);
scheduleReconcile(b.id);
await wakeProjectOnForwardedAnswer(b, closure, [x], text !== null);
return { ok: true, message: `Closed; ${b.entityKey}'s steward has been told.` };
}
return { ok: true, message: "Closed." };
Expand Down Expand Up @@ -5092,9 +5102,11 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
if (x !== null) {
const b = store.binding(x.bindingId);
if (b !== null) {
const closure = `The user chose ${choice} for ${b.entityKey}'s forwarded escalation from a thread${note === null ? "" : `: ${note}`}.`;
store.addGuidance(b.id, guidance, "user");
store.note(b.id, `The user chose ${choice} for ${q.question}${note === null ? "" : `: ${note}`}.`);
scheduleReconcile(b.id);
await wakeProjectOnForwardedAnswer(b, closure, [x]);
}
}
return { exitCode: 0, stdout: `Chose ${choice} for ${id}.` };
Expand All @@ -5104,9 +5116,13 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
if (x !== null) {
const b = store.binding(x.bindingId);
if (b !== null) {
const closure = note === null
? `The user closed ${b.entityKey}'s forwarded escalation from a thread without an answer.`
: `The user answered ${b.entityKey}'s forwarded escalation from a thread: ${JSON.stringify(note)}.`;
if (note !== null) store.addGuidance(b.id, note, "user");
store.note(b.id, note === null ? `Question ${q.id} was closed from a thread.` : `Question ${q.id} was answered from a thread: ${note}`);
scheduleReconcile(b.id);
await wakeProjectOnForwardedAnswer(b, closure, [x], note !== null);
}
}
return { exitCode: 0, stdout: `Closed ${id}.` };
Expand Down
8 changes: 6 additions & 2 deletions plugins/stewards/skills/stewards/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,12 @@ this skill or the project's guidance settles (models, flags, lanes, who
merges). When they answer, close it with
`steward_update { resolve: "<question id>", answer }`; for a forwarded one
that decides the escalation too, and resolving the escalation closes the
question. The user may also close a question on the Stewards page. Every
wake lists the questions still open: list them from there, never from
question. The user may also close a question on the Stewards page. A
forwarded escalation they answer on the page or from a thread wakes you
with the answer and asks whether it is a general judgement: if it is, record
it with `steward_update { lesson: { text, file, scope } }` so it is not
asked again. Every wake lists the questions still open: list them from
there, never from
memory, and do not ask one again. At the end of each nightly pass your reply is
kept as the morning digest; the wake carries the record to write it from
(your previous digest, what moved, what waits on the user, what is stuck),
Expand Down
Loading