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
scout/forge:scout/1354-a-half-sure-stop-parks-a-red-pull-and-cl → main 2 commits fork
8 files
changed +155
−15
docs/PLANNING.md +1
| @@ -526,6 +526,7 @@ long it took are always in the forge's log. | ||
| 526 | 526 | ## Closing takes a reason |
| 527 | 527 | |
| 528 | 528 | `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. | |
| 529 | 530 | No reason means done. Done frees what waited. Dropped or split closes the |
| 530 | 531 | issue but holds its dependents as _parked_, the map saying why ("#4 was |
| 531 | 532 | dropped"), until a writer relinks them or confirms the edge |
src/actions/issues.ts +8 −2
| @@ -406,7 +406,11 @@ export function setIssueState( | ||
| 406 | 406 | return err("already_merged"); |
| 407 | 407 | const reason = state === "closed" ? (closing.reason ?? "done") : undefined; |
| 408 | 408 | 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) { | |
| 410 | 414 | // A reason is how an issue closes; a pull or a reopen has none. |
| 411 | 415 | if (state !== "closed" || issue.kind !== "issue") |
| 412 | 416 | return err("invalid_reason"); |
| @@ -430,7 +434,9 @@ export function setIssueState( | ||
| 430 | 434 | actorId: user.value.id, |
| 431 | 435 | payload: { |
| 432 | 436 | number: issue.number, |
| 433 | ...(issue.kind === "issue" && reason !== undefined ? { reason } : {}), | |
| 437 | ...((issue.kind === "issue" || reason === "parked") && reason !== undefined | |
| 438 | ? { reason } | |
| 439 | : {}), | |
| 434 | 440 | ...(children.length > 0 ? { into: children.map((c) => c.number) } : {}), |
| 435 | 441 | }, |
| 436 | 442 | }); |
src/core/issues.ts +15 −6
| @@ -12,8 +12,12 @@ import { repoVisible } from "./visibility.ts"; | ||
| 12 | 12 | |
| 13 | 13 | export type IssueKind = "issue" | "pull"; |
| 14 | 14 | 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"; | |
| 17 | 21 | export const CLOSE_REASONS: readonly CloseReason[] = [ |
| 18 | 22 | "done", |
| 19 | 23 | "dropped", |
| @@ -78,6 +82,7 @@ interface IssueRow { | ||
| 78 | 82 | updated_at: string; |
| 79 | 83 | closed_at: string | null; |
| 80 | 84 | close_reason: CloseReason | null; |
| 85 | close_outcome: "parked" | null; | |
| 81 | 86 | origin_author: string | null; |
| 82 | 87 | origin_html_url: string | null; |
| 83 | 88 | assignee_id: string | null; |
| @@ -107,7 +112,7 @@ function toIssue(row: IssueRow): Issue { | ||
| 107 | 112 | createdAt: row.created_at, |
| 108 | 113 | updatedAt: row.updated_at, |
| 109 | 114 | closedAt: row.closed_at, |
| 110 | closeReason: row.close_reason, | |
| 115 | closeReason: row.close_outcome ?? row.close_reason, | |
| 111 | 116 | originAuthor: row.origin_author, |
| 112 | 117 | originUrl: row.origin_html_url, |
| 113 | 118 | assigneeId: row.assignee_id, |
| @@ -469,12 +474,16 @@ export function setIssueState( | ||
| 469 | 474 | ): Issue | undefined { |
| 470 | 475 | const now = new Date().toISOString(); |
| 471 | 476 | 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; | |
| 473 | 482 | const changed = db |
| 474 | 483 | .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", | |
| 476 | 485 | ) |
| 477 | .run(state, closedAt, now, issueId, why).changes; | |
| 486 | .run(state, closedAt, now, issueId, why, parked ? "parked" : null).changes; | |
| 478 | 487 | return changed > 0 ? getIssueById(db, issueId) : undefined; |
| 479 | 488 | } |
| 480 | 489 |
src/core/schema.ts +7
| @@ -1578,6 +1578,13 @@ export const migrations: readonly string[] = [ | ||
| 1578 | 1578 | expires_at TEXT NOT NULL |
| 1579 | 1579 | ); |
| 1580 | 1580 | `, |
| 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 | `, | |
| 1581 | 1588 | ]; |
| 1582 | 1589 | |
| 1583 | 1590 | /** |
src/crew/autonomy.ts +3 −1
| @@ -820,7 +820,9 @@ export function parkPull( | ||
| 820 | 820 | const issue = getIssueById(app.db, pull.id); |
| 821 | 821 | if (!issue || issue.state !== "open") return false; |
| 822 | 822 | 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 | }); | |
| 824 | 826 | if (!closed.ok) return false; |
| 825 | 827 | for (const number of closesFromBody(pull.body)) { |
| 826 | 828 | const about = getIssue(app.db, repo.id, number); |
src/crew/dispatch.ts +19 −4
| @@ -750,6 +750,9 @@ export interface CheckJudgement { | ||
| 750 | 750 | readonly failingTest: string | undefined; |
| 751 | 751 | } |
| 752 | 752 | |
| 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 | ||
| 753 | 756 | const RETRY_OPTIONS = ["again", "stop"]; |
| 754 | 757 | const CAUSE_OPTIONS = ["change", "environment", "base"]; |
| 755 | 758 | |
| @@ -823,18 +826,30 @@ export async function judgeFailedCheck( | ||
| 823 | 826 | cause: certain(CAUSE_OPTIONS, "change"), |
| 824 | 827 | }), |
| 825 | 828 | ); |
| 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"; | |
| 827 | 835 | // The change is what a half-sure answer means: an environment called |
| 828 | 836 | // that way on a hunch is how a broken change escapes a rework. |
| 829 | 837 | const cause = |
| 830 | decided.answers.cause.p >= 0.7 | |
| 838 | decided.answers.cause.p >= STOP_BAR | |
| 831 | 839 | ? (decided.answers.cause.choice as CheckJudgement["cause"]) |
| 832 | 840 | : "change"; |
| 833 | 841 | 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`, { | |
| 835 | 843 | issue: issue.number, |
| 836 | 844 | 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)})`, | |
| 838 | 853 | cause, |
| 839 | 854 | }); |
| 840 | 855 | return { retry, cause, failingTest }; |
src/web/pages/pull.ts +5 −1
| @@ -337,7 +337,11 @@ function mergeBox( | ||
| 337 | 337 | return card( |
| 338 | 338 | html`${icon("x")} |
| 339 | 339 | <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> | |
| 341 | 345 | <p class="merge-sub"> |
| 342 | 346 | Nothing was applied to |
| 343 | 347 | <span class="mono">${pull.baseBranch}</span>. |
test/ledger.test.ts +97 −1
| @@ -36,6 +36,9 @@ import { answerFailedCheck, judgeFailedCheck } from "../src/crew/dispatch.ts"; | ||
| 36 | 36 | import { startChecks } from "../src/checks/service.ts"; |
| 37 | 37 | import { serve, type Servers } from "../src/http/server.ts"; |
| 38 | 38 | |
| 39 | /** How sure the scripted decider is of its `retry` answer. */ | |
| 40 | let retryP = 0.8; | |
| 41 | ||
| 39 | 42 | /** A decider that answers from a script: question name → choice. */ |
| 40 | 43 | function scripted(answers: Record<string, string>): Decider & { |
| 41 | 44 | seen: unknown[]; |
| @@ -51,7 +54,7 @@ function scripted(answers: Record<string, string>): Decider & { | ||
| 51 | 54 | const choice = answers[key] ?? q.options[0]!; |
| 52 | 55 | const probabilities: Record<string, number> = {}; |
| 53 | 56 | 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 }; | |
| 55 | 58 | } |
| 56 | 59 | return out as { [K in keyof Q]: Answer }; |
| 57 | 60 | }, |
| @@ -360,6 +363,99 @@ describe("the decision ledger", () => { | ||
| 360 | 363 | } |
| 361 | 364 | }, 60_000); |
| 362 | 365 | |
| 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 | ||
| 363 | 459 | test("the change's fault parks as it always has, and says so", async () => { |
| 364 | 460 | const { getAgentByName } = await import("../src/core/agents.ts"); |
| 365 | 461 | const { listComments } = await import("../src/core/issues.ts"); |
new above
offline