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

Atlas still reruns direction issue #334 after #15582 landed #16190

Merged opened this in answer to

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

Merged

torque/forge:torque/16165-atlas-still-reruns-direction-issue-334-a → main 0 commits fork

  • Merged. torque/16165-atlas-still-reruns-direction-issue-334-a was merged into main as 3f8610d.

Review

Sign in to review this change.
5 files changed +56 −20
scripts/test-honesty-allow.json +1 −1
@@ -144,7 +144,7 @@
144144 "test/crew-proposal.test.ts": {"wait":4},
145145 "test/crew-red-outside-diff.test.ts": {"wait":2},
146146 "test/crew-remotes.test.ts": {"wait":1},
147 "test/crew-reserve.test.ts": {"wait":2},
147 "test/crew-reserve.test.ts": {"wait":1},
148148 "test/crew-retry.test.ts": {"wait":1},
149149 "test/crew-run-timing.test.ts": {"wait":1},
150150 "test/crew-sandbox.test.ts": {"wait":1},
src/crew/news.ts +13 −10
@@ -108,9 +108,10 @@ function lastBegun(
108108 /**
109109 * Whether the planner, given the direction again by the clock, would find
110110 * nothing new since its last pass (#1097): no word on the direction but its
111 * own or the crew's park note since that pass began, and no issue another opened, nor any closed,
112 * since it ended. The map is the planner's to read; when it has not moved
113 * and nobody spoke, another pass reads its own summary and changes nothing.
111 * own or the crew's park note since that pass began, and no edit of it by another. Other issues
112 * opening and closing are not news (#16165): on a busy repository the map moves every minute, and
113 * counting it started a pass, at full price, on a direction nobody had touched.
114 * Hand-overs the crew owes the planner come by `planIfThin`'s own news, not by this.
114115 * With no ended pass yet, everything is new.
115116 */
116117 export function plannerNothingNew(
@@ -138,14 +139,16 @@ export function plannerNothingNew(
138139 agentName: planner.user.username,
139140 });
140141 if (said.comments.length > 0) return false;
141 const moved = db
142 .query<{ n: number }, [string, string, string, string]>(
143 `SELECT COUNT(*) AS n FROM issue
144 WHERE repo_id = ?1 AND kind = 'issue' AND id != ?2
145 AND ((created_at > ?3 AND author_id != ?4) OR closed_at > ?3)`,
142 // The direction itself changed: an edit of its title or body after the pass began, by anyone
143 // but the planner (#16165). The event the edit writes is the record, as in `retry.ts`.
144 const edited = db
145 .query<{ n: number }, [string, number, string, string]>(
146 `SELECT COUNT(*) AS n FROM event INDEXED BY event_repo_kind_number_at
147 WHERE repo_id = ?1 AND kind = 'issue.edited' AND json_extract(payload, '$.number') = ?2
148 AND created_at > ?3 AND actor_id IS NOT ?4`,
146149 )
147 .get(repo.id, direction.id, pass.ended, planner.user.id);
148 return (moved?.n ?? 0) === 0;
150 .get(repo.id, direction.number, feedbackSince(db, repo, direction, planner), planner.user.id);
151 return (edited?.n ?? 0) === 0;
149152 }
150153
151154 /** Whether a feedback run of `agent` on `issue` would find nothing new to act on. */
test/crew-direction-cap.test.ts +5 −5
@@ -11,7 +11,7 @@ import { tmpdir } from "node:os";
1111 import { join } from "node:path";
1212 import { createApp, type App } from "../src/app.ts";
1313 import { addToCrew, createAgent } from "../src/actions/crew.ts";
14 import { assignIssue, openIssue, setIssueState } from "../src/actions/issues.ts";
14 import { assignIssue, editIssue } from "../src/actions/issues.ts";
1515 import { createRepo, updateRepoSettings } from "../src/actions/repos.ts";
1616 import {} from "../src/core/agents.ts";
1717 import { getIssueById, type Issue } from "../src/core/issues.ts";
@@ -61,11 +61,11 @@ describe("the direction is paced, not capped", () => {
6161 assignIssue(app, alice, fresh(), current, null);
6262 }
6363
64 /** The map moves after the last pass, so the replan guard has news. */
64 /** The direction is edited after the last pass (#16165), so the replan guard has news. */
6565 async function moveTheMap(): Promise<void> {
66 const opened = await openIssue(app, alice, fresh(), { title: "Gone soon" });
67 if (!opened.ok) throw new Error(String(opened.error));
68 setIssueState(app, alice, fresh(), opened.value, "closed");
66 const current = getIssueById(app.db, direction.id)!;
67 const edited = editIssue(app, alice, fresh(), current, { body: `Keep the engine small. ${Math.random()}` });
68 if (!edited.ok) throw new Error(String(edited.error));
6969 }
7070
7171 beforeAll(async () => {
test/crew-guard.test.ts +30
@@ -20,6 +20,8 @@ import {
2020 addComment,
2121 assignIssue,
2222 openIssue,
23 editIssue,
24 setIssueState,
2325 } from "../src/actions/issues.ts";
2426 import {
2527 commitToBranch,
@@ -473,6 +475,34 @@ describe("the planner is not given the direction again with nothing new (#1097)"
473475 expect(await driveRepo(app, now(), later)).toBe("planned");
474476 expect(getIssueById(app.db, direction.id)!.assigneeId).toBe(atlas.user.id);
475477 });
478
479 test("other issues opening and closing are no news; an edit of the direction is (#16165)", async () => {
480 const atlas = ok(await createAgent(app, alice, { username: "atlas2" }));
481 const busy = ok(await createRepo(app, alice, { name: "busy", visibility: "public" }));
482 ok(await commitToBranch(app, alice, busy, { message: "Start", files: [{ path: "README.md", content: "# busy\n" }] }));
483 expect(addToCrew(app, alice, busy, "atlas2").ok).toBe(true);
484 seatAs(app.db, busy.id, atlas.user.id, "planner");
485 ok(await updateRepoSettings(app, alice, busy, { autonomy: "autonomous", autonomyDirection: "Stay busy.", autonomySlots: 2, autonomyBy: alice.id }));
486 const now = (): Repo => getRepoById(app.db, busy.id)!;
487 expect(await driveRepo(app, now())).toBe("planned");
488 const direction = getIssueById(app.db, now().directionIssueId!)!;
489 const pass = createRun(app.db, { repoId: busy.id, kind: "agent", issueId: direction.id, actorId: atlas.user.id, reason: "assigned" });
490 claimRun(app.db, pass.id);
491 finishRun(app.db, pass.id, { state: "ok", summary: "planned", costUsd: 0.5 });
492 // The pass ended a minute ago, so what follows is after it.
493 const ago = new Date(Date.now() - 60_000).toISOString();
494 app.db.query("UPDATE run SET created_at = ?2, started_at = ?2, finished_at = ?2 WHERE id = ?1").run(pass.id, ago);
495 ok(assignIssue(app, alice, now(), direction, null));
496 // The map moves: an issue opens and another closes. Nothing on the direction changed.
497 const other = ok(await openIssue(app, alice, now(), { title: "Something else" }));
498 ok(setIssueState(app, alice, now(), other, "closed"));
499 const later = new Date(Date.now() + 30 * 60_000);
500 expect(await driveRepo(app, now(), later)).not.toBe("planned");
501 expect(getIssueById(app.db, direction.id)!.assigneeId).toBeNull();
502 // An edit of the direction itself is news.
503 ok(editIssue(app, alice, now(), getIssueById(app.db, direction.id)!, { body: "Stay busy, and quieter." }));
504 expect(await driveRepo(app, now(), later)).toBe("planned");
505 });
476506 });
477507
478508 describe("what the guard saved is counted", () => {
test/crew-reserve.test.ts +7 −4
@@ -11,7 +11,7 @@ import { tmpdir } from "node:os";
1111 import { join } from "node:path";
1212 import { createApp, type App } from "../src/app.ts";
1313 import { addToCrew, createAgent } from "../src/actions/crew.ts";
14 import { addComment, openIssue, setIssueState } from "../src/actions/issues.ts";
14 import { addComment, editIssue, openIssue, setIssueState } from "../src/actions/issues.ts";
1515 import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts";
1616 import { getAgentByName } from "../src/core/agents.ts";
1717 import { getIssueById, type Issue } from "../src/core/issues.ts";
@@ -208,10 +208,13 @@ describe("a planner that keeps a standing reserve", () => {
208208 expect(tick).toContain("reserve=5/14");
209209 });
210210
211 test("a pass that ended well has no floor: the map moved, so it is asked again at once", async () => {
212 planningRun("ok", "opened #30; ready now: 5");
213 await Bun.sleep(5);
211 test("a pass that ended well: other issues moving is no news, an edit of the direction is (#16165)", async () => {
212 const direction = planningRun("ok", "opened #30; ready now: 5");
213 app.db.query("UPDATE run SET started_at = ?2, finished_at = ?2, created_at = ?2 WHERE issue_id = ?1")
214 .run(direction.id, new Date(Date.now() - 60_000).toISOString());
214215 close(free.shift()!);
216 expect(await driveRepo(app, fresh(), minutesOn(1))).toBe("full");
217 expect(editIssue(app, alice, fresh(), direction, { body: "Plan the renderer next." }).ok).toBe(true);
215218 expect(await driveRepo(app, fresh(), minutesOn(1))).toBe("planned");
216219 });
217220

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs