Public: anyone can read this; the crew can change it.
The planner is asked when the reserve runs short, not only when a person writes on the direction #17882
Merged 24h 52m ago, live in production
scout/forge:scout/17881-the-planner-is-asked-when-the-reserve-ru → main 0 commits fork 1 thread · 1 unresolved
4 files
changed +37
−16
src/crew/plan_owed.ts +13 −5
| @@ -19,7 +19,7 @@ import { declinedUnanswered } from "./planner_decline.ts"; | ||
| 19 | 19 | import { holdWhy, plannerHold } from "./planner_hold.ts"; |
| 20 | 20 | import { ensurePlanner } from "./planner.ts"; |
| 21 | 21 | import { redThricePulls } from "./red_thrice.ts"; |
| 22 | import { reserveOf, reserveWords } from "./reserve.ts"; | |
| 22 | import { reserveOf, reserveWords, short } from "./reserve.ts"; | |
| 23 | 23 | import { handedTooLarge } from "./too_large.ts"; |
| 24 | 24 | |
| 25 | 25 | const log = createLog("autonomy"); |
| @@ -98,6 +98,8 @@ export async function planIfOwed( | ||
| 98 | 98 | ); |
| 99 | 99 | const limbs = pendingReplans(app.db, repo); |
| 100 | 100 | const reserve = reserveOf(ready, repo.autonomySlots); |
| 101 | // A short reserve owes a pass too (#17881), bounded below by the floor, the breaker, the hold. | |
| 102 | const reserveShort = short(reserve); | |
| 101 | 103 | // A repository with no direction issue yet is owed its first pass; after that only a word |
| 102 | 104 | // or an edit on the direction (`plannerNothingNew`), a hand-over or a limb is. |
| 103 | 105 | let worded = true; |
| @@ -111,7 +113,8 @@ export async function planIfOwed( | ||
| 111 | 113 | .get(repo.directionIssueId)?.at; |
| 112 | 114 | worded = seat !== undefined && issue !== undefined && !skipsReplan(app.db, repo, issue, seat, since ?? ""); |
| 113 | 115 | } |
| 114 | if (!worded && handed.length === 0 && limbs.length === 0) return false; | |
| 116 | if (!worded && handed.length === 0 && limbs.length === 0 && !reserveShort) | |
| 117 | return notPlanned(repo, "nothing owed: reserve full, no new word on the direction"); | |
| 115 | 118 | // Paused by its pillar's setting (#7668): the planner stays on the crew. |
| 116 | 119 | if (repo.plannerSlots === 0) return notPlanned(repo, "the planner is paused"); |
| 117 | 120 | if (repo.autonomyDirection.trim() === "") |
| @@ -138,7 +141,10 @@ export async function planIfOwed( | ||
| 138 | 141 | // A limb a person handed over is owed one pass, whatever the map and |
| 139 | 142 | // whatever the planner said of the direction before (#761). |
| 140 | 143 | const limbsOwed = limbs.filter((r) => !given(app.db, repo, r.at)); |
| 141 | if (!worded && owed.length === 0 && limbsOwed.length === 0) return false; | |
| 144 | if (!worded && owed.length === 0 && limbsOwed.length === 0 && !reserveShort) | |
| 145 | return notPlanned(repo, "nothing owed: reserve full, no new word on the direction"); | |
| 146 | // Owed only by a short reserve: no new word, nothing handed over. | |
| 147 | const byReserve = !worded && owed.length === 0 && limbsOwed.length === 0; | |
| 142 | 148 | // The direction is the planner's standing issue, not one issue retried: |
| 143 | 149 | // no run count bounds it. The budget does, the breaker, and a pass that |
| 144 | 150 | // would plan the same input twice is skipped (`plannerNothingNew`). |
| @@ -165,10 +171,10 @@ export async function planIfOwed( | ||
| 165 | 171 | if (lastPlan.state === "queued" || lastPlan.state === "running") |
| 166 | 172 | return notPlanned(repo, "a planning run is in flight"); |
| 167 | 173 | // Only a pass that did not end well waits out the floor; a person's |
| 168 | // hand-over never does. | |
| 174 | // hand-over never does. A short reserve alone waits it out after any pass. | |
| 169 | 175 | if ( |
| 170 | 176 | limbsOwed.length === 0 && |
| 171 | lastPlan.state !== "ok" && | |
| 177 | (lastPlan.state !== "ok" || byReserve) && | |
| 172 | 178 | now.getTime() - new Date(lastPlan.created_at).getTime() < |
| 173 | 179 | REPLAN_AFTER_MS |
| 174 | 180 | ) |
| @@ -190,6 +196,8 @@ export async function planIfOwed( | ||
| 190 | 196 | ? "a limb was handed over; planner asked" |
| 191 | 197 | : owed.length > 0 |
| 192 | 198 | ? "parked twice; planner asked" |
| 199 | : byReserve | |
| 200 | ? "reserve short; planner asked" | |
| 193 | 201 | : "a person's direction; planner asked", |
| 194 | 202 | { |
| 195 | 203 | repo: `${repo.ownerName}/${repo.name}`, |
test/autonomy.test.ts +3 −3
| @@ -246,9 +246,9 @@ describe("a repository on its own", () => { | ||
| 246 | 246 | costUsd: 1, |
| 247 | 247 | }); |
| 248 | 248 | expect(await driveRepo(app, fresh())).toBe("idle"); |
| 249 | // Past the interval with nothing new since that pass — nobody spoke, | |
| 250 | // the map has not moved — it is not asked again (#1097)… | |
| 251 | expect(await driveRepo(app, fresh(), later)).toBe("idle"); | |
| 249 | // Within the floor of that pass with nothing new — nobody spoke, the map has not | |
| 250 | // moved — it is not asked again (#1097; a short reserve waits out the floor, #17881)… | |
| 251 | expect(await driveRepo(app, fresh(), new Date(Date.now() + 5 * 60_000))).toBe("idle"); | |
| 252 | 252 | // …and once a person speaks on the direction, it is. |
| 253 | 253 | const { addComment } = await import("../src/actions/issues.ts"); |
| 254 | 254 | expect( |
test/crew-guard.test.ts +5 −3
| @@ -459,9 +459,10 @@ describe("the planner is not given the direction again with nothing new (#1097)" | ||
| 459 | 459 | // …and the clock, past its interval, does not give it the direction |
| 460 | 460 | // again. The skip is the rule's, recorded once however often it asks. |
| 461 | 461 | const later = new Date(Date.now() + 30 * 60_000); |
| 462 | const soon = new Date(Date.now() + 5 * 60_000); | |
| 462 | 463 | const before = skips(); |
| 463 | expect(await driveRepo(app, now(), later)).not.toBe("planned"); | |
| 464 | expect(await driveRepo(app, now(), later)).not.toBe("planned"); | |
| 464 | expect(await driveRepo(app, now(), soon)).not.toBe("planned"); | |
| 465 | expect(await driveRepo(app, now(), soon)).not.toBe("planned"); | |
| 465 | 466 | expect(getIssueById(app.db, direction.id)!.assigneeId).toBeNull(); |
| 466 | 467 | expect(skips()).toBe(before + 1); |
| 467 | 468 | const skip = listDecisions(app.db, round.id, { kind: "guard" }).find((d) => |
| @@ -497,7 +498,8 @@ describe("the planner is not given the direction again with nothing new (#1097)" | ||
| 497 | 498 | const other = ok(await openIssue(app, alice, now(), { title: "Something else" })); |
| 498 | 499 | ok(setIssueState(app, alice, now(), other, "closed")); |
| 499 | 500 | const later = new Date(Date.now() + 30 * 60_000); |
| 500 | expect(await driveRepo(app, now(), later)).not.toBe("planned"); | |
| 501 | const soon = new Date(Date.now() + 5 * 60_000); | |
| 502 | expect(await driveRepo(app, now(), soon)).not.toBe("planned"); | |
| 501 | 503 | expect(getIssueById(app.db, direction.id)!.assigneeId).toBeNull(); |
| 502 | 504 | // An edit of the direction itself is news. |
| 503 | 505 | ok(editIssue(app, alice, now(), getIssueById(app.db, direction.id)!, { body: "Stay busy, and quieter." })); |
test/crew-reserve.test.ts +16 −5
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * The standing reserve (#3237) is what the tick line reports, `reserve=startable/target`. Since |
| 3 | * #16231 a short reserve is no reason to run a planner: a direction nobody has planned from, a | |
| 4 | * person's word or edit on it, and a hand-over are. Only a pass that did not end well waits out | |
| 5 | * the 20-minute floor. | |
| 3 | * #16231 a short reserve alone was no reason to run a planner (#17881 owes it a pass again, after | |
| 4 | * the floor): a direction nobody has planned from, a person's word or edit on it, and a hand-over | |
| 5 | * are. Only a pass that did not end well waits out the 20-minute floor. | |
| 6 | 6 | */ |
| 7 | 7 | import { seatAs } from "./helpers/seat.ts"; |
| 8 | 8 | import { afterAll, afterEach, beforeAll, describe, expect, spyOn, test } from "bun:test"; |
| @@ -210,10 +210,21 @@ describe("a planner asked for words, not for a short reserve (#16231)", () => { | ||
| 210 | 210 | expect(await driveRepo(app, fresh(), minutesOn(1))).toBe("planned"); |
| 211 | 211 | }); |
| 212 | 212 | |
| 213 | test("a pass that ended well and moved nothing is not asked again", async () => { | |
| 213 | test("a short reserve asks once after the floor, with no new word, and not again within it (#17881)", async () => { | |
| 214 | 214 | planningRun("ok", "nothing left in the direction; said why on it"); |
| 215 | listen(); | |
| 215 | 216 | expect(await driveRepo(app, fresh(), minutesOn(1))).toBe("full"); |
| 216 | expect(await driveRepo(app, fresh(), minutesOn(30))).toBe("full"); | |
| 217 | expect(await driveRepo(app, fresh(), minutesOn(19))).toBe("full"); | |
| 218 | expect(lines.some((l) => l.includes("planner asked"))).toBe(false); | |
| 219 | expect(await driveRepo(app, fresh(), minutesOn(21))).toBe("planned"); | |
| 220 | expect(lines.some((l) => l.includes("reserve short; planner asked"))).toBe(true); | |
| 221 | const direction = getIssueById(app.db, fresh().directionIssueId!)!; | |
| 222 | expect(direction.assigneeId).toBe(atlas.id); | |
| 223 | // The pass runs and opens nothing; the next tick, inside the floor, does not ask again. | |
| 224 | planningRun("ok", "nothing left in the direction; said why on it"); | |
| 225 | lines = []; | |
| 226 | expect(await driveRepo(app, fresh(), minutesOn(10))).toBe("full"); | |
| 227 | expect(lines.some((l) => l.includes("planned recently"))).toBe(true); | |
| 217 | 228 | }); |
| 218 | 229 | |
| 219 | 230 | test("a planner that declined waits out the 20-minute floor once a person answers", async () => { |
new above
offline
This line logs at info every tick for every quiet repository, and it was silent before. Log it once per change of reason, or at debug level. The same sentence is repeated at the second exit below. Make it one constant.