mirror of
https://github.com/storytold/autocraft.git
synced 2026-11-24 16:31:06 +01:00
Merge superseded-decisions
This commit is contained in:
commit
eea45eb50d
7 files changed
+63
-5
No files matched your search
@@ -164,6 +164,8 @@ Model: Opus. Daily limit 100.
|
||||
|
||||
**Closed items.** After every sync, open scope, close, merge and single-item duplicate decisions of items that are closed or merged in the mirror, and open duplicate-group decisions with fewer than two open members, are answered `withdrawn` by the pipeline with the reason as the note ("the pull request was closed on GitHub", "the pull request was merged", "the duplicate group has one open item left") and audited as `decision-withdrawn`; the item's timeline shows it. The first run after deploy clears the existing ones. A single-item question is renamed (`~replaced-<time>`), so an item that reopens is asked again under the same id; a withdrawn scope decision does not cover its item. Nothing is written to GitHub.
|
||||
|
||||
**One open question per item.** An item has at most one open single-item decision: when a newer scope, Merge? or Close? question is asked, the item's older open ones (any of the three kinds, at any head) are set aside like a withdrawn question (renamed `~replaced-<time>`, answered `withdrawn` by the pipeline with a note, audited as `decision-withdrawn`); a set-aside scope question is not asked again. Every sync applies the same rule to existing rows.
|
||||
|
||||
**Withdraw.** `autocraft decisions withdraw --outside-pilot` (or `--repo R`, dry run unless `--apply`) deletes open scope decisions with their opinions, comments and the stage row Decide wrote when asking, so the items count as never asked and Decide asks them again when they are in scope. Other kinds are not withdrawn. Each is audited as `withdraw`; nothing is written to GitHub.
|
||||
|
||||
## Label
|
||||
|
||||
+2
-1
@@ -37,6 +37,7 @@ import { actOnGroups, type GroupIo } from "./dupe-groups.ts";
|
||||
import { cleanReason, duplicateComment, prCloseComment, scopeCloseComment } from "./templates.ts";
|
||||
import { plannedItems } from "../core/select-items.ts";
|
||||
import { jobItem } from "../runner/job-items.ts";
|
||||
import { setAsideSupersededQuestions } from "../merge/withdraw.ts";
|
||||
import { ownerOf } from "../owners.ts";
|
||||
import { authFailure, isWaiting, laneForDecision, markExecDone, noWriteReason, setExecState, SIGN_IN_REASON, type LaneDeps, type Lane } from "../github/user-lane.ts";
|
||||
|
||||
@@ -129,7 +130,7 @@ export function closeQuestion(r: ReviewRow, why: string | null = null, quiet = f
|
||||
|
||||
export function askCloseDecisions(db: DatabaseSync, repo: string, at: string): string[] {
|
||||
const qs = closeRows(db, repo).map((r) => closeQuestion(r, reviewText(db, r.repo, r.number, r.head_oid)?.why ?? null, isQuiet(db, r.repo, r.number)));
|
||||
if (qs.length) ask(db, qs.map((q) => ({ ...q, asked_at: at })));
|
||||
if (qs.length) { ask(db, qs.map((q) => ({ ...q, asked_at: at }))); setAsideSupersededQuestions(db, at, repo); }
|
||||
fillReviewSummaries(db, at, repo);
|
||||
return qs.map((q) => q.id);
|
||||
}
|
||||
|
||||
+2
-1
@@ -30,7 +30,7 @@ import { liveGateChecked } from "../review/discussion.ts";
|
||||
import { fillReviewSummaries, reviewText } from "../review/summary.ts";
|
||||
import { verificationOf } from "../verify/results.ts";
|
||||
import { TIER_LABEL } from "../whitelist.ts";
|
||||
import { closeMergedQuestions, withdrawBlockedQuestions, withdrawGroupedQuestions, withdrawOtherHeadQuestions } from "./withdraw.ts";
|
||||
import { closeMergedQuestions, withdrawBlockedQuestions, setAsideSupersededQuestions, withdrawGroupedQuestions, withdrawOtherHeadQuestions } from "./withdraw.ts";
|
||||
import { buildQueue, UNSURE_REASON, PREMERGE_DEFECT_REASON, PREMERGE_UNSURE_REASON, PREMERGE_FAILED_REASON, ciAllows, countStates, HEAD_FACT, MERGE_OPTIONS, mergeDecisionId, QUEUE_STATES, VERIFY_UNAVAILABLE, verifyAllows, type QueueEntry } from "./queue.ts";
|
||||
|
||||
export { buildQueue, countStates, QUEUE_STATES, type QueueEntry, type QueueState } from "./queue.ts";
|
||||
@@ -216,6 +216,7 @@ function askDue(db: DatabaseSync, due: QueueEntry[], at: string, log: (line: str
|
||||
ask(db, qs.map((q) => ({ ...q, asked_at: at })));
|
||||
due.forEach((e, i) => jobItem(db, e.repo, e.number, "asked Merge?", log, qs[i]!.id));
|
||||
for (const e of due) withdrawOtherHeadQuestions(db, e.repo, e.number, e.head, at);
|
||||
setAsideSupersededQuestions(db, at);
|
||||
return qs.map((q) => q.id);
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +97,43 @@ export function withdrawOtherHeadQuestions(db: DatabaseSync, repo: string, numbe
|
||||
}
|
||||
}
|
||||
|
||||
/** Why a question is set aside for a newer one. */
|
||||
const NEWER_NOTE = "superseded by a newer question about the item";
|
||||
|
||||
/**
|
||||
* An item has at most one open single-item decision: of its open scope, merge and close questions the newest asked stays
|
||||
* and the others are set aside (renamed like a superseded Merge? question, so an answer to them never counts). A set-aside
|
||||
* scope question keeps its stages row, so Decide does not ask it again. Returns how many were set aside. Idempotent.
|
||||
*/
|
||||
export function setAsideSupersededQuestions(db: DatabaseSync, at: string, repo?: string): number {
|
||||
const rows = db.prepare(`SELECT id, kind, repo, number FROM decisions WHERE answer IS NULL AND number IS NOT NULL
|
||||
AND kind IN ('scope', 'merge', 'close') AND id NOT LIKE '%:dupegroup:%' AND id NOT LIKE '%~replaced-%' ${repo ? "AND repo = ?" : ""}
|
||||
ORDER BY asked_at DESC, rowid DESC`).all(...(repo ? [repo] : [])) as { id: string; kind: string; repo: string; number: number }[];
|
||||
const seen = new Set<string>();
|
||||
const aside: { r: (typeof rows)[number]; why: string }[] = [];
|
||||
for (const r of rows) {
|
||||
const k = `${r.repo}#${r.number}`;
|
||||
if (seen.has(k)) aside.push({ r, why: NEWER_NOTE });
|
||||
else seen.add(k);
|
||||
}
|
||||
if (!aside.length) return 0;
|
||||
const close = db.prepare("UPDATE main.decisions SET answer = ?, answered_by = 'pipeline', answered_at = ?, applied_at = ?, answer_note = ?, adopted_opinion = NULL WHERE id = ? AND answer IS NULL");
|
||||
db.exec("BEGIN IMMEDIATE");
|
||||
try {
|
||||
for (const { r, why } of aside) {
|
||||
const old = `${r.id}~replaced-${at}`;
|
||||
renameDecision(db, r.id, old);
|
||||
close.run(WITHDRAWN, at, at, why, old);
|
||||
audit(db, "pipeline", "decision-withdrawn", old, { repo: r.repo, number: r.number, kind: r.kind, why });
|
||||
}
|
||||
db.exec("COMMIT");
|
||||
} catch (e) {
|
||||
db.exec("ROLLBACK");
|
||||
throw e;
|
||||
}
|
||||
return aside.length;
|
||||
}
|
||||
|
||||
type OpenRow = { id: string; kind: string; repo: string | null; number: number | null; state: string | null; itemKind: string | null };
|
||||
|
||||
const closedWhy = (r: OpenRow): string => r.state === "MERGED" ? "the pull request was merged" : `the ${r.itemKind === "pr" ? "pull request" : "issue"} was closed on GitHub`;
|
||||
|
||||
+3
-1
@@ -823,9 +823,11 @@ export async function runSync(db: DatabaseSync, client: Querier, opts: SyncOpts,
|
||||
if (client.resetAt) setSetting(db, "sync_rate_reset_at", client.resetAt.toISOString());
|
||||
}
|
||||
// Questions about items this sync found closed or merged no longer apply. Writes decisions only.
|
||||
const { withdrawClosedQuestions } = await import("./merge/withdraw.ts");
|
||||
const { withdrawClosedQuestions, setAsideSupersededQuestions } = await import("./merge/withdraw.ts");
|
||||
const withdrawn = withdrawClosedQuestions(db, iso(new Date()));
|
||||
if (withdrawn) console.log(`withdrew ${withdrawn} decision${withdrawn === 1 ? "" : "s"} about closed items`);
|
||||
const aside = setAsideSupersededQuestions(db, iso(new Date()));
|
||||
if (aside) console.log(`set aside ${aside} superseded decision${aside === 1 ? "" : "s"}`);
|
||||
return { mode, items };
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import { longLivedOf, pushable } from "../fixup/pushable.ts";
|
||||
import { pushApprovalOf } from "../fixup/approval.ts";
|
||||
import { mergeApprovalOf } from "../merge/approval.ts";
|
||||
import { repoHasNoCi } from "../merge/no-ci.ts";
|
||||
import { withdrawOtherHeadQuestions } from "../merge/withdraw.ts";
|
||||
import { setAsideSupersededQuestions, withdrawOtherHeadQuestions } from "../merge/withdraw.ts";
|
||||
import { findingsOf, premergeAt } from "../premerge/store.ts";
|
||||
import { releaseMerge, removeFromBatch } from "../merge/controls.ts";
|
||||
import type { Exec } from "../fixup/git.ts";
|
||||
@@ -191,6 +191,7 @@ function askMerge(db: DatabaseSync, p: Row, head: string, why: string, facts: st
|
||||
facts: [...facts.slice(0, 4), `${HEAD_FACT}${head}`], options: Object.values(MERGE_OPTIONS).map((x) => ({ ...x })), asked_by: ACTOR, asked_at: at,
|
||||
}]);
|
||||
withdrawOtherHeadQuestions(db, p.repo, p.number, head, at);
|
||||
setAsideSupersededQuestions(db, at, p.repo);
|
||||
}
|
||||
|
||||
type Hand = { done: true } | { gone: true } | { stop: string };
|
||||
|
||||
@@ -11,7 +11,7 @@ import { doCard } from "../src/conversations/act.ts";
|
||||
import { insertTurn } from "../src/conversations/store.ts";
|
||||
import { connect } from "../src/db.ts";
|
||||
import { ask, getDecision } from "../src/decisions.ts";
|
||||
import { withdrawClosedQuestions } from "../src/merge/withdraw.ts";
|
||||
import { setAsideSupersededQuestions, withdrawClosedQuestions } from "../src/merge/withdraw.ts";
|
||||
|
||||
mkdirSync(SCRATCH, { recursive: true });
|
||||
const T0 = "2026-01-01T00:00:00Z";
|
||||
@@ -70,3 +70,17 @@ describe("resolve card", () => {
|
||||
assert.deepEqual({ answer: d.answer, note: d.answer_note, by: d.answered_by, applied: !!d.applied_at }, { answer: "handled", note: "Asked for a use case.", by: "op", applied: true });
|
||||
});
|
||||
});
|
||||
|
||||
describe("one open question per item", () => {
|
||||
test("a newer merge question replaces the older one, and a newer merge question displaces an older scope question", () => {
|
||||
const db = fresh();
|
||||
const q = (id: string, kind: string, n: number, at: string) => ({ id, kind, repo: "app", number: n, question: "Q?", options: OPTIONS, asked_at: at });
|
||||
ask(db, [q("app#1:merge@aaa", "merge", 1, "2026-01-01T00:00:00Z"), q("app#1:merge@bbb", "merge", 1, "2026-01-01T01:00:00Z"), q("app#1:close@bbb", "close", 1, "2026-01-01T02:00:00Z"),
|
||||
q("app#2:scope", "scope", 2, "2026-01-01T00:00:00Z"), q("app#2:merge@ccc", "merge", 2, "2026-01-01T01:00:00Z")]);
|
||||
assert.equal(setAsideSupersededQuestions(db, T0), 3);
|
||||
const open = (db.prepare("SELECT id FROM decisions WHERE answer IS NULL ORDER BY id").all() as { id: string }[]).map((r) => r.id);
|
||||
assert.deepEqual(open, ["app#1:close@bbb", "app#2:merge@ccc"]);
|
||||
assert.equal(getDecision(db, `app#1:merge@aaa~replaced-${T0}`)?.answer, "withdrawn");
|
||||
assert.equal(setAsideSupersededQuestions(db, T0), 0);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user