Duplicate groups: release stale or failing members, hash check on adopt

This commit is contained in:
aiongg committed 2026-11-03 06:23:27 +00:00
1 parent 213cf83102
commit 8aae8d2f80
8 files changed
+52 -9

No files matched your search

+1 -1
View File
@@ -38,7 +38,7 @@ Finds open issues and PRs that describe the same bug or request as another open
- **Decision.** One per group, asked once the group is compared: "Keep #A and close #B, #C as duplicates?" with Use this answer, Keep #N instead (up to three alternatives) and Not duplicates. The summary lists, per item, what it does better, what is worth carrying over or what it adds. Every `#number` in the decision links to the item page and to GitHub. Only an operator's answer counts. Open per-pair decisions of the group are superseded by it (audited); answered ones keep their effect.
- **Held out.** While the decision is open or answered Use this answer / Keep #N instead, the items it closes are left out of Decide, Review, Verify, Fix-up and Fix. "Not duplicates" releases them for good and stores every pair of the group as distinct.
- **Comments.** The exact texts are written when the decision is asked, one set per answer (Use this answer and each Keep #N instead), and shown under that answer, so the answer approves exactly the words it posts. The page sends a hash of the shown texts with the answer; a changed set is refused (409) and the page reloads. Each member to close gets "Closing as a duplicate of #A." and, for a PR with parts to carry over, a second line "Parts to carry over to #A: ..." naming the first two points. For issue groups the kept issue gets one comment, "Details from the closed duplicates:", with at most six bullets built from the points each closed report adds, each crediting its source (`- #n: ...`; links, HTML, cross-repo references and mentions removed). The kept PR's fallback suggestion (used when its branch can't be pushed to) is part of the set. No model writes these, and none is written after an answer.
- **Act.** In a repo approved for comments, Act posts the stored texts for an answered group (Use this answer or Keep #N instead) and closes the members, within the step's limit and pilot. Each write is recorded in `dupe_group_posts` right after it happens, so a crash or retry never repeats a comment or a close. Before closing, Act reads the kept items (a closed, unmerged one stops the decision) and each member on GitHub: one already closed or merged, a PR whose head differs from the head stored when the decision was asked, or an issue whose text changed is skipped and recorded. Roles and answer are re-read before every write, so an undo or refresh stops the decision. A member whose writes fail three times is skipped. Undo is refused once Act wrote to GitHub. The decision is applied when every member to close has been closed.
- **Act.** In a repo approved for comments, Act posts the stored texts for an answered group (Use this answer or Keep #N instead) and closes the members, within the step's limit and pilot. Each write is recorded in `dupe_group_posts` right after it happens, so a crash or retry never repeats a comment or a close. Before closing, Act reads the kept items (a closed, unmerged one stops the decision) and each member on GitHub: one already closed or merged, a PR whose head differs from the head stored when the decision was asked, or an issue whose text changed is skipped and recorded; such a member (and one whose close failed three times) is released: its role becomes stay, it is no longer held or settled by the decision, and the next comparison may ask about it again. Roles and answer are re-read before every write, so an undo or refresh stops the decision. A member whose writes fail three times is skipped. Undo is refused once Act wrote to GitHub. The decision is applied when every member to close has been closed.
- **Carry-over.** When PRs closed in a group name parts worth carrying over, Act queues a job for the kept PR (`dupe_carries`). Fix-up works it with its take-fix rules: a model (sandboxed) writes a diff porting the listed parts, shown with the closed PRs' diffs; the patch check (Opus) must approve; the push to the PR's branch needs push approval and maintainer edits. Without them, in a repo approved for comments, the parts are posted on the kept PR as one comment instead. Two failed tries hold the job. Take-fix tries and stages of the PR are not touched.
- **Hand-off.** A close goes to Act. Confirmed duplicates raise the original's priority.
+10 -4
View File
@@ -68,8 +68,14 @@ export async function actOnGroups(db: DatabaseSync, run: GroupRun): Promise<Grou
for (const c of closers) if (!posted.get(dec.id, c.number, "close")) run.log(` would comment and close ${ref(c.number)} (${dec.id})`);
continue;
}
const skip = (n: number, step: string, reason: string) => {
const skip = (n: number, step: string, reason: string, release = false) => {
record(dec.id, n, step, null);
if (release) {
// Not closed by this decision: it stays open, is no longer held or settled by it, and the next comparison may ask about it again.
db.prepare("UPDATE dupe_group_items SET role = 'stay', target = NULL, base_role = 'stay', base_target = NULL WHERE decision_id = ? AND number = ?").run(dec.id, n);
record(dec.id, n, "released", null);
audit(db, ACTOR, "duplicate-member-released", ref(n), { decision: dec.id, reason });
}
audit(db, ACTOR, "act-skip", ref(n), { decision: dec.id, reason });
res.skipped.push({ ref: ref(n), reason });
run.log(` ${ref(n)}: skipped: ${reason}`);
@@ -115,10 +121,10 @@ export async function actOnGroups(db: DatabaseSync, run: GroupRun): Promise<Grou
const live = await run.io.live(c.number);
if (!live) { skip(c.number, "close", "GitHub returned no such item"); continue; }
if (live.state !== "OPEN") { skip(c.number, "close", `already ${live.state.toLowerCase()} on GitHub`); continue; }
if (c.kind === "pr" && c.head && live.head !== c.head) { skip(c.number, "close", "the head moved since the comparison"); continue; }
if (c.kind === "pr" && c.head && live.head !== c.head) { skip(c.number, "close", "the head moved since the comparison", true); continue; }
if (c.kind === "issue" && c.head) {
const now = (db.prepare("SELECT embed_hash FROM items WHERE repo = ? AND number = ?").get(run.repo, c.number) as { embed_hash: string | null } | undefined)?.embed_hash;
if (now && now !== c.head) { skip(c.number, "close", "the text changed since the comparison"); continue; }
if (now && now !== c.head) { skip(c.number, "close", "the text changed since the comparison", true); continue; }
}
const text = texts.get(`${c.number}:close`);
if (!text) { skip(c.number, "close", "the decision stores no comment for this answer"); continue; }
@@ -146,7 +152,7 @@ export async function actOnGroups(db: DatabaseSync, run: GroupRun): Promise<Grou
db.prepare("INSERT INTO dupe_group_fails (decision_id, number, fails) VALUES (?, ?, 1) ON CONFLICT (decision_id, number) DO UPDATE SET fails = fails + 1").run(dec.id, cur.item.number);
const n = (db.prepare("SELECT fails FROM dupe_group_fails WHERE decision_id = ? AND number = ?").get(dec.id, cur.item.number) as { fails: number }).fails;
if (n < MAX_FAILS) return res;
skip(cur.item.number, cur.step, `${n} writes failed: ${why}`);
skip(cur.item.number, cur.step, `${n} writes failed: ${why}`, cur.step === "close");
}
// Applied once every member to close has a close record and the details comment is settled.
if (closers.every((c) => posted.get(dec.id, c.number, "close")) && (!details || posted.get(dec.id, details.number, "details"))) {
+2
View File
@@ -332,6 +332,8 @@ export async function adopt(db: DatabaseSync, req: Req): Promise<Decision> {
{ id: string; login: string; option: string | null } | undefined;
if (!o) throw new HttpError(404, "no such live opinion on this decision");
if (!o.option || !optionsOf(d).some((x) => x.key === o.option)) throw new HttpError(400, "that opinion picks no option");
const stored = d.kind === "duplicate" && d.id.includes(":dupegroup:") ? textsFor(db, d.id, o.option) : [];
if (stored.length && body(req).textsHash !== textsHash(stored)) throw new HttpError(409, "the comments for this answer changed; reload the decision");
const r = db.prepare(`UPDATE main.decisions SET answer = ?, answer_note = NULL, exceptions = ?, answered_by = ?, answered_at = ?, adopted_opinion = ?
WHERE id = ? AND answer IS NULL`).run(o.option, isBatch(d) ? "[]" : null, req.user.login, new Date().toISOString(), o.id, d.id);
if (r.changes !== 1) throw new HttpError(409, "someone answered this a moment ago");
+2 -1
View File
@@ -39,7 +39,8 @@ function answeredKeeps(db: DatabaseSync, repo: string, members: number[]): { set
WHERE d.kind = 'duplicate' AND d.answer IS NOT NULL AND d.answer NOT IN ('superseded', 'distinct') AND gi.repo = ? AND gi.number IN (${ph}) ORDER BY d.asked_at, d.id`).all(repo, ...members) as { id: string }[];
const settled = new Set<number>(), keep = new Map<string, number>();
for (const { id } of ids)
for (const r of db.prepare("SELECT number, kind, role FROM dupe_group_items WHERE decision_id = ?").all(id) as { number: number; kind: string; role: string }[]) {
for (const r of db.prepare(`SELECT gi.number, gi.kind, gi.role FROM dupe_group_items gi WHERE gi.decision_id = ?
AND NOT EXISTS (SELECT 1 FROM dupe_group_posts p WHERE p.decision_id = gi.decision_id AND p.number = gi.number AND p.step = 'released')`).all(id) as { number: number; kind: string; role: string }[]) {
settled.add(r.number);
if (r.role === "keep") keep.set(r.kind, r.number);
}
+9 -1
View File
@@ -217,10 +217,17 @@ describe("api", () => {
db.prepare("UPDATE dupe_group_texts SET text = 'Closing as a duplicate of #4.\nParts to carry over to #4: x.' WHERE decision_id = ?").run(id);
await boss.post(dpath(id, "/answer"), { answer: "accept", textsHash: ot.hash }, 409);
const fresh = (await boss.get<Decision>(dpath(id))).optionTexts[0]!;
// Adopting an opinion approves the same texts, so it needs the same hash.
db.prepare("INSERT INTO decision_opinions (id, decision_id, login, option, note, at, permission) VALUES ('op1', ?, 'maint', 'accept', NULL, 'now', 'write')").run(id);
await boss.post(dpath(id, "/adopt"), { opinionId: "op1" }, 409);
await boss.post(dpath(id, "/adopt"), { opinionId: "op1", textsHash: ot.hash }, 409);
assert.equal((await boss.post<Decision>(dpath(id, "/adopt"), { opinionId: "op1", textsHash: fresh.hash })).answer, "accept");
await boss.post<Decision>(dpath(id, "/undo"));
assert.equal((await boss.post<Decision>(dpath(id, "/answer"), { answer: "accept", textsHash: fresh.hash })).answer, "accept");
db.prepare("INSERT INTO dupe_group_posts (decision_id, number, step, url, at) VALUES (?, 5, 'comment', 'https://x/c', 'now')").run(id);
await boss.post(dpath(id, "/undo"), undefined, 409);
db.prepare("UPDATE main.decisions SET applied_at = 'now' WHERE id = ?").run(id);
db.prepare("DELETE FROM decision_opinions WHERE id = 'op1'").run();
});
test("adopt records the operator's answer and credits the opinion; opinions close once answered", async () => {
@@ -232,7 +239,8 @@ describe("api", () => {
assert.equal(d.answeredBy, "boss");
assert.equal(d.adoptedOpinion?.id, op.id);
assert.equal(d.adoptedOpinion?.login, "maint");
assert.equal(auditCount("adopt", "boss"), 1);
// The group decision test above adopted once as well.
assert.equal(auditCount("adopt", "boss"), 2);
await maint.post(dpath(P4, "/opinion"), { option: "small" }, 409);
await maint.post(dpath(P4, "/retract"), undefined, 409);
});
+26
View File
@@ -9,6 +9,7 @@ import { setCommentApproval } from "../src/act/approval.ts";
import { runAct, writeEffect, type ActDeps } from "../src/act/index.ts";
import { connect } from "../src/db.ts";
import { getDecision } from "../src/decisions.ts";
import { duplicateHeld } from "../src/dupes/held.ts";
import { kindSetsOf, duplicateGroups } from "../src/dupes/plan.ts";
import { askGroupDecisions } from "../src/dupes/decide.ts";
import { cleanReason } from "../src/act/templates.ts";
@@ -260,6 +261,31 @@ describe("act on group decisions", () => {
});
});
describe("released members", () => {
test("a member skipped as stale is released and the next comparison plans a new decision for it", async () => {
const db = await world();
answer(db, PR_GROUP, "accept");
assert.equal(duplicateHeld(db, "app", 12), true);
await run(db, fakes([], { heads: new Map([[12, "newsha"]]) }));
assert.equal(duplicateHeld(db, "app", 12), false);
assert.equal(db.prepare("SELECT role FROM dupe_group_items WHERE decision_id = ? AND number = 12").get(PR_GROUP)!.role, "stay");
assert.equal(db.prepare("SELECT COUNT(*) AS n FROM audit WHERE action = 'duplicate-member-released'").get()!.n, 1);
// The mirror sees the new head; the comparison runs again for the released member.
db.prepare("UPDATE items SET head_oid = 'newsha' WHERE repo = 'app' AND number = 12").run();
const cd: CompareDeps = {
fetchDiff: async () => ({ ok: true, text: "diff --git a/src/a.rs b/src/a.rs\n--- a/src/a.rs\n+++ b/src/a.rs\n@@ -1 +1 @@\n-old\n+new\n" }),
baseCheckout: async () => "/checkout/base",
ask: (async (): Promise<Reply> => ({ text: JSON.stringify({ keep: 11, reason: "again", others: [{ number: 12, duplicate: true, better: [], carry: [] }] }), usage: USAGE })) as CompareDeps["ask"],
now: () => new Date(T1),
};
db.prepare("UPDATE items SET state = 'CLOSED' WHERE repo = 'app' AND number = 13").run();
const r = await runDupeCompare(db, {}, quiet, cd);
assert.ok(r.asked.includes("app:dupegroup:12"));
assert.deepEqual(db.prepare("SELECT number, role FROM dupe_group_items WHERE decision_id = 'app:dupegroup:12' ORDER BY number").all().map((x: any) => `${x.number}:${x.role}`), ["11:keep", "12:close"]);
assert.equal(duplicateHeld(db, "app", 12), true);
});
});
describe("cleanReason", () => {
test("strips HTML tags, protocol-relative links and cross-repo references", () => {
assert.equal(cleanReason("see <b>this</b> //evil.example/x and other/repo#12 plus <img src=x onerror=y> @bob"), "see this and plus bob.");
+1 -1
View File
@@ -77,7 +77,7 @@ export interface Api {
opine(id: string, input: { option: string | null; note?: string }): Promise<Decision>;
retract(id: string): Promise<Decision>;
/** Operator only: answer with the opinion's option. */
adopt(id: string, opinionId: string): Promise<Decision>;
adopt(id: string, opinionId: string, textsHash?: string): Promise<Decision>;
claim(id: string): Promise<void>;
thread(id: string): Promise<DecisionComment[]>;
comment(id: string, body: string): Promise<DecisionComment>;
+1 -1
View File
@@ -113,7 +113,7 @@ export function createHttpApi(): Api {
undo: (id) => post(dec(id, "/undo")),
opine: (id, input) => post(dec(id, "/opinion"), input),
retract: (id) => post(dec(id, "/retract")),
adopt: (id, opinionId) => post(dec(id, "/adopt"), { opinionId }),
adopt: (id, opinionId, textsHash) => post(dec(id, "/adopt"), { opinionId, textsHash }),
// A claim changes nothing anyone is looking at, so open views don't refetch.
claim: (id) => call("POST", dec(id, "/claim")),
thread: (id) => get(dec(id, "/thread")),