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

opened this in answer to

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

  • Merged. scout/17881-the-planner-is-asked-when-the-reserve-ru was merged into main as 4ab714b.

Review

Sign in to review this change.
4 files changed +37 −16
src/crew/plan_owed.ts +13 −5
@@ -19,7 +19,7 @@ import { declinedUnanswered } from "./planner_decline.ts";
1919 import { holdWhy, plannerHold } from "./planner_hold.ts";
2020 import { ensurePlanner } from "./planner.ts";
2121 import { redThricePulls } from "./red_thrice.ts";
22 import { reserveOf, reserveWords } from "./reserve.ts";
22 import { reserveOf, reserveWords, short } from "./reserve.ts";
2323 import { handedTooLarge } from "./too_large.ts";
2424
2525 const log = createLog("autonomy");
@@ -98,6 +98,8 @@ export async function planIfOwed(
9898 );
9999 const limbs = pendingReplans(app.db, repo);
100100 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);
101103 // A repository with no direction issue yet is owed its first pass; after that only a word
102104 // or an edit on the direction (`plannerNothingNew`), a hand-over or a limb is.
103105 let worded = true;
@@ -111,7 +113,8 @@ export async function planIfOwed(
111113 .get(repo.directionIssueId)?.at;
112114 worded = seat !== undefined && issue !== undefined && !skipsReplan(app.db, repo, issue, seat, since ?? "");
113115 }
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");

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.

115118 // Paused by its pillar's setting (#7668): the planner stays on the crew.
116119 if (repo.plannerSlots === 0) return notPlanned(repo, "the planner is paused");
117120 if (repo.autonomyDirection.trim() === "")
@@ -138,7 +141,10 @@ export async function planIfOwed(
138141 // A limb a person handed over is owed one pass, whatever the map and
139142 // whatever the planner said of the direction before (#761).
140143 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;
142148 // The direction is the planner's standing issue, not one issue retried:
143149 // no run count bounds it. The budget does, the breaker, and a pass that
144150 // would plan the same input twice is skipped (`plannerNothingNew`).
@@ -165,10 +171,10 @@ export async function planIfOwed(
165171 if (lastPlan.state === "queued" || lastPlan.state === "running")
166172 return notPlanned(repo, "a planning run is in flight");
167173 // 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.
169175 if (
170176 limbsOwed.length === 0 &&
171 lastPlan.state !== "ok" &&
177 (lastPlan.state !== "ok" || byReserve) &&
172178 now.getTime() - new Date(lastPlan.created_at).getTime() <
173179 REPLAN_AFTER_MS
174180 )
@@ -190,6 +196,8 @@ export async function planIfOwed(
190196 ? "a limb was handed over; planner asked"
191197 : owed.length > 0
192198 ? "parked twice; planner asked"
199 : byReserve
200 ? "reserve short; planner asked"
193201 : "a person's direction; planner asked",
194202 {
195203 repo: `${repo.ownerName}/${repo.name}`,
test/autonomy.test.ts +3 −3
@@ -246,9 +246,9 @@ describe("a repository on its own", () => {
246246 costUsd: 1,
247247 });
248248 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");
252252 // …and once a person speaks on the direction, it is.
253253 const { addComment } = await import("../src/actions/issues.ts");
254254 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)"
459459 // …and the clock, past its interval, does not give it the direction
460460 // again. The skip is the rule's, recorded once however often it asks.
461461 const later = new Date(Date.now() + 30 * 60_000);
462 const soon = new Date(Date.now() + 5 * 60_000);
462463 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");
465466 expect(getIssueById(app.db, direction.id)!.assigneeId).toBeNull();
466467 expect(skips()).toBe(before + 1);
467468 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)"
497498 const other = ok(await openIssue(app, alice, now(), { title: "Something else" }));
498499 ok(setIssueState(app, alice, now(), other, "closed"));
499500 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");
501503 expect(getIssueById(app.db, direction.id)!.assigneeId).toBeNull();
502504 // An edit of the direction itself is news.
503505 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 @@
11 /**
22 * 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.
66 */
77 import { seatAs } from "./helpers/seat.ts";
88 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)", () => {
210210 expect(await driveRepo(app, fresh(), minutesOn(1))).toBe("planned");
211211 });
212212
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 () => {
214214 planningRun("ok", "nothing left in the direction; said why on it");
215 listen();
215216 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);
217228 });
218229
219230 test("a planner that declined waits out the 20-minute floor once a person answers", async () => {

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs