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 #1370

Closed opened this in answer to
Closed without merging

scout/forge:scout/1354-a-half-sure-stop-parks-a-red-pull-and-cl → main 2 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
8 files changed +155 −15
docs/PLANNING.md +1
@@ -526,6 +526,7 @@ long it took are always in the forge's log.
526526 ## Closing takes a reason
527527
528528 `PATCH …/issues/:n { "state": "closed", "reason": "done"|"dropped"|"split", "into": [m, …] }`.
529 A pull the crew parks closes with reason `parked` (set by the crew only; the endpoint above refuses it): it is not done, and no milestone counts it.
529530 No reason means done. Done frees what waited. Dropped or split closes the
530531 issue but holds its dependents as _parked_, the map saying why ("#4 was
531532 dropped"), until a writer relinks them or confirms the edge
src/actions/issues.ts +8 −2
@@ -406,7 +406,11 @@ export function setIssueState(
406406 return err("already_merged");
407407 const reason = state === "closed" ? (closing.reason ?? "done") : undefined;
408408 const children: Issue[] = [];
409 if (closing.reason !== undefined || closing.into !== undefined) {
409 if (reason === "parked") {
410 // Only a pull is parked, and only by closing it.
411 if (state !== "closed" || issue.kind !== "pull" || closing.into)
412 return err("invalid_reason");
413 } else if (closing.reason !== undefined || closing.into !== undefined) {
410414 // A reason is how an issue closes; a pull or a reopen has none.
411415 if (state !== "closed" || issue.kind !== "issue")
412416 return err("invalid_reason");
@@ -430,7 +434,9 @@ export function setIssueState(
430434 actorId: user.value.id,
431435 payload: {
432436 number: issue.number,
433 ...(issue.kind === "issue" && reason !== undefined ? { reason } : {}),
437 ...((issue.kind === "issue" || reason === "parked") && reason !== undefined
438 ? { reason }
439 : {}),
434440 ...(children.length > 0 ? { into: children.map((c) => c.number) } : {}),
435441 },
436442 });
src/core/issues.ts +15 −6
@@ -12,8 +12,12 @@ 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 a pull the crew gave up on: it never landed, so it is not
18 * done. Nobody picks it from a form; `CLOSE_REASONS` is what a person may say.
19 */
20 export type CloseReason = "done" | "dropped" | "split" | "parked";
1721 export const CLOSE_REASONS: readonly CloseReason[] = [
1822 "done",
1923 "dropped",
@@ -78,6 +82,7 @@ interface IssueRow {
7882 updated_at: string;
7983 closed_at: string | null;
8084 close_reason: CloseReason | null;
85 close_outcome: "parked" | null;
8186 origin_author: string | null;
8287 origin_html_url: string | null;
8388 assignee_id: string | null;
@@ -107,7 +112,7 @@ function toIssue(row: IssueRow): Issue {
107112 createdAt: row.created_at,
108113 updatedAt: row.updated_at,
109114 closedAt: row.closed_at,
110 closeReason: row.close_reason,
115 closeReason: row.close_outcome ?? row.close_reason,
111116 originAuthor: row.origin_author,
112117 originUrl: row.origin_html_url,
113118 assigneeId: row.assignee_id,
@@ -469,12 +474,16 @@ export function setIssueState(
469474 ): Issue | undefined {
470475 const now = new Date().toISOString();
471476 const closedAt = state === "closed" ? now : null;
472 const why = state === "closed" ? reason : null;
477 // `parked` lives in its own column: the reason column's CHECK cannot gain
478 // a word without a rebuild, and a migration may only add (#875). An old
479 // process reads the NULL reason as done, for the length of a roll.
480 const parked = state === "closed" && reason === "parked";
481 const why = state === "closed" && !parked ? reason : null;
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, close_outcome = ?6 WHERE id = ?4 AND state != ?1",
476485 )
477 .run(state, closedAt, now, issueId, why).changes;
486 .run(state, closedAt, now, issueId, why, parked ? "parked" : null).changes;
478487 return changed > 0 ? getIssueById(db, issueId) : undefined;
479488 }
480489
src/core/schema.ts +7
@@ -1578,6 +1578,13 @@ export const migrations: readonly string[] = [
15781578 expires_at TEXT NOT NULL
15791579 );
15801580 `,
1581 // 74 — a pull the crew parked closes as `parked`, not `done` (#1354).
1582 // The reason column's CHECK cannot take a new word without a rebuild, so
1583 // the outcome gets a column of its own.
1584 `
1585 ALTER TABLE issue ADD COLUMN close_outcome TEXT
1586 CHECK (close_outcome IN ('parked'));
1587 `,
15811588 ];
15821589
15831590 /**
src/crew/autonomy.ts +3 −1
@@ -820,7 +820,9 @@ export function parkPull(
820820 const issue = getIssueById(app.db, pull.id);
821821 if (!issue || issue.state !== "open") return false;
822822 addComment(app, by, repo, issue, `${PARK_NOTE}${why}`);
823 const closed = setIssueState(app, by, repo, issue, "closed");
823 const closed = setIssueState(app, by, repo, issue, "closed", {
824 reason: "parked",
825 });
824826 if (!closed.ok) return false;
825827 for (const number of closesFromBody(pull.body)) {
826828 const about = getIssue(app.db, repo.id, number);
src/crew/dispatch.ts +19 −4
@@ -750,6 +750,9 @@ export interface CheckJudgement {
750750 readonly failingTest: string | undefined;
751751 }
752752
753 /** How sure the decider must be of a cause, or of a stop, to act on it. */
754 const STOP_BAR = 0.7;
755
753756 const RETRY_OPTIONS = ["again", "stop"];
754757 const CAUSE_OPTIONS = ["change", "environment", "base"];
755758
@@ -823,18 +826,30 @@ export async function judgeFailedCheck(
823826 cause: certain(CAUSE_OPTIONS, "change"),
824827 }),
825828 );
826 const retry = decided.answers.retry.choice === "stop" ? "stop" : "again";
829 // A stop is the expensive answer — the pull is thrown away — so it takes
830 // the same bar as the cause: a half-sure stop reworks, which is the cheap
831 // path.
832 const asked = decided.answers.retry;
833 const stopped = asked.choice === "stop";
834 const retry = stopped && asked.p >= STOP_BAR ? "stop" : "again";
827835 // The change is what a half-sure answer means: an environment called
828836 // that way on a hunch is how a broken change escapes a rework.
829837 const cause =
830 decided.answers.cause.p >= 0.7
838 decided.answers.cause.p >= STOP_BAR
831839 ? (decided.answers.cause.choice as CheckJudgement["cause"])
832840 : "change";
833841 if (retry === "stop")
834 log.info("check failed; the decider stopped here for a person", {
842 log.info(`check failed; the decider stopped here for a person`, {
835843 issue: issue.number,
836844 by: decided.by,
837 p: decided.answers.retry.p.toFixed(2),
845 retry: `stop (p=${asked.p.toFixed(2)})`,
846 cause,
847 });
848 else if (stopped)
849 log.info("check failed; a half-sure stop reworks", {
850 issue: issue.number,
851 by: decided.by,
852 retry: `again: a half-sure stop reworks (p=${asked.p.toFixed(2)})`,
838853 cause,
839854 });
840855 return { retry, cause, failingTest };
src/web/pages/pull.ts +5 −1
@@ -337,7 +337,11 @@ function mergeBox(
337337 return card(
338338 html`${icon("x")}
339339 <div class="grow">
340 <div class="merge-headline">Closed without merging.</div>
340 <div class="merge-headline">
341 ${pull.closeReason === "parked"
342 ? "Parked: closed without merging."
343 : "Closed without merging."}
344 </div>
341345 <p class="merge-sub">
342346 Nothing was applied to
343347 <span class="mono">${pull.baseBranch}</span>.
test/ledger.test.ts +97 −1
@@ -36,6 +36,9 @@ 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 /** How sure the scripted decider is of its `retry` answer. */
40 let retryP = 0.8;
41
3942 /** A decider that answers from a script: question name → choice. */
4043 function scripted(answers: Record<string, string>): Decider & {
4144 seen: unknown[];
@@ -51,7 +54,7 @@ function scripted(answers: Record<string, string>): Decider & {
5154 const choice = answers[key] ?? q.options[0]!;
5255 const probabilities: Record<string, number> = {};
5356 for (const o of q.options) probabilities[o] = o === choice ? 0.8 : 0.2;
54 out[key] = { choice, p: 0.8, probabilities };
57 out[key] = { choice, p: key === "retry" ? retryP : 0.8, probabilities };
5558 }
5659 return out as { [K in keyof Q]: Answer };
5760 },
@@ -360,6 +363,99 @@ describe("the decision ledger", () => {
360363 }
361364 }, 60_000);
362365
366 test("a half-sure stop reworks; a sure one parks, and the pull closes as parked, not done", async () => {
367 const { getAgentByName } = await import("../src/core/agents.ts");
368 const scoutAgent = getAgentByName(app.db, "scout")!;
369 const make = async (name: string) => {
370 const branch = await commitToBranch(app, alice, repo, {
371 branch: `feature/${name}`,
372 base: "main",
373 message: name,
374 files: [{ path: `${name}.ts`, content: `export const x = 1;\n` }],
375 });
376 if (!branch.ok) throw new Error(JSON.stringify(branch.error));
377 const opened = await openPull(app, scout, repo, {
378 title: name,
379 baseBranch: "main",
380 headBranch: `feature/${name}`,
381 });
382 if (!opened.ok) throw new Error(String(opened.error));
383 const pull = opened.value;
384 const run = createRun(app.db, {
385 repoId: repo.id,
386 kind: "check",
387 issueId: pull.id,
388 env: `pull-${pull.number}`,
389 commitOid: pull.headOid,
390 reason: "pull",
391 });
392 claimRun(app.db, run.id);
393 finishRun(app.db, run.id, {
394 state: "failed",
395 summary: "check failed: 1 of 18 tests",
396 });
397 return {
398 pull,
399 failed: {
400 runId: run.id,
401 kind: "check",
402 commitOid: pull.headOid,
403 env: `pull-${pull.number}`,
404 since: pull.createdAt,
405 },
406 };
407 };
408 script["retry"] = "stop";
409 script["cause"] = "change";
410 try {
411 retryP = 0.6;
412 const unsure = await make("unsure");
413 expect(
414 (
415 await judgeFailedCheck(
416 app,
417 fresh(),
418 unsure.pull,
419 unsure.failed.runId,
420 unsure.pull.createdAt,
421 )
422 ).retry,
423 ).toBe("again");
424 expect(
425 await answerFailedCheck(
426 app,
427 fresh(),
428 unsure.pull,
429 scoutAgent,
430 unsure.failed,
431 ),
432 ).toBe("reworked");
433 expect(getPull(app.db, repo.id, unsure.pull.number)?.state).toBe("open");
434 expect(
435 listRuns(app.db, repo.id, { kind: "agent" }).some(
436 (r) => r.issueId === unsure.pull.id && r.reason === "check_failed",
437 ),
438 ).toBe(true);
439
440 retryP = 0.8;
441 const sure = await make("sure");
442 expect(
443 await answerFailedCheck(
444 app,
445 fresh(),
446 sure.pull,
447 scoutAgent,
448 sure.failed,
449 ),
450 ).toBe("parked");
451 const parked = getPull(app.db, repo.id, sure.pull.number)!;
452 expect(parked.state).toBe("closed");
453 expect(parked.closeReason).toBe("parked");
454 } finally {
455 retryP = 0.8;
456 }
457 });
458
363459 test("the change's fault parks as it always has, and says so", async () => {
364460 const { getAgentByName } = await import("../src/core/agents.ts");
365461 const { listComments } = await import("../src/core/issues.ts");

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs