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

A hold placed because a pull was red releases itself when that pull's check is green on the same head #6357

Closed opened this
Closed without merging

scout/forge:scout/6348-a-hold-placed-because-a-pull-was-red-rel → main 7 commits fork 10 threads · 10 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
12 files changed +197 −10
docs/MCP.md +1 −1
@@ -80,7 +80,7 @@ for a tunnel and a forge that sleeps.
8080 | `forges` | an admin's list of the forges sent from here: name, address, whom for, apps, claimed or not, last activity | |
8181 | `front_page` | `{ pinned?, hidden?, weights?, dryRun? }`: the front page as a stranger sees it, ranked, with numbers; a site admin sets what is pinned (first public one featured), hidden, and what counts (weights of forks, ships, use, fresh, 0 to 10) | yes |
8282 | `health` | how this forge is: the version and commit it runs, draining or not, the rollout and its incidents | |
83 | `hold` | `{ app, pull | path, why?, until?, release?, dryRun? }`: hold a pull so no rule reviews or lands it, or let it go; a person who can write, never an agent; or with `path` (no `pull`) hold new work on a file so the picker starts no build whose issue names it, or list the holds and who set each; an admin of the app; plans unless `dryRun: false` | yes |
83 | `hold` | `{ app, pull | path, why?, until?, forRed?, release?, dryRun? }`: hold a pull so no rule reviews or lands it, or let it go; `until: "green"` frees it when a check passes on its head; `forRed` frees it on green or in a day; a person who can write, never an agent; or with `path` (no `pull`) hold new work on a file so the picker starts no build whose issue names it, or list the holds and who set each; an admin of the app; plans unless `dryRun: false` | yes |
8484 | `hooks` | `{ repo, action, url, secret, kinds, id }`: `list`, `add` (`secret`, 16–200 characters, is required) or `remove` the repository's webhooks, as `…/hooks`; an admin-scope token on a repository you administer, and a secret is never shown | yes |
8585 | `invites` | `{ action, id? }`: `list` the outstanding invites (state and expiry, never a link) or `revoke` one by `id`; a person admin with an admin token, stricter than the API's list, which an `ro` token may read | yes |
8686 | `issue` | `{ repo, number }`: one issue's title, state, closeReason, body, labels, assignee, comments (author, authorIsAgent, body, at) and blockedBy/blocks, as `GET …/issues/:number`; a sealed one you cannot see is not found; draws the `ui://forge/issue` card: title, state, assignee, labels and what it waits for, never the body or comments | |
src/actions/holds.ts +13 −2
@@ -47,7 +47,9 @@ function requireHolder(
4747
4848 /**
4949 * Hold an open pull, with one line that says why. Holding a held pull
50 * changes who and why. `dry` checks everything and answers with the hold
50 * changes who and why. `forRed` says the hold is for the red on the pull's
51 * current head: the tick lets it go when that head is green, or after a
52 * day (`crew/hold_sweep.ts`). `dry` checks everything and answers with the hold
5153 * that would stand, and writes nothing.
5254 */
5355 export function holdPull(
@@ -58,6 +60,7 @@ export function holdPull(
5860 why: string,
5961 dry = false,
6062 until?: "green",
63 forRed = false,
6164 ): Result<Hold, HoldError> {
6265 const holder = requireHolder(app, actor, repo, pull);
6366 if (!holder.ok) return holder;
@@ -72,8 +75,16 @@ export function holdPull(
7275 why: reason.value,
7376 heldAt: getHold(app.db, pull.id)?.heldAt ?? new Date().toISOString(),
7477 ...(until ? { until } : {}),
78 redHead: forRed ? pull.headOid : null,
7579 });
outdated

Medium: red_head is written but never shown. The pull page, GET …/hold, the studio and the tty cannot tell an automatic hold from a person's, so nobody can see a hold is due to let itself go. Show it where the hold is read (Hold gains forRed/redHead, and the pull's hold line says "held for red: frees on green or in a day").

76 const hold = setHold(app.db, pull.id, holder.value.id, reason.value, until);
80 const hold = setHold(
81 app.db,
82 pull.id,
83 holder.value.id,
84 reason.value,
85 until,
86 forRed ? pull.headOid : null,
87 );
7788 app.bus.append({
7889 kind: "pull.held",
7990 repoId: repo.id,
src/core/holds.ts +49 −5
@@ -28,6 +28,8 @@ export interface Hold {
2828 readonly heldAt: string;
2929 /** "green": the forge lets it go when a check passes on the pull's head. */
3030 readonly until?: "green";
31 /** The head a red-placed hold was placed on; null for a person's hold. */
32 readonly redHead: string | null;
3133 }
3234
3335 interface Row {
@@ -37,6 +39,7 @@ interface Row {
3739 why: string;
3840 held_at: string;
3941 until_green: number;
42 red_head: string | null;
4043 }
4144
4245 const fromRow = (row: Row): Hold => ({
@@ -46,10 +49,11 @@ const fromRow = (row: Row): Hold => ({
4649 why: row.why,
4750 heldAt: row.held_at,
4851 ...(row.until_green === 1 ? { until: "green" as const } : {}),
52 redHead: row.red_head,
4953 });
5054
5155 const STANDING = `SELECT pull_hold.issue_id, pull_hold.held_by, user.username,
52 pull_hold.why, pull_hold.held_at, pull_hold.until_green
56 pull_hold.why, pull_hold.held_at, pull_hold.until_green, pull_hold.red_head
5357 FROM pull_hold JOIN user ON user.id = pull_hold.held_by
5458 WHERE pull_hold.released_at IS NULL`;
5559
@@ -99,18 +103,19 @@ export function setHold(
99103 by: string,
100104 why: string,
101105 until?: "green",
106 redHead: string | null = null,
102107 ): Hold {
103108 const green = until === "green" ? 1 : 0;
104109 const changed = db
105110 .query(
106 `UPDATE pull_hold SET held_by = ?2, why = ?3, until_green = ?4
111 `UPDATE pull_hold SET held_by = ?2, why = ?3, until_green = ?4, red_head = ?5
107112 WHERE issue_id = ?1 AND released_at IS NULL`,
108113 )
109 .run(pullId, by, why, green).changes;
114 .run(pullId, by, why, green, redHead).changes;
110115 if (changed === 0)
111116 db.query(
112 "INSERT INTO pull_hold (id, issue_id, held_by, why, until_green) VALUES (?1, ?2, ?3, ?4, ?5)",
113 ).run(id(), pullId, by, why, green);
117 "INSERT INTO pull_hold (id, issue_id, held_by, why, until_green, red_head) VALUES (?1, ?2, ?3, ?4, ?5, ?6)",
118 ).run(id(), pullId, by, why, green, redHead);
114119 return getHold(db, pullId)!;
115120 }
116121
@@ -127,6 +132,45 @@ export function releaseHold(db: Database, pullId: string, by: string): boolean {
127132 );
128133 }
129134
135 /** A hold the rules placed because the pull was red: the head it was red on, and since when. */
136 export interface RedHold {
137 readonly pullId: string;
138 readonly heldBy: string;
139 readonly redHead: string;
140 readonly heldAt: string;
141 }
142
143 /** Every standing hold placed for red. A person's hold is never among them. */
144 export function redHolds(db: Database): RedHold[] {
145 return db
146 .query<
147 { issue_id: string; held_by: string; red_head: string; held_at: string },
148 []
149 >(
150 `SELECT issue_id, held_by, red_head, held_at FROM pull_hold
151 WHERE released_at IS NULL AND red_head IS NOT NULL`,
152 )
153 .all()
154 .map((r) => ({
155 pullId: r.issue_id,
156 heldBy: r.held_by,
157 redHead: r.red_head,
158 heldAt: r.held_at,
159 }));
160 }
161
162 /** Let a red-placed hold go in the forge's own name: no person released it. False when it no longer stands. */
163 export function releaseRedHold(db: Database, pullId: string): boolean {
164 return (
165 db
166 .query(
167 `UPDATE pull_hold SET released_at = strftime('%Y-%m-%dT%H:%M:%fZ','now')
168 WHERE issue_id = ?1 AND released_at IS NULL AND red_head IS NOT NULL`,
169 )
170 .run(pullId).changes > 0
171 );
172 }
173
130174 /**
131175 * The forge lets go of a hold set "until green". False when none stands or
132176 * the hold is a plain one: a green check never lifts those.
src/core/migration-pins.json +1
@@ -122,5 +122,6 @@
122122 "20261019140000-route-timing": "0fd7cfa4e0a50c4b2b36162601f9ddc3318e7fa445559732364b2b52a06de011",
123123 "20261019150000-page-vitals": "63fe647d95733a5194a99ae955181f2456d5c2e8c9c38d37bbf1bad395b72bdf",
124124 "20261020120000-app-vitals-five": "6c75f4137e5592bf728ffe05d42d33bc158c9dabab3c666c58bc7b6dceb57576",
125 "20261026120000-hold-for-red": "77b7d02257e9dd589fb5ad0827d159607f1913caf27e476111dc9450187b1f15",
125126 "20261026190000-hold-until-green": "2be50f3a7ee590b05ae1048f3adbe7040452501a9c684d981e2efbaf88256c58"
126127 }
src/core/migrations/20261026120000-hold-for-red.ts added +6
@@ -0,0 +1,6 @@
1 // A hold the forge's own rules placed because a pull was red (#6348) keeps
2 // the head it was red on, so the tick can let it go when that head is
3 // green. Null: a person's hold, which only a person lets go. Additive.
4 export default `
5 ALTER TABLE pull_hold ADD COLUMN red_head TEXT;
6 `;
src/crew/autonomy.ts +7
@@ -50,6 +50,7 @@ import {
5050 stopStands,
5151 } from "../core/decisions.ts";
5252 import { getHold } from "../core/holds.ts";
53 import { sweepRedHolds } from "./hold_sweep.ts";
5354 import { certain } from "./decide.ts";
5455 import { decideAndRecord } from "./ledger.ts";
5556 import { sentinelTick } from "./sentinel.ts";
@@ -1362,6 +1363,12 @@ export async function autonomyTick(
13621363 } catch (error) {
13631364 log.error("sentinel failed", { error: String(error) });
13641365 }
1366 // A hold placed for red lets go on green or after a day (`hold_sweep.ts`).
1367 try {
1368 sweepRedHolds(app, now.getTime());
1369 } catch (error) {
1370 log.error("hold sweep failed", { error: String(error) });
1371 }
13651372 // Review is not autonomy's alone: an agent's green pull is read by the
13661373 // crew's reviewer in every repository that has one.
13671374 try {
src/crew/hold_sweep.ts added +42
@@ -0,0 +1,42 @@
1 /**
2 * A hold placed for red lets itself go (#6348). The tick releases it when
3 * the pull's check on its head is green (the red head or a newer one), and after a day

Re-wrap this docblock: the parenthetical runs past the line width.

4 * whatever the check says: a hold nobody remembers is not a hold. A
5 * person's hold (no `red_head`) is never read here.
6 */
7
8 import type { App } from "../app.ts";
9 import { redHolds, releaseRedHold } from "../core/holds.ts";
10 import { getIssueById } from "../core/issues.ts";
11 import { getPull } from "../core/pulls.ts";
12 import { verdictForHead } from "../core/runs.ts";
13
14 /** How long an automatic hold may stand. */
15 export const AUTO_HOLD_MS = 24 * 60 * 60 * 1000;
16
17 /** Release every red-placed hold that is green on its head or a day old; how many went. */
18 export function sweepRedHolds(app: App, now: number): number {
19 let released = 0;
20 for (const hold of redHolds(app.db)) {
21 const issue = getIssueById(app.db, hold.pullId);
22 if (!issue) continue;
23 const pull = getPull(app.db, issue.repoId, issue.number);
24 if (!pull) continue;
25 const checks = verdictForHead(app.db, pull.id, pull.headOid);
26 const green =
27 checks.length > 0 &&
outdated

Low: when the builder pushes a fix and the new head goes green, the hold stays for 24 h. The red it was placed for no longer exists, and the hold now blocks a green pull. That matches the title's "same head" reading, but it is the common case. Consider releasing when the head moved and the new head is green, or explain in the pull why the hold should wait.

28 checks.every((c) => c.state === "ok");
29 const aged = now - Date.parse(hold.heldAt) >= AUTO_HOLD_MS;
30 if (!green && !aged) continue;
31 if (!releaseRedHold(app.db, hold.pullId)) continue;
32 released++;
33 // The forge let it go: no person is named, and no comment is signed as
34 // the holder. The event is what the live page and the feed read.
35 app.bus.append({
36 kind: "pull.released",
outdated

High: once this succeeds, append pull.released to app.bus (repoId, payload: { number, auto: true }) the way releasePull does. Without it the live page and the activity feed still show the pull as held.

outdated

High: this event has no actor, and eventActor falls back to "someone" for every pull.* kind. The feed then credits a person who does not exist with the release. Credit "the forge" when payload.auto is set, use words that carry reason, and test the rendered line. That line is the issue's "note on the pull".

37 repoId: pull.repoId,
38 payload: { number: pull.number, auto: true, reason: green ? (pull.headOid === hold.redHead ? "green" : "moved") : "aged" },

Run this through the formatter; it's well past the line width. Give the nested ternary a name too, e.g. const reason = !green ? "aged" : pull.headOid === hold.redHead ? "green" : "moved".

39 });
40 }
41 return released;
42 }
outdated

High: this posts a comment as the person who placed the hold, saying something they never wrote. Do not author it as hold.heldBy. Use a non-person/system author, or rely on the bus event alone.

src/design/activity.ts +7
@@ -78,6 +78,12 @@ export function eventVerb(event: ForgeEvent): string {
7878 ? `told the crew the top Instagram comment as #${issue}`
7979 : "told the crew the top Instagram comment";
8080 }
81 if (kind === "pull.released" && payload["auto"] === true)
82 return payload["reason"] === "aged"
83 ? "released the hold: it stood a day"
84 : payload["reason"] === "moved"
85 ? "released the hold: the new head is green"
86 : "released the hold: green on its head";
8187 return WORDS[kind] ?? "acted on this repository";
8288 }
8389
@@ -88,6 +94,7 @@ export function eventActor(
8894 ): string {
8995 if (actorName !== undefined) return actorName;
9096 return event.kind.startsWith("run.") ||
97 (event.kind === "pull.released" && event.payload["auto"] === true) ||
9198 event.kind.startsWith("app.") ||
9299 event.kind.startsWith("prompt.") ||
93100 (event.kind === "pull.released" && event.actorId === null)
src/http/api.ts +1
@@ -1224,6 +1224,7 @@ const holdJson = (hold: Hold) => ({
12241224 why: hold.why,
12251225 at: hold.heldAt,
12261226 ...(hold.until ? { until: hold.until } : {}),
1227 forRed: hold.redHead !== null,
12271228 });
12281229
12291230 function loadPull(ctx: Ctx): Found<{ pull: Pull }> {
src/http/mcp/tools/hold.ts +3 −1
@@ -47,7 +47,7 @@ function fileHold(ctx: Ctx, user: User, repo: Repo, args: Args): Answer {
4747
4848 export const tool: Tool = {
4949 name: "hold",
50 doc: "`{ app, pull | path, why?, until?, release?, dryRun? }`: hold a pull so no rule reviews or lands it, or let it go; a person who can write, never an agent; or with `path` (no `pull`) hold new work on a file so the picker starts no build whose issue names it, or list the holds and who set each; an admin of the app; plans unless `dryRun: false`",
50 doc: "`{ app, pull | path, why?, until?, forRed?, release?, dryRun? }`: hold a pull so no rule reviews or lands it, or let it go; `until: \"green\"` frees it when a check passes on its head; `forRed` frees it on green or in a day; a person who can write, never an agent; or with `path` (no `pull`) hold new work on a file so the picker starts no build whose issue names it, or list the holds and who set each; an admin of the app; plans unless `dryRun: false`",
5151 description:
5252 "Hold a pull (`why`) or `release` it; or `path`: hold new work on a file. Neither: list file holds.",
5353 inputSchema: {
@@ -65,6 +65,7 @@ export const tool: Tool = {
6565 enum: ["green"],
6666 description: "green: released when a check passes.",
6767 },
68 forRed: { type: "boolean" },
6869 release: {
6970 type: "boolean",
7071 },
@@ -115,6 +116,7 @@ export const tool: Tool = {
115116 str(args["why"]),
116117 dry,
117118 args["until"] === "green" ? "green" : undefined,
119 args["forRed"] === true,
118120 );
119121 if (!held.ok)
120122 return bad(
src/web/studio/hold.ts +3 −1
@@ -47,7 +47,9 @@ export function holdCard(
4747 )}
4848 <p class="muted small">
4949 No rule sends it to review or lands it until it is released. A person
50 can still ship it.
50 can still ship it.${hold.redHead === null
51 ? ""
52 : " Held for red: it frees when the check is green or in a day."}
5153 </p>
5254 ${when(
5355 may,
test/holds.test.ts +64
@@ -32,6 +32,9 @@ import { claimRun, createRun, finishRun, listRuns } from "../src/core/runs.ts";
3232 import { createToken } from "../src/core/tokens.ts";
3333 import { createUser, getUserByName, type User } from "../src/core/users.ts";
3434 import { landIfGreen, parkPull } from "../src/crew/autonomy.ts";
35 import { eventActor, eventVerb } from "../src/design/activity.ts";
36 import { AUTO_HOLD_MS, sweepRedHolds } from "../src/crew/hold_sweep.ts";
37 import { listComments } from "../src/core/issues.ts";
3538 import { sendToReview, sweepReviews } from "../src/crew/review.ts";
3639 import { serve, type Servers } from "../src/http/server.ts";
3740 import { recordAskLedger } from "../src/web/studio/asks.ts";
@@ -902,6 +905,67 @@ describe("a hold, as it is kept", () => {
902905 });
903906 });
904907
908 describe("a hold placed for red lets itself go (#6348)", () => {
909 test("green on the same head releases it, with a note; green on a newer head too, a person's hold, and a young red hold stay", async () => {
910 const f = await forge("forge-hold-red-", "public");
911 try {
912 const now = Date.now();
913 const same = await f.pullOn("same");
914 const moved = await f.pullOn("moved");
915 const hand = await f.pullOn("hand");
916 const waiting = await f.pullOn("waiting");
917 for (const p of [same, moved, hand]) f.passCheck(p);
918 expect(
919 holdPull(f.app, f.alice, f.repo, same, "red alone, held", false, undefined, true).ok,
920 ).toBe(true);
921 // Held for red on a head the pull has since left.
922 setHold(f.app.db, moved.id, f.alice.id, "red alone, held", undefined, "0".repeat(40));
923 setHold(f.app.db, hand.id, f.alice.id, "wait for the design");
924 holdPull(f.app, f.alice, f.repo, waiting, "red", false, undefined, true);
925
926 expect(sweepRedHolds(f.app, now)).toBe(2);
927 expect(getHold(f.app.db, same.id)).toBeUndefined();
928 expect(getHold(f.app.db, moved.id)).toBeUndefined();
929 expect(getHold(f.app.db, hand.id)).toBeDefined();
930 expect(getHold(f.app.db, waiting.id)).toBeDefined();
931 expect(lastRelease(f.app.db, same.id)).toBeDefined();
932 // The release is an event with no person behind it, and no comment is
933 // signed as the holder.
934 const events = f.app.db
935 .query<{ actor_id: string | null; payload: string }, [string]>(
936 "SELECT actor_id, payload FROM event WHERE kind = 'pull.released' AND repo_id = ?1",
937 )
938 .all(f.repo.id);
939 expect(events.length).toBe(2);
940 expect(events[0]!.actor_id).toBeNull();
941 expect(JSON.parse(events[0]!.payload)).toEqual({
942 number: same.number,
943 auto: true,
944 reason: "green",
945 });
946 expect(JSON.parse(events[1]!.payload).reason).toBe("moved");
947 expect(listComments(f.app.db, same.id)).toEqual([]);
948 // The feed names the forge and the reason, not "someone".
949 const ev = { kind: "pull.released", payload: JSON.parse(events[0]!.payload) } as never;
950 expect(eventActor(ev, undefined)).toBe("the forge");
951 expect(eventVerb(ev)).toBe("released the hold: green on its head");
952 const aged = { kind: "pull.released", payload: { auto: true, reason: "aged" } } as never;
953 expect(eventVerb(aged)).toBe("released the hold: it stood a day");
954 const person = { kind: "pull.released", payload: {} } as never;
955 expect(eventActor(person, undefined)).toBe("someone");
956
957 // A day on, every red-placed hold goes; the person's never does.
958 const later = now + AUTO_HOLD_MS + 60_000;
959 expect(sweepRedHolds(f.app, later)).toBe(1);
960 expect(getHold(f.app.db, waiting.id)).toBeUndefined();
961 expect(getHold(f.app.db, hand.id)).toBeDefined();
962 expect(sweepRedHolds(f.app, later + AUTO_HOLD_MS * 10)).toBe(0);
963 } finally {
964 await f.close();
965 }
966 });
967 });
968
905969 describe("a hold set until green", () => {
906970 let f: Awaited<ReturnType<typeof forge>>;
907971 let app: App;

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs