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
13 changes: 7 additions & 6 deletions plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1623,8 +1623,8 @@ for the length of the crossfade.

**Grouping is the steward relationship, then the thread tree.** A worker
belongs to its binding through the plugin's `workers` table and a reviewer
through the worker the RPC names, so the grouping survives a worker spawned
without a parent. The thread tree (`parentThreadId ?? lifecycleOwnerThreadId`)
through the live thread whose parent is a claimed worker, so the grouping
survives a worker spawned without a parent. The thread tree (`parentThreadId ?? lifecycleOwnerThreadId`)
places what the records do not cover: a worker an older steward parented under
it, and a one-off thread's children. BB-72 restored the parent link — stewards
under the project steward, workers under their steward, reviewers under their
Expand All @@ -1648,9 +1648,10 @@ lane gate re-checked server-side). There is no **Details** button: the row
itself opens the effort's detail view (BB-85), where the free-text answer and
the secret form live. The inline block adds no write path the page does not
already make. The
project dropdown carries each project's count in its option label, and that
count is the number of yellow effort rows, so the picker and the sections
cannot disagree. `stewardsSidebar` carries, per project,
project dropdown carries each project's count in its option label, and the
server counts the needs-you bindings (`needsCount`, the open bindings with
`needsUser`), so the picker and the sections cannot disagree. `stewardsSidebar`
carries, per project,
`needs: { count, items }` with the board's row shapes, each tagged
`question`/`withUser`/`need` and carrying the binding's entity key as
`bindingKey` so a row owns its item; the effort row filters the items by that
Expand Down Expand Up @@ -1685,7 +1686,7 @@ to the user or resolved (`reroute`, `resolve`, `approve`, `decline`), and a
need filed, updated or closed (`fileNeed`, `closeNeed`, `closeNeeds`,
`closeNeedByKey`). A synchronous coalescing guard makes one question filed or
answered publish exactly one event even when the operation nests (`answer`
resolves its escalation). Every open sidebar refetches when the event names a
resolves its escalation). Every open sidebar refetches when the event names the
project it shows, the board page refetches when it names its project, and the
overview (which covers every project) refetches on any event; the half-minute
poll remains the fallback.
Expand Down
24 changes: 16 additions & 8 deletions plugins/stewards/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,20 @@ const sidebarBinding = (over: Record<string, unknown>) => ({
...over,
});

const sidebarData = (over: { p1?: Record<string, unknown>; p2?: Record<string, unknown> } = {}) => ({
projects: [
{ projectId: "p1", name: "Acme", projectStewardThreadId: null, needs: { count: 0, items: [] }, bindings: [], ended: [], ...over.p1 },
{ projectId: "p2", name: "Beta", projectStewardThreadId: null, needs: { count: 0, items: [] }, bindings: [], ended: [], ...over.p2 },
],
});
const sidebarData = (over: { p1?: Record<string, unknown>; p2?: Record<string, unknown>; needsCounts?: Record<string, number> } = {}) => {
const p1 = over.p1 ?? {};
return {
projects: [
{ projectId: "p1", name: "Acme", needsCount: over.needsCounts?.p1 ?? 0 },
{ projectId: "p2", name: "Beta", needsCount: over.needsCounts?.p2 ?? 0 },
],
projectId: "p1",
projectStewardThreadId: (p1.projectStewardThreadId as string | null) ?? null,
needs: p1.needs ?? { count: 0, items: [] },
bindings: p1.bindings ?? [],
ended: p1.ended ?? [],
};
};

