Public: anyone can read this; the crew can change it.
Atlas still reruns direction issue #334 after #15582 landed #16190
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/16165-atlas-still-reruns-direction-issue-334-a → main 0 commits fork
5 files
changed +56
−20
scripts/test-honesty-allow.json +1 −1
| @@ -144,7 +144,7 @@ | ||
| 144 | 144 | "test/crew-proposal.test.ts": {"wait":4}, |
| 145 | 145 | "test/crew-red-outside-diff.test.ts": {"wait":2}, |
| 146 | 146 | "test/crew-remotes.test.ts": {"wait":1}, |
| 147 | "test/crew-reserve.test.ts": {"wait":2}, | |
| 147 | "test/crew-reserve.test.ts": {"wait":1}, | |
| 148 | 148 | "test/crew-retry.test.ts": {"wait":1}, |
| 149 | 149 | "test/crew-run-timing.test.ts": {"wait":1}, |
| 150 | 150 | "test/crew-sandbox.test.ts": {"wait":1}, |
src/crew/news.ts +13 −10
| @@ -108,9 +108,10 @@ function lastBegun( | ||
| 108 | 108 | /** |
| 109 | 109 | * Whether the planner, given the direction again by the clock, would find |
| 110 | 110 | * 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. | |
| 114 | 115 | * With no ended pass yet, everything is new. |
| 115 | 116 | */ |
| 116 | 117 | export function plannerNothingNew( |
| @@ -138,14 +139,16 @@ export function plannerNothingNew( | ||
| 138 | 139 | agentName: planner.user.username, |
| 139 | 140 | }); |
| 140 | 141 | 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`, | |
| 146 | 149 | ) |
| 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; | |
| 149 | 152 | } |
| 150 | 153 | |
| 151 | 154 | /** 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"; | ||
| 11 | 11 | import { join } from "node:path"; |
| 12 | 12 | import { createApp, type App } from "../src/app.ts"; |
| 13 | 13 | 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"; | |
| 15 | 15 | import { createRepo, updateRepoSettings } from "../src/actions/repos.ts"; |
| 16 | 16 | import {} from "../src/core/agents.ts"; |
| 17 | 17 | import { getIssueById, type Issue } from "../src/core/issues.ts"; |
| @@ -61,11 +61,11 @@ describe("the direction is paced, not capped", () => { | ||
| 61 | 61 | assignIssue(app, alice, fresh(), current, null); |
| 62 | 62 | } |
| 63 | 63 | |
| 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. */ | |
| 65 | 65 | 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)); | |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | beforeAll(async () => { |
test/crew-guard.test.ts +30
| @@ -20,6 +20,8 @@ import { | ||
| 20 | 20 | addComment, |
| 21 | 21 | assignIssue, |
| 22 | 22 | openIssue, |
| 23 | editIssue, | |
| 24 | setIssueState, | |
| 23 | 25 | } from "../src/actions/issues.ts"; |
| 24 | 26 | import { |
| 25 | 27 | commitToBranch, |
| @@ -473,6 +475,34 @@ describe("the planner is not given the direction again with nothing new (#1097)" | ||
| 473 | 475 | expect(await driveRepo(app, now(), later)).toBe("planned"); |
| 474 | 476 | expect(getIssueById(app.db, direction.id)!.assigneeId).toBe(atlas.user.id); |
| 475 | 477 | }); |
| 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 | }); | |
| 476 | 506 | }); |
| 477 | 507 | |
| 478 | 508 | describe("what the guard saved is counted", () => { |
test/crew-reserve.test.ts +7 −4
| @@ -11,7 +11,7 @@ import { tmpdir } from "node:os"; | ||
| 11 | 11 | import { join } from "node:path"; |
| 12 | 12 | import { createApp, type App } from "../src/app.ts"; |
| 13 | 13 | 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"; | |
| 15 | 15 | import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts"; |
| 16 | 16 | import { getAgentByName } from "../src/core/agents.ts"; |
| 17 | 17 | import { getIssueById, type Issue } from "../src/core/issues.ts"; |
| @@ -208,10 +208,13 @@ describe("a planner that keeps a standing reserve", () => { | ||
| 208 | 208 | expect(tick).toContain("reserve=5/14"); |
| 209 | 209 | }); |
| 210 | 210 | |
| 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()); | |
| 214 | 215 | 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); | |
| 215 | 218 | expect(await driveRepo(app, fresh(), minutesOn(1))).toBe("planned"); |
| 216 | 219 | }); |
| 217 | 220 |
new above
offline