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
2 changes: 1 addition & 1 deletion plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ which writes the status record:
| Field | Holds |
|---|---|
| phase, summary | Where the entity is, in a sentence. |
| next action, actor | What happens next, and who does it: `me`, `steward`, `other`. |
| next action, actor | What happens next, and who does it: `user` (the server's owner has to act), `steward` (the steward itself, including its own next step such as re-checking on the next deployment wake) or `other` (someone else). The actor is a party, not a pronoun: BB-95 misread `me` as the steward and filed its own re-check as needing the user. |
| blocked on | Who or what outside the thread it waits for. |
| requeue after | When to wake it if nothing else does. Defaults to the playbook's `requeue-default`. |
| conditions | Open escalations, `stuck`. |
Expand Down
5 changes: 4 additions & 1 deletion plugins/stewards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
- **Two tools.** `steward_report` ends a turn with the status record and,
when needed, an escalation; `steward_update` steers a binding (guidance,
deciding or forwarding escalations, priority, holds, models, approving a
spec).
spec). The report's `actor` names who acts next: `user` (the server's
owner has to act), `steward` (the steward itself, including its own next
step such as re-checking on the next deployment wake) or `other`
(someone else).
- **Scheduling.** Two tickets changing the same files at once end in a
rebase for whichever merges second, so the project steward sequences
them. Each steward reports the repo-relative paths its work changes
Expand Down
10 changes: 10 additions & 0 deletions plugins/stewards/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,16 @@ describe("the Stewards page's project view and detail views (BB-85)", () => {
slot.lifecycle.unmount();
});

it("labels the `user` actor as you in an effort's status (BB-97)", async () => {
const slot = await renderBoardWith({
subPath: "p1/ENG-1",
stewards: [boardSteward({ key: "ENG-1", title: "Fix login", needsUser: true, phase: "In Review", summary: "In review", nextAction: "On the next deployment wake, re-run the carries check", actor: "user", statusAt: 1_000, createdAt: 2_000, stage: "build" })],
});
await waitFor(() => expect(slot.getByText("Fix login")).toBeTruthy());
expect(slot.getByText(/Next: On the next deployment wake, re-run the carries check \(you\)/u)).toBeTruthy();
slot.lifecycle.unmount();
});