describe("the stewards sidebar's picker counts and refresh (BB-46)", () => {
const renderSidebar = async (rpc: Record<string, unknown>, props: Record<string, unknown> = {}, threads: unknown[] = []): Promise<RenderedSlot> => {
Expand All @@ -464,8 +472,8 @@ describe("the stewards sidebar's picker counts and refresh (BB-46)", () => {
{
stewardsSidebar: () =>
sidebarData({
needsCounts: { p1: 2, p2: 1 },
p1: { bindings: [sidebarBinding({ key: "ENG-1", threadId: "thr_a", needsUser: true }), sidebarBinding({ key: "ENG-2", threadId: "thr_b", needsUser: true })], needs: { count: 9, items: [] } },
p2: { bindings: [sidebarBinding({ key: "ENG-3", threadId: "thr_c", needsUser: true })] },
}),
},
{},
Expand Down Expand Up @@ -542,7 +550,7 @@ describe("the stewards overview's refresh (BB-90)", () => {
rpc: {
stewardsOverview: () => {
calls += 1;
return { paused: false, projects: [], lastSweepAt: 0 };
return { paused: false, projects: [], lastSweepAt: 0, stats: { rpc: {}, cli: {}, signals: {} } };
},
},
} as never);
Expand Down
111 changes: 87 additions & 24 deletions plugins/stewards/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ type Project = Overview["projects"][number];
type Steward = Project["stewards"][number];
type BoardResult = Awaited<ReturnType<Client["call"]>> extends infer R ? Extract<R, { board: unknown }> : never;
type Board = NonNullable<BoardResult["board"]>;
type SidebarResult = Awaited<ReturnType<Client["call"]>> extends infer R ? Extract<R, { projects: Array<{ needs: unknown }> }> : never;
type SidebarNeeds = SidebarResult["projects"][number]["needs"];
type SidebarResult = Awaited<ReturnType<Client["call"]>> extends infer R ? Extract<R, { needs: unknown; bindings: unknown }> : never;
type SidebarNeeds = SidebarResult["needs"];
type SidebarNeedItem = SidebarNeeds["items"][number];
type CheckResult = { ok: boolean; lines: string[] };

Expand Down Expand Up @@ -202,6 +202,28 @@ function Row({ label, children }: { label: string; children: ReactNode }) {

// ---- Status ---------------------------------------------------------------------------------------

/** The plugin's in-memory per-method stat (BB-100), shown in the Status section. */
function MethodStats({ title, rows }: { title: string; rows: Record<string, { count: number; totalMs: number; maxMs: number; lastMs: number; lastAt: number | null }> }) {
const entries = Object.entries(rows).sort((a, b) => a[0].localeCompare(b[0]));
return (
<div>
<p className="font-medium">{title}</p>
{entries.length === 0 ? (
<p className="text-muted-foreground">none</p>
) : (
<ul>
{entries.map(([name, s]) => (
<li key={name}>
{name}: {s.count} call{s.count === 1 ? "" : "s"}, total {s.totalMs}ms, max {s.maxMs}ms, last {s.lastMs}ms
{s.lastAt === null ? "" : ` (${ago(s.lastAt, Date.now())})`}
</li>
))}
</ul>
)}
</div>
);
}

function StatusSection() {
const { overview, error } = useOverview();
if (overview === null) return <Loading error={error} />;
Expand All @@ -222,6 +244,29 @@ function StatusSection() {
overview.projects.map((p) => <ProjectStatus key={p.projectId} project={p} now={now} />)
)}
<p className="text-xs text-muted-foreground">Last sweep {ago(overview.lastSweepAt, now)}; the sweep runs every half hour. Configuration is reread from committed HEAD every few minutes.</p>
<details className="rounded-lg border border-border p-3 text-xs">
<summary className="cursor-pointer font-medium text-muted-foreground">Handler stats (this process)</summary>
<div className="mt-2 flex flex-col gap-2">
<MethodStats title="RPC methods" rows={overview.stats.rpc} />
<MethodStats title="CLI commands" rows={overview.stats.cli} />
<div>
<p className="font-medium">Signals published in the last hour</p>
{Object.keys(overview.stats.signals).length === 0 ? (
<p className="text-muted-foreground">none</p>
) : (
<ul>
{Object.entries(overview.stats.signals)
.sort((a, b) => a[0].localeCompare(b[0]))
.map(([projectId, count]) => (
<li key={projectId}>
{projectId}: {count}
</li>
))}
</ul>
)}
</div>
</div>
</details>
{error !== null ? <p className="text-xs text-destructive">Refresh failed: {error}</p> : null}
</div>
);
Expand Down Expand Up @@ -1830,44 +1875,63 @@ function StewardsSidebarCore({
}) {
const rpc = useRpc<typeof rpcContract>();
const { status, threads, projects } = experimental_useSidebarThreads();
const { data, error, loaded, refetch } = usePolled(useCallback(() => rpc.call("stewardsSidebar", null), [rpc]));
// The Stewards page's route, when that panel is mounted (BB-94). It is null
// on a thread route, where the props above are the source.
const boardRoute = useBoardRoute();
const navigate = useBbNavigate();
const [picked, setPicked] = useState<string | null>(null);
// The active tab follows the panel route, then the thread route; a pick only
// lasts until one of them moves.
useEffect(() => setPicked(null), [activeProjectId, boardRoute.projectId]);
// The one project the RPC is asked for; null lets the server pick the first
// by name. `load` depends on it, so a pick refetches like the board's `wanted`.
const wanted = picked ?? boardRoute.projectId ?? activeProjectId;
const { data, error, loaded, refetch } = usePolled(useCallback(() => rpc.call("stewardsSidebar", { projectId: wanted }), [rpc, wanted]));
// The previous tabs, so `buildSidebar` can hand back the same effort and
// thread objects for unchanged rows and the memoised rows skip a render
// (BB-95). The ref is written during render; the call is idempotent.
const previousTabs = useRef<readonly SidebarTab[]>([]);
const tabs = useMemo(() => {
const next = buildSidebar({ projects, threads, data: data?.projects ?? [], now: Date.now() }, previousTabs.current);
// The RPC carries one project's data; that tab is the only one whose rows
// render, so the others are built from the live threads alone (BB-100).
const projectData =
data === null || data.projectId === null
? []
: [
{
projectId: data.projectId,
name: data.projects.find((p) => p.projectId === data.projectId)?.name ?? data.projectId,
projectStewardThreadId: data.projectStewardThreadId,
bindings: data.bindings,
ended: data.ended,
},
];
const next = buildSidebar({ projects, threads, data: projectData, now: Date.now() }, previousTabs.current);
previousTabs.current = next;
return next;
}, [projects, threads, data]);
const needsByProject = useMemo(() => new Map((data?.projects ?? []).map((p) => [p.projectId, p.needs] as const)), [data]);
// The picker counts the yellow rows, so the pill and the sections cannot disagree (BB-76).
const counts = useMemo(() => new Map(tabs.map((t) => [t.projectId, t.blocked.filter((e) => e.state === "you").length] as const)), [tabs]);
// A steward's visible change updates the badge and block within seconds;
// the half-minute poll stays the fallback. Only a project this sidebar shows
// triggers a refetch.
// The picker's count is the server's needs-you binding count, so the pill and
// the yellow rows cannot disagree (BB-100).
const counts = useMemo(() => new Map((data?.projects ?? []).map((p) => [p.projectId, p.needsCount] as const)), [data]);
const active = tabs.find((t) => t.projectId === wanted) ?? tabs.find((t) => t.projectId === data?.projectId) ?? tabs[0] ?? null;
// A steward's visible change updates the badge and block within seconds; the
// half-minute poll stays the fallback. Only a signal that names the shown
// project triggers a refetch, not one for another listed project (BB-100).
const shownProjectId = active?.projectId ?? data?.projectId ?? wanted;
useRealtime(
PROJECT_CHANGED,
useCallback(
(payload) => {
const projectId = payload === null || typeof payload !== "object" ? null : (payload as { projectId?: unknown }).projectId;
if (typeof projectId === "string" && projects.some((p) => p.id === projectId)) refetch();
if (typeof projectId === "string" && projectId === shownProjectId) refetch();
},
[projects, refetch],
[shownProjectId, refetch],
),
);
const byId = useMemo(() => new Map(threads.map((t) => [t.id, t] as const)), [threads]);
// The Stewards page's route, when that panel is mounted (BB-94). It is null
// on a thread route, where the props above are the source.
const boardRoute = useBoardRoute();
const navigate = useBbNavigate();
const [picked, setPicked] = useState<string | null>(null);
// The active tab follows the panel route, then the thread route; a pick only
// lasts until one of them moves.
useEffect(() => setPicked(null), [activeProjectId, boardRoute.projectId]);
const wanted = picked ?? boardRoute.projectId ?? activeProjectId;
const active = tabs.find((t) => t.projectId === wanted) ?? tabs[0] ?? null;
const activeNeeds = active === null ? undefined : needsByProject.get(active.projectId);
// The requested project's needs items, only while the data matches the tab on
// screen; a stale answer for a previous project shows nothing (BB-100).
const needItems = active !== null && data?.projectId === active.projectId ? data.needs.items : EMPTY_NEEDS;
const now = Date.now();
const activeKey = boardRoute.key;
const openThreads = useMemo(() => revealThreads(tabs, activeThreadId), [tabs, activeThreadId]);
Expand All @@ -1885,7 +1949,6 @@ function StewardsSidebarCore({
const newThread = useCallback(() => {
if (active !== null) onNewThread(active.projectId);
}, [active, onNewThread]);
const needItems = activeNeeds?.items ?? EMPTY_NEEDS;
const rows = (list: readonly SidebarEffort[]) =>
list.map((e) => (
<SidebarEffortRow
Expand Down
Loading
Loading