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

The planner stops opening issues past an open-issue ceiling the owner sets, and says why #12927

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/12868-the-planner-stops-opening-issues-past-an → main 6 commits fork 5 threads · 5 unresolved

  • Merged. scout/12868-the-planner-stops-opening-issues-past-an was merged into main as fdb806b.

Review

Sign in to review this change.
17 files changed +489 −22
docs/features/README.md +1
@@ -130,6 +130,7 @@ Read with the guide page [Tell the crew](../guide-tell-the-crew.md).
130130 - [The map, lightly](map.md)
131131 - [The pulls a crew team's review holds](team-waiting.md)
132132 - [The pulls waiting on a crew team](team-queue.md)
133 - [The open-issue ceiling](planner-ceiling.md)
133134 - [The queue](queue.md)
134135 - [The space](space.md)
135136 - [The thank-you note](thanks.md)
docs/features/planner-ceiling.md added +26
@@ -0,0 +1,26 @@
1 # The open-issue ceiling
2
3 Past a number of open issues the planner stops opening more, so the pile shrinks before it grows again. The
4 default is 150 open issues per repository; the owner (a person who administers it, never an agent) sets any
5 whole number from 1 to 100000 or 0 for off.
6
7 **Set it.** On `/:owner/:name/queue` the row "Open-issue ceiling" shows the number and, under it, why; the owner
8 types a new one and presses "Set the ceiling". In the terminal, the Queue screen takes `c` to set it and `r` to
9 resume. Setting it ends any resume. `planner.ceiling` is heard by the admins.
10
11 **Held.** Over the ceiling the repository's planner opens no issue, adds no plan and starts no run, and says why
12 in the words of the row ("the planner is held by the open-issue ceiling: 151 issues are open, past the ceiling
13 of 150"). The API answers `409 planner_ceiling` with the same words. /flow lists every repository held, the
14 default ceiling's too. People, builders and reviewers are never held. When closes bring the count back under it,
15 the planner carries on by itself.
16
17 **Resume.** "Resume the planner for one plan" (`r` in the terminal) lets the planner open the next 12 issues past
18 the ceiling, once: the allowance is the open count then plus 12.
19
20 **What still goes in.**
21 - A split of an issue the crew handed to the planner: the run starts, and the children it opens are let through.
22 - A defect whose body has a line starting `Evidence:` with something after it. The planner writes that line
23 itself, so it is a convention, not proof; the ceiling bounds it instead of trusting it: such issues take the
24 pile at most 12 past the ceiling.
25
26 Not done: a limit for builders or people, a ceiling per label, and checking what an `Evidence:` line cites.
src/actions/issues.ts +24 −4
@@ -25,7 +25,7 @@ import { requireAbility } from "./roles.ts";
2525 import type { App } from "../app.ts";
2626 import { adoptResolution } from "../core/trusted_sources.ts";
2727 import { crewRole, isCrew } from "../core/agents.ts";
28 import { pausedUntil } from "../core/planner_pause.ts";
28 import { ceilingHold, EVIDENCE_ROOM, hasEvidence, pausedUntil } from "../core/planner_pause.ts";
2929 import { keepWithinChapter } from "./chapters.ts";
3030 import { inheritChapter } from "../core/chapters.ts";
3131 import { moveBlockersToChildren } from "../core/dependencies.ts";
@@ -62,7 +62,7 @@ import {
6262 } from "../crew/direct.ts";
6363 import { laterGate } from "../crew/later.ts";
6464 import { replanSince } from "../core/limb_replan.ts";
65 import { handedOver } from "../crew/parks.ts";
65 import { handedOver, struckOut } from "../crew/parks.ts";
6666 import { alreadyDone, CLOSED_NOTE } from "../core/done_on_main.ts";
6767 import { listReviews } from "../core/reviews.ts";
6868 import {
@@ -98,7 +98,7 @@ export function openIssue(
9898 input: { title: string; body?: string; sealed?: boolean },
9999 ): Result<
100100 Issue,
101 "not_found" | "unauthorized" | "planner_paused" | TitleError | "body_too_long" | MirrorError
101 "not_found" | "unauthorized" | "planner_paused" | "planner_ceiling" | TitleError | "body_too_long" | MirrorError
102102 > {
103103 const user = requireParticipant(app, actor, repo);
104104 if (!user.ok) return user;
@@ -110,6 +110,14 @@ export function openIssue(
110110 pausedUntil(app.db, repo.id, new Date()) !== null
111111 )
112112 return err("planner_paused");
113 // The open-issue ceiling (#12868): past it the planner opens nothing but a defect with evidence.
114 if (
115 user.value.kind === "agent" &&
116 crewRole(app.db, repo.id, user.value.id) === "planner" &&
117 ceilingHold(app.db, repo.id, hasEvidence(input.body ?? "") ? EVIDENCE_ROOM : 0) !== null &&
118 !splitPending(app, repo)
119 )
120 return err("planner_ceiling");
113121 // Anyone who may open an issue may seal it: a reader reporting a hole
114122 // seals it too, and from then on only writers and the crew see it
115123 // (`core/sealed.ts`).
@@ -714,6 +722,18 @@ export type CloseError =
714722 /** The longest note a close takes: one sentence. */
715723 export const MAX_NOTE = 300;
716724
725 /**
726 * Whether an open issue is handed to the planner to split (`handedOver`): the children it opens
727 * for that are the split the ceiling lets through while it holds the planner.
728 */
729 export function splitPending(app: App, repo: Repo): boolean {
730 const ids = app.db
731 .query<{ id: string }, [string]>("SELECT id FROM issue WHERE repo_id = ?1 AND kind = 'issue' AND state = 'open'")
732 .all(repo.id)
733 .map((r) => r.id);
734 return ids.length > 0 && struckOut(app.db, repo, ids).size > 0;
735 }
736
717737 /** How an issue closes: done unless said otherwise; split names its children. */
718738 export interface Closing {
719739 readonly reason?: CloseReason;
@@ -823,7 +843,7 @@ export async function openIssueThrough(
823843 ): Promise<
824844 Result<
825845 Issue,
826 ThroughError<"not_found" | "unauthorized" | "planner_paused" | TitleError | "body_too_long">
846 ThroughError<"not_found" | "unauthorized" | "planner_paused" | "planner_ceiling" | TitleError | "body_too_long">
827847 >
828848 > {
829849 const user = requireParticipant(app, actor, repo);
src/actions/plan.ts +5 −1
@@ -10,7 +10,8 @@
1010 * nothing reaches the ready list without a reason to be built now.
1111 */
1212
13 import { pausedUntil, PAUSE_REFUSAL } from "../core/planner_pause.ts";
13 import { ceilingHold, EVIDENCE_ROOM, hasEvidence, pausedUntil, PAUSE_REFUSAL } from "../core/planner_pause.ts";
14 import { splitPending } from "./issues.ts";
1415 import { sealedScope } from "../core/sealed.ts";
1516 import type { App } from "../app.ts";
1617 import { crewRole, isCrew } from "../core/agents.ts";
@@ -233,6 +234,9 @@ function vet(
233234 // Only the repo's planner is held; it lifts when a crew member comments, or the issue is closed or hidden.
234235 if (actor.kind === "agent" && crewRole(app.db, repo.id, actor.id) === "planner") {
235236 if (pausedUntil(app.db, repo.id, new Date()) !== null) return refuse("planner_paused", PAUSE_REFUSAL);
237 const held = ceilingHold(app.db, repo.id, items.every((i) => hasEvidence(i.body)) ? EVIDENCE_ROOM : 0);
238 if (held !== null && !splitPending(app, repo))
239 return refuse("planner_ceiling", `${held}; a plan whose every item has an \`Evidence:\` line, or a split of an issue handed to the planner, still goes in`);
236240 const waiting = unansweredFromApp(app.db, repo.id);
237241 if (waiting !== undefined)
238242 return refuse(
src/actions/planner_switch.ts +26 −1
@@ -8,7 +8,7 @@ import type { App } from "../app.ts";
88 import { canAdmin, type Repo } from "../core/repos.ts";
99 import type { User } from "../core/users.ts";
1010 import { err, ok, type Result } from "../kernel/result.ts";
11 import { FOREVER, nextWeek, pausePlanner, pausedUntil, resumePlanner } from "../core/planner_pause.ts";
11 import { FOREVER, liftCeilingOnce, nextWeek, parseCeiling, pausePlanner, pausedUntil, resumePlanner, setOpenCeiling } from "../core/planner_pause.ts";
1212 import { weekCapacity } from "../flow/week.ts";
1313
1414 export type SwitchInput =
@@ -64,3 +64,28 @@ export function switchInput(mode: string, at: string): SwitchInput | undefined {
6464 if (mode === "on" || mode === "week" || mode === "owner") return { mode };
6565 return mode === "until" ? { mode, at: utcAt(at) } : undefined;
6666 }
67
68 /**
69 * The open-issue ceiling (#12868): the owner sets it (a whole number, 0 = off) or resumes the
70 * planner past it for one plan's worth. Same rule as the switch: a person who administers, never
71 * an agent.
72 */
73 export function setCeiling(
74 app: App,
75 actor: User | undefined,
76 repo: Repo,
77 input: { readonly mode: "set"; readonly value: string } | { readonly mode: "resume" },
78 ): Result<number, SwitchError> {
79 if (actor === undefined) return err("not_found");
80 if (actor.kind === "agent" || !canAdmin(app.db, repo, actor)) return err("forbidden");
81 let value: number;
82 if (input.mode === "resume") value = liftCeilingOnce(app.db, repo.id, actor.id);
83 else {
84 const n = parseCeiling(input.value);
85 if (n === undefined) return err("invalid");
86 setOpenCeiling(app.db, repo.id, n, actor.id);
87 value = n;
88 }
89 app.bus.append({ kind: "planner.ceiling", repoId: repo.id, actorId: actor.id, payload: { mode: input.mode, value } });
90 return ok(value);
91 }
src/actions/tell.ts +2
@@ -69,6 +69,8 @@ export type TellError =
6969 | "unauthorized"
7070 /** The owner paused the planner (`core/planner_pause.ts`). */
7171 | "planner_paused"
72 /** Past the owner's open-issue ceiling (`core/planner_pause.ts`). */
73 | "planner_ceiling"

Unused error: nothing returns it and tell gives no ceiling answer. Box 2 asks for the cause in tell's planner_paused answer; do that or remove this.

7274 /** Someone who may not direct the crew here (`crew/direct.ts`). */
7375 | "forbidden"
7476 /** Someone whose email is not verified yet (`verify.ts`). */
src/core/event_audience.ts +2
@@ -257,6 +257,8 @@ export function classifiedAudience(kind: string): EventAudience | undefined {
257257 // The owner's planner switch is the admins' to hear (#11604).
258258 kind === "planner.paused" ||
259259 kind === "planner.resumed" ||
260 // The open-issue ceiling the owner sets or lifts (#12868).
261 kind === "planner.ceiling" ||
260262 // Events the retired FLOW ONLY switch wrote stay the admins' to hear.
261263 kind === "flow_only.cleared" ||
262264 // A report from outside waits for a person who decides; its arrival is
src/core/planner_pause.ts +92
@@ -46,3 +46,95 @@ export function pauseSentence(until: string | null): string {
4646 if (until.startsWith("9999")) return "The planner is paused until you switch it on.";
4747 return `The planner is paused until ${until.slice(0, 16).replace("T", " ")} UTC.`;
4848 }
49
50 /**
51 * The open-issue ceiling (#12868): past it the planner pauses itself. Per repository, in
52 * `forge_setting`; no row is the default.
53 */
54 export const DEFAULT_CEILING = 150;
55 export const MAX_CEILING = 100_000;
56 /** What one resume allows: a plan's worth of issues past the ceiling, once. */
57 export const LIFT_ROOM = 12;
58 export const CEILING_REFUSAL =
59 "the planner is held by the open-issue ceiling: it opens no issues until the pile is under it or the owner resumes it for one plan; a defect with an `Evidence:` line and a split of an issue handed to it still go in";
60 export const CEILING_REASON =
61 "Past this many open issues the planner stops opening more, so the pile shrinks before it grows again. 0 turns it off.";
62 /** The reason line when the ceiling holds: the cause says it, so the reason is not said twice. */
63 export const CEILING_HELD_NOTE = "Resume lets it open one plan past the ceiling.";
64 const ceilingKey = (repoId: string) => `planner.openCeiling.${repoId}`;
65 const liftKey = (repoId: string) => `planner.ceilingLift.${repoId}`;
66
67 function setting(db: Database, key: string): number | null {
68 const row = db.query<{ value: string }, [string]>("SELECT value FROM forge_setting WHERE key = ?1").get(key);
69 const n = row === null ? NaN : Number(row.value);
70 return Number.isInteger(n) ? n : null;
71 }
72
73 function put(db: Database, key: string, value: number, byId: string): void {
74 db.query(
75 `INSERT INTO forge_setting (key, value, updated_by, updated_at) VALUES (?1, ?2, ?3, strftime('%Y-%m-%dT%H:%M:%fZ','now'))
76 ON CONFLICT(key) DO UPDATE SET value = ?2, updated_by = ?3, updated_at = strftime('%Y-%m-%dT%H:%M:%fZ','now')`,
77 ).run(key, String(value), byId);
78 }
79
80 export function openCeiling(db: Database, repoId: string): number {
81 return setting(db, ceilingKey(repoId)) ?? DEFAULT_CEILING;
82 }
83
84 /**
85 * Whole number from 0 to MAX_CEILING, or undefined. Changing the ceiling ends any one-run
86 * resume.
87 */
88 export function parseCeiling(raw: string): number | undefined {
89 const t = raw.trim();
90 if (!/^\d{1,6}$/.test(t)) return undefined;
91 const n = Number(t);
92 return n <= MAX_CEILING ? n : undefined;
93 }
94
95 export function setOpenCeiling(db: Database, repoId: string, value: number, byId: string): void {
96 put(db, ceilingKey(repoId), value, byId);
97 db.query("DELETE FROM forge_setting WHERE key = ?1").run(liftKey(repoId));
98 }
99
100 /**
101 * The owner resumes the planner past the ceiling for one plan's worth: the allowance is the open
102 * count now plus LIFT_ROOM.
103 */
104 export function liftCeilingOnce(db: Database, repoId: string, byId: string): number {
105 const allowance = openNow(db, repoId) + LIFT_ROOM;
106 put(db, liftKey(repoId), allowance, byId);
107 return allowance;
108 }
109
110 export function openNow(db: Database, repoId: string): number {
111 return db
112 .query<{ c: number }, [string]>("SELECT COUNT(*) AS c FROM issue WHERE repo_id = ?1 AND kind = 'issue' AND state = 'open'")
113 .get(repoId)?.c ?? 0;
114 }
115
116 /**
117 * The cause the planner is held, in words, or null when it may open issues. `slack` is the room
118 * past the ceiling a defect with evidence gets (`EVIDENCE_ROOM`), so the exception is bounded.
119 */
120 export function ceilingHold(db: Database, repoId: string, slack = 0): string | null {
121 const ceiling = openCeiling(db, repoId);
122 if (ceiling === 0) return null;
123 const allowed = Math.max(ceiling, setting(db, liftKey(repoId)) ?? 0) + slack;
124 const open = openNow(db, repoId);
125 return open > allowed
126 ? `the planner is held by the open-issue ceiling: ${open} issues are open, past the ceiling of ${allowed}; it opens none until the pile is under it or the owner resumes it for one plan`
127 : null;
128 }
129
130 /** How far past the ceiling defects with an `Evidence:` line may take the pile. */
outdated

Security/unsafe default: any planner can write 'Evidence: x' and walk past the ceiling. Needs a check the planner cannot self-assert.

131 export const EVIDENCE_ROOM = 12;
132
133 /**
134 * An issue that quotes its evidence (a line starting `Evidence:` with something after it) is a
135 * defect recorded, which the ceiling lets through. A planner writes that line itself, so it is a
136 * convention, not proof: the ceiling bounds it (`EVIDENCE_ROOM`) rather than trusting it.
137 */
138 export function hasEvidence(body: string): boolean {
139 return /^Evidence:[ \t]*\S/m.test(body);
140 }
src/crew/dispatch.ts +10 −3
@@ -8,7 +8,7 @@
88 * time. A missed wake-up costs a tick, never a run.
99 */
1010
11 import { pausedUntil } from "../core/planner_pause.ts";
11 import { ceilingHold, pausedUntil } from "../core/planner_pause.ts";
1212 import { chapterHold } from "../core/chapters.ts";
1313 import { crewFilters, isStrangerPull } from "./stranger.ts";
1414 import { TEMP_FULL } from "../checks/disk_full.ts";
@@ -26,7 +26,7 @@ import { rmSync } from "node:fs";
2626 import type { App } from "../app.ts";
2727 import { landedPullOf, settleLanded } from "./interrupted.ts";
2828 import { transact } from "../kernel/db.ts";
29 import { addComment } from "../actions/issues.ts";
29 import { addComment, splitPending } from "../actions/issues.ts";
3030 import { planAnotherRound } from "../actions/give_back.ts";
3131 import { announceRun } from "../actions/runs.ts";
3232 import { crewRole, getAgent, type Agent } from "../core/agents.ts";
@@ -476,7 +476,14 @@ export function queueAgentRun(
476476 // Never a job outside the agent's seat: building is a builder's, reviewing a reviewer's.
477477 if (outsideSeat(app, repo, issue, agent, reason)) return undefined;
478478 // The owner's switch (#11604): a paused planner starts nothing; builders and reviewers carry on.
479 if (crewRole(app.db, repo.id, agent.user.id) === "planner" && pausedUntil(app.db, repo.id, new Date()) !== null)
479 // Past the open-issue ceiling (#12868) it starts nothing either, until the pile shrinks or the
480 // owner resumes it.
481 if (
482 crewRole(app.db, repo.id, agent.user.id) === "planner" &&
483 (pausedUntil(app.db, repo.id, new Date()) !== null ||
484 // Held by the ceiling its pass still runs while an issue is handed to it to split.
485 (ceilingHold(app.db, repo.id) !== null && !splitPending(app, repo)))
486 )
480487 return undefined;
481488 // A chapter is open (#11603): builders and reviewers start only what it holds, and the crew rests
482489 // between chapters. A planner plans (its scope is kept where it opens issues); a run carrying on finishes.
src/flow/planner_held.ts added +30
@@ -0,0 +1,30 @@
1 /**
2 * Repositories whose planner the open-issue ceiling holds (#12868), for /flow: the cause named
3 * beside each. Walked are the repositories whose owner set a ceiling (a handful of
4 * `forge_setting` rows) and any with more open issues than the default ceiling, so a planner held
5 * by the default shows too.
6 */
7 import type { Database } from "bun:sqlite";
8 import { ceilingHold, DEFAULT_CEILING } from "../core/planner_pause.ts";
9
10 export interface Held {
11 readonly repo: string;
12 readonly cause: string;
13 }
14
15 export function plannerHeld(db: Database): Held[] {
16 const rows = db
17 .query<{ id: string; owner: string; name: string }, [number]>(
18 `SELECT r.id, u.username AS owner, r.name FROM repo r JOIN user u ON u.id = r.owner_id
19 WHERE EXISTS (SELECT 1 FROM forge_setting s WHERE s.key = 'planner.openCeiling.' || r.id)
20 OR (SELECT COUNT(*) FROM issue i
21 WHERE i.repo_id = r.id AND i.kind = 'issue' AND i.state = 'open') > ?1`,
22 )
23 .all(DEFAULT_CEILING);
24 const held: Held[] = [];
25 for (const r of rows) {
26 const cause = ceilingHold(db, r.id);
27 if (cause !== null) held.push({ repo: `${r.owner}/${r.name}`, cause });
28 }
29 return held;
30 }
src/http/api.ts +2 −1
@@ -12,7 +12,7 @@ import { CHECK_ASKED } from "../actions/pull_ask_words.ts";
1212 import { liveOf } from "../perf/live.ts";
1313 import { reviewWords } from "../actions/review_words.ts";
1414 import { growth, MAX_DAYS as MAX_GROWTH_DAYS } from "../core/growth.ts";
15 import { PAUSE_REFUSAL, pausedUntil } from "../core/planner_pause.ts";
15 import { CEILING_REFUSAL, PAUSE_REFUSAL, pausedUntil } from "../core/planner_pause.ts";
1616 import { teamHoldRefusal } from "../core/teams_words.ts";
1717 import { guardedRefusal } from "../crew/stranger.ts";
1818 import { MAX_PASS, passOf } from "../actions/box_pass.ts";
@@ -692,6 +692,7 @@ export function originAware(error: string, status = 422): Response {
692692 );
693693 if (error === "check_stale") return apiError("check_stale", 409, CHECK_STALE_REFUSAL);
694694 if (error === "planner_paused") return apiError("planner_paused", 409, PAUSE_REFUSAL);
695 if (error === "planner_ceiling") return apiError("planner_ceiling", 409, CEILING_REFUSAL);
695696 if (error === "mirrored")
696697 return apiError(
697698 "mirrored",
src/http/server.ts +2 −1
@@ -189,7 +189,7 @@ import { auditCsv, auditPage, auditProbeSubmit } from "../web/pages/audit.ts";
189189 import { apiPage, appApiPage } from "../web/pages/api.ts";
190190 import { flowsCheck, flowsPage, flowsProbe, flowsUpdate } from "../web/pages/flows.ts";
191191 import { findingAccept, findingsPage } from "../web/pages/findings.ts";
192 import { queuePage, queueSwitch } from "../web/pages/queue.ts";
192 import { queueCeiling, queuePage, queueSwitch } from "../web/pages/queue.ts";
193193 import { chapterAct, chapterPage, chaptersPage } from "../web/pages/chapters.ts";
194194 import { betAct, betPage, betPropose, betsPage } from "../web/pages/bets.ts";
195195 import { changelogJson, changelogPage } from "../web/pages/changelog.ts";
@@ -1389,6 +1389,7 @@ export function buildRouter(): Router<Handler> {
13891389 router.add("POST", "/:owner/:name/findings/:id/accept", findingAccept);
13901390 router.add("GET", "/:owner/:name/queue", queuePage);
13911391 router.add("POST", "/:owner/:name/queue/planner", queueSwitch);
1392 router.add("POST", "/:owner/:name/queue/ceiling", queueCeiling);
13921393 router.add("GET", "/:owner/:name/chapters", chaptersPage);
13931394 router.add("POST", "/:owner/:name/chapters", chapterAct);
13941395 router.add("GET", "/:owner/:name/chapters/:chapter", chapterPage);
src/tui/screens/queuegrowth.ts +29 −4
@@ -3,12 +3,13 @@
33 * reads (`core/growth.ts`, sealed issues left out for this viewer) and the planner's switch, which
44 * only a human admin of the repository changes: `o` pauses until they switch it on, `w` until the
55 * weekly reset, `t` until a time typed in UTC, `n` switches it on. Each goes through
6 * `setPlannerSwitch`, the page's one door, so a web viewer sees it at once.
6 * `setPlannerSwitch`, the page's one door, so a web viewer sees it at once. The open-issue ceiling
7 * (#12868) is the same: `c` sets it, `r` resumes the planner for one plan, through `setCeiling`.
78 */
89
9 import { setPlannerSwitch, switchInput, type SwitchInput } from "../../actions/planner_switch.ts";
10 import { setCeiling, setPlannerSwitch, switchInput, type SwitchInput } from "../../actions/planner_switch.ts";
1011 import { growth, oldest, WHO } from "../../core/growth.ts";
11 import { PAUSE_STOPS, pauseSentence, pausedUntil } from "../../core/planner_pause.ts";
12 import { ceilingHold, CEILING_REASON, openCeiling, PAUSE_STOPS, pauseSentence, pausedUntil } from "../../core/planner_pause.ts";
1213 import { canAdmin, getRepoById, type Repo } from "../../core/repos.ts";
1314 import { sealedScope } from "../../core/sealed.ts";
1415 import type { Ctx, Screen } from "../app/app.ts";
@@ -39,6 +40,9 @@ export function queueLines(f: Session, repo: Repo, now = new Date()): string[] {
3940 "",
4041 pauseSentence(until) + (until === null ? "" : ` ${PAUSE_STOPS}`),
4142 "",
43 `Open-issue ceiling: ${openCeiling(f.db, repo.id) === 0 ? "off" : String(openCeiling(f.db, repo.id))}. ${CEILING_REASON}`,
44 ...(ceilingHold(f.db, repo.id) === null ? [] : [`${ceilingHold(f.db, repo.id)}.`]),
45 "",
4246 ...g.sentences,
4347 ...(g.suggest === null ? [] : [g.suggest]),
4448 "",
@@ -61,11 +65,17 @@ export function queueScreen(f: Session, ctx: Ctx, repo: Repo): Screen {
6165 ctx.invalidate();
6266 return undefined;
6367 };
68 const ceil = (input: Parameters<typeof setCeiling>[3]): void => {
69 const done = setCeiling(f.app, f.user, current(), input);
70 if (done.ok) ctx.toast(input.mode === "set" ? (done.value === 0 ? "Ceiling off." : `Ceiling set to ${done.value}.`) : "The planner may open one plan past the ceiling.", "success");
71 else ctx.toast(done.error === "invalid" ? "The ceiling is a whole number from 0 (off) to 100000." : "Only the owner sets the ceiling.", "danger");
72 ctx.invalidate();
73 };
6474 const screen: Screen = {
6575 title: "Queue",
6676 get keys() {
6777 return mayFlip(f, current())
68 ? [binding(["o"], "pause until on"), binding(["w"], "pause to weekly reset"), binding(["t"], "pause until a time"), binding(["n"], "switch on")]
78 ? [binding(["o"], "pause until on"), binding(["w"], "pause to weekly reset"), binding(["t"], "pause until a time"), binding(["n"], "switch on"), binding(["c"], "set the ceiling"), binding(["r"], "resume past the ceiling")]
6979 : [];
7080 },
7181 render(area, s) {
@@ -79,6 +89,21 @@ export function queueScreen(f: Session, ctx: Ctx, repo: Repo): Screen {
7989 if (e.key === "o") return flip({ mode: "owner" }), true;
8090 if (e.key === "w") return flip({ mode: "week" }), true;
8191 if (e.key === "n") return flip({ mode: "on" }), true;
92 if (e.key === "r") return ceil({ mode: "resume" }), true;
93 if (e.key === "c") {
94 ctx.push(
95 promptScreen(ctx, screen, {
96 title: "Open-issue ceiling",
97 label: "A whole number, 0 for off",
98 placeholder: "150",
99 onSubmit: (raw) => {
100 ceil({ mode: "set", value: raw });
101 return undefined;
102 },
103 }),
104 );
105 return true;
106 }
82107 if (e.key === "t") {
83108 ctx.push(
84109 promptScreen(ctx, screen, {
src/web/pages/flow.ts +11
@@ -28,6 +28,7 @@ import { waitingSection } from "./flow-waiting.ts";
2828 import { estimatesSection } from "./flow-estimates.ts";
2929 import { clogSection } from "./flow-clog.ts";
3030 import { cpuStopsSection } from "./flow-cpu.ts";
31 import { plannerHeld, type Held } from "../../flow/planner_held.ts";
3132 import { cpuStops } from "../../flow/cpu_stops.ts";
3233
3334 const plural = (n: number, one: string, many = `${one}s`): string => `${String(n)} ${n === 1 ? one : many}`;
@@ -109,6 +110,15 @@ export function backupRow(alarm: BackupAlarm) {
109110 })}</ul>`;
110111 }
111112
113 /**
114 * One row for each repository whose planner the open-issue ceiling holds, with the cause.
115 * Nothing when none is.
116 */
117 function heldRows(held: readonly Held[]) {
118 if (held.length === 0) return html``;
119 return html`<ul class="list mb" data-planner-held>${held.map((h) => row({ lead: icon("alert"), title: html`${h.repo}: ${h.cause}`, href: `/${h.repo}/queue`, nav: true }))}</ul>`;

Box 2: only repos with an explicit ceiling reach here, so a repo held by the default 150 is invisible on /flow. Name the cause for those too.

120 }
121
112122 // GET /flow
113123 export async function flowPage(ctx: Ctx): Promise<Response> {
114124 const waiting = ctx.url.search === "?wait=1";
@@ -147,6 +157,7 @@ export async function flowPage(ctx: Ctx): Promise<Response> {
147157 </header>
148158 <section class="bd-now" aria-label="How the week stands">
149159 <p class="bd-lead" id="flow-week"><strong>${weekSays(p)}</strong></p>
160 ${heldRows(plannerHeld(ctx.app.db))}
150161 ${backupRow(alarmBackup(ctx.app.config.dataDir, new Date()))}
151162 ${clogSection(picture.clog)}
152163 ${cpuStopsSection(cpuStops(ctx.app.db).stopped, picture.cpuClosed)}
src/web/pages/issues.ts +4 −2
@@ -5,7 +5,7 @@
55 * Mobile-first, no JavaScript required.
66 */
77
8 import { PAUSE_REFUSAL } from "../../core/planner_pause.ts";
8 import { CEILING_REFUSAL, PAUSE_REFUSAL } from "../../core/planner_pause.ts";
99 import {
1010 addCommentThrough,
1111 openIssueThrough,
@@ -273,7 +273,9 @@ export async function newIssueSubmit(ctx: Ctx): Promise<Response> {
273273 ? BODY_TOO_LONG
274274 : created.error === "planner_paused"
275275 ? PAUSE_REFUSAL
276 : "You cannot open an issue here.");
276 : created.error === "planner_ceiling"
277 ? CEILING_REFUSAL
278 : "You cannot open an issue here.");
277279 return composePage(ctx, repo, typed, message);
278280 }
279281 return flashTo(ctx, `${repoBase(repo)}/issues/${created.value.number}`, {
src/web/pages/queue.ts +40 −5
@@ -5,18 +5,18 @@
55 * issues) is left out of every number and title (`core/sealed.ts`).
66 */
77
8 import { setPlannerSwitch, switchInput } from "../../actions/planner_switch.ts";
8 import { setCeiling, setPlannerSwitch, switchInput } from "../../actions/planner_switch.ts";
99 import { growth, oldest, WHO, type Growth } from "../../core/growth.ts";
10 import { PAUSE_STOPS, pauseSentence, pausedUntil } from "../../core/planner_pause.ts";
10 import { ceilingHold, CEILING_HELD_NOTE, CEILING_REASON, openCeiling, PAUSE_STOPS, pauseSentence, pausedUntil } from "../../core/planner_pause.ts";
1111 import { canAdmin, type Repo } from "../../core/repos.ts";
1212 import { sealedScope } from "../../core/sealed.ts";
1313 import type { Ctx } from "../../http/context.ts";
1414 import { notePhase, takeSessionTime } from "../../core/route_timing.ts";
1515 import { crumbsFor, loadRepo, notFoundPage, pageHead, repoBase, repoHeader, repoPalette } from "../chrome.ts";
16 import { backTo, field, readForm } from "../form.ts";
16 import { backTo, field as formField, readForm } from "../form.ts";
1717 import { html, type Html } from "../html.ts";
1818 import { flashTo, page } from "../layout.ts";
19 import { badge, btn, row } from "../ui.ts";
19 import { badge, btn, field, row } from "../ui.ts";
2020
2121 export const DAYS = 14;
2222
@@ -63,6 +63,25 @@ function switchRow(repo: Repo, until: string | null, owner: boolean): Html {
6363 ${btn("Pause the planner", { variant: "primary" })}</form>`;
6464 }
6565
66 /**
67 * The ceiling setting as one row: its value, and one line under it: the cause when it holds the
68 * planner, the reason otherwise. The owner gets the two forms, plain buttons beside the switch's
69 * one primary.
70 */
71 function ceilingRow(repo: Repo, ceiling: number, held: string | null, owner: boolean): Html {
72 const post = `${repoBase(repo)}/queue/ceiling`;
outdated

Principle 1: the reason line and the held-cause line below say the same thing. Principle 7: a setting is a dl row, not a hand-rolled section; the input is bare markup. Use the named setting row/components.

73 const line = held === null ? CEILING_REASON : `${held.charAt(0).toUpperCase()}${held.slice(1)}. ${CEILING_HELD_NOTE}`;
74 return html`<ul class="list setting-list" data-planner-ceiling>
75 ${row({ title: "Open-issue ceiling", meta: html`<span data-ceiling-held="${held === null ? "no" : "yes"}">${line}</span>`, trail: badge(ceiling === 0 ? "off" : String(ceiling)) })}
76 </ul>
77 ${owner
outdated

Principle 5: a second primary button on the page, beside the planner switch's. Make this one plain.

78 ? html`<form method="post" action="${post}" class="bar"><input type="hidden" name="mode" value="set">
79 ${field({ label: "Ceiling", name: "value", value: String(ceiling), pattern: "[0-9]{1,6}" })}
80 ${btn("Set the ceiling")}</form>
81 ${held === null ? null : html`<form method="post" action="${post}"><input type="hidden" name="mode" value="resume">${btn("Resume the planner for one plan")}</form>`}`
82 : null}`;
83 }
84
6685 const ago = (iso: string, now: Date) => `${Math.max(0, Math.floor((now.getTime() - Date.parse(iso)) / 86_400_000))} days old`;
6786
6887 // GET /:owner/:name/queue
@@ -86,6 +105,7 @@ export function queuePage(ctx: Ctx): Response {
86105 const body = html`${repoHeader(ctx, repo, "issues")}
87106 ${pageHead("Queue", { sub: "Is the work growing or shrinking?" })}
88107 ${switchRow(repo, until, owner)}
108 ${ceilingRow(repo, openCeiling(ctx.app.db, repo.id), ceilingHold(ctx.app.db, repo.id), owner)}
89109 <p><a href="${base}/chapters">Chapters</a></p>
90110 ${aged.length === 0 ? null : html`<ul class="list setting-list">${aged}</ul>`}
91111 ${growthRows(g)}`;
@@ -101,10 +121,25 @@ export async function queueSwitch(ctx: Ctx): Promise<Response> {
101121 const form = await readForm(ctx, "rw");
102122 if (form instanceof Response) return form;
103123 const back = backTo(form, `${repoBase(repo)}/queue`);
104 const input = switchInput(field(form, "mode"), field(form, "at"));
124 const input = switchInput(formField(form, "mode"), formField(form, "at"));
105125 if (input === undefined) return flashTo(ctx, back, { tone: "danger", message: "Choose on, a time, the weekly reset or until you switch it on." });
106126 const done = setPlannerSwitch(ctx.app, ctx.auth.user, repo, input);
107127 if (!done.ok)
108128 return flashTo(ctx, back, { tone: "danger", message: done.error === "invalid" ? "Pick a time in the future, within a year." : "Only the owner switches the planner." });
109129 return flashTo(ctx, back, { message: pauseSentence(done.value) });
110130 }
131
132 // POST /:owner/:name/queue/ceiling
133 export async function queueCeiling(ctx: Ctx): Promise<Response> {
134 const repo = loadRepo(ctx);
135 if (!repo) return notFoundPage(ctx);
136 const form = await readForm(ctx, "rw");
137 if (form instanceof Response) return form;
138 const back = backTo(form, `${repoBase(repo)}/queue`);
139 const mode = formField(form, "mode");
140 if (mode !== "set" && mode !== "resume") return flashTo(ctx, back, { tone: "danger", message: "Set the ceiling or resume the planner." });
141 const done = setCeiling(ctx.app, ctx.auth.user, repo, mode === "set" ? { mode, value: formField(form, "value") } : { mode });
142 if (!done.ok)
143 return flashTo(ctx, back, { tone: "danger", message: done.error === "invalid" ? "The ceiling is a whole number from 0 (off) to 100000." : "Only the owner sets the ceiling." });
144 return flashTo(ctx, back, { message: mode === "set" ? (done.value === 0 ? "Ceiling off." : `Ceiling set to ${done.value}.`) : "The planner may open one plan past the ceiling." });
145 }
test/planner-ceiling.test.ts added +183
@@ -0,0 +1,183 @@
1 /**
2 * The open-issue ceiling (#12868): past it the planner's issues and plans are refused with the
3 * cause, under it they are accepted; a defect with evidence goes in; a person's
4 * issue is never held; the owner sets it (and only the owner), resumes for one plan, and the
5 * queue page and /flow say why.
6 */
7 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
8 import { mkdtemp, rm } from "node:fs/promises";
9 import { tmpdir } from "node:os";
10 import { join } from "node:path";
11 import { newApp } from "../src/actions/apps.ts";
12 import { addComment, openIssue } from "../src/actions/issues.ts";
13 import { openPlan } from "../src/actions/plan.ts";
14 import { setCeiling } from "../src/actions/planner_switch.ts";
15 import { createApp, type App } from "../src/app.ts";
16 import { addCrew, createAgentRow, getAgent } from "../src/core/agents.ts";
17 import { PARK_NOTE } from "../src/crew/parks.ts";
18 import { ceilingHold, DEFAULT_CEILING, EVIDENCE_ROOM, openCeiling } from "../src/core/planner_pause.ts";
19 import { getRepo, setDirectionIssue, type Repo } from "../src/core/repos.ts";
20 import { createUser, type User } from "../src/core/users.ts";
21 import type { Ctx } from "../src/http/context.ts";
22 import { queueAgentRun } from "../src/crew/dispatch.ts";
23 import { plannerHeld } from "../src/flow/planner_held.ts";
24 import { queuePage } from "../src/web/pages/queue.ts";
25 import { quietLogs } from "./helpers/globals.ts";
26
27 quietLogs();
28
29 describe("the open-issue ceiling", () => {
30 let dataDir = "";
31 let app: App;
32 let owner: User;
33 let person: User;
34 let planner: User;
35 let repo: Repo;
36 const plan = (key: string, body = "x") => [{ key, title: `Plan ${key}`, body, blockedBy: [] }];
37
38 beforeAll(async () => {
39 dataDir = await mkdtemp(join(tmpdir(), "forge-ceiling-"));
40 app = createApp({ dataDir, port: 0, host: "forge.test" });
41 const mk = async (username: string, agent: boolean) => {
42 const made = await createUser(app.db, {
43 username,
44 email: `${username}@forge.test`,
45 ...(agent
46 ? { agent: true, origin: "agent" as const }
47 : { password: "a-good-passphrase", origin: "seed" as const, trusted: true, adminIfFirst: username === "alice" }),
48 });
49 if (!made.ok) throw new Error(String(made.error));
50 if (agent) createAgentRow(app.db, { userId: made.value.id, roles: ["planner" as const] });
51 return made.value;
52 };
53 owner = await mk("alice", false);
54 person = await mk("pat", false);
55 planner = await mk("plan", true);
56 const made = await newApp(app, owner, { name: "shop", description: "Words", visibility: "public" });
57 if (!made.ok) throw new Error(String(made.error));
58 repo = getRepo(app.db, "alice", "shop")!;
59 addCrew(app.db, repo.id, planner.id, owner.id, "planner");
60 });
61
62 afterAll(async () => {
63 app.close();
64 await rm(dataDir, { recursive: true, force: true, maxRetries: 20, retryDelay: 100 });
65 });
66
67 test("the default is 150, and only the owner sets it", () => {
68 expect(openCeiling(app.db, repo.id)).toBe(DEFAULT_CEILING);
69 expect(setCeiling(app, person, repo, { mode: "set", value: "2" })).toEqual({ ok: false, error: "forbidden" });
70 expect(setCeiling(app, planner, repo, { mode: "set", value: "2" })).toEqual({ ok: false, error: "forbidden" });
71 for (const bad of ["-1", "x", "1.5", "", "1000000"])
72 expect(setCeiling(app, owner, repo, { mode: "set", value: bad })).toEqual({ ok: false, error: "invalid" });
73 expect(setCeiling(app, owner, repo, { mode: "set", value: "2" })).toEqual({ ok: true, value: 2 });
74 expect(openCeiling(app.db, repo.id)).toBe(2);
75 });
76
77 test("under the ceiling a plan and an issue are accepted; past it they are refused with the cause", () => {
78 app.db.query("DELETE FROM issue WHERE repo_id = ?1").run(repo.id);
79 expect(openPlan(app, planner, repo, plan("a")).ok).toBe(true);
80 expect(openIssue(app, planner, repo, { title: "Second" }).ok).toBe(true);
81 // two open: at the ceiling, not past it
82 expect(ceilingHold(app.db, repo.id)).toBeNull();
83 expect(openIssue(app, planner, repo, { title: "Third" }).ok).toBe(true);
84 expect(ceilingHold(app.db, repo.id)).toContain("3 issues are open, past the ceiling of 2");
85
86 expect(openIssue(app, planner, repo, { title: "Fourth" })).toEqual({ ok: false, error: "planner_ceiling" });
87 const refused = openPlan(app, planner, repo, plan("b"));
88 expect(refused.ok ? "" : refused.error.error).toBe("planner_ceiling");
89 expect(refused.ok ? "" : refused.error.message).toContain("ceiling");
90 });
91
92 test("a defect with evidence goes in, a person's issue is never held, the planner's run waits", () => {
93 expect(openIssue(app, planner, repo, { title: "Broken", body: "Evidence: GET /x answers 500" }).ok).toBe(true);
94 expect(openPlan(app, planner, repo, plan("c", "Evidence: log line 12")).ok).toBe(true);
95 expect(openIssue(app, owner, repo, { title: "Owner asks" }).ok).toBe(true);
96 expect(openIssue(app, person, repo, { title: "Person asks" }).ok).toBe(true);
97 const issue = openIssue(app, owner, repo, { title: "Work" });
98 if (!issue.ok) throw new Error(issue.error);
99 expect(queueAgentRun(app, repo, issue.value, getAgent(app.db, planner.id)!, "assigned")).toBeUndefined();
100 });
101
102 test("closing an issue brings the pile under the ceiling and the planner opens again", () => {
103 expect(openIssue(app, planner, repo, { title: "Held" }).ok).toBe(false);
104 app.db.query("UPDATE issue SET state = 'closed', closed_at = '2026-01-01T00:00:00.000Z' WHERE repo_id = ?1 AND kind = 'issue'").run(repo.id);
105 expect(ceilingHold(app.db, repo.id)).toBeNull();
106 expect(openIssue(app, planner, repo, { title: "Back" }).ok).toBe(true);
107 });
108
109 test("0 turns it off; resuming allows one plan's worth past it, and a new ceiling ends that", () => {
110 setCeiling(app, owner, repo, { mode: "set", value: "1" });
111 openIssue(app, owner, repo, { title: "One more" });
112 expect(ceilingHold(app.db, repo.id)).not.toBeNull();
113 expect(plannerHeld(app.db).map((h) => h.repo)).toEqual(["alice/shop"]);
114 expect(setCeiling(app, planner, repo, { mode: "resume" })).toEqual({ ok: false, error: "forbidden" });
115 expect(setCeiling(app, owner, repo, { mode: "resume" }).ok).toBe(true);
116 expect(ceilingHold(app.db, repo.id)).toBeNull();
117 expect(openPlan(app, planner, repo, plan("d")).ok).toBe(true);
118 setCeiling(app, owner, repo, { mode: "set", value: "1" });
119 expect(ceilingHold(app.db, repo.id)).not.toBeNull();
120 setCeiling(app, owner, repo, { mode: "set", value: "0" });
121 expect(ceilingHold(app.db, repo.id)).toBeNull();
122 expect(openIssue(app, planner, repo, { title: "Off" }).ok).toBe(true);
123 expect(plannerHeld(app.db)).toEqual([]);
124 });
125
126 test("defects with evidence are bounded: past the ceiling by a dozen at most", () => {
127 setCeiling(app, owner, repo, { mode: "set", value: "1" });
128 app.db.query("UPDATE issue SET state = 'closed', closed_at = '2026-01-01T00:00:00.000Z' WHERE repo_id = ?1 AND kind = 'issue'").run(repo.id);
129 let opened = 0;
130 while (openIssue(app, planner, repo, { title: `Defect ${opened}`, body: "Evidence: x" }).ok) opened++;
131 expect(opened).toBe(EVIDENCE_ROOM + 2); // up to ceiling + room, as the ceiling itself: at it is not past it
132 expect(openIssue(app, planner, repo, { title: "Plain" })).toEqual({ ok: false, error: "planner_ceiling" });
133 });
134
135 test("a held planner still splits an issue handed to it: the run starts, the children go in", () => {
136 app.db.query("UPDATE issue SET state = 'closed', closed_at = '2026-01-01T00:00:00.000Z' WHERE repo_id = ?1 AND kind = 'issue'").run(repo.id);
137 const dir = openIssue(app, owner, repo, { title: "Direction" });
138 if (!dir.ok) throw new Error(dir.error);
139 setDirectionIssue(app.db, repo.id, dir.value.id);
140 repo = getRepo(app.db, "alice", "shop")!;
141 const direction = dir.value;
142 const big = openIssue(app, owner, repo, { title: "Too big" });
143 openIssue(app, owner, repo, { title: "Another" });
144 if (!big.ok) throw new Error(big.error);
145 const agent = getAgent(app.db, planner.id)!;
146 expect(openIssue(app, planner, repo, { title: "Child" })).toEqual({ ok: false, error: "planner_ceiling" });
147 expect(queueAgentRun(app, repo, direction, agent, "assigned", owner.id)).toBeUndefined();
148 for (let n = 0; n < 2; n++) {
149 const parked = addComment(app, owner, repo, big.value, `${PARK_NOTE}the build failed`);
150 if (!parked.ok) throw new Error(String(parked.error));
151 }
152 expect(queueAgentRun(app, repo, direction, agent, "assigned", owner.id)).toBeDefined();
153 expect(openIssue(app, planner, repo, { title: "Child" }).ok).toBe(true);
154 });
155
156 test("/flow names a planner held by the default ceiling too", () => {
157 app.db.query("DELETE FROM forge_setting WHERE key LIKE 'planner.openCeiling.%'").run();
158 app.db.query("UPDATE issue SET state = 'closed', closed_at = '2026-01-01T00:00:00.000Z' WHERE repo_id = ?1 AND kind = 'issue'").run(repo.id);
159 expect(plannerHeld(app.db)).toEqual([]);
160 for (let n = 0; n <= DEFAULT_CEILING; n++) openIssue(app, owner, repo, { title: `Open ${n}` });
161 expect(plannerHeld(app.db).map((h) => h.repo)).toEqual(["alice/shop"]);
162 });
163
164 test("the queue page shows the setting, its reason and, past it, the cause", async () => {
165 setCeiling(app, owner, repo, { mode: "set", value: "1" });
166 const url = new URL("http://forge.test/alice/shop/queue");
167 const sessionless: Ctx = {
168 app,
169 request: new Request(url.href),
170 params: { owner: "alice", name: "shop" },
171 url,
172 auth: { user: undefined, scope: undefined, via: "none" },
173 theme: undefined,
174 };
175 const text = await queuePage(sessionless).text();
176 expect(text).toContain("Open-issue ceiling");
177 expect(text).toContain("held by the open-issue ceiling");
178 expect(text).toContain('data-ceiling-held="yes"');
179 expect(text).not.toContain("stops opening more");
180 // one primary button: the ceiling's forms are plain
181 expect((text.match(/class="btn primary/g) ?? []).length).toBeLessThanOrEqual(1);
182 });
183 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs