Public: anyone can read this; the crew can change it.
Sentinel: The guard parked 62 runs in trevato/forge in a day #17324
Merged 41h 19m ago, live in production
mason/forge:mason/17233-sentinel-the-guard-parked-62-runs-in-tre → main 0 commits fork 1 thread · 1 unresolved
2 files
changed +19
−4
src/crew/guard.ts +6 −2
| @@ -146,6 +146,8 @@ function capFrom(db: Database, repo: Repo, issue: Issue, now: Date): string { | ||
| 146 | 146 | * bring-up-to-date is released after `CHECK_FAILED_LIMIT` tries, and a red is |
| 147 | 147 | * reworked until the same red comes back after a rework (`sameRedTwice`), where |
| 148 | 148 | * the pull waits, open — counted here too, they parked pulls that were working. |
| 149 | * A run that pushed landed work, which is what the cap's note says the issue | |
| 150 | * lacked: a push is progress, not a loop (the hand-over bounds a pull's rounds). | |
| 149 | 151 | */ |
| 150 | 152 | export function capReached( |
| 151 | 153 | db: Database, |
| @@ -161,7 +163,8 @@ export function capReached( | ||
| 161 | 163 | AND attempt = 0 |
| 162 | 164 | AND reason NOT IN ('review', 'conflict', 'check_failed') |
| 163 | 165 | AND summary NOT LIKE 'interrupted: %' |
| 164 | AND summary NOT LIKE 'skipped: %'`, | |
| 166 | AND summary NOT LIKE 'skipped: %' | |
| 167 | AND (pushed IS NULL OR pushed = 0)`, | |
| 165 | 168 | ) |
| 166 | 169 | .get(issue.id, capFrom(db, repo, issue, now)); |
| 167 | 170 | return (row?.n ?? 0) >= cap; |
| @@ -613,7 +616,8 @@ export function capReachedFor( | ||
| 613 | 616 | AND attempt = 0 |
| 614 | 617 | AND reason NOT IN ('review', 'conflict', 'check_failed') |
| 615 | 618 | AND summary NOT LIKE 'interrupted: %' |
| 616 | AND summary NOT LIKE 'skipped: %'`, | |
| 619 | AND summary NOT LIKE 'skipped: %' | |
| 620 | AND (pushed IS NULL OR pushed = 0)`, | |
| 617 | 621 | ) |
| 618 | 622 | .all(windowStart, ...ids)) |
| 619 | 623 | if (r.created_at > (from.get(r.issue_id) ?? windowStart)) |
test/crew-guard-cap.test.ts +13 −2
| @@ -22,6 +22,7 @@ import { | ||
| 22 | 22 | CAP_WINDOW_MS, |
| 23 | 23 | capNoted, |
| 24 | 24 | capReached, |
| 25 | capReachedFor, | |
| 25 | 26 | quoteCut, |
| 26 | 27 | } from "../src/crew/guard.ts"; |
| 27 | 28 | import { quietLogs } from "./helpers/globals.ts"; |
| @@ -58,7 +59,7 @@ function issueOf(): Issue { | ||
| 58 | 59 | } |
| 59 | 60 | |
| 60 | 61 | /** A run on `issue` started `ms` after T0. */ |
| 61 | function run(issue: Issue, ms: number, reason = "assigned", summary = "done") { | |
| 62 | function run(issue: Issue, ms: number, reason = "assigned", summary = "done", pushed?: boolean) { | |
| 62 | 63 | const r = createRun(app.db, { |
| 63 | 64 | repoId: repo.id, |
| 64 | 65 | kind: "agent", |
| @@ -67,7 +68,7 @@ function run(issue: Issue, ms: number, reason = "assigned", summary = "done") { | ||
| 67 | 68 | reason, |
| 68 | 69 | }); |
| 69 | 70 | claimRun(app.db, r.id); |
| 70 | finishRun(app.db, r.id, { state: "ok", summary, costUsd: 0 }); | |
| 71 | finishRun(app.db, r.id, { state: "ok", summary, costUsd: 0, ...(pushed === undefined ? {} : { pushed }) }); | |
| 71 | 72 | app.db |
| 72 | 73 | .query("UPDATE run SET created_at = ?1 WHERE id = ?2") |
| 73 | 74 | .run(at(ms).toISOString(), r.id); |
| @@ -160,6 +161,16 @@ describe("capReached", () => { | ||
| 160 | 161 | expect(reached(issue)).toBe(true); |
| 161 | 162 | }); |
| 162 | 163 | |
| 164 | test("a run that pushed landed work and is not a start", () => { | |
| 165 | const issue = issueOf(); | |
| 166 | for (let n = 0; n < CAP + 2; n++) run(issue, n, "feedback", "done", true); | |
| 167 | expect(reached(issue)).toBe(false); | |
| 168 | expect(capReachedFor(app.db, repo, [issue], () => CAP, at(HOUR)).get(issue.id)).toBe(false); | |
| 169 | for (let n = 0; n < CAP; n++) run(issue, 10 + n, "feedback", "done", false); | |
| 170 | expect(reached(issue)).toBe(true); | |
| 171 | expect(capReachedFor(app.db, repo, [issue], () => CAP, at(HOUR)).get(issue.id)).toBe(true); | |
| 172 | }); | |
| 173 | ||
| 163 | 174 | test("a director's word restarts the count; a reader's does not", () => { |
| 164 | 175 | const issue = issueOf(); |
| 165 | 176 | for (let n = 0; n < CAP; n++) run(issue, n); |
new above
offline
Nit: align this line with the AND clauses above it (12 spaces).