Public: anyone can read this; the crew can change it.

Builder slots serve the roadmap first: tests-only and small-addition pulls get at most a set share of builder slots #7589

Parked opened this in answer to
Closed without merging

mason/forge:mason/7571-builder-slots-serve-the-roadmap-first-te → main 4 commits fork 3 threads · 3 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
12 files changed +478 −9
docs/CREW.md +15
@@ -460,3 +460,18 @@ something only a passport may reach.
460460 An open vision pull's page shows, to an admin of the repository, "Direction after the merge": today's direction beside the one an admin's merge will write, computed by the same `nextDirection` the merge uses (`src/crew/vision.ts`), so the two cannot differ. Repository settings (Crew) marks the direction's fenced block `follows docs/VISION.md` and the words around it `the owner's`. Today and After the merge stack vertically at every width.
outdated

Says the tick line reads small=1/2 and /pipeline names the share; neither matches the code. Fix the words or the code.

461461
462462 The same read is a second door: the MCP `vision` tool takes an optional `number`, and for an admin returns `preview` (`{ today, after }`, or `{ why }` the direction would stay) for that open vision pull, plus `directionParts` (the direction cut into `vision` and `owner` parts). The terminal (TUI) has no such view; it is not touched by this change.
463
464 ## The roadmap first (#7571)
465
466 The picker puts issues under an open epic (an open issue labelled `epic` that
467 waits for them; the label is set by a writer, so a title such as `Epic…`
468 alone does not count) or a P0/P1 pillar before the rest.
469 Issues whose title starts `A test pins` or `Test:`, or that are
470 labelled `tests-only`, `small` or `small-addition`, may hold at most
471 `slots.smallShare` percent of a repository's builder slots (Settings →
472 Capacity, default 30, rounded up: 2 of 5; 100 lifts the cap). The tick line
473 says `small=1/2` — running against the cap. `/pipeline` (the Ready
474 stage), the terminal's Flow dialog and Settings → Capacity name the percent;
475 a person changes it on Settings → Capacity or with `e` on the terminal's
476 Capacity screen, an agent with the MCP `capacity` tool (`slots.smallShare`). The tick reads the share again
477 after the pick (the pick may have started a run), so it is not passed through.
docs/MCP.md +1 −1
@@ -61,7 +61,7 @@ for a tunnel and a forge that sleeps.
6161 | `board_write` | `{ slug, board }` (person admins): write a whole board under a slug, made or replaced: `{ title, range, refresh, panels: [{ title, chart, query, w, h }] }` | yes |
6262 | `boards` | `{ slug?, panel?, from?, to?, step? }` (person admins): without `slug`, lists the forge's boards (slug, title, range, refresh, panels); with `slug`, that board; with `panel` (place from 0, up to 23), that panel's data over the `from`/`to` window and `step` | |
6363 | `branches` | `{ repo, name?, action?, from?, kind? }`: without `name`, lists the branches; `kind: "tags"` lists the tags instead (as GET `/api/v1/repos/:owner/:name/tags` does, newest first; no `name` or `action`); with `name` and `action` (`create` from `from`, or `delete`) it does what the branches page does: the default branch is never deleted, only a writer may act | yes |
64 | `capacity` | `{ key?, value?, dryRun? }` (forge admin): the forge's capacity and guards, live (crew and checks concurrency, check shards, cell egress, the new-account guard, the sign-in edge, queue depth, child forges; only the first six are settable by `key`); with `key` and `value` (`""` restores the default), planned first (`dryRun` is true unless `false`); applying needs an admin-scope token | yes |
64 | `capacity` | `{ key?, value?, dryRun? }` (forge admin): the forge's capacity and guards, live (crew and checks concurrency, check shards, cell egress, the new-account guard, the sign-in edge, queue depth, child forges; only the first six and `slots.smallShare` are settable by `key`); with `key` and `value` (`""` restores the default), planned first (`dryRun` is true unless `false`); applying needs an admin-scope token | yes |
6565 | `claim_link` | `{ name }`: a new claim link for a child you spawned that nobody has claimed; the old one stops working. An admin's | yes |
6666 | `close` | `{ repo, number, state?, reason?, into? }`: close an issue or a pull (`state` closed by default) or reopen it (`open`); the same rules and refusals as `PATCH …/issues/:number`: an agent closes only what the rules give it and reopens nothing; answers `state` and `closeReason` | yes |
6767 | `cloud_account` | `{ verb, provider, name, value?, to?, allowed?, repo? }`: change a cloud account: `attach` or `rotate` a token (`value`), `verify` it, `rename` it (`to`), `remove` it, `allow_writes` (`allowed` true or false) or `audit` (`repo` owner/name); a forge admin with an admin-scope token; answers a one-line `says` | yes |
src/actions/capacity.ts +2 −1
@@ -26,7 +26,7 @@ import { passkeyIds } from "../core/passkeys.ts";
2626 import type { User } from "../core/users.ts";
2727 import { err, ok, type Result } from "../kernel/result.ts";
2828
29 /** The six guards a caller may set by `key`: the MCP tool's enum and the terminal's `e`. */
29 /** The guards a caller may set by `key`: the MCP tool's enum. */
3030 export const SETTABLE_CAPACITY = [
3131 "crew.concurrency",
3232 "checks.concurrency",
@@ -34,6 +34,7 @@ export const SETTABLE_CAPACITY = [
3434 "cells.egress",
3535 "guard_new_accounts",
3636 "signin.edge",
37 "slots.smallShare",
3738 ] as const satisfies readonly CapacityKey[];
3839
3940 export interface CapacityRow {
src/core/capacity.ts +13
@@ -21,6 +21,7 @@ export type CapacityKey =
2121 | "checks.shards"
2222 | "queue.depth"
2323 | "queue.batch"
24 | "slots.smallShare"
2425 | "children.max"
2526 | "cells.egress"
2627 | "guard_new_accounts"
@@ -80,6 +81,13 @@ export const CAPACITY: Record<CapacityKey, Definition> = {
8081 fallback: "8",
8182 help: "The most pulls one merge-queue candidate carries. A bigger batch lands more pulls per green gate; a red one costs more search gates to find its culprit (one bad pull in 16 is found in two rounds, at most √16 = 4 gates each). The queue starts each line here, halves the batch after a red gate and doubles it back after two green gates in a row, never past this. Read on every sweep.",
8283 },
84 "slots.smallShare": {
85 label: "Builder share for small issues",
86 env: "FORGE_SLOTS_SMALL_SHARE",
87 kind: { type: "count", min: 0, max: 100 },
88 fallback: "30",
89 help: "The most builder slots, in percent and rounded up, that tests-only and small-addition issues may hold at once; the rest go to the roadmap — issues under an open epic or a P0/P1 pillar first (#7571). 100 lifts the cap.",
90 },
8391 "children.max": {
8492 label: "Forges this one may send",
8593 env: "FORGE_CHILDREN_MAX",
@@ -331,6 +339,11 @@ export function queueBatch(db: Database): number {
331339 return Number(capacityValue(db, "queue.batch"));
332340 }
333341
342 /** The percent of builder slots small issues may hold (#7571); 0 is a real answer, so not `capacityCount`. */
343 export function smallShare(db: Database): number {
344 return Number(capacityValue(db, "slots.smallShare"));
345 }
346
334347 /** Whether the platform edge's identity is read at all; on every request. */
335348 export function edgeSigninOn(db: Database): boolean {
336349 return capacityValue(db, "signin.edge") !== "off";
src/crew/autonomy.ts +12 −3
@@ -30,7 +30,7 @@ import { queueStore } from "../checks/queue_store.ts";
3030 import { addLearned } from "../checks/learned.ts";
3131 import { batchWords, dropFromLine, enqueue, type GateCandidate, type Queued, type QueueOptions, queueClashes, queueWords, waitingPulls } from "../checks/queue.ts";
3232 import { checksFor } from "../checks/service.ts";
33 import { queueBatch, queueDepth } from "../core/capacity.ts";
33 import { queueBatch, queueDepth, smallShare } from "../core/capacity.ts";
3434 import { readConflictLane, readConflictRoom } from "./conflict_room.ts";
3535 import { mergeable, resolveOid, treeOf } from "../git/merge.ts";
3636 import { CLOSED_NOTE } from "../core/done_on_main.ts";
@@ -120,6 +120,7 @@ import {
120120 parkReasons,
121121 } from "./parks.ts";
122122 import { reserveOf, reserveWords, short } from "./reserve.ts";
123 import { pickOrder, shareOf, smallWords } from "./small_share.ts";
123124 import { createLog } from "../kernel/log.ts";
124125 import { err, ok, type Result } from "../kernel/result.ts";
125126 import {
@@ -432,12 +433,17 @@ export async function driveRepo(
432433 const shunned = shunnedBy(app.db, repo, issue.id, now);
433434 return crew.filter((c) => c.role !== "builder" || !shunned.has(c.agent.user.id));
434435 };
435 const pickable = (
436 // The roadmap first, and the small issues held to their share (#7571).
437 const share = shareOf(app.db, repo, ready, slotted, paced.slots, smallShare(app.db));
438 const pickable = pickOrder(
436439 await withoutRetired(
437440 app,
438441 repo,
439442 ready.filter((r) => crewFor(r.issue).some((c) => c.role === "builder")),
440 )
443 ),
444 share.sizing,
445 share.running,
446 share.cap,
441447 );
442448 const next = await nextOf(app, repo, pickable);
443449 if (next !== undefined) {
@@ -1311,6 +1317,7 @@ export async function autonomyTick(
13111317 const crewNow = listCrewRoles(app.db, current.id);
13121318 const activeNow = activeRuns(app, current.id);
13131319 const held = heldBy(app, current, ready, crewNow, activeNow);
1320 const smallNow = shareOf(app.db, current, ready, slottedRuns(activeNow, crewNow), status.slots, smallShare(app.db));
13141321 const boots = bootCounts(app.config.dataDir);
13151322 const staleToday = closedToday(app, current.id, now);
13161323 // Says when the governor lowers the slots (#6375); one feed item per change.
@@ -1336,6 +1343,8 @@ export async function autonomyTick(
13361343 ...flowVitals(app.db, now),
13371344 active: status.active,
13381345 slots: status.slots,
1346 // Slots on tests-only and small issues against their share (#7571).
1347 small: smallWords(smallNow.running, smallNow.cap),
13391348 // Builders with nothing in flight: what bounds active beside slots and startable (#7006).
13401349 idle: idleBuilders(activeNow, crewNow),
13411350 ...(governor === undefined ? {} : { governor }),
src/crew/small_share.ts added +125
@@ -0,0 +1,125 @@
1 /**
2 * The roadmap goes first (#7571). Tests-only and small-addition issues are
3 * cheap, and left alone they fill the builder slots and the open-pull limit
4 * while the epics wait. So the pick order puts issues under an open epic or
5 * a P0/P1 pillar first, and the small ones may hold at most
6 * `slots.smallShare` percent of the builder slots at once.
7 *
8 * Plain data in, plain data out; `autonomy.ts` reads the issues and runs.
9 */
10
11 import type { Database } from "bun:sqlite";
12 import type { Issue } from "../core/issues.ts";
13 import { getIssuesByIds, labelsForIssues } from "../core/issues.ts";
14 import { pillarsOf, servedBy } from "../core/pillars.ts";
15 import type { Repo } from "../core/repos.ts";
16 import type { Ranked } from "../core/dependencies.ts";
17 import type { Run } from "../core/runs.ts";
18
19 const SMALL_LABELS = new Set(["tests-only", "small", "small-addition"]);
20 const SMALL_TITLE = /^(a test pins\b|test:)/i;
21 const EPIC_LABELS = new Set(["epic"]);

Too broad: tests?[:\s] and small\b match ordinary titles ("Small business page", "Test sort order"). Anchor to the documented forms: A test pins, Test:, Small as the issue says, and test each.

22 const ROADMAP_PILLARS = /^P[01]\b/;
23
24 /** Whether an issue's title or labels mark it tests-only or a small addition. */
25 export function isSmall(title: string, labels: readonly string[]): boolean {
26 return SMALL_TITLE.test(title.trim()) || labels.some((l) => SMALL_LABELS.has(l.toLowerCase()));
27 }
28
29 /**
30 * Whether the labels mark an issue an epic. Labels are set by writers; a
31 * title is anyone's, so a title alone does not make an epic.
32 */
33 export function isEpic(labels: readonly string[]): boolean {
34 return labels.some((l) => EPIC_LABELS.has(l.toLowerCase()));
35 }
36
37 /** The most builders the small issues may hold of `slots`, at `share` percent: rounded up. */
38 export function smallCap(slots: number, share: number): number {
39 return Math.ceil((Math.max(0, slots) * Math.min(100, Math.max(0, share))) / 100);
40 }
41
42 /** What the tick line's `small` field says: `1/2` — running against the cap. */
outdated

Returns "1/2 small" but CREW.md documents small=1/2. Pick one and test the tick line.

43 export function smallWords(running: number, cap: number): string {
44 return `${running}/${cap}`;
45 }
46
47 /** What the picker knows of the ready issues and the runs in flight. */
48 export interface Sizing {
49 /** Ids of issues under an open epic or a P0/P1 pillar. */
50 readonly roadmap: ReadonlySet<string>;
51 /** Ids of issues marked small. */
52 readonly small: ReadonlySet<string>;
53 }
54
55 /** Read which of `issues` are roadmap and which are small. */
56 export function sizeIssues(db: Database, repo: Repo, issues: readonly Issue[]): Sizing {
57 const labels = labelsForIssues(db, issues.map((i) => i.id));
58 const names = (i: Issue) => (labels.get(i.id) ?? []).map((l) => l.name);
59 const served = servedBy(db, pillarsOf(db, repo));
60 const underEpic = new Set<string>();
61 const rows = db
62 .query<{ id: string; epic: string }, [string]>(
63 `SELECT d.blocked_by_id AS id, e.id AS epic
64 FROM issue_dependency d JOIN issue e ON e.id = d.issue_id
65 WHERE e.state = 'open' AND e.repo_id = ?1`,
66 )
67 .all(repo.id);
68 const epicLabels = labelsForIssues(db, [...new Set(rows.map((r) => r.epic))]);
69 for (const r of rows)
70 if (isEpic((epicLabels.get(r.epic) ?? []).map((l) => l.name))) underEpic.add(r.id);
71 const roadmap = new Set<string>();
72 const small = new Set<string>();
73 for (const i of issues) {
74 const pillar = served.get(i.id);
75 if (underEpic.has(i.id) || (pillar !== undefined && ROADMAP_PILLARS.test(pillar))) roadmap.add(i.id);
76 if (isSmall(i.title, names(i))) small.add(i.id);
77 }
78 return { roadmap, small };
79 }
80
81 /**
82 * The pick order, and the cap: roadmap issues first (the order within each
83 * half is kept), and no small issue once `running` small ones hold `cap`.
84 */
85 export function pickOrder(
86 ready: readonly Ranked[],
87 sizing: Sizing,
88 running: number,
89 cap: number,
90 ): Ranked[] {
91 const open = running < cap;
92 const eligible = ready.filter((r) => open || !sizing.small.has(r.issue.id));
93 return [
94 ...eligible.filter((r) => sizing.roadmap.has(r.issue.id)),
95 ...eligible.filter((r) => !sizing.roadmap.has(r.issue.id)),
96 ];
97 }
98
99 /** How many of the slotted runs are on small issues. */
100 export function runningSmall(slotted: readonly Run[], small: ReadonlySet<string>): number {
101 return slotted.filter((r) => r.issueId !== null && small.has(r.issueId)).length;
102 }
103
104 /** The small share as the picker and the tick line read it. */
105 export interface Share {
106 readonly sizing: Sizing;
107 /** Slotted runs on small issues. */
108 readonly running: number;
109 /** The most small issues may hold. */
110 readonly cap: number;
111 }
112
113 /** Read the share for `ready` issues against the `slotted` runs and the percent allowed. */
114 export function shareOf(
115 db: Database,
116 repo: Repo,
117 ready: readonly Ranked[],
118 slotted: readonly Run[],
119 slots: number,
120 percent: number,
121 ): Share {
122 const inFlight = [...getIssuesByIds(db, slotted.flatMap((r) => (r.issueId === null ? [] : [r.issueId]))).values()];
123 const sizing = sizeIssues(db, repo, [...ready.map((r) => r.issue), ...inFlight]);
124 return { sizing, running: runningSmall(slotted, sizing.small), cap: smallCap(slots, percent) };
125 }
src/flow/pipeline.ts +2 −2
@@ -17,7 +17,7 @@
1717 */
1818
1919 import type { Database } from "bun:sqlite";
20 import { capacityValue } from "../core/capacity.ts";
20 import { capacityValue, smallShare } from "../core/capacity.ts";
2121
2222 export const PIPELINE = [
2323 "ready",
@@ -180,7 +180,7 @@ function capacities(db: Database): Record<PipelineKey, string | null> {
180180 const checks = `checks at once ${auto(capacityValue(db, "checks.concurrency"))}`;
181181 const s = slots(db);
182182 return {
183 ready: `${s.slots} slot${s.slots === 1 ? "" : "s"} in ${s.repos} autonomous ${s.repos === 1 ? "repository" : "repositories"}`,
183 ready: `${s.slots} slot${s.slots === 1 ? "" : "s"} in ${s.repos} autonomous ${s.repos === 1 ? "repository" : "repositories"}, small issues at most ${smallShare(db)}%`,
184184 building: crew,
185185 "check-queue": checks,
186186 checking: checks,
src/http/mcp/tools/capacity.ts +1 −1
@@ -5,7 +5,7 @@ import { good, bad, type Tool } from "../shared.ts";
55
66 export const tool: Tool = {
77 name: "capacity",
8 doc: "`{ key?, value?, dryRun? }` (forge admin): the forge's capacity and guards, live (crew and checks concurrency, check shards, cell egress, the new-account guard, the sign-in edge, queue depth, child forges; only the first six are settable by `key`); with `key` and `value` (`\"\"` restores the default), planned first (`dryRun` is true unless `false`); applying needs an admin-scope token",
8 doc: "`{ key?, value?, dryRun? }` (forge admin): the forge's capacity and guards, live (crew and checks concurrency, check shards, cell egress, the new-account guard, the sign-in edge, queue depth, child forges; only the first six and `slots.smallShare` are settable by `key`); with `key` and `value` (`\"\"` restores the default), planned first (`dryRun` is true unless `false`); applying needs an admin-scope token",
99 description:
1010 "Forge capacity and guards, live. With `key` and `value` (\"\" restores default), plans.",
1111 inputSchema: {
src/tui/screens/flow.ts +2
@@ -17,6 +17,7 @@
1717 */
1818
1919 import type { Database } from "bun:sqlite";
20 import { smallShare } from "../../core/capacity.ts";
2021 import { recentGates, type KeptResult } from "../../checks/gate_result.ts";
2122 import { HOLDS } from "../../crew/held.ts";
2223 import { pullCounts } from "../../crew/hot_files.ts";
@@ -86,6 +87,7 @@ export function flowLines(
8687 ...(agent === undefined ? clogLines(readClog(db, now), now.getTime()).flatMap((l) => wrap(l, inner)) : []),
8788 ...firedAlarms(db, now, { publicOnly: agent !== undefined, ceilingUsd }).flatMap((a) => wrap(a.says, inner)),
8889 "",
90 ...wrap(`Small issues hold at most ${smallShare(db)}% of the builder slots (slots.smallShare).`, inner),
8991 ...wrap(parkedSays(fig.parked), inner),
9092 "",
9193 ...wrap(throughputSays(flow), inner),
test/crew-small-share.test.ts added +293
@@ -0,0 +1,293 @@
1 /**
2 * Builder slots serve the roadmap first (#7571): issues under an open epic
3 * or a P0/P1 pillar are picked before the rest, and tests-only and
4 * small-addition issues hold at most `slots.smallShare` of the builders.
5 */
6 import { afterAll, beforeAll, expect, spyOn, test } from "bun:test";
7 import { mkdtemp, rm } from "node:fs/promises";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { createApp, type App } from "../src/app.ts";
11 import { addToCrew, createAgent } from "../src/actions/crew.ts";
12 import { assignIssue, openIssue } from "../src/actions/issues.ts";
13 import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts";
14 import { addDependency } from "../src/core/dependencies.ts";
15 import { getIssueById, type Issue } from "../src/core/issues.ts";
16 import { getRepoById, type Repo } from "../src/core/repos.ts";
17 import { createRun } from "../src/core/runs.ts";
18 import { createUser, getUserByName, type User } from "../src/core/users.ts";
19 import { changeCapacity } from "../src/actions/capacity.ts";
20 import { smallShare } from "../src/core/capacity.ts";
21 import { createLabel, listLabels, setIssueLabels } from "../src/core/issues.ts";
22 import { tool as capacityTool } from "../src/http/mcp/tools/capacity.ts";
23 import { autonomyTick, driveRepo } from "../src/crew/autonomy.ts";
24 import { isEpic, isSmall, sizeIssues, smallCap, smallWords } from "../src/crew/small_share.ts";
25
26 let dataDir: string;
27 let app: App;
28 let alice: User;
29 let repo: Repo;
30
31 const open = (title: string): Issue => {
32 const made = openIssue(app, alice, getRepoById(app.db, repo.id)!, { title });
33 if (!made.ok) throw new Error(String(made.error));
34 return made.value;
35 };
36
37 beforeAll(async () => {
38 dataDir = await mkdtemp(join(tmpdir(), "forge-small-share-"));
39 app = createApp({ dataDir, port: 0 });
40 const a = await createUser(app.db, {
41 origin: "seed", trusted: true, username: "alice", email: "[email protected]",
42 password: "a-good-passphrase", adminIfFirst: true,
43 });
44 if (!a.ok) throw new Error(a.error);
45 alice = a.value;
46 const made = await createRepo(app, alice, { name: "notes", visibility: "private" });
47 if (!made.ok) throw new Error(String(made.error));
48 repo = made.value;
49 const first = await commitToBranch(app, alice, repo, {
50 message: "Start",
51 files: [{ path: "README.md", content: "# notes\n" }],
52 });
53 if (!first.ok) throw new Error(JSON.stringify(first.error));
54 for (const name of ["mason", "scout", "quill", "smith", "atlas"]) {
55 const agent = await createAgent(app, alice, { username: name });
56 if (!agent.ok) throw new Error(String(agent.error));
57 expect(addToCrew(app, alice, repo, name).ok).toBe(true);
58 }
59 const on = await updateRepoSettings(app, alice, repo, {
60 autonomy: "autonomous",
61 autonomyDirection: "Keep the notes tidy.",
62 autonomyCeilingUsd: 10,
63 autonomySlots: 5,
64 autonomyBy: alice.id,
65 });
66 expect(on.ok).toBe(true);
67 });
68
69 afterAll(async () => {
70 app.close();
71 await rm(dataDir, { recursive: true, force: true });
72 });
73
74 test("small is read from the title or the labels, and the cap rounds up", () => {
75 expect(isSmall("A test pins the sort order", [])).toBe(true);
76 expect(isSmall("Sort notes", ["Tests-only"])).toBe(true);
77 expect(isSmall("Sort notes by date", [])).toBe(false);
78 expect(isSmall("Test: the sort order", [])).toBe(true);
79 expect(isSmall("Sort notes", ["small"])).toBe(true);
80 expect(isSmall("Sort notes", ["small-addition"])).toBe(true);
81 // Ordinary titles that only look like the forms are not small.
82 expect(isSmall("Small business page", [])).toBe(false);
83 expect(isSmall("Test sort order", [])).toBe(false);
84 expect(isSmall("Tests for the sort", [])).toBe(false);
85 expect(isSmall("Make it tests-only friendly", [])).toBe(false);
86 expect(isEpic(["epic"])).toBe(true);
87 expect(isEpic(["Epic"])).toBe(true);
88 expect(isEpic([])).toBe(false);
89 expect(smallCap(5, 30)).toBe(2);
90 expect(smallCap(1, 30)).toBe(1);
91 expect(smallCap(5, 0)).toBe(0);
92 expect(smallCap(5, 100)).toBe(5);
93 expect(smallWords(1, 2)).toBe("1/2");
94 });
95
96 test("with 5 slots and only small issues ready, at most 2 start; an epic's issue starts before a small one", async () => {
97 const mason = getUserByName(app.db, "mason")!;
98 const scout = getUserByName(app.db, "scout")!;
99 // Two small issues already building, one builder each.
100 for (const [title, who] of [["A test pins the sort", mason], ["A test pins the filter", scout]] as const) {
101 const issue = open(title);
102 const assigned = assignIssue(app, alice, getRepoById(app.db, repo.id)!, issue, who);
103 expect(assigned.ok).toBe(true);
104 createRun(app.db, { repoId: repo.id, kind: "agent", actorId: who.id, issueId: issue.id, reason: "assigned" });
105 }
106 const third = open("A test pins the export");
107 // The cap is full: the third small issue is not started (the cap-cause
108 // test below proves the cap is the reason).
109 expect(getIssueById(app.db, third.id)!.assigneeId).toBeNull();
110
111 // An issue under an open epic, opened after the small one, starts at once.
112 const epic = open("Search the notes");
113 label(repo, epic, "epic");
114 const under = open("Index the notes");
115 expect(addDependency(app.db, epic, under, alice.id).ok).toBe(true);
116 expect(await driveRepo(app, getRepoById(app.db, repo.id)!)).toBe("picked");
117 expect(getIssueById(app.db, under.id)!.assigneeId).not.toBeNull();
118 expect(getIssueById(app.db, third.id)!.assigneeId).toBeNull();
119 });
120
121 /** A repository of its own, 5 slots, the whole crew, for the tests that start from nothing running. */
122 async function fresh(name: string): Promise<Repo> {
123 const made = await createRepo(app, alice, { name, visibility: "private" });
124 if (!made.ok) throw new Error(String(made.error));
125 const first = await commitToBranch(app, alice, made.value, {
126 message: "Start",
127 files: [{ path: "README.md", content: `# ${name}\n` }],
128 });
129 if (!first.ok) throw new Error(JSON.stringify(first.error));
130 for (const who of ["mason", "scout", "quill", "smith", "atlas"]) expect(addToCrew(app, alice, made.value, who).ok).toBe(true);
131 const on = await updateRepoSettings(app, alice, made.value, {
132 autonomy: "autonomous",
133 autonomyDirection: "Keep it tidy.",
134 autonomyCeilingUsd: 10,
135 autonomySlots: 5,
136 autonomyBy: alice.id,
137 });
138 expect(on.ok).toBe(true);
139 return getRepoById(app.db, made.value.id)!;
140 }
141
142 const openIn = (r: Repo, title: string): Issue => {
143 const made = openIssue(app, alice, r, { title });
144 if (!made.ok) throw new Error(String(made.error));
145 return made.value;
146 };
147
148 const label = (r: Repo, issue: Issue, name: string): void => {
149 let found = listLabels(app.db, r.id).find((l) => l.name === name);
150 if (found === undefined) {
151 const made = createLabel(app.db, r.id, name, "aabbcc");
152 if (!made.ok) throw new Error(made.error);
153 found = made.value;
154 }
155 setIssueLabels(app.db, issue.id, [found.id]);
156 };
157
158 test("the share, not another reason, holds the small issues: 0 starts none, 100 starts one", async () => {
159 const r = await fresh("share-edges");
160 const small = openIn(r, "A test pins the sort");
161 expect(changeCapacity(app, alice, "slots.smallShare", "0").ok).toBe(true);
162 try {
163 expect(await driveRepo(app, getRepoById(app.db, r.id)!)).not.toBe("picked");
164 expect(getIssueById(app.db, small.id)!.assigneeId).toBeNull();
165 expect(changeCapacity(app, alice, "slots.smallShare", "100").ok).toBe(true);
166 expect(await driveRepo(app, getRepoById(app.db, r.id)!)).toBe("picked");
167 expect(getIssueById(app.db, small.id)!.assigneeId).not.toBeNull();
168 } finally {
169 changeCapacity(app, alice, "slots.smallShare", null);
170 }
171 });
172
173 test("the cap is full of running small issues, and lifting it starts the next", async () => {
174 const r = await fresh("cap-cause");
175 for (const who of ["mason", "scout"]) {
176 const user = getUserByName(app.db, who)!;
177 const issue = openIn(r, `A test pins the ${who}`);
178 expect(assignIssue(app, alice, getRepoById(app.db, r.id)!, issue, user).ok).toBe(true);
179 createRun(app.db, { repoId: r.id, kind: "agent", actorId: user.id, issueId: issue.id, reason: "assigned" });
180 }
181 const third = openIn(r, "A test pins the export");
182 expect(await driveRepo(app, getRepoById(app.db, r.id)!)).not.toBe("picked");
183 expect(getIssueById(app.db, third.id)!.assigneeId).toBeNull();
184 expect(changeCapacity(app, alice, "slots.smallShare", "100").ok).toBe(true);
185 try {
186 expect(await driveRepo(app, getRepoById(app.db, r.id)!)).toBe("picked");
187 expect(getIssueById(app.db, third.id)!.assigneeId).not.toBeNull();
188 } finally {
189 changeCapacity(app, alice, "slots.smallShare", null);
190 }
191 });
192
193 test("an issue under a P0 pillar starts before an older plain one", async () => {
194 const r = await fresh("pillar-first");
195 const umbrella = openIn(r, "P0 Trust: keep the notes safe");
196 const plain = openIn(r, "Rename the export button");
197 const served = openIn(r, "Escape the note titles");
198 expect(addDependency(app.db, umbrella, served, alice.id).ok).toBe(true);
199 expect(await driveRepo(app, getRepoById(app.db, r.id)!)).toBe("picked");
200 expect(getIssueById(app.db, served.id)!.assigneeId).not.toBeNull();
201 expect(getIssueById(app.db, plain.id)!.assigneeId).toBeNull();
202 });
203
204 test("an issue under an epic by label starts first, and a tests-only label counts as small", async () => {
205 const r = await fresh("label-paths");
206 const epic = openIn(r, "Search for the notes");
207 label(r, epic, "epic");
208 const under = openIn(r, "Index the notes");
209 expect(addDependency(app.db, epic, under, alice.id).ok).toBe(true);
210 const plain = openIn(r, "Rename the export button");
211 expect(await driveRepo(app, getRepoById(app.db, r.id)!)).toBe("picked");
212 expect(getIssueById(app.db, under.id)!.assigneeId).not.toBeNull();
213 expect(getIssueById(app.db, plain.id)!.assigneeId).toBeNull();
214
215 });
216
217 test("an issue titled Epic… with no label is not an epic: what waits for it is not roadmap", () => {
218 const r = getRepoById(app.db, repo.id)!;
219 const epic = open("Epic: roadmap by title only");
220 const under = open("Index by title");
221 expect(addDependency(app.db, epic, under, alice.id).ok).toBe(true);
222 expect(sizeIssues(app.db, r, [under]).roadmap.has(under.id)).toBe(false);
223 label(repo, epic, "epic");
224 expect(sizeIssues(app.db, r, [under]).roadmap.has(under.id)).toBe(true);
225 });
226
227 /** Two issues small only by label, running; the cap (2 of 5) is full. */
228 async function labelledCapFull(name: string): Promise<{ r: Repo; ready: Issue }> {
229 const r = await fresh(name);
230 for (const who of ["mason", "scout"]) {
231 const user = getUserByName(app.db, who)!;
232 const issue = openIn(r, `Pin the ${who} order`);
233 label(r, issue, "tests-only");
234 expect(assignIssue(app, alice, getRepoById(app.db, r.id)!, issue, user).ok).toBe(true);
235 createRun(app.db, { repoId: r.id, kind: "agent", actorId: user.id, issueId: issue.id, reason: "assigned" });
236 }
237 const ready = openIn(r, "Pin the export order");
238 label(r, ready, "tests-only");
239 return { r, ready };
240 }
241
242 test("small only by label: running ones fill the cap and a ready one waits, until the share is 100", async () => {
243 const { r, ready } = await labelledCapFull("label-cap");
244 expect(await driveRepo(app, getRepoById(app.db, r.id)!)).not.toBe("picked");
245 expect(getIssueById(app.db, ready.id)!.assigneeId).toBeNull();
246 expect(changeCapacity(app, alice, "slots.smallShare", "100").ok).toBe(true);
247 try {
248 expect(await driveRepo(app, getRepoById(app.db, r.id)!)).toBe("picked");
249 expect(getIssueById(app.db, ready.id)!.assigneeId).not.toBeNull();
250 } finally {
251 changeCapacity(app, alice, "slots.smallShare", null);
252 }
253 });
254
255 test("a plain ready issue still starts when labelled small ones fill the cap", async () => {
256 const { r, ready } = await labelledCapFull("label-cap-plain");
257 const plain = openIn(r, "Rename the export button");
258 expect(await driveRepo(app, getRepoById(app.db, r.id)!)).toBe("picked");
259 expect(getIssueById(app.db, plain.id)!.assigneeId).not.toBeNull();
260 expect(getIssueById(app.db, ready.id)!.assigneeId).toBeNull();
261 });
262
263 test("the tick line carries the small share as running/cap", async () => {
264 const r = await fresh("tick-line");
265 const small = openIn(r, "A test pins the tick");
266 expect(assignIssue(app, alice, getRepoById(app.db, r.id)!, small, getUserByName(app.db, "mason")!).ok).toBe(true);
267 createRun(app.db, { repoId: r.id, kind: "agent", actorId: getUserByName(app.db, "mason")!.id, issueId: small.id, reason: "assigned" });
268 const lines: string[] = [];
269 const spy = spyOn(console, "info").mockImplementation((line: unknown) => {
270 lines.push(String(line));
271 });
272 try {
273 await autonomyTick(app, new Date(), async () => 0);
274 } finally {
275 spy.mockRestore();
276 }
277 const mine = lines.filter((l) => l.includes("[autonomy] tick repo=alice/tick-line"));
278 expect(mine.length).toBe(1);
279 expect(mine[0]).toContain(" small=1/2");
280 });
281
282 test("slots.smallShare is a capacity setting an agent can change through the MCP tool", () => {
283 const enumerated = (capacityTool.inputSchema as { properties: { key: { enum: string[] } } }).properties.key.enum;
284 expect(enumerated).toContain("slots.smallShare");
285 expect(smallShare(app.db)).toBe(30);
286 expect(changeCapacity(app, alice, "slots.smallShare", "50").ok).toBe(true);
287 expect(smallShare(app.db)).toBe(50);
288 const bad = changeCapacity(app, alice, "slots.smallShare", "101");
289 expect(bad.ok).toBe(false);
290 expect(smallShare(app.db)).toBe(50);
291 expect(changeCapacity(app, alice, "slots.smallShare", null).ok).toBe(true);
292 expect(smallShare(app.db)).toBe(30);
293 });
test/flow-pipeline.test.ts +1 −1
@@ -216,7 +216,7 @@ describe("/flow: the forge shows its own bottleneck", () => {
216216 ]);
217217 const by = new Map(stages.map((s) => [s.key, s]));
218218 expect(by.get("ready")).toMatchObject({ waiting: 2, active: 0 });
219 expect(by.get("ready")?.capacity).toBe("2 slots in 1 autonomous repository");
219 expect(by.get("ready")?.capacity).toBe("2 slots in 1 autonomous repository, small issues at most 30%");
220220 expect(by.get("building")).toMatchObject({ waiting: 2, capacity: "crew runs at once 3" });
221221 expect(by.get("check-queue")).toMatchObject({ waiting: 3, capacity: "checks at once 1" });
222222 expect(by.get("checking")).toMatchObject({ waiting: 0, active: 1 });
test/tui-capacity.test.ts +11
@@ -126,6 +126,17 @@ describe("tui capacity", () => {
126126 h.stop();
127127 });
128128
129 test("slots.smallShare, the small-issue share of builder slots, changes after a confirm (#7571)", async () => {
130 const h = boot(carol);
131 for (let i = 0; i < CAPACITY_KEYS.indexOf("slots.smallShare"); i++) await h.press("j");
132 await h.press("e");
133 for (let i = 0; i < 4; i++) await h.press("backspace");
134 await h.press("5", "0", "enter");
135 await h.press("left", "enter");
136 expect(capacityValue(app.db, "slots.smallShare")).toBe("50");
137 h.stop();
138 });
139
129140 test("a change leaves a capacity.changed event, and restoring the default with an empty value works", async () => {
130141 const seen = () => listEvents(app.db, {}).filter((e) => e.kind === "capacity.changed").length;
131142 const before = seen();

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs