Public: anyone can read this; the crew can change it.
An engine is never idle beside a backlog without saying why: a closed blocker frees what waited for it, and no ceiling holds the planner until the owner sets one #13023
Check · Review · Land · Live done — Landed and live in production.
trevato/engine-never-idle-beside-a-backlog → main 2 commits 2 threads · 2 unresolved
14 files
changed +619
−37
docs/features/README.md +1
| @@ -133,6 +133,7 @@ Read with the guide page [Tell the crew](../guide-tell-the-crew.md). | ||
| 133 | 133 | - [](team-waiting.md) |
| 134 | 134 | - [](team-queue.md) |
| 135 | 135 | - [](planner-ceiling.md) |
| 136 | - [](backlog-beside-idle.md) | |
| 136 | 137 | - [](queue.md) |
| 137 | 138 | - [](space.md) |
| 138 | 139 | - [](thanks.md) |
docs/features/backlog-beside-idle.md added +40
| @@ -0,0 +1,40 @@ | ||
| 1 | # A crew beside a backlog says why it stands still | |
| 2 | ||
| 3 | An engine that reads idle next to open issues accounts for every one of them, and raises its hand when only a | |
| 4 | person can release the work. | |
| 5 | ||
| 6 | **The tick line.** Each tick of a repository the crew works says how many issues are open and why the ones that | |
| 7 | are not ready wait, one count per reason: | |
| 8 | ||
| 9 | ||
| 10 | [autonomy] tick repo=trevato/forge did=idle open=278 waiting="later=245 plan=17 blocked=6" ready=10 startable=0 held="open_pull=2 twin=1" | |
| 11 | ||
| 12 | ||
| 13 | - `later`: deferred behind the Later gate. A person lifts an issue or closes the gate. | |
| 14 | - `plan`: the plan's own issues (a pillar's umbrella, the Later gate, the Later umbrella). A person closes them. | |
| 15 | - `blocked`: it waits for other open work. That is order. | |
| 16 | - `unconfirmed`: a blocker closed as dropped or split and nobody confirmed the plan (never on go). | |
| 17 | - `unadopted`: a reader's issue that nobody who directs the crew has adopted. | |
| 18 | ||
| 19 | `ready`, `startable`, `held` and `passed` account for the rest, as before. | |
| 20 | ||
| 21 | **A closed blocker frees what waited for it.** An issue whose only blocker closed is ready, whatever that | |
| 22 | blocker itself once waited for. Before, the closed blocker's own links still counted, so such an issue was never | |
| 23 | ready while Next up called it ready and the map called it blocked. | |
| 24 | ||
| 25 | **The planner's hold is named.** When the owner's pause or open-issue ceiling holds the planner, the tick says so | |
| 26 | (`planner not asked why="the planner is held by the open-issue ceiling: …"`) and gives the planner nothing. | |
| 27 | ||
| 28 | **The need.** When a tick picks nothing, asks no planner, nothing can start, and open issues wait for a person | |
| 29 | (`later`, `unconfirmed` or `unadopted`), the needs stack carries one row for the repository, for whoever may write | |
| 30 | to it: | |
| 31 | ||
| 32 | > trevato/forge: the crew has nothing to start, and 278 issues are open. 245 wait behind the Later gate, 17 are | |
| 33 | > the plan's own, 6 wait for other open work. | |
| 34 | ||
| 35 | Its one choice, "Open what is held", opens `/:owner/:name/held`, where held issues are lifted one at a time or | |
| 36 | closed in one approval (the terminal's held screen and the `held` and `lift` MCP tools do the same). The row is | |
| 37 | on the home page's needs count, `/asks`, the terminal and the MCP `forge` tool, and is gone on the next tick that | |
| 38 | starts something. Nothing is lifted without a person: which held work goes next is the owner's order. | |
| 39 | ||
| 40 | Not done: the count is the last tick's, kept in memory, so the row appears a tick after a restart. |
docs/features/planner-ceiling.md +7 −5
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | # The open-issue ceiling |
| 2 | 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. | |
| 3 | Past a number of open issues the planner stops opening more, so the pile shrinks before it grows again. It is | |
| 4 | off until the owner (a person who administers the repository, never an agent) sets it: any whole number from 1 | |
| 5 | to 100000, or 0 for off again. The count is every open issue, the ones behind the Later gate too, which no | |
| 6 | builder starts: set it above what the gate holds, or the pile cannot shrink under it. | |
| 6 | 7 | |
| 7 | 8 | **Set it.** On `/:owner/:name/queue` the row "Open-issue ceiling" shows the number and, under it, why; the owner |
| 8 | 9 | types a new one and presses "Set the ceiling". In the terminal, the Queue screen takes `c` to set it and `r` to |
| @@ -10,8 +11,9 @@ resume. Setting it ends any resume. `planner.ceiling` is heard by the admins. | ||
| 10 | 11 | |
| 11 | 12 | **Held.** Over the ceiling the repository's planner opens no issue, adds no plan and starts no run, and says why |
| 12 | 13 | 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, | |
| 14 | of 150"). The API answers `409 planner_ceiling` with the same words. /flow lists every repository held, and | |
| 15 | the engine's tick line says it each time the planner is not asked (`planner not asked why="the planner is held | |
| 16 | by the open-issue ceiling: …"`). People, builders and reviewers are never held. When closes bring the count back under it, | |
| 15 | 17 | the planner carries on by itself. |
| 16 | 18 | |
| 17 | 19 | **Resume.** "Resume the planner for one plan" (`r` in the terminal) lets the planner open the next 12 issues past |
src/actions/needs.ts +45 −1
| @@ -16,6 +16,7 @@ import { STALE_DAYS } from "../web/studio/review_set.ts"; | ||
| 16 | 16 | import { askStackFor, type askLinesFor } from "../web/studio/asks.ts"; |
| 17 | 17 | import { weekOld } from "../flow/oldest_approved.ts"; |
| 18 | 18 | import { pileLine, stuckReposCached } from "../flow/stuck_pile.ts"; |
| 19 | import { backlogs, heldForAPerson, waitingSaid } from "../crew/backlog.ts"; | |
| 19 | 20 | import { drillNow } from "./backups_now.ts"; |
| 20 | 21 | import { builderOf, giveBack, handBack } from "./give_back.ts"; |
| 21 | 22 | import { getIssueById } from "../core/issues.ts"; |
| @@ -270,6 +271,42 @@ function stuckNeeds(ctx: Home, user: User): Need[] { | ||
| 270 | 271 | return out; |
| 271 | 272 | } |
| 272 | 273 | |
| 274 | /** The one choice on a crew that stands still: the page where held work is lifted or closed. */ | |
| 275 | export const STILL_CHOICE = "Open what is held"; | |
| 276 | ||
| 277 | /** | |
| 278 | * A crew with nothing to start beside open issues only a person releases (the Later gate, a plan | |
| 279 | * nobody confirmed, a reader's issue nobody adopted), raised by name for whoever may write there. | |
| 280 | * Read from the last tick's counts (`crew/backlog.ts`), so the stack reads no graph. Which work | |
| 281 | * goes next is the owner's order: the choice opens the page that lifts or closes it. | |
| 282 | */ | |
| 283 | function stillNeeds(ctx: Home, user: User): Need[] { | |
| 284 | if (user.kind !== "user") return []; | |
| 285 | const out: Need[] = []; | |
| 286 | const now = Date.now(); | |
| 287 | for (const [repoId, b] of backlogs(ctx.app, now)) { | |
| 288 | if (!heldForAPerson(b, now)) continue; | |
| 289 | const repo = getRepoById(ctx.app.db, repoId); | |
| 290 | if (repo === undefined || repo.archivedAt !== null || !canWrite(ctx.app.db, repo, user)) continue; | |
| 291 | const ref = `${repo.ownerName}/${repo.name}`; | |
| 292 | out.push({ | |
| 293 | id: `still:${repoId}`, | |
| 294 | sentence: `${ref}: the crew has nothing to start, and ${b.open} issues are open. ${waitingSaid(b.waiting)}.`, | |
| 295 | why: "open work that nothing will start is the engine standing still", | |
| 296 | waits: "builders sit empty there until some of it is released", | |
| 297 | choices: [STILL_CHOICE], | |
| 298 | recommended: needsDecision( | |
| 299 | `${ref}: release work for the crew, or leave it held?`, | |
| 300 | "which held work goes next is the owner's order: lifting an issue makes it ready, closing the Later gate opens them all", | |
| 301 | [STILL_CHOICE, "Leave it held"], | |
| 302 | ), | |
| 303 | link: b.waiting.later > 0 ? `/${ref}/held` : `/${ref}/next`, | |
| 304 | items: [], | |
| 305 | }); | |
| 306 | } | |
| 307 | return out; | |
| 308 | } | |
| 309 | ||
| 273 | 310 | /** The stack: the forge's own needs first (an admin's), then the asks, most consequential first. */ |
| 274 | 311 | export function needsStack(ctx: Home, user: User, chips?: Chips): Need[] { |
| 275 | 312 | const db = ctx.app.db; |
| @@ -325,7 +362,14 @@ export function needsStack(ctx: Home, user: User, chips?: Chips): Need[] { | ||
| 325 | 362 | items: [a.repo.id], |
| 326 | 363 | }), |
| 327 | 364 | ); |
| 328 | return [...forge, ...stuckNeeds(ctx, user), ...(user.isAdmin ? approvedNeeds(ctx) : []), ...rows, ...asleep]; | |
| 365 | return [ | |
| 366 | ...forge, | |
| 367 | ...stuckNeeds(ctx, user), | |
| 368 | ...stillNeeds(ctx, user), | |
| 369 | ...(user.isAdmin ? approvedNeeds(ctx) : []), | |
| 370 | ...rows, | |
| 371 | ...asleep, | |
| 372 | ]; | |
| 329 | 373 | } |
| 330 | 374 | |
| 331 | 375 | /** One or two sentences: serving or not, the crew, what is unusual. */ |
src/core/dependencies.ts +11 −2
| @@ -646,10 +646,19 @@ function reachMap(graph: Graph, open: Set<string>, next: Map<string, string[]>): | ||
| 646 | 646 | return counted; |
| 647 | 647 | } |
| 648 | 648 | |
| 649 | /** | |
| 650 | * The edges that still hold: both ends open. A closed blocker frees what waited for it, so the | |
| 651 | * edges it left behind (what it waited for itself) reach no further: an issue whose only blocker | |
| 652 | * closed waits for nothing, whatever that blocker once waited for. | |
| 653 | */ | |
| 654 | function liveEdges(graph: Graph, open: Set<string>): Edge[] { | |
| 655 | return graph.edges.filter((e) => open.has(e.issueId) && open.has(e.blockedById)); | |
| 656 | } | |
| 657 | ||
| 649 | 658 | /** For each issue, the open issues it transitively holds up. */ |
| 650 | 659 | function holdsUpMap(graph: Graph, open: Set<string>): Reach { |
| 651 | 660 | const dependents = new Map<string, string[]>(); |
| 652 | for (const e of graph.edges) { | |
| 661 | for (const e of liveEdges(graph, open)) { | |
| 653 | 662 | const list = dependents.get(e.blockedById) ?? []; |
| 654 | 663 | list.push(e.issueId); |
| 655 | 664 | dependents.set(e.blockedById, list); |
| @@ -660,7 +669,7 @@ function holdsUpMap(graph: Graph, open: Set<string>): Reach { | ||
| 660 | 669 | /** For each issue, the open issues it transitively waits for. */ |
| 661 | 670 | function waitsForMap(graph: Graph, open: Set<string>): Reach { |
| 662 | 671 | const blockers = new Map<string, string[]>(); |
| 663 | for (const e of graph.edges) { | |
| 672 | for (const e of liveEdges(graph, open)) { | |
| 664 | 673 | const list = blockers.get(e.issueId) ?? []; |
| 665 | 674 | list.push(e.blockedById); |
| 666 | 675 | blockers.set(e.issueId, list); |
src/core/planner_pause.ts +4 −2
| @@ -49,9 +49,11 @@ export function pauseSentence(until: string | null): string { | ||
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * The open-issue ceiling (#12868): past it the planner pauses itself. Per repository, in |
| 52 | * `forge_setting`; no row is the default. | |
| 52 | * `forge_setting`; no row is the default, and the default is off. A ceiling is the owner's to | |
| 53 | * set: a number nobody chose read "held" on production at 278 open issues, 262 of them behind | |
| 54 | * the Later gate or the plan's own, which no builder may start, so the pile could not shrink. | |
| 53 | 55 | */ |
| 54 | export const DEFAULT_CEILING = 150; | |
| 56 | export const DEFAULT_CEILING = 0; | |
| 55 | 57 | export const MAX_CEILING = 100_000; |
| 56 | 58 | /** What one resume allows: a plan's worth of issues past the ceiling, once. */ |
| 57 | 59 | export const LIFT_ROOM = 12; |
src/crew/autonomy.ts +35 −3
| @@ -26,6 +26,7 @@ import { | ||
| 26 | 26 | assignIssue, |
| 27 | 27 | openIssue, |
| 28 | 28 | setIssueState, |
| 29 | splitPending, | |
| 29 | 30 | } from "../actions/issues.ts"; |
| 30 | 31 | import type { AccessError } from "../actions/access.ts"; |
| 31 | 32 | import { adoptGate, gateCandidate, releaseOnLand } from "../checks/landing.ts"; |
| @@ -114,6 +115,8 @@ import { REPEAT_NOTE } from "./repeat_note.ts"; | ||
| 114 | 115 | import { given, pendingReplans } from "../core/limb_replan.ts"; |
| 115 | 116 | import { handedOverPulls, SKIP_SUMMARY, skipsReplan } from "./guard.ts"; |
| 116 | 117 | import { type Held, heldBy, heldWords, replannable } from "./held.ts"; |
| 118 | import { forgetBacklog, noteBacklog, waitingBy, waitingWords } from "./backlog.ts"; | |
| 119 | import { ceilingHold, pausedUntil, pauseSentence } from "../core/planner_pause.ts"; | |
| 117 | 120 | import { holdHot, hotFiles, hotWords, learnPullFiles } from "./hot_files.ts"; |
| 118 | 121 | import { landedUnder, NO_PULL, stallReason } from "./stalls.ts"; |
| 119 | 122 | import { alreadyDone, BY_CREW, DONE_LIKE } from "../core/done_on_main.ts"; |
| @@ -771,7 +774,12 @@ async function planIfThin( | ||
| 771 | 774 | now: Date, |
| 772 | 775 | stuck: Held | null = null, |
| 773 | 776 | ): Promise<boolean> { |
| 774 | const handed = [...parkedTwice(app.db, [repo]), ...handedOverPulls(app.db, repo)]; | |
| 777 | // The direction is the planner's own issue: a park on it (the breaker's, for runs that repeat) | |
| 778 | // hands the planner nothing it has not read, so it owes no pass. Counted, each park bought | |
| 779 | // another empty pass, which bought another park. | |
| 780 | const handed = [...parkedTwice(app.db, [repo]), ...handedOverPulls(app.db, repo)].filter( | |
| 781 | (h) => h.issueId !== repo.directionIssueId, | |
| 782 | ); | |
| 775 | 783 | const limbs = pendingReplans(app.db, repo); |
| 776 | 784 | const reserve = reserveOf(ready, repo.autonomySlots); |
| 777 | 785 | if (!due(reserve) && handed.length === 0 && limbs.length === 0) return false; |
| @@ -811,6 +819,12 @@ async function planIfThin( | ||
| 811 | 819 | // would plan the same input twice is skipped (`plannerNothingNew`). |
| 812 | 820 | // An issue the crew handed over is owed its pass whatever the hold: the |
| 813 | 821 | // planner splitting it is how work starts landing again. |
| 822 | // The owner's switch and ceiling stop the planner's run where it is queued (`dispatch.ts`). The | |
| 823 | // tick says which one holds it, and gives the planner nothing the dispatcher would refuse. | |
| 824 | const until = pausedUntil(app.db, repo.id, now); | |
| 825 | if (until !== null) return notPlanned(repo, pauseSentence(until)); | |
| 826 | const ceiling = splitPending(app, repo) ? null : ceilingHold(app.db, repo.id); | |
| 827 | if (ceiling !== null) return notPlanned(repo, ceiling); | |
| 814 | 828 | const hold = news === 0 ? plannerHold(app, repo, now) : null; |
| 815 | 829 | if (hold !== null) return held(repo, holdWhy(hold)); |
| 816 | 830 | if (lastPlan !== null && lastPlan !== undefined) { |
| @@ -1310,7 +1324,10 @@ export async function autonomyTick( | ||
| 1310 | 1324 | const picked = new Map<string, Set<string>>(); |
| 1311 | 1325 | for (const repo of byBackedBets(app.db, listAutonomousRepos(app.db))) { |
| 1312 | 1326 | // An archived repository is put away: the crew starts nothing in it. |
| 1313 | if (repo.archivedAt !== null) continue; | |
| 1327 | if (repo.archivedAt !== null) { | |
| 1328 | forgetBacklog(app, repo.id); | |
| 1329 | continue; | |
| 1330 | } | |
| 1314 | 1331 | try { |
| 1315 | 1332 | // A hold, a close, a push or a lost approval leaves the line before |
| 1316 | 1333 | // the next batch is formed, not at its gate (#6611). |
| @@ -1375,11 +1392,23 @@ export async function autonomyTick( | ||
| 1375 | 1392 | const status = autonomyStatus(app, current, now); |
| 1376 | 1393 | await breathe(); |
| 1377 | 1394 | const approved = waitWords(lastWaits(current.id)); |
| 1378 | const ready = readyNow(repoGraph(app.db, current.id, { sealed: true })); | |
| 1395 | const graphNow = repoGraph(app.db, current.id, { sealed: true }); | |
| 1396 | const ready = readyNow(graphNow); | |
| 1379 | 1397 | const crewNow = listCrewRoles(app.db, current.id); |
| 1380 | 1398 | const activeNow = activeRuns(app, current.id); |
| 1381 | 1399 | await breathe(); |
| 1382 | 1400 | const held = heldBy(app, current, ready, crewNow, activeNow); |
| 1401 | // Every open issue is accounted for: the ready ones below, the rest per reason. A crew that | |
| 1402 | // stands still beside them is kept for the needs stack (`actions/needs.ts`). | |
| 1403 | const waiting = waitingBy(graphNow, ready); | |
| 1404 | const openNow = graphNow.issues.filter((i) => i.state === "open").length; | |
| 1405 | noteBacklog(app, current.id, { | |
| 1406 | open: openNow, | |
| 1407 | startable: held.startable.length, | |
| 1408 | waiting, | |
| 1409 | still: did === "idle" && !activeNow.some((r) => r.issueId === current.directionIssueId), | |
| 1410 | at: now.getTime(), | |
| 1411 | }); | |
| 1383 | 1412 | const boots = bootCounts(app.config.dataDir); |
| 1384 | 1413 | await breathe(); |
| 1385 | 1414 | await breathe(); |
| @@ -1390,6 +1419,9 @@ export async function autonomyTick( | ||
| 1390 | 1419 | repo: `${repo.ownerName}/${repo.name}`, |
| 1391 | 1420 | did, |
| 1392 | 1421 | ...tickFields(triaged), |
| 1422 | // The open issues, and why the ones that are not ready wait: `later=245 plan=17 blocked=6`. | |
| 1423 | open: openNow, | |
| 1424 | waiting: waitingWords(waiting), | |
| 1393 | 1425 | ready: ready.length, |
| 1394 | 1426 | // What the builders could start after the filters (#2143), and |
| 1395 | 1427 | // what holds the rest, per filter (#2244). |
src/crew/backlog.ts added +113
| @@ -0,0 +1,113 @@ | ||
| 1 | /** | |
| 2 | * What stands between a repository's open issues and a builder, counted. The tick's `ready` and | |
| 3 | * `held` say why a ready issue does not start; nothing said why an open issue is not ready, so a | |
| 4 | * tick could read `did=idle ready=4 startable=0` beside 278 open issues and name 4 of them. Every | |
| 5 | * open issue that is not ready is counted here under the first reason that holds it: | |
| 6 | * - `plan`: the plan's own (an umbrella, the Later gate, the Later umbrella): a person closes it. | |
| 7 | * - `later`: deferred behind the Later gate, which only a person lifts. | |
| 8 | * - `blocked`: it waits for other open work, which is order. | |
| 9 | * - `unconfirmed`: a blocker closed as dropped or split and nobody confirmed the plan. | |
| 10 | * - `unadopted`: a reader's issue nobody who directs the crew has adopted. | |
| 11 | * | |
| 12 | * The last tick's counts are kept per repository, in memory and by forge, so the needs stack can | |
| 13 | * raise a crew that stands still beside work a person holds without reading the graph again. | |
| 14 | */ | |
| 15 | ||
| 16 | import type { App } from "../app.ts"; | |
| 17 | import { reachOf, type Graph, type Ranked } from "../core/dependencies.ts"; | |
| 18 | ||
| 19 | export const WAITS = ["later", "plan", "blocked", "unconfirmed", "unadopted"] as const; | |
| 20 | export type WaitName = (typeof WAITS)[number]; | |
| 21 | export type Waiting = Readonly<Record<WaitName, number>>; | |
| 22 | ||
| 23 | /** The reasons only a person lifts: the rest is order, or the plan's own furniture. */ | |
| 24 | export const A_PERSONS: readonly WaitName[] = ["later", "unconfirmed", "unadopted"]; | |
| 25 | ||
| 26 | export interface Backlog { | |
| 27 | /** Open issues on the graph. */ | |
| 28 | readonly open: number; | |
| 29 | /** Ready issues a builder may start now. */ | |
| 30 | readonly startable: number; | |
| 31 | /** The open issues that are not ready, per reason. */ | |
| 32 | readonly waiting: Waiting; | |
| 33 | /** The tick picked nothing and asked no planner, and no planning run is going. */ | |
| 34 | readonly still: boolean; | |
| 35 | /** When the tick counted it, in milliseconds: an old count says nothing about now. */ | |
| 36 | readonly at: number; | |
| 37 | } | |
| 38 | ||
| 39 | /** | |
| 40 | * How long a count stands. The tick counts every minute; a repository the tick stopped driving | |
| 41 | * (autonomy off, archived, deleted) keeps its last count, which must not raise a need for good. | |
| 42 | */ | |
| 43 | export const BACKLOG_STANDS_MS = 5 * 60_000; | |
| 44 | ||
| 45 | /** Each open issue that is not in `ready`, under the first reason that holds it. */ | |
| 46 | export function waitingBy(graph: Graph, ready: readonly Ranked[]): Waiting { | |
| 47 | const { open, waits } = reachOf(graph); | |
| 48 | const isReady = new Set(ready.map((r) => r.issue.id)); | |
| 49 | const unconfirmed = new Set(graph.held.map((h) => h.issueId)); | |
| 50 | const out: Record<WaitName, number> = { later: 0, plan: 0, blocked: 0, unconfirmed: 0, unadopted: 0 }; | |
| 51 | for (const id of open) { | |
| 52 | if (isReady.has(id)) continue; | |
| 53 | if (graph.structural.has(id)) out.plan++; | |
| 54 | else if (graph.deferred.has(id)) out.later++; | |
| 55 | else if ((waits.get(id)?.size ?? 0) > 0) out.blocked++; | |
| 56 | else if (unconfirmed.has(id)) out.unconfirmed++; | |
| 57 | else if (graph.unadopted.has(id)) out.unadopted++; | |
| 58 | } | |
| 59 | return out; | |
| 60 | } | |
| 61 | ||
| 62 | /** The counts as the tick line says them: `later=245 plan=17 blocked=6`, or `none`. */ | |
| 63 | export function waitingWords(waiting: Waiting): string { | |
| 64 | const said = WAITS.filter((w) => waiting[w] > 0).map((w) => `${w}=${waiting[w]}`); | |
| 65 | return said.length === 0 ? "none" : said.join(" "); | |
| 66 | } | |
| 67 | ||
| 68 | const SAID: Readonly<Record<WaitName, (n: number) => string>> = { | |
| 69 | later: (n) => `${n} wait${n === 1 ? "s" : ""} behind the Later gate`, | |
| 70 | plan: (n) => `${n} ${n === 1 ? "is" : "are"} the plan's own`, | |
| 71 | blocked: (n) => `${n} wait${n === 1 ? "s" : ""} for other open work`, | |
| 72 | unconfirmed: (n) => `${n} wait${n === 1 ? "s" : ""} for a person to confirm the plan`, | |
| 73 | unadopted: (n) => `${n} ${n === 1 ? "is a reader's" : "are readers'"}, adopted by nobody`, | |
| 74 | }; | |
| 75 | ||
| 76 | /** The same counts inside a sentence: "245 wait behind the Later gate, 17 are the plan's own". */ | |
| 77 | export function waitingSaid(waiting: Waiting): string { | |
| 78 | return WAITS.filter((w) => waiting[w] > 0).map((w) => SAID[w](waiting[w])).join(", "); | |
| 79 | } | |
| 80 | ||
| 81 | /** Whether the crew stands still beside open work that only a person releases. */ | |
| 82 | export function heldForAPerson(b: Backlog, now: number): boolean { | |
| 83 | if (now - b.at > BACKLOG_STANDS_MS) return false; | |
| 84 | return b.still && b.startable === 0 && A_PERSONS.some((w) => b.waiting[w] > 0); | |
| 85 | } | |
| 86 | ||
| 87 | /** State belongs to a forge, not to the process (#12569): one map per app. */ | |
| 88 | const kept = new WeakMap<App, Map<string, Backlog>>(); | |
| 89 | ||
| 90 | function keptOf(app: App): Map<string, Backlog> { | |
| 91 | let known = kept.get(app); | |
| 92 | if (known === undefined) kept.set(app, (known = new Map())); | |
| 93 | return known; | |
| 94 | } | |
| 95 | ||
| 96 | export function noteBacklog(app: App, repoId: string, backlog: Backlog): void { | |
| 97 | keptOf(app).set(repoId, backlog); | |
| 98 | } | |
| 99 | ||
| 100 | /** The tick no longer drives this repository: its count is forgotten. */ | |
| 101 | export function forgetBacklog(app: App, repoId: string): void { | |
| 102 | kept.get(app)?.delete(repoId); | |
| 103 | } | |
| 104 | ||
| 105 | /** | |
| 106 | * What this forge's last ticks counted, the counts that still stand at `now`: one past | |
| 107 | * `BACKLOG_STANDS_MS` is dropped here, so a repository that stopped ticking leaves the map. | |
| 108 | */ | |
| 109 | export function backlogs(app: App, now: number): ReadonlyMap<string, Backlog> { | |
| 110 | const known = keptOf(app); | |
| 111 | for (const [repoId, b] of known) if (now - b.at > BACKLOG_STANDS_MS) known.delete(repoId); | |
| 112 | return known; | |
| 113 | } |
src/crew/news.ts +12 −2
| @@ -13,6 +13,7 @@ import { getPull } from "../core/pulls.ts"; | ||
| 13 | 13 | import type { Repo } from "../core/repos.ts"; |
| 14 | 14 | import { listReviewComments, listReviews } from "../core/reviews.ts"; |
| 15 | 15 | import { issueOfBranch } from "./brief.ts"; |
| 16 | import { PARK_NOTE } from "./parks.ts"; | |
| 16 | 17 | |
| 17 | 18 | interface Said { |
| 18 | 19 | readonly authorName: string; |
| @@ -107,7 +108,7 @@ function lastBegun( | ||
| 107 | 108 | /** |
| 108 | 109 | * Whether the planner, given the direction again by the clock, would find |
| 109 | 110 | * nothing new since its last pass (#1097): no word on the direction but its |
| 110 | * own since that pass began, and no issue another opened, nor any closed, | |
| 111 | * own or the crew's park note since that pass began, and no issue another opened, nor any closed, | |
| 111 | 112 | * since it ended. The map is the planner's to read; when it has not moved |
| 112 | 113 | * and nobody spoke, another pass reads its own summary and changes nothing. |
| 113 | 114 | * With no ended pass yet, everything is new. |
| @@ -127,7 +128,16 @@ export function plannerNothingNew( | ||
| 127 | 128 | ) |
| 128 | 129 | .get(direction.id, planner.user.id); |
| 129 | 130 | if (pass === null || pass === undefined) return false; |
| 130 | if (!nothingNew(db, repo, direction, planner)) return false; | |
| 131 | // The crew's park on the direction (the breaker's, for runs that repeat) is no one's word, | |
| 132 | // whoever's name it carries: read as news, each park bought another empty pass. | |
| 133 | const said = newsSince({ | |
| 134 | comments: listComments(db, direction.id, { kind: "comment" }).filter((c) => !c.body.startsWith(PARK_NOTE)), | |
| 135 | reviews: [], | |
| 136 | reviewComments: [], | |
| 137 | since: feedbackSince(db, repo, direction, planner), | |
| 138 | agentName: planner.user.username, | |
| 139 | }); | |
| 140 | if (said.comments.length > 0) return false; | |
| 131 | 141 | const moved = db |
| 132 | 142 | .query<{ n: number }, [string, string, string, string]>( |
| 133 | 143 | `SELECT COUNT(*) AS n FROM issue |
src/flow/planner_held.ts +5 −8
| @@ -1,11 +1,10 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * Repositories whose planner the open-issue ceiling holds (#12868), for /flow: the cause named |
| 3 | 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. | |
| 4 | * `forge_setting` rows): with no row there is no ceiling, so nothing is held. | |
| 6 | 5 | */ |
| 7 | 6 | import type { Database } from "bun:sqlite"; |
| 8 | import { ceilingHold, DEFAULT_CEILING } from "../core/planner_pause.ts"; | |
| 7 | import { ceilingHold } from "../core/planner_pause.ts"; | |
| 9 | 8 | |
| 10 | 9 | export interface Held { |
| 11 | 10 | readonly repo: string; |
| @@ -14,13 +13,11 @@ export interface Held { | ||
| 14 | 13 | |
| 15 | 14 | export function plannerHeld(db: Database): Held[] { |
| 16 | 15 | const rows = db |
| 17 | .query<{ id: string; owner: string; name: string }, [number]>( | |
| 16 | .query<{ id: string; owner: string; name: string }, []>( | |
| 18 | 17 | `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`, | |
| 18 | WHERE EXISTS (SELECT 1 FROM forge_setting s WHERE s.key = 'planner.openCeiling.' || r.id)`, | |
| 22 | 19 | ) |
| 23 | .all(DEFAULT_CEILING); | |
| 20 | .all(); | |
| 24 | 21 | const held: Held[] = []; |
| 25 | 22 | for (const r of rows) { |
| 26 | 23 | const cause = ceilingHold(db, r.id); |
test/dependencies-reach.test.ts +26 −3
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * How many open issues each issue holds up and waits for (`reachOf`) is counted over bit sets. |
| 3 | * It must give what the sets of ids it replaced gave, cycles and closed issues included. | |
| 3 | * It must give what the sets of ids it replaced gave over the edges that still hold (both ends | |
| 4 | * open), cycles included: a closed blocker frees what waited for it. | |
| 4 | 5 | */ |
| 5 | 6 | |
| 6 | 7 | import { expect, test } from "bun:test"; |
| @@ -56,8 +57,9 @@ test("the reach counts are the sets' sizes, on random graphs with cycles and clo | ||
| 56 | 57 | const graph = { issues, edges } as unknown as Graph; |
| 57 | 58 | const open = new Set(issues.filter((i) => i.state === "open").map((i) => i.id)); |
| 58 | 59 | const { holds, waits } = reachOf(graph); |
| 59 | const wantHolds = reference(ids, open, edges, true); | |
| 60 | const wantWaits = reference(ids, open, edges, false); | |
| 60 | const live = edges.filter((e) => open.has(e.issueId) && open.has(e.blockedById)); | |
| 61 | const wantHolds = reference(ids, open, live, true); | |
| 62 | const wantWaits = reference(ids, open, live, false); | |
| 61 | 63 | for (const id of ids) { |
| 62 | 64 | expect(holds.get(id)?.size ?? 0).toBe(wantHolds.get(id)?.size ?? 0); |
| 63 | 65 | expect(waits.get(id)?.size ?? 0).toBe(wantWaits.get(id)?.size ?? 0); |
| @@ -75,3 +77,24 @@ test("more than 32 open issues use more than one word", () => { | ||
| 75 | 77 | expect(holds.get("i000")?.size).toBe(0); |
| 76 | 78 | expect(waits.get("i000")?.size).toBe(99); |
| 77 | 79 | }); |
| 80 | ||
| 81 | test("a closed blocker frees what waited for it, whatever the blocker itself waited for", () => { | |
| 82 | // Production, 2026-11-15: #644 waited for #642 (closed, done), and #642 for the direction #334, | |
| 83 | // open for good. #644 was never ready and no page said why. | |
| 84 | const issues = [ | |
| 85 | { id: "direction", number: 334, state: "open" }, | |
| 86 | { id: "hold", number: 642, state: "closed" }, | |
| 87 | { id: "work", number: 644, state: "open" }, | |
| 88 | { id: "next", number: 647, state: "open" }, | |
| 89 | ]; | |
| 90 | const edges = [ | |
| 91 | { issueId: "hold", blockedById: "direction" }, | |
| 92 | { issueId: "work", blockedById: "hold" }, | |
| 93 | { issueId: "next", blockedById: "work" }, | |
| 94 | ]; | |
| 95 | const { holds, waits } = reachOf({ issues, edges } as unknown as Graph); | |
| 96 | expect(waits.get("work")?.size).toBe(0); | |
| 97 | expect(waits.get("next")?.size).toBe(1); | |
| 98 | expect(holds.get("direction")?.size).toBe(0); | |
| 99 | expect(holds.get("work")?.size).toBe(1); | |
| 100 | }); |
test/engine-backlog.test.ts added +300
| @@ -0,0 +1,300 @@ | ||
| 1 | /** | |
| 2 | * An engine is never idle beside a backlog without saying why. Production, 2026-11-15: the tick | |
| 3 | * read `did=idle ready=4 startable=0` with 278 issues open. 245 waited behind the Later gate, 6 | |
| 4 | * behind a blocker that had closed, and a ceiling nobody set held the planner. Here: the tick line | |
| 5 | * counts every open issue that is not ready by its reason, a closed blocker frees what waited for | |
| 6 | * it, a held planner is named with its cause, and a crew that stands still beside work only a | |
| 7 | * person releases is one row of the needs stack, gone once the owner lifts an issue. | |
| 8 | */ | |
| 9 | import { seatAs } from "./helpers/seat.ts"; | |
| 10 | import { afterAll, afterEach, beforeAll, describe, expect, spyOn, test } from "bun:test"; | |
| 11 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 12 | import { tmpdir } from "node:os"; | |
| 13 | import { join } from "node:path"; | |
| 14 | import { createApp, type App } from "../src/app.ts"; | |
| 15 | import { addToCrew, createAgent } from "../src/actions/crew.ts"; | |
| 16 | import { linkIssue } from "../src/actions/dependencies.ts"; | |
| 17 | import { liftHold } from "../src/actions/gate.ts"; | |
| 18 | import { addComment, openIssue, setIssueState } from "../src/actions/issues.ts"; | |
| 19 | import { needsStack, STILL_CHOICE } from "../src/actions/needs.ts"; | |
| 20 | import { setCeiling } from "../src/actions/planner_switch.ts"; | |
| 21 | import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts"; | |
| 22 | import { readyNow, repoGraph, type Graph } from "../src/core/dependencies.ts"; | |
| 23 | import { getIssueById, type Issue } from "../src/core/issues.ts"; | |
| 24 | import { getRepoById, type Repo } from "../src/core/repos.ts"; | |
| 25 | import { createUser, getUserByName, type User } from "../src/core/users.ts"; | |
| 26 | import { autonomyTick, driveRepo } from "../src/crew/autonomy.ts"; | |
| 27 | import { | |
| 28 | BACKLOG_STANDS_MS, | |
| 29 | backlogs, | |
| 30 | heldForAPerson, | |
| 31 | noteBacklog, | |
| 32 | waitingBy, | |
| 33 | waitingSaid, | |
| 34 | waitingWords, | |
| 35 | } from "../src/crew/backlog.ts"; | |
| 36 | import { PARK_NOTE } from "../src/crew/parks.ts"; | |
| 37 | import { claimRun, createRun, finishRun } from "../src/core/runs.ts"; | |
| 38 | import type { Ctx as HttpCtx } from "../src/http/context.ts"; | |
| 39 | import { tool as forgeTool } from "../src/http/mcp/tools/forge.ts"; | |
| 40 | import { stackFor } from "../src/tui/screens/needs.ts"; | |
| 41 | import type { Session } from "../src/tui/session.ts"; | |
| 42 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 43 | import { logLevel, setLogLevel } from "../src/kernel/log.ts"; | |
| 44 | ||
| 45 | describe("the open issues that are not ready, counted by reason", () => { | |
| 46 | const issue = (id: string, state = "open") => ({ id, number: 1, state, createdAt: id }); | |
| 47 | const graph = { | |
| 48 | issues: [issue("gate"), issue("viewers"), issue("cad"), issue("first"), issue("second"), issue("split", "closed"), | |
| 49 | issue("after-split"), issue("reader"), issue("free")], | |
| 50 | edges: [ | |
| 51 | { issueId: "viewers", blockedById: "gate" }, | |
| 52 | { issueId: "cad", blockedById: "gate" }, | |
| 53 | { issueId: "second", blockedById: "first" }, | |
| 54 | { issueId: "after-split", blockedById: "split" }, | |
| 55 | ], | |
| 56 | held: [{ issueId: "after-split", blockedById: "split", reason: "split" }], | |
| 57 | unadopted: new Set(["reader"]), | |
| 58 | structural: new Set(["gate"]), | |
| 59 | deferred: new Map([["viewers", "behind the Later gate"], ["cad", "behind the Later gate"]]), | |
| 60 | } as unknown as Graph; | |
| 61 | ||
| 62 | test("each is counted once, under the first reason that holds it; the ready ones are not", () => { | |
| 63 | const ready = readyNow(graph); | |
| 64 | expect(ready.map((r) => r.issue.id).sort()).toEqual(["first", "free"]); | |
| 65 | const waiting = waitingBy(graph, ready); | |
| 66 | expect(waiting).toEqual({ later: 2, plan: 1, blocked: 1, unconfirmed: 1, unadopted: 1 }); | |
| 67 | expect(waitingWords(waiting)).toBe("later=2 plan=1 blocked=1 unconfirmed=1 unadopted=1"); | |
| 68 | expect(waitingSaid(waiting)).toBe( | |
| 69 | "2 wait behind the Later gate, 1 is the plan's own, 1 waits for other open work, " + | |
| 70 | "1 waits for a person to confirm the plan, 1 is a reader's, adopted by nobody", | |
| 71 | ); | |
| 72 | const bare = { ...graph, issues: [issue("free")], edges: [], held: [] } as unknown as Graph; | |
| 73 | expect(waitingWords(waitingBy(bare, ready))).toBe("none"); | |
| 74 | }); | |
| 75 | ||
| 76 | test("a crew is held for a person only when it stands still beside work a person releases", () => { | |
| 77 | const waiting = { later: 2, plan: 1, blocked: 1, unconfirmed: 0, unadopted: 0 }; | |
| 78 | const at = 1_000_000; | |
| 79 | expect(heldForAPerson({ open: 4, startable: 0, waiting, still: true, at }, at)).toBe(true); | |
| 80 | expect(heldForAPerson({ open: 4, startable: 0, waiting, still: false, at }, at)).toBe(false); | |
| 81 | expect(heldForAPerson({ open: 4, startable: 1, waiting, still: true, at }, at)).toBe(false); | |
| 82 | // Only order and the plan's own: nothing for a person to release. | |
| 83 | expect(heldForAPerson({ open: 2, startable: 0, waiting: { ...waiting, later: 0 }, still: true, at }, at)).toBe(false); | |
| 84 | // A count the tick stopped renewing says nothing about now. | |
| 85 | expect(heldForAPerson({ open: 4, startable: 0, waiting, still: true, at }, at + BACKLOG_STANDS_MS)).toBe(true); | |
| 86 | expect(heldForAPerson({ open: 4, startable: 0, waiting, still: true, at }, at + BACKLOG_STANDS_MS + 1)).toBe(false); | |
| 87 | }); | |
| 88 | }); | |
| 89 | ||
| 90 | describe("a crew beside a backlog", () => { | |
| 91 | let dataDir: string; | |
| 92 | let app: App; | |
| 93 | let servers: Servers; | |
| 94 | let alice: User; | |
| 95 | let bob: User; | |
| 96 | let mason: User; | |
| 97 | let repo: Repo; | |
| 98 | let work: Issue; | |
| 99 | let viewers: Issue; | |
| 100 | const fresh = () => getRepoById(app.db, repo.id)!; | |
| 101 | const level = logLevel(); | |
| 102 | let lines: string[] = []; | |
| 103 | let spy: ReturnType<typeof spyOn> | undefined; | |
| 104 | const tick = async (): Promise<string> => { | |
| 105 | lines = []; | |
| 106 | spy = spyOn(console, "info").mockImplementation((line: unknown) => { | |
| 107 | lines.push(String(line)); | |
| 108 | }); | |
| 109 | await autonomyTick(app); | |
| 110 | spy.mockRestore(); | |
| 111 | spy = undefined; | |
| 112 | return lines.find((l) => l.includes("[autonomy] tick") && l.includes("did=")) ?? ""; | |
| 113 | }; | |
| 114 | const open = (title: string): Issue => { | |
| 115 | const made = openIssue(app, alice, fresh(), { title }); | |
| 116 | if (!made.ok) throw new Error(String(made.error)); | |
| 117 | return made.value; | |
| 118 | }; | |
| 119 | const still = (user: User) => needsStack({ app }, user).filter((n) => n.id.startsWith("still:")); | |
| 120 | ||
| 121 | beforeAll(async () => { | |
| 122 | setLogLevel("info"); | |
| 123 | dataDir = await mkdtemp(join(tmpdir(), "forge-backlog-")); | |
| 124 | app = createApp({ dataDir, port: 0 }); | |
| 125 | servers = await serve(app); | |
| 126 | const person = async (username: string, first: boolean): Promise<User> => { | |
| 127 | const made = await createUser(app.db, { | |
| 128 | origin: "seed", | |
| 129 | trusted: true, | |
| 130 | username, | |
| 131 | email: `${username}@forge.local`, | |
| 132 | password: "a-good-passphrase", | |
| 133 | adminIfFirst: first, | |
| 134 | }); | |
| 135 | if (!made.ok) throw new Error(made.error); | |
| 136 | return made.value; | |
| 137 | }; | |
| 138 | alice = await person("alice", true); | |
| 139 | bob = await person("bob", false); | |
| 140 | const made = await createRepo(app, alice, { name: "engine", visibility: "private" }); | |
| 141 | if (!made.ok) throw new Error(String(made.error)); | |
| 142 | repo = made.value; | |
| 143 | const seeded = await commitToBranch(app, alice, repo, { | |
| 144 | message: "Start", | |
| 145 | files: [{ path: "README.md", content: "# engine\n" }], | |
| 146 | }); | |
| 147 | if (!seeded.ok) throw new Error(JSON.stringify(seeded.error)); | |
| 148 | for (const name of ["mason", "atlas"]) { | |
| 149 | const agent = await createAgent(app, alice, { username: name }); | |
| 150 | if (!agent.ok) throw new Error(String(agent.error)); | |
| 151 | expect(addToCrew(app, alice, repo, name).ok).toBe(true); | |
| 152 | } | |
| 153 | mason = getUserByName(app.db, "mason")!; | |
| 154 | seatAs(app.db, repo.id, getUserByName(app.db, "atlas")!.id, "planner"); | |
| 155 | // The owner's gate with two issues behind it, and one issue whose only blocker closed while | |
| 156 | // that blocker itself still waited for the gate (production's #7836 behind #7557). | |
| 157 | const gate = open("Later gate: nothing behind this starts until the owner opens it"); | |
| 158 | viewers = open("File viewers"); | |
| 159 | for (const held of [viewers, open("A CAD viewer")]) expect(linkIssue(app, alice, fresh(), held, gate).ok).toBe(true); | |
| 160 | const hold = open("The keeper cuts on a cadence"); | |
| 161 | expect(linkIssue(app, alice, fresh(), hold, gate).ok).toBe(true); | |
| 162 | work = open("The keeper measures its write pause"); | |
| 163 | expect(linkIssue(app, alice, fresh(), work, hold).ok).toBe(true); | |
| 164 | expect(setIssueState(app, alice, fresh(), getIssueById(app.db, hold.id)!, "closed").ok).toBe(true); | |
| 165 | const set = await updateRepoSettings(app, alice, repo, { | |
| 166 | autonomy: "autonomous", | |
| 167 | autonomyDirection: "Keep the engine small.", | |
| 168 | autonomySlots: 2, | |
| 169 | autonomyBy: alice.id, | |
| 170 | }); | |
| 171 | if (!set.ok) throw new Error(JSON.stringify(set.error)); | |
| 172 | }); | |
| 173 | ||
| 174 | afterEach(() => { | |
| 175 | spy?.mockRestore(); | |
| 176 | spy = undefined; | |
| 177 | }); | |
| 178 | ||
| 179 | afterAll(async () => { | |
| 180 | setLogLevel(level); | |
| 181 | servers.stop(); | |
| 182 | app.close(); | |
| 183 | await rm(dataDir, { recursive: true, force: true }); | |
| 184 | }); | |
| 185 | ||
| 186 | test("an issue whose only blocker closed is ready, and the tick starts it", async () => { | |
| 187 | const ready = readyNow(repoGraph(app.db, repo.id, { sealed: true })).map((r) => r.issue.number); | |
| 188 | expect(ready).toContain(work.number); | |
| 189 | const line = await tick(); | |
| 190 | expect(line).toContain("did=picked"); | |
| 191 | expect(getIssueById(app.db, work.id)!.assigneeId).toBe(mason.id); | |
| 192 | }); | |
| 193 | ||
| 194 | test("the tick line counts the open issues and why the rest wait; nothing stands still yet", async () => { | |
| 195 | const line = await tick(); | |
| 196 | expect(line).toMatch(/ open=\d+ /); | |
| 197 | expect(line).toContain('waiting="later=2 plan=1"'); | |
| 198 | expect(still(alice)).toEqual([]); | |
| 199 | }); | |
| 200 | ||
| 201 | test("a planner the owner's ceiling holds is named with its cause, and the crew's stillness is one need", async () => { | |
| 202 | expect(setIssueState(app, alice, fresh(), getIssueById(app.db, work.id)!, "closed").ok).toBe(true); | |
| 203 | expect(setCeiling(app, alice, fresh(), { mode: "set", value: "1" }).ok).toBe(true); | |
| 204 | const line = await tick(); | |
| 205 | expect(line).toContain("did=idle"); | |
| 206 | expect(line).toContain("startable=0"); | |
| 207 | expect(line).toContain('waiting="later=2 plan=1"'); | |
| 208 | const why = lines.find((l) => l.includes("planner not asked")) ?? ""; | |
| 209 | expect(why).toContain("held by the open-issue ceiling"); | |
| 210 | expect(why).not.toContain("nothing new to act on"); | |
| 211 | expect(heldForAPerson(backlogs(app, Date.now()).get(repo.id)!, Date.now())).toBe(true); | |
| 212 | ||
| 213 | const needs = still(alice); | |
| 214 | expect(needs.map((n) => n.id)).toEqual([`still:${repo.id}`]); | |
| 215 | expect(needs[0]!.sentence).toContain("alice/engine: the crew has nothing to start, and "); | |
| 216 | expect(needs[0]!.sentence).toContain("2 wait behind the Later gate, 1 is the plan's own."); | |
| 217 | expect(needs[0]!.choices).toEqual([STILL_CHOICE]); | |
| 218 | expect(needs[0]!.link).toBe("/alice/engine/held"); | |
| 219 | expect(needs[0]!.recommended.safe).toBe(false); | |
| 220 | // Someone who cannot write there is told nothing about it. | |
| 221 | expect(still(bob)).toEqual([]); | |
| 222 | }); | |
| 223 | ||
| 224 | test("the terminal and the MCP forge tool carry the row for a writer, and for nobody else", async () => { | |
| 225 | const id = `still:${repo.id}`; | |
| 226 | const session = (user: User | undefined) => ({ user, db: app.db, app }) as unknown as Session; | |
| 227 | expect(stackFor(session(alice)).map((n) => n.id)).toContain(id); | |
| 228 | expect(stackFor(session(bob)).map((n) => n.id)).not.toContain(id); | |
| 229 | // A guest: nobody signed in. | |
| 230 | expect(stackFor(session(undefined))).toEqual([]); | |
| 231 | const mcp = async (user: User): Promise<string[]> => { | |
| 232 | const ctx: HttpCtx = { | |
| 233 | app, | |
| 234 | request: new Request("http://localhost/mcp"), | |
| 235 | url: new URL("http://localhost/mcp"), | |
| 236 | params: {}, | |
| 237 | auth: { user, scope: undefined, via: "session" }, | |
| 238 | theme: undefined, | |
| 239 | }; | |
| 240 | const said = (await forgeTool.run(ctx, user, {})) as { ok: boolean; value?: { needs: { id: string; link: string }[] } }; | |
| 241 | expect(said.ok).toBe(true); | |
| 242 | return (said.value?.needs ?? []).map((n) => `${n.id} ${n.link}`); | |
| 243 | }; | |
| 244 | expect(await mcp(alice)).toContain(`${id} /alice/engine/held`); | |
| 245 | expect((await mcp(bob)).filter((n) => n.startsWith("still:"))).toEqual([]); | |
| 246 | }); | |
| 247 | ||
| 248 | test("a repository the tick stopped driving raises nothing: its count ages out and is dropped", () => { | |
| 249 | const counted = backlogs(app, Date.now()).get(repo.id)!; | |
| 250 | // The same count, last renewed past the window: as when autonomy was switched off. | |
| 251 | noteBacklog(app, repo.id, { ...counted, at: Date.now() - BACKLOG_STANDS_MS - 1 }); | |
| 252 | expect(still(alice)).toEqual([]); | |
| 253 | expect(backlogs(app, Date.now()).has(repo.id)).toBe(false); | |
| 254 | noteBacklog(app, repo.id, { ...counted, at: Date.now() }); | |
| 255 | expect(still(alice).map((n) => n.id)).toEqual([`still:${repo.id}`]); | |
| 256 | }); | |
| 257 | ||
| 258 | test("an archived repository's count is forgotten by the next tick", async () => { | |
| 259 | app.db.query("UPDATE repo SET archived_at = '2026-01-01T00:00:00.000Z' WHERE id = ?1").run(repo.id); | |
| 260 | await tick(); | |
| 261 | expect(backlogs(app, Date.now()).has(repo.id)).toBe(false); | |
| 262 | expect(still(alice)).toEqual([]); | |
| 263 | app.db.query("UPDATE repo SET archived_at = NULL WHERE id = ?1").run(repo.id); | |
| 264 | await tick(); | |
| 265 | expect(still(alice).map((n) => n.id)).toEqual([`still:${repo.id}`]); | |
| 266 | }); | |
| 267 | ||
| 268 | test("a park on the direction itself buys the planner no pass: a declined pass is not run again", async () => { | |
| 269 | expect(setCeiling(app, alice, fresh(), { mode: "set", value: "0" }).ok).toBe(true); | |
| 270 | const direction = getIssueById(app.db, fresh().directionIssueId!)!; | |
| 271 | const atlas = getUserByName(app.db, "atlas")!; | |
| 272 | // The planner's pass has ended having opened nothing; nothing was opened or closed since. | |
| 273 | app.db.query("UPDATE issue SET assignee_id = NULL WHERE id = ?1").run(direction.id); | |
| 274 | const pass = createRun(app.db, { repoId: repo.id, kind: "agent", issueId: direction.id, actorId: atlas.id, reason: "assigned" }); | |
| 275 | claimRun(app.db, pass.id); | |
| 276 | finishRun(app.db, pass.id, { state: "ok", summary: "no changes pushed: I opened no issues", costUsd: 0.1 }); | |
| 277 | expect(await driveRepo(app, fresh())).toBe("idle"); | |
| 278 | // Production, 2026-11-15: the breaker parked #334 for runs that repeated, twice; each park was | |
| 279 | // read as a hand-over, and the planner ran 39 passes in 4.5 hours to decline each time. | |
| 280 | for (let n = 0; n < 2; n++) | |
| 281 | app.db | |
| 282 | .query("INSERT INTO comment (id, issue_id, author_id, body, created_at) VALUES (?1, ?2, ?3, ?4, ?5)") | |
| 283 | .run(`park-${n}`, direction.id, alice.id, `${PARK_NOTE}runs on this issue repeated`, new Date(Date.now() + 60_000 + n).toISOString()); | |
| 284 | expect(await driveRepo(app, fresh())).toBe("idle"); | |
| 285 | expect(getIssueById(app.db, direction.id)!.assigneeId).toBeNull(); | |
| 286 | // A person's word on the direction is new: the planner is asked. | |
| 287 | expect(addComment(app, alice, fresh(), getIssueById(app.db, direction.id)!, "Chapter two is the file viewers.").ok).toBe(true); | |
| 288 | expect(await driveRepo(app, fresh(), new Date(Date.now() + 120_000))).toBe("planned"); | |
| 289 | }); | |
| 290 | ||
| 291 | test("the owner lifts one issue from behind the gate: the crew starts it and the need is gone", async () => { | |
| 292 | const lifted = liftHold(app, alice, fresh(), getIssueById(app.db, viewers.id)!); | |
| 293 | expect(lifted.ok).toBe(true); | |
| 294 | const line = await tick(); | |
| 295 | expect(line).toContain("did=picked"); | |
| 296 | expect(line).toContain('waiting="later=1 plan=1"'); | |
| 297 | expect(getIssueById(app.db, viewers.id)!.assigneeId).toBe(mason.id); | |
| 298 | expect(still(alice)).toEqual([]); | |
| 299 | }); | |
| 300 | }); |
test/map-cache.test.ts +9 −5
| @@ -178,27 +178,31 @@ describe("/map after a write", () => { | ||
| 178 | 178 | |
| 179 | 179 | test("an issue opened, then closed, shows on the next /map", async () => { |
| 180 | 180 | const repo = repoOf("plan-0"); |
| 181 | await get(servers, "/map", f.ownerCookie); | |
| 181 | // The repository's own lane, drawn: the Next list above the lanes holds five rows of the | |
| 182 | // whole forge, and which five is the ready order's business, not this test's. | |
| 183 | const lane = "/map?lane=keeper/plan-0"; | |
| 184 | await get(servers, lane, f.ownerCookie); | |
| 182 | 185 | const opened = openIssue(f.app, owner, repo, { title: "Zebra crossing" }); |
| 183 | 186 | expect(opened.ok).toBe(true); |
| 184 | 187 | if (!opened.ok) return; |
| 185 | expect(await get(servers, "/map", f.ownerCookie)).toContain("Zebra crossing"); | |
| 188 | expect(await get(servers, lane, f.ownerCookie)).toContain("Zebra crossing"); | |
| 186 | 189 | const issue = getIssue(f.app.db, repo.id, opened.value.number)!; |
| 187 | 190 | const closed = setIssueState(f.app, owner, repo, issue, "closed"); |
| 188 | 191 | expect(closed.ok).toBe(true); |
| 189 | expect(await get(servers, "/map", f.ownerCookie)).not.toContain("Zebra crossing"); | |
| 192 | expect(await get(servers, lane, f.ownerCookie)).not.toContain("Zebra crossing"); | |
| 190 | 193 | }); |
| 191 | 194 | |
| 192 | 195 | test("an edited title shows although the layout is kept", async () => { |
| 193 | 196 | const repo = repoOf("plan-1"); |
| 194 | const before = await get(servers, "/map", f.ownerCookie); | |
| 197 | const lane = "/map?lane=keeper/plan-1"; | |
| 198 | const before = await get(servers, lane, f.ownerCookie); | |
| 195 | 199 | expect(before).toContain("Plan 1 step 0"); |
| 196 | 200 | f.app.db |
| 197 | 201 | .query("UPDATE issue SET title = 'Renamed step' WHERE repo_id = ?1 AND title = 'Plan 1 step 0'") |
| 198 | 202 | .run(repo.id); |
| 199 | 203 | // A title is not part of the layout's key, so the layout is the same entry. |
| 200 | 204 | f.app.bus.append({ kind: "issue.edited", repoId: repo.id, payload: {} }); |
| 201 | const after = await get(servers, "/map", f.ownerCookie); | |
| 205 | const after = await get(servers, lane, f.ownerCookie); | |
| 202 | 206 | expect(after).toContain("Renamed step"); |
| 203 | 207 | expect(after).not.toContain("Plan 1 step 0"); |
| 204 | 208 | }); |
test/planner-ceiling.test.ts +11 −6
| @@ -64,8 +64,13 @@ describe("the open-issue ceiling", () => { | ||
| 64 | 64 | await rm(dataDir, { recursive: true, force: true, maxRetries: 20, retryDelay: 100 }); |
| 65 | 65 | }); |
| 66 | 66 | |
| 67 | test("the default is 150, and only the owner sets it", () => { | |
| 68 | expect(openCeiling(app.db, repo.id)).toBe(DEFAULT_CEILING); | |
| 67 | test("there is no ceiling until the owner sets one, and only the owner sets it", () => { | |
| 68 | expect(DEFAULT_CEILING).toBe(0); | |
| 69 | expect(openCeiling(app.db, repo.id)).toBe(0); | |
| 70 | // production on 2026-11-15: 278 open against a default of 150 nobody chose | |
| 71 | for (let n = 0; n < 3; n++) expect(openIssue(app, planner, repo, { title: `Before any ceiling ${n}` }).ok).toBe(true); | |
| 72 | expect(ceilingHold(app.db, repo.id)).toBeNull(); | |
| 73 | expect(plannerHeld(app.db)).toEqual([]); | |
| 69 | 74 | expect(setCeiling(app, person, repo, { mode: "set", value: "2" })).toEqual({ ok: false, error: "forbidden" }); |
| 70 | 75 | expect(setCeiling(app, planner, repo, { mode: "set", value: "2" })).toEqual({ ok: false, error: "forbidden" }); |
| 71 | 76 | for (const bad of ["-1", "x", "1.5", "", "1000000"]) |
| @@ -153,12 +158,12 @@ describe("the open-issue ceiling", () => { | ||
| 153 | 158 | expect(openIssue(app, planner, repo, { title: "Child" }).ok).toBe(true); |
| 154 | 159 | }); |
| 155 | 160 | |
| 156 | test("/flow names a planner held by the default ceiling too", () => { | |
| 161 | test("with the owner's ceiling taken away nothing holds the planner, however many are open", () => { | |
| 157 | 162 | 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); | |
| 163 | for (let n = 0; n < 5; n++) openIssue(app, owner, repo, { title: `Open ${n}` }); | |
| 164 | expect(ceilingHold(app.db, repo.id)).toBeNull(); | |
| 159 | 165 | 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"]); | |
| 166 | expect(openIssue(app, planner, repo, { title: "The planner opens one" }).ok).toBe(true); | |
| 162 | 167 | }); |
| 163 | 168 | |
| 164 | 169 | test("the queue page shows the setting, its reason and, past it, the cause", async () => { |
new above
offline
Entries are never removed: a repo that stops ticking keeps its last
stillforever and keeps raising the need. Forget it when the tick skips the repo, or timestamp it and ignore old ones; test it.