it("keeps the page-only controls on the detail's needs-you items: the secret form and the approve-spec note", async () => {
const slot = await renderBoardWith({
subPath: "p1/ENG-1",
Expand Down
2 changes: 1 addition & 1 deletion plugins/stewards/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ function ProjectStatus({ project: p, now }: { project: Project; now: number }) {

// ---- Stewards -------------------------------------------------------------------------------------

const ACTOR_LABEL: Record<string, string> = { me: "you", steward: "the steward", other: "someone else" };
const ACTOR_LABEL: Record<string, string> = { user: "you", steward: "the steward", other: "someone else" };

/**
* The BB-76 effort row (BB-78): the glyph, the shortened key and the title on
Expand Down
2 changes: 1 addition & 1 deletion plugins/stewards/reconcile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ describe("approval words", () => {
});

it("flags a report that asks for an approval already open, and only that", () => {
const status = (summary: string, nextAction: string) => ({ phase: "Todo", summary, nextAction, actor: "me" as const, blockedOn: null, requeueAfterMs: null, conditions: [], resources: { workers: [], pullRequests: [], children: [] }, at: 1 });
const status = (summary: string, nextAction: string) => ({ phase: "Todo", summary, nextAction, actor: "user" as const, blockedOn: null, requeueAfterMs: null, conditions: [], resources: { workers: [], pullRequests: [], children: [] }, at: 1 });
const open = [{ kind: "approval" } as never];
expect(asksForOpenApproval(status("Spec posted.", "Ask the user to approve the spec"), open)).toMatch(/already open/u);
// Waiting on the request, or on the project steward, is not asking again.
Expand Down
107 changes: 79 additions & 28 deletions plugins/stewards/server.test.ts

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions plugins/stewards/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
*/
function needsUser(b: Binding): boolean {
return (
b.status?.actor === "me" ||
b.status?.actor === "user" ||
store.openEscalations(b.id).length > 0 ||
store.openNeeds(b.id).length > 0 ||
store.openQuestions(b.projectId).some((q) => q.bindingId === b.id)
Expand Down Expand Up @@ -5440,7 +5440,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
phase: z.string().trim().min(1).max(100).describe("The entity's phase as you understand it, usually its state."),
summary: z.string().trim().min(1).max(600).describe("Where the entity is, in a sentence."),
nextAction: z.string().trim().min(1).max(600).describe("What happens next."),
actor: z.enum(ACTORS).describe("Who does the next action: me (the user), steward (you or your workers), other (someone else)."),
actor: z.enum([...ACTORS, "me"]).describe("Who does the next action. `user` means the server's owner has to act — a decision, a credential, a step outside the repos — and leaves the row needing them (unread and ringing). `steward` is you: your own next step, including re-checking on the next deployment wake, is `steward`, not `user`. On BB-95 a steward filed \"On the next deployment wake, re-run the carries check and report deployed or not-yet\" as `me` and the row wrongly read \"needs you\"; that next step is `steward`. `other` is someone else."),
blockedOn: z.string().trim().max(300).optional().describe("Who or what outside this thread it waits for."),
requeueAfter: durationSchema.optional().describe('When to wake you if nothing else does, such as "4h" or "2d". The playbook\'s default when left out.'),
conditions: z.array(z.string().trim().min(1).max(200)).max(10).optional().describe("Anything else a reader of the status should know at a glance."),
Expand Down Expand Up @@ -5535,6 +5535,11 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
}),
execute: store.coalescingTool(async (input, { threadId }) => {
try {
// BB-97: `me` is the old name for `user`. Accept it for one release
// so a steward whose prompt predates the rename is not wedged: it is
// normalised here and the stored value is always `user`.
const actor: (typeof ACTORS)[number] = input.actor === "me" ? "user" : input.actor;
if (input.actor === "me") bb.log.info(`stewards: steward_report actor "me" is renamed to "user"; recording this report as user (thread ${threadId}).`);
let b = ownBinding(threadId);
// Validate the input that does not depend on which pull request the
// binding is on before a replacement moves it: a wrap-up report that
Expand Down Expand Up @@ -5655,7 +5660,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
phase: input.phase,
summary: input.summary,
nextAction: input.nextAction,
actor: input.actor,
actor,
blockedOn: input.blockedOn ?? null,
requeueAfterMs: requeueMs,
conditions: [...(input.conditions ?? []), ...open.map((x) => `${x.kind} escalation with ${x.route}`)],
Expand Down
6 changes: 4 additions & 2 deletions plugins/stewards/skills/stewards/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ copy the command.
Two tools are yours; everything else you do with the tools every thread has.

- **`steward_report` ends every woken turn**: phase, a one-sentence summary,
the next action and who does it (`me` = the user, `steward`, `other`), what
the next action and who does it (`user` = the server's owner has to act,
`steward` = you, including your own next step such as re-checking on the
next deployment wake, `other` = someone else), what
you are blocked on, and `requeueAfter`. On a ticket, report the ready
checklist too, each item by its number in the wake
(`{ item: 1, met: true }`); a paraphrase is refused. Three turns in a row
Expand Down Expand Up @@ -245,7 +247,7 @@ is the plugin's, so diagnose from the wake and the code in your workspace.
`actor: other` and end the turn.
- **No Sentry token** (the wake says so): raise the escalation it describes
(variable `SENTRY_TOKEN`, setting `sentryToken`, the Sentry auth-tokens
page, the scopes), report with `actor: me`, and end the turn.
page, the scopes), report with `actor: user`, and end the turn.
- **No logs** (the wake says so): diagnose from status and events, and say
in the ticket that logs were not available.

Expand Down
102 changes: 90 additions & 12 deletions plugins/stewards/store.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import Database from "better-sqlite3";
import { describe, expect, it } from "vitest";
import { APPROVAL_MARKER_MIGRATIONS, BASE_MIGRATIONS, CHAIN_MIGRATIONS, GUIDANCE_MIGRATIONS, IDLE_MIGRATIONS, LESSON_COUNTER_MIGRATIONS, LESSON_TIER_MIGRATIONS, MIGRATIONS, RATIONALE_MIGRATIONS, VALIDATION_MIGRATIONS, WORKER_CHECK_MIGRATIONS, createStore, lessonScope } from "./store.js";
import { z } from "zod";
import { ACTOR_MIGRATIONS, APPROVAL_MARKER_MIGRATIONS, BASE_MIGRATIONS, CHAIN_MIGRATIONS, GUIDANCE_MIGRATIONS, IDLE_MIGRATIONS, LESSON_COUNTER_MIGRATIONS, LESSON_TIER_MIGRATIONS, MIGRATIONS, RATIONALE_MIGRATIONS, VALIDATION_MIGRATIONS, WORKER_CHECK_MIGRATIONS, createStore, lessonScope, statusRecordSchema } from "./store.js";

/** MIGRATIONS without the groups appended after the ones these order tests assert. */
const beforeActorMigrations = MIGRATIONS.slice(0, MIGRATIONS.length - ACTOR_MIGRATIONS.length);

function store() {
const db = new Database(":memory:");
Expand Down Expand Up @@ -311,14 +315,88 @@ describe("the lesson tier migration (BB-35 step 3)", () => {
// `bb.storage.migrate` records each statement by index and refuses a changed
// one; a group spliced in mid-array would fail every live database on load.
// BB-35 step 4 appended the rationale group, step 5 the validation group,
// step 6 the guidance group, BB-83 the idle group, and BB-77 the approval
// marker group, after this one.
expect(MIGRATIONS.slice(-APPROVAL_MARKER_MIGRATIONS.length)).toEqual([...APPROVAL_MARKER_MIGRATIONS]);
expect(MIGRATIONS.slice(-(APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length), -APPROVAL_MARKER_MIGRATIONS.length)).toEqual([...IDLE_MIGRATIONS]);
expect(MIGRATIONS.slice(-(APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length + GUIDANCE_MIGRATIONS.length), -(APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length))).toEqual([...GUIDANCE_MIGRATIONS]);
expect(MIGRATIONS.slice(-(APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length + GUIDANCE_MIGRATIONS.length + VALIDATION_MIGRATIONS.length), -(APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length + GUIDANCE_MIGRATIONS.length))).toEqual([...VALIDATION_MIGRATIONS]);
// step 6 the guidance group, BB-83 the idle group, BB-77 the approval
// marker group, and BB-97 the actor rename group, after this one. The
// slices stop at the actor group so this test still checks its own order.
expect(beforeActorMigrations.slice(-APPROVAL_MARKER_MIGRATIONS.length)).toEqual([...APPROVAL_MARKER_MIGRATIONS]);
expect(beforeActorMigrations.slice(-(APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length), -APPROVAL_MARKER_MIGRATIONS.length)).toEqual([...IDLE_MIGRATIONS]);
expect(beforeActorMigrations.slice(-(APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length + GUIDANCE_MIGRATIONS.length), -(APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length))).toEqual([...GUIDANCE_MIGRATIONS]);
expect(beforeActorMigrations.slice(-(APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length + GUIDANCE_MIGRATIONS.length + VALIDATION_MIGRATIONS.length), -(APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length + GUIDANCE_MIGRATIONS.length))).toEqual([...VALIDATION_MIGRATIONS]);
const afterTier = APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length + GUIDANCE_MIGRATIONS.length + VALIDATION_MIGRATIONS.length + RATIONALE_MIGRATIONS.length;
expect(MIGRATIONS.slice(-(afterTier + LESSON_TIER_MIGRATIONS.length), -afterTier)).toEqual([...LESSON_TIER_MIGRATIONS]);
expect(beforeActorMigrations.slice(-(afterTier + LESSON_TIER_MIGRATIONS.length), -afterTier)).toEqual([...LESSON_TIER_MIGRATIONS]);
});
});

describe("the actor rename migration (BB-97)", () => {
// The pre-rename build parsed `status` with this schema through the same
// `json()` helper (a safeParse inside try/catch, falling back to null). A
// migrated `user` row must read back as no status there, never throw.
const preRenameStatusSchema = statusRecordSchema.extend({ actor: z.enum(["me", "steward", "other"]) });
const readAsOldBuild = (raw: string | null) => {
if (raw === null) return null;
try {
const parsed = preRenameStatusSchema.safeParse(JSON.parse(raw));
return parsed.success ? parsed.data : null;
} catch {
return null;
}
};

/** A database as the pre-rename build left it, with the actor migration not yet applied. */
const legacy = () => {
const db = new Database(":memory:");
for (const sql of MIGRATIONS.slice(0, MIGRATIONS.indexOf(ACTOR_MIGRATIONS[0]!))) db.exec(sql);
return db;
};
const insert = (db: ReturnType<typeof legacy>, id: string, key: string, status: string | null) =>
db.prepare(`INSERT INTO bindings (id, project_id, source, entity_id, entity_key, kind, playbook, playbook_version, status, created_at)
VALUES (?, 'p1', 'linear', ?, ?, 'ticket', 'linear-tickets', 'v1', ?, 1000)`).run(id, `uuid-${id}`, key, status);
const actor = (s: ReturnType<typeof createStore>, key: string) => s.find(key, "p1")!.status!.actor;

it("rewrites `me` to `user` in the stored status, leaving the rest of the record alone", () => {
const db = legacy();
insert(db, "bnd_1", "ENG-12", JSON.stringify({ phase: "In Review", summary: "Waiting.", nextAction: "On the next deployment wake, re-run the carries check", actor: "me", blockedOn: "a bb-gate deployment", requeueAfterMs: null, conditions: ["a condition"], resources: { workers: ["thr_w1"], pullRequests: [], children: [] }, at: 1_000 }));
for (const sql of ACTOR_MIGRATIONS) db.exec(sql);
const s = createStore(db, () => 2_000);
expect(s.find("ENG-12", "p1")!.status).toEqual({ phase: "In Review", summary: "Waiting.", nextAction: "On the next deployment wake, re-run the carries check", actor: "user", blockedOn: "a bb-gate deployment", requeueAfterMs: null, conditions: ["a condition"], resources: { workers: ["thr_w1"], pullRequests: [], children: [] }, at: 1_000 });
});

it("is idempotent, and leaves `steward` and `other` untouched", () => {
const db = legacy();
insert(db, "bnd_me", "ENG-12", JSON.stringify({ phase: "x", summary: "y", nextAction: "z", actor: "me", blockedOn: null, requeueAfterMs: null, conditions: [], resources: { workers: [], pullRequests: [], children: [] }, at: 1 }));
insert(db, "bnd_steward", "ENG-13", JSON.stringify({ phase: "x", summary: "y", nextAction: "z", actor: "steward", blockedOn: null, requeueAfterMs: null, conditions: [], resources: { workers: [], pullRequests: [], children: [] }, at: 2 }));
insert(db, "bnd_other", "ENG-14", JSON.stringify({ phase: "x", summary: "y", nextAction: "z", actor: "other", blockedOn: null, requeueAfterMs: null, conditions: [], resources: { workers: [], pullRequests: [], children: [] }, at: 3 }));
for (const sql of ACTOR_MIGRATIONS) db.exec(sql);
// A second run matches nothing and changes nothing.
for (const sql of ACTOR_MIGRATIONS) db.exec(sql);
const s = createStore(db, () => 2_000);
expect(actor(s, "ENG-12")).toBe("user");
expect(actor(s, "ENG-13")).toBe("steward");
expect(actor(s, "ENG-14")).toBe("other");
});

it("a pre-rename build reads a migrated row as no status, never throwing (rollback)", () => {
const db = legacy();
insert(db, "bnd_1", "ENG-12", JSON.stringify({ phase: "x", summary: "y", nextAction: "z", actor: "me", blockedOn: null, requeueAfterMs: null, conditions: [], resources: { workers: [], pullRequests: [], children: [] }, at: 1 }));
for (const sql of ACTOR_MIGRATIONS) db.exec(sql);
const raw = (db.prepare("SELECT status FROM bindings WHERE id = 'bnd_1'").get() as { status: string }).status;
expect(JSON.parse(raw).actor).toBe("user");
expect(() => readAsOldBuild(raw)).not.toThrow();
expect(readAsOldBuild(raw)).toBeNull();
});

it("leaves a malformed status alone rather than making the migration throw", () => {
const db = legacy();
insert(db, "bnd_1", "ENG-12", "not json");
expect(() => {
for (const sql of ACTOR_MIGRATIONS) db.exec(sql);
}).not.toThrow();
expect((db.prepare("SELECT status FROM bindings WHERE id = 'bnd_1'").get() as { status: string }).status).toBe("not json");
});

it("is appended at the end of MIGRATIONS, so a shipped statement index is never reused", () => {
expect(MIGRATIONS.slice(-ACTOR_MIGRATIONS.length)).toEqual([...ACTOR_MIGRATIONS]);
expect(MIGRATIONS.slice(-(ACTOR_MIGRATIONS.length + APPROVAL_MARKER_MIGRATIONS.length), -ACTOR_MIGRATIONS.length)).toEqual([...APPROVAL_MARKER_MIGRATIONS]);
});
});

Expand Down Expand Up @@ -504,10 +582,10 @@ describe("the guidance-citation migration (BB-35 step 6)", () => {
});

it("is appended at the end of MIGRATIONS, so a shipped statement index is never reused", () => {
expect(MIGRATIONS.slice(-APPROVAL_MARKER_MIGRATIONS.length)).toEqual([...APPROVAL_MARKER_MIGRATIONS]);
expect(MIGRATIONS.slice(-(APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length), -APPROVAL_MARKER_MIGRATIONS.length)).toEqual([...IDLE_MIGRATIONS]);
expect(MIGRATIONS.slice(-(APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length + GUIDANCE_MIGRATIONS.length), -(APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length))).toEqual([...GUIDANCE_MIGRATIONS]);
expect(MIGRATIONS.slice(-(APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length + GUIDANCE_MIGRATIONS.length + VALIDATION_MIGRATIONS.length), -(APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length + GUIDANCE_MIGRATIONS.length))).toEqual([...VALIDATION_MIGRATIONS]);
expect(beforeActorMigrations.slice(-APPROVAL_MARKER_MIGRATIONS.length)).toEqual([...APPROVAL_MARKER_MIGRATIONS]);
expect(beforeActorMigrations.slice(-(APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length), -APPROVAL_MARKER_MIGRATIONS.length)).toEqual([...IDLE_MIGRATIONS]);
expect(beforeActorMigrations.slice(-(APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length + GUIDANCE_MIGRATIONS.length), -(APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length))).toEqual([...GUIDANCE_MIGRATIONS]);
expect(beforeActorMigrations.slice(-(APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length + GUIDANCE_MIGRATIONS.length + VALIDATION_MIGRATIONS.length), -(APPROVAL_MARKER_MIGRATIONS.length + IDLE_MIGRATIONS.length + GUIDANCE_MIGRATIONS.length))).toEqual([...VALIDATION_MIGRATIONS]);
});
});

Expand Down
Loading
Loading