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

A half-sure stop parks a red pull and closes it as done: the decider's stop takes the same 0.7 bar as its cause; a parked pull closes as parked #1469

Closed opened this in answer to
Closed without merging

mason/forge:mason/1354-a-half-sure-stop-parks-a-red-pull-and-cl → main 9 commits fork 2 threads · 2 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
11 files changed +267 −26
README.md +11
@@ -346,6 +346,17 @@ changes, a line comment — and the agent picks it up in the background,
346346 resuming its session. A failed check re-engages it too, a bounded number of
347347 times before a person must speak.
348348
349 A red check is weighed by the decider: the builder reworks the pull unless
350 the decider is sure (p ≥ 0.7) another try is pointless. Then, on an
351 autonomous repository, the crew **parks** the pull: it says why on the pull,
352 closes it unmerged, and hands its issues back to the map unassigned. A parked
353 pull is not delivered. Its `closeReason` is `parked` in the API and on the
354 `pull.closed` event, the change page says the crew parked it and the timeline
355 "parked this", and the terminal's fleet plans read it as `closed (parked)`.
356 Parked differs from dropped: a person drops an *issue* they will not do,
357 while only the crew parks, and only a *pull* — nobody can choose it when
358 closing. Reopening a parked pull clears it.
359
349360 **Already done.** A builder that finds its issue already built on the base
350361 branch declines with `DECLINED: already done on main in <commit>`, naming the
351362 full or abbreviated id of each commit that did it (at most five). The forge
src/actions/issues.ts +10 −2
@@ -407,7 +407,12 @@ export function setIssueState(
407407 return err("already_merged");
408408 const reason = state === "closed" ? (closing.reason ?? "done") : undefined;
409409 const children: Issue[] = [];
410 if (closing.reason !== undefined || closing.into !== undefined) {
410 if (closing.reason === "parked") {
411 // Parked is how the crew closes a pull it could not land (`parkPull`),
412 // and nothing else: an issue is dropped or split, never parked.
413 if (state !== "closed" || issue.kind !== "pull" || closing.into !== undefined)
414 return err("invalid_reason");
415 } else if (closing.reason !== undefined || closing.into !== undefined) {
411416 // A reason is how an issue closes; a pull or a reopen has none.
412417 if (state !== "closed" || issue.kind !== "issue")
413418 return err("invalid_reason");
@@ -449,7 +454,10 @@ export function setIssueState(
449454 actorId: user.value.id,
450455 payload: {
451456 number: issue.number,
452 ...(issue.kind === "issue" && reason !== undefined ? { reason } : {}),
457 ...((issue.kind === "issue" || reason === "parked") &&
458 reason !== undefined
459 ? { reason }
460 : {}),
453461 ...(children.length > 0 ? { into: children.map((c) => c.number) } : {}),
454462 },
455463 });
src/core/issues.ts +16 −7
@@ -12,8 +12,13 @@ import { repoVisible } from "./visibility.ts";
1212
1313 export type IssueKind = "issue" | "pull";
1414 export type IssueState = "open" | "closed";
15 /** Why an issue closed: done frees what waited on it; the others hold it. */
16 export type CloseReason = "done" | "dropped" | "split";
15 /**
16 * Why an issue closed: done frees what waited on it; the others hold it.
17 * `parked` is the crew's own, for a pull it closed without landing
18 * (`parkPull`); nobody chooses it, so it is not in `CLOSE_REASONS`.
19 */
20 export type CloseReason = "done" | "dropped" | "split" | "parked";
21 /** The reasons a person may close an issue with. */
1722 export const CLOSE_REASONS: readonly CloseReason[] = [
1823 "done",
1924 "dropped",
@@ -77,7 +82,8 @@ interface IssueRow {
7782 created_at: string;
7883 updated_at: string;
7984 closed_at: string | null;
80 close_reason: CloseReason | null;
85 close_reason: Exclude<CloseReason, "parked"> | null;
86 parked: number;
8187 origin_author: string | null;
8288 origin_html_url: string | null;
8389 assignee_id: string | null;
@@ -107,7 +113,8 @@ function toIssue(row: IssueRow): Issue {
107113 createdAt: row.created_at,
108114 updatedAt: row.updated_at,
109115 closedAt: row.closed_at,
110 closeReason: row.close_reason,
116 closeReason:
117 row.state === "closed" && row.parked === 1 ? "parked" : row.close_reason,
111118 originAuthor: row.origin_author,
112119 originUrl: row.origin_html_url,
113120 assigneeId: row.assignee_id,
@@ -469,12 +476,14 @@ export function setIssueState(
469476 ): Issue | undefined {
470477 const now = new Date().toISOString();
471478 const closedAt = state === "closed" ? now : null;
472 const why = state === "closed" ? reason : null;
479 const parked = state === "closed" && reason === "parked";
480 // Parked is stored as dropped plus the flag (migration 77).
481 const why = state !== "closed" ? null : parked ? "dropped" : reason;
473482 const changed = db
474483 .query(
475 "UPDATE issue SET state = ?1, closed_at = ?2, updated_at = ?3, close_reason = ?5 WHERE id = ?4 AND state != ?1",
484 "UPDATE issue SET state = ?1, closed_at = ?2, updated_at = ?3, close_reason = ?5, parked = ?6 WHERE id = ?4 AND state != ?1",
476485 )
477 .run(state, closedAt, now, issueId, why).changes;
486 .run(state, closedAt, now, issueId, why, parked ? 1 : 0).changes;
478487 return changed > 0 ? getIssueById(db, issueId) : undefined;
479488 }
480489
src/core/schema.ts +8
@@ -1614,6 +1614,14 @@ export const migrations: readonly string[] = [
16141614 PRIMARY KEY (key, issue_id)
16151615 );
16161616 `,
1617 // 77 — a pull the crew parked (#1354): closed without landing. Its
1618 // `close_reason` is stored as 'dropped', which the CHECK of 44 already
1619 // allows and an older process reads as not delivered; `toIssue` reads
1620 // the pair as `parked`. A column, not a widened CHECK: that would mean a
1621 // table rebuild.
1622 `
1623 ALTER TABLE issue ADD COLUMN parked INTEGER NOT NULL DEFAULT 0;
1624 `,
16171625 ];
16181626
16191627 /**
src/crew/autonomy.ts +4 −1
@@ -956,7 +956,10 @@ export function parkPull(
956956 const issue = getIssueById(app.db, pull.id);
957957 if (!issue || issue.state !== "open") return false;
958958 addComment(app, by, repo, issue, `${PARK_NOTE}${why}`);
959 const closed = setIssueState(app, by, repo, issue, "closed");
959 // Parked, not done: the record of a pull that never landed says so.
960 const closed = setIssueState(app, by, repo, issue, "closed", {
961 reason: "parked",
962 });
960963 if (!closed.ok) return false;
961964 for (const number of closesFromBody(pull.body)) {
962965 const about = getIssue(app.db, repo.id, number);
src/crew/dispatch.ts +16 −6
@@ -758,6 +758,9 @@ export interface CheckJudgement {
758758 readonly failingTest: string | undefined;
759759 }
760760
761 /** How sure the decider must be for its answer to stand over the rule's. */
762 const SURE = 0.7;
763
761764 const RETRY_OPTIONS = ["again", "stop"];
762765 const CAUSE_OPTIONS = ["change", "environment", "base"];
763766
@@ -835,18 +838,25 @@ export async function judgeFailedCheck(
835838 cause: certain(CAUSE_OPTIONS, "change"),
836839 }),
837840 );
838 const retry = decided.answers.retry.choice === "stop" ? "stop" : "again";
839 // The change is what a half-sure answer means: an environment called
841 // A half-sure answer means the cheap path, for both questions. A stop
842 // throws the pull away, so it takes the bar: below it the builder reworks.
843 const stopP = decided.answers.retry.p;
844 const stopChosen = decided.answers.retry.choice === "stop";
845 const retry = stopChosen && stopP >= SURE ? "stop" : "again";
846 // The change is what a half-sure cause means: an environment called
840847 // that way on a hunch is how a broken change escapes a rework.
841848 const cause =
842 decided.answers.cause.p >= 0.7
849 decided.answers.cause.p >= SURE
843850 ? (decided.answers.cause.choice as CheckJudgement["cause"])
844851 : "change";
845 if (retry === "stop")
846 log.info("check failed; the decider stopped here for a person", {
852 if (stopChosen)
853 log.info("check failed; the decider's answer", {
847854 issue: issue.number,
848855 by: decided.by,
849 p: decided.answers.retry.p.toFixed(2),
856 retry:
857 retry === "stop"
858 ? `stop (p=${stopP.toFixed(2)})`
859 : `again: a half-sure stop reworks (p=${stopP.toFixed(2)})`,
850860 cause,
851861 });
852862 return { retry, cause, failingTest };
src/web/pages/pull.ts +5 −1
@@ -347,7 +347,11 @@ function mergeBox(
347347 return card(
348348 html`${icon("x")}
349349 <div class="grow">
350 <div class="merge-headline">Closed without merging.</div>
350 <div class="merge-headline">
351 ${pull.closeReason === "parked"
352 ? "Parked by the crew: closed without merging."
353 : "Closed without merging."}
354 </div>
351355 <p class="merge-sub">
352356 Nothing was applied to
353357 <span class="mono">${pull.baseBranch}</span>.
src/web/pages/thread.ts +4 −1
@@ -174,7 +174,10 @@ function stateEvents(ctx: Ctx, repo: Repo, issue: Issue): Entry[] {
174174 );
175175 const entries: Entry[] = [];
176176 for (const event of events) {
177 const look = EVENT_LOOK[event.kind]!;
177 const look =

The "parked this" verb has no test; render a parked thread and assert it.

178 event.kind === "pull.closed" && event.payload.reason === "parked"
179 ? { ...EVENT_LOOK[event.kind]!, verb: "parked this" }
180 : EVENT_LOOK[event.kind]!;
178181 const actor =
179182 event.actorId !== null ? actors.get(event.actorId) : undefined;
180183 entries.push({
src/web/studio/words.ts +8 −2
@@ -180,7 +180,7 @@ function checkRunWord(check: CheckSummary): { word: Word; note: string } {
180180
181181 /**
182182 * A pull's word: open goes by its own check, closed without a merge is
183 * simply stopped, and merged is *shipped* only once production is at or
183 * simply stopped (a parked one says the crew parked it), and merged is *shipped* only once production is at or
184184 * past the commit that merge carried — the one place that fact is asked,
185185 * so the app page, the change page, the home and the board never invent
186186 * their own answer to it.
@@ -209,7 +209,13 @@ export async function pullWord(
209209 return mergedPullWord(production, commitOid);
210210 }
211211 if (pull.state === "closed")
212 return { word: "stopped", note: "closed without shipping" };
212 return {
213 word: "stopped",
214 note:
215 pull.closeReason === "parked"
216 ? "parked by the crew, never landed"
217 : "closed without shipping",
218 };
213219 const check = checkSummary(ctx.db, pull.id, pull.headOid);
214220 // A repository that is not an app never deploys a head, so it never gets
215221 // a look: an open change there waits on a person, and says so.
test/ledger.test.ts +142 −5
@@ -36,8 +36,14 @@ import { answerFailedCheck, judgeFailedCheck } from "../src/crew/dispatch.ts";
3636 import { startChecks } from "../src/checks/service.ts";
3737 import { serve, type Servers } from "../src/http/server.ts";
3838
39 /** A decider that answers from a script: question name → choice. */
40 function scripted(answers: Record<string, string>): Decider & {
39 /**
40 * A decider that answers from a script: question name → choice, sure to
41 * p = 0.8 unless `sure` names another for that question.
42 */
43 function scripted(
44 answers: Record<string, string>,
45 sure: Record<string, number> = {},
46 ): Decider & {
4147 seen: unknown[];
4248 } {
4349 const seen: unknown[] = [];
@@ -50,8 +56,10 @@ function scripted(answers: Record<string, string>): Decider & {
5056 for (const [key, q] of Object.entries(questions)) {
5157 const choice = answers[key] ?? q.options[0]!;
5258 const probabilities: Record<string, number> = {};
53 for (const o of q.options) probabilities[o] = o === choice ? 0.8 : 0.2;
54 out[key] = { choice, p: 0.8, probabilities };
59 const p = sure[key] ?? 0.8;
60 for (const o of q.options)
61 probabilities[o] = o === choice ? p : (1 - p) / (q.options.length - 1);
62 out[key] = { choice, p, probabilities };
5563 }
5664 return out as { [K in keyof Q]: Answer };
5765 },
@@ -66,7 +74,8 @@ describe("the decision ledger", () => {
6674 let scout: User;
6775 let repo: Repo;
6876 const script: Record<string, string> = {};
69 const decider = scripted(script);
77 const sure: Record<string, number> = {};
78 const decider = scripted(script, sure);
7079 const fresh = () => getRepoById(app.db, repo.id)!;
7180
7281 beforeAll(async () => {
@@ -422,6 +431,134 @@ describe("the decision ledger", () => {
422431 }
423432 });
424433
434 test("a half-sure stop reworks; a sure one parks, and the pull closes as parked, not done (#1354)", async () => {
435 const { getAgentByName } = await import("../src/core/agents.ts");
436 const { listEvents } = await import("../src/core/events.ts");
437 const { setIssueState } = await import("../src/actions/issues.ts");
438 const scoutAgent = getAgentByName(app.db, "scout")!;
439 const branch = await commitToBranch(app, alice, repo, {
440 branch: "feature/unsure",
441 base: "main",
442 message: "Unsure",
443 files: [{ path: "unsure.ts", content: "export const unsure = 1;\n" }],
444 });
445 if (!branch.ok) throw new Error(JSON.stringify(branch.error));
446 const opened = await openPull(app, scout, repo, {
447 title: "Unsure",
448 baseBranch: "main",
449 headBranch: "feature/unsure",
450 });
451 if (!opened.ok) throw new Error(String(opened.error));
452 const pull = opened.value;
453 const red = (): string => {
454 const run = createRun(app.db, {
455 repoId: repo.id,
456 kind: "check",
457 issueId: pull.id,
458 env: `pull-${pull.number}`,
459 commitOid: pull.headOid,
460 reason: "pull",
461 });
462 claimRun(app.db, run.id);
463 finishRun(app.db, run.id, {
464 state: "failed",
465 summary: "check failed: 1 of 18 tests",
466 });
467 return run.id;
468 };
469 const failure = {
470 kind: "check",
471 commitOid: pull.headOid,
472 env: `pull-${pull.number}`,
473 since: pull.createdAt,
474 };
475 const reworks = () =>
476 listRuns(app.db, repo.id, { kind: "agent" }).filter(
477 (r) => r.issueId === pull.id && r.reason === "check_failed",
478 ).length;
479 script["retry"] = "stop";
480 script["cause"] = "change";
481 try {
482 // p = 0.6: unsure means the cheap path. The builder reworks it and
483 // the pull stays open.
484 sure["retry"] = 0.6;
485 expect(
486 await answerFailedCheck(app, fresh(), pull, scoutAgent, {
487 runId: red(),
488 ...failure,
489 }),
490 ).toBe("reworked");
491 expect(reworks()).toBe(1);
492 expect(getPull(app.db, repo.id, pull.number)?.state).toBe("open");
493
494 // p = 0.8: a sure stop parks it, and the record says parked.
495 sure["retry"] = 0.8;
496 expect(
497 await answerFailedCheck(app, fresh(), pull, scoutAgent, {
498 runId: red(),
499 ...failure,
500 }),
501 ).toBe("parked");
502 expect(reworks()).toBe(1);
503 const parked = getPull(app.db, repo.id, pull.number)!;
504 expect(parked.state).toBe("closed");
505 expect(parked.closeReason).toBe("parked");
506 const closed = listEvents(app.db, { repoId: repo.id, limit: 50 }).find(
507 (e) => e.kind === "pull.closed" && e.payload["number"] === pull.number,
508 );
509 expect(closed?.payload["reason"]).toBe("parked");
510
511 // The pages say parked: the timeline's verb, the change's word, the
512 // merge box on its files step, and the changes list.
513 const cookie = (
514 (
515 await fetch(`${servers.url}/signin`, {
516 method: "POST",
517 body: new URLSearchParams({
518 username: "alice",
519 password: "a-good-passphrase",
520 }),
521 redirect: "manual",
522 })
523 ).headers.get("set-cookie") ?? ""
524 ).split(";")[0]!;
525 const read = async (path: string) =>
526 (await fetch(`${servers.url}${path}`, { headers: { cookie } })).text();
527 const page = await read(`/alice/shop/pulls/${pull.number}`);
528 expect(page).toContain("parked this");
529 expect(page).toContain("parked by the crew, never landed");
530 expect(await read(`/alice/shop/pulls/${pull.number}/files`)).toContain(
531 "Parked by the crew: closed without merging.",
532 );
533 expect(await read("/alice/shop/pulls?state=closed")).toContain(
534 "parked by the crew, never landed",
535 );
536 // The terminal's plans read it the same way.
537 const { VERBS } = await import("../src/fleet/verbs.ts");
538 expect(VERBS["drop"]!.read({ issue: parked } as never)).toBe(
539 "closed (parked)",
540 );
541
542 // Reopened, it is no longer parked; nobody may close as parked but
543 // the crew, and never an issue.
544 expect(
545 setIssueState(app, alice, fresh(), parked, "open").ok,
546 ).toBe(true);
547 expect(getPull(app.db, repo.id, pull.number)?.closeReason).toBeNull();
548 const ask = await openIssue(app, alice, fresh(), { title: "An ask" });
549 if (!ask.ok) throw new Error(String(ask.error));
550 expect(
551 setIssueState(app, alice, fresh(), ask.value, "closed", {
552 reason: "parked",
553 }),
554 ).toEqual({ ok: false, error: "invalid_reason" });
555 } finally {
556 delete script["retry"];
557 delete script["cause"];
558 delete sure["retry"];
559 }
560 });
561
425562 test("conflicts come first: a green pull that no longer merges gets a conflict run before anyone decides", async () => {
426563 const branch = await commitToBranch(app, alice, repo, {
427564 branch: "feature/readme",
test/milestones.test.ts +43 −1
@@ -14,7 +14,7 @@ import { join } from "node:path";
1414 import { createApp, type App } from "../src/app.ts";
1515 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1616 import { linkIssue } from "../src/actions/dependencies.ts";
17 import { openIssue } from "../src/actions/issues.ts";
17 import { openIssue, setIssueState } from "../src/actions/issues.ts";
1818 import { mergePull, openPull } from "../src/actions/pulls.ts";
1919 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
2020 import { createApp as insertApp } from "../src/core/apps.ts";
@@ -515,4 +515,46 @@ describe("milestones", () => {
515515 expect(page).toMatch(/<b>0<\/b> of 2 done/);
516516 expect(page).toContain("A profit slider");
517517 });
518 test("a parked pull is not delivered: its issue stays open work and nothing merged (#1354)", async () => {
519 const before = readPlan(app.db, fresh(engine), { spend: false });
520 const p0 = before.limbs.find((l) => l.issue.number === trust.number)!;
521 const branch = await commitToBranch(app, alice, fresh(engine), {
522 branch: "feature/names",
523 base: "main",
524 message: "names",
525 files: [{ path: "names.md", content: "names\n" }],
526 });
527 if (!branch.ok) throw new Error(JSON.stringify(branch.error));
528 const opened = await openPull(app, mason, fresh(engine), {
529 title: "Reserve the names",
530 body: `Closes #${names.number}`,
531 baseBranch: "main",
532 headBranch: "feature/names",
533 });
534 if (!opened.ok) throw new Error(String(opened.error));
535 const parked = setIssueState(
536 app,
537 alice,
538 fresh(engine),
539 opened.value,
540 "closed",
541 { reason: "parked" },
542 );
543 if (!parked.ok) throw new Error(String(parked.error));
544 expect(parked.value.closeReason).toBe("parked");
545
546 const plan = readPlan(app.db, fresh(engine), { spend: false });
547 const after = plan.limbs.find((l) => l.issue.number === trust.number)!;
548 expect(after.weight).toMatchObject({
549 total: p0.weight.total,
550 done: p0.weight.done,
551 open: p0.weight.open,
552 merged: p0.weight.merged,
553 });
554 const m = plan.milestone(trust.number)!;
555 expect(m.merged.map((p) => p.number)).not.toContain(opened.value.number);
556 expect(
557 m.leaves.find((l) => l.issue.number === names.number)?.state,
558 ).toBe("ready");
559 });
518560 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs