From 26261201835d6e31dfa42cadc7d0ca7d7c46370f Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Fri, 13 Nov 2026 00:04:08 +0800 Subject: [PATCH 1/4] feat(daemon): dispatch_priority boost lane for root-cause aggregations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Owner policy 2026-11-12 (m13948): RC aggregation issues must always run at the front of the global drain — their member work is suppressed, so waiting behind a multi-hour FIFO backlog idles the whole batch. - issues.dispatch_priority column (migration + DDL, default 0) - getGlobalPendingMessages / priorityOrderedPending order by dispatch_priority DESC before created_at (RC beats age AND project priorities; same-bucket order stays strict FIFO) - POST /api/admin/boost {issue_ids} (mirror ids only, like stop-work) - classifier board re-stamps the live rc-agg.db set every round - tests: 6 new (ordering both branches, idempotency, '645' vs '6453' text prefix guard), 497/0 full daemon suite - daemon 0.4.214 --- packages/daemon/package.json | 2 +- packages/daemon/src/db.ts | 13 +++ packages/daemon/src/op.ts | 22 +++- packages/daemon/src/opencode.ts | 13 +++ packages/daemon/src/server.ts | 9 ++ packages/daemon/tests/rc-boost.test.ts | 136 +++++++++++++++++++++++++ scripts/classifier-board.py | 70 +++++++++++++ 7 files changed, 262 insertions(+), 3 deletions(-) create mode 100644 packages/daemon/tests/rc-boost.test.ts diff --git a/packages/daemon/package.json b/packages/daemon/package.json index 5e44010..b4c85e4 100644 --- a/packages/daemon/package.json +++ b/packages/daemon/package.json @@ -1,6 +1,6 @@ { "name": "ework-daemon", - "version": "0.4.217", + "version": "0.4.220", "description": "Issue-driven AI development daemon. Spawns opencode subprocesses to resolve Gitea issues.", "module": "src/index.ts", "type": "module", diff --git a/packages/daemon/src/db.ts b/packages/daemon/src/db.ts index fba4065..023228f 100644 --- a/packages/daemon/src/db.ts +++ b/packages/daemon/src/db.ts @@ -407,6 +407,7 @@ async function runMigrations(db: AsyncDatabase): Promise { title TEXT NOT NULL DEFAULT '', created_at TEXT NOT NULL, updated_at TEXT NOT NULL, + dispatch_priority INTEGER NOT NULL DEFAULT 0, UNIQUE(tracker_type, tracker_scope_key, tracker_issue_id) )`, mysqlCreate: `CREATE TABLE ${tIssues} ( @@ -420,6 +421,7 @@ async function runMigrations(db: AsyncDatabase): Promise { title VARCHAR(512) NOT NULL DEFAULT '', created_at VARCHAR(40) NOT NULL, updated_at VARCHAR(40) NOT NULL, + dispatch_priority INT NOT NULL DEFAULT 0, UNIQUE (tracker_type, tracker_scope_key, tracker_issue_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`, oldCols: @@ -551,6 +553,17 @@ async function runMigrations(db: AsyncDatabase): Promise { sqlite ? "reset_at INTEGER NOT NULL DEFAULT 0" : "reset_at BIGINT NOT NULL DEFAULT 0" ); + // issues.dispatch_priority — 1 = top-of-queue for the global drain + // (owner policy 2026-11-12: root-cause aggregation issues run ahead of the + // FIFO backlog). The classifier board re-stamps the live set every round via + // POST /api/admin/boost; stale flags are harmless (closed issues hold no + // pending messages). + await ensureColumn( + tIssues, + "dispatch_priority", + sqlite ? "dispatch_priority INTEGER NOT NULL DEFAULT 0" : "dispatch_priority INT NOT NULL DEFAULT 0" + ); + // op_sessions runtime-state columns (previously in-memory Maps; now persisted // so a restarted daemon can recover the nudge/generation state). await ensureColumn(tSessions, "last_output_at", "last_output_at VARCHAR(40)"); diff --git a/packages/daemon/src/op.ts b/packages/daemon/src/op.ts index a41d42c..6ffd9d4 100644 --- a/packages/daemon/src/op.ts +++ b/packages/daemon/src/op.ts @@ -399,7 +399,11 @@ export class Store { const rows = this.projectPriorities.length > 0 ? await this.priorityOrderedPending(now, limit) : await getDB().all( - `SELECT * FROM {{messages}} WHERE status = 'pending' AND ${Store.RETRY_HOLD_SQL} ORDER BY created_at ASC LIMIT ?`, + `SELECT m.* FROM {{messages}} m + JOIN {{op_sessions}} s ON s.uid = m.session_id + JOIN {{issues}} i ON i.uid = s.issue_id + WHERE m.status = 'pending' AND (m.retry_after IS NULL OR m.retry_after <= ?) + ORDER BY COALESCE(i.dispatch_priority, 0) DESC, m.created_at ASC LIMIT ?`, [now, limit] ); return rows.map(rowToMessage); @@ -426,13 +430,27 @@ export class Store { JOIN {{op_sessions}} s ON s.uid = m.session_id JOIN {{issues}} i ON i.uid = s.issue_id WHERE m.status = 'pending' AND (m.retry_after IS NULL OR m.retry_after <= ?) - ORDER BY m.created_at ASC, + ORDER BY COALESCE(i.dispatch_priority, 0) DESC, m.created_at ASC, CASE ${whens.join(" ")} ELSE 0 END DESC LIMIT ?`, [nowIso, ...caseParams, limit] ); } + /** Set the drain-dispatch priority of mirror issues (admin boost endpoint; + * the classifier board re-stamps the root-cause aggregation set every + * round). Tracker ids only, like stop-work. Returns rows updated. */ + async setIssueDispatchPriority(trackerIssueIds: string[], priority: number): Promise { + const ids = [...new Set(trackerIssueIds)]; + if (ids.length === 0) return 0; + const ph = ids.map(() => "?").join(","); + const res = await getDB().run( + `UPDATE {{issues}} SET dispatch_priority = ?, updated_at = ? WHERE tracker_issue_id IN (${ph})`, + [priority, new Date().toISOString(), ...ids] + ); + return res.changes; + } + async bumpMessageAttempts(id: string): Promise { await getDB().run("UPDATE {{messages}} SET attempts = attempts + 1, updated_at = ? WHERE uid = ?", [ new Date().toISOString(), diff --git a/packages/daemon/src/opencode.ts b/packages/daemon/src/opencode.ts index 763f06d..c42d14d 100644 --- a/packages/daemon/src/opencode.ts +++ b/packages/daemon/src/opencode.ts @@ -4343,6 +4343,19 @@ Check states: read the mirror cache (see AGENTS.md), do not poll gh for check st return { issues, killed, superseded }; } + /** Mark mirror issues top-of-queue for the global drain (owner policy + * 2026-11-12: root-cause aggregation issues run ahead of the FIFO + * backlog). Idempotent stamp — the classifier board re-applies the + * current set every round; a stale flag is harmless (a closed issue + * holds no pending messages). */ + async boostIssueWork(mirrorIssueIds: string[]): Promise<{ issues: number }> { + const set = await this.store.setIssueDispatchPriority(mirrorIssueIds, 1); + if (set > 0) { + log.info(`engine: boost — ${set} issue(s) marked top-of-queue`); + } + return { issues: set }; + } + private buildForwardPrompt( opName: string, commentBody: string, diff --git a/packages/daemon/src/server.ts b/packages/daemon/src/server.ts index 140fe33..c27e263 100644 --- a/packages/daemon/src/server.ts +++ b/packages/daemon/src/server.ts @@ -245,6 +245,15 @@ export function createServer( const report = await engine.stopIssueWork(ids.map(String)); return json({ ok: true, ...report }); } + if (pathname === "/api/admin/boost" && req.method === "POST") { + const body = await req.json().catch(() => ({} as unknown)); + const ids = (body as { issue_ids?: unknown })?.issue_ids; + if (!Array.isArray(ids) || ids.length === 0 || ids.some((x) => typeof x !== "string" && typeof x !== "number")) { + return json({ error: "issue_ids must be a non-empty array of mirror issue ids" }, 400); + } + const report = await engine.boostIssueWork(ids.map(String)); + return json({ ok: true, ...report }); + } return json({ error: "not found" }, 404); } diff --git a/packages/daemon/tests/rc-boost.test.ts b/packages/daemon/tests/rc-boost.test.ts new file mode 100644 index 0000000..79563d3 --- /dev/null +++ b/packages/daemon/tests/rc-boost.test.ts @@ -0,0 +1,136 @@ +import { beforeAll, beforeEach, describe, expect, it } from "bun:test"; +import { Store } from "../src/op"; +import { getDB, initDB } from "../src/db"; +import type { TrackerRef } from "../src/trackers/types"; + +// Owner policy 2026-11-12: root-cause aggregation issues run AHEAD of the +// normal FIFO backlog (their member work is suppressed, so waiting on the +// tail wastes hours while the whole batch idles). The classifier board +// re-stamps the live set via POST /api/admin/boost every round; the drain +// orders dispatch_priority DESC before created_at. +beforeAll(async () => { + await initDB(); +}); + +beforeEach(async () => { + const db = getDB(); + const mysql = db.dialect === "mysql"; + await db.exec(mysql ? "SET FOREIGN_KEY_CHECKS = 0" : "PRAGMA foreign_keys = OFF"); + for (const t of ["messages", "op_sessions", "issues"]) { + await db.exec(`DELETE FROM {{${t}}}`); + } + await db.exec(mysql ? "SET FOREIGN_KEY_CHECKS = 1" : "PRAGMA foreign_keys = ON"); +}); + +function ref(issueId: string, scopeKey: string): TrackerRef { + const [owner, repo] = scopeKey.split("/"); + return { trackerType: "gitea", scope: { owner: owner!, repo: repo! }, issueId }; +} + +async function seedPending(scopeKey: string, issueNum: string, createdAt: string): Promise { + const store = new Store(); + const issue = await store.findOrCreateIssue(ref(issueNum, scopeKey), scopeKey, "t"); + const session = await store.createSession(issue.id, "ework"); + const msg = await store.createMessage(session.id, `msg ${scopeKey}#${issueNum}`); + await getDB().run("UPDATE {{messages}} SET created_at = ? WHERE uid = ?", [createdAt, msg.id]); + await store.close(); + return msg.id; +} + +async function pendingOrder(store: Store): Promise { + return (await store.getGlobalPendingMessages(10)).map((m) => m.content); +} + +describe("setIssueDispatchPriority", () => { + it("stamps by mirror tracker id and reports rows updated", async () => { + const store = new Store(); + await seedPending("a/b", "7", "2026-11-12T10:00:00.000Z"); + expect(await store.setIssueDispatchPriority(["7"], 1)).toBe(1); + const row = await getDB().get<{ p: number }>( + `SELECT dispatch_priority AS p FROM {{issues}} WHERE tracker_issue_id = '7'` + ); + expect(row?.p).toBe(1); + // idempotent re-stamp (the board calls this every round) + expect(await store.setIssueDispatchPriority(["7", "7"], 1)).toBe(1); + // unknown ids change nothing, never throw + expect(await store.setIssueDispatchPriority(["nope"], 1)).toBe(0); + // text ids only: '645' must not match issue '6453' + await seedPending("a/b", "6453", "2026-11-12T10:00:00.000Z"); + expect(await store.setIssueDispatchPriority(["645"], 1)).toBe(0); + const row6453 = await getDB().get<{ p: number }>( + `SELECT dispatch_priority AS p FROM {{issues}} WHERE tracker_issue_id = '6453'` + ); + expect(row6453?.p).toBe(0); + await store.close(); + }); + + it("empty list is a no-op", async () => { + const store = new Store(); + expect(await store.setIssueDispatchPriority([], 1)).toBe(0); + await store.close(); + }); +}); + +describe("global drain ordering (pure FIFO branch, no project priorities)", () => { + it("boosted issue jumps an OLDER unboosted message", async () => { + const store = new Store(); + // old normal message first in FIFO ... + await seedPending("a/b", "100", "2026-11-10T00:00:00.000Z"); + // ... then a newer RC message that gets stamped. + await seedPending("a/b", "6442", "2026-11-12T23:00:00.000Z"); + expect(await pendingOrder(store)).toEqual([ + "msg a/b#100", + "msg a/b#6442", + ]); + await store.setIssueDispatchPriority(["6442"], 1); + expect(await pendingOrder(store)).toEqual([ + "msg a/b#6442", + "msg a/b#100", + ]); + await store.close(); + }); + + it("within the same priority bucket the FIFO order holds", async () => { + const store = new Store(); + await seedPending("a/b", "6442", "2026-11-12T01:00:00.000Z"); + await seedPending("a/b", "6443", "2026-11-12T02:00:00.000Z"); + await store.setIssueDispatchPriority(["6442", "6443"], 1); + expect(await pendingOrder(store)).toEqual([ + "msg a/b#6442", + "msg a/b#6443", + ]); + await store.close(); + }); + + it("unboosted rows keep strict FIFO after a boost elsewhere", async () => { + const store = new Store(); + await seedPending("a/b", "1", "2026-11-12T01:00:00.000Z"); + await seedPending("a/b", "2", "2026-11-12T02:00:00.000Z"); + await seedPending("a/b", "3", "2026-11-12T03:00:00.000Z"); + await store.setIssueDispatchPriority(["2"], 1); + expect(await pendingOrder(store)).toEqual([ + "msg a/b#2", + "msg a/b#1", + "msg a/b#3", + ]); + await store.close(); + }); +}); + +describe("global drain ordering (WORK_PROJECT_PRIORITIES branch)", () => { + it("issue dispatch priority outranks both age AND project priority", async () => { + const store = new Store([ + { scope: "low/repo", priority: 100 }, + ]); + // oldest + highest project priority ... + await seedPending("low/repo", "9", "2026-11-01T00:00:00.000Z"); + // ... still loses to a newer stamped RC message. + await seedPending("other/repo", "6442", "2026-11-12T23:00:00.000Z"); + await store.setIssueDispatchPriority(["6442"], 1); + expect(await pendingOrder(store)).toEqual([ + "msg other/repo#6442", + "msg low/repo#9", + ]); + await store.close(); + }); +}); diff --git a/scripts/classifier-board.py b/scripts/classifier-board.py index d9441de..2d418cb 100644 --- a/scripts/classifier-board.py +++ b/scripts/classifier-board.py @@ -43,6 +43,11 @@ # (owner decision), embedded as an HTML comment in the issue body AND recorded # in a sqlite DB (authoritative). Titles are English-only and purely cosmetic. RCAGG_DB = "/var/lib/ework-web/share/rc-agg.db" +# Owner policy 2026-11-12: the [Root Cause] aggregations themselves run at the +# FRONT of the daemon's FIFO drain (their members are suppressed, so a RC +# issue waiting behind hours of backlog wastes the whole batch). The board +# re-stamps the live set from rc-agg.db every round via this endpoint. +DAEMON_BOOST_URL = "http://127.0.0.1:3101/api/admin/boost" ABSORBED_LABEL = "已被收" ABSORBED_COMMENT = ( "(已收)本单已归入根因聚合 issue(token 见聚合单 body),机器人已停止在本单上的工作," @@ -285,6 +290,7 @@ def open_numbers(): # and stop-work stops any live/queued work on each render (idempotent, silent). SUPPRESSION_PATH = "/var/lib/ework-daemon/share/classifier/suppressed.json" DAEMON_STOP_URL = "http://127.0.0.1:3101/api/admin/stop-work" +DAEMON_BOOST_URL = "http://127.0.0.1:3101/api/admin/boost" def incorporated_numbers(merged, open_set): """{mirror number: reason} for every open issue absorbed into a root-cause @@ -330,6 +336,68 @@ def write_suppression(merged, open_set): time.sleep(5 * (attempt + 1)) print(f"classifier-board: suppression set = {len(nums)} issue(s) -> {SUPPRESSION_PATH}") +def boost_rc(): + """Stamp the live [Root Cause] aggregation issues top-of-queue in the + daemon drain (idempotent; re-applied every round, also covers issues + created earlier in the same round).""" + try: + c = sqlite3.connect(f"file:{RCAGG_DB}?mode=ro", uri=True) + rows = c.execute("SELECT issue_number FROM rc_agg").fetchall() + c.close() + except sqlite3.OperationalError: + return # no rc-agg.db yet (nothing aggregated) — nothing to boost + ids = [n for (n,) in rows if n] + if not ids: + return + for attempt in range(3): + try: + req = urllib.request.Request( + DAEMON_BOOST_URL, + data=json.dumps({"issue_ids": ids}).encode(), + headers={"Content-Type": "application/json"}, + method="POST", + ) + with urllib.request.urlopen(req, timeout=30) as r: + print(f"classifier-board: boost -> {r.read().decode()[:200]}") + break + except Exception as e: + print(f"classifier-board: boost POST failed (attempt {attempt+1}/3): {e}") + if attempt < 2: + time.sleep(5 * (attempt + 1)) + +def boost_rc(): + """Top-of-queue for the root-cause aggregations themselves (owner policy + 2026-11-12): the daemon drains their pending work ahead of the normal + FIFO backlog. Re-stamped every round from rc-agg.db (the live set), so a + freshly created aggregation jumps the queue in the same round it appears; + a stale stamp is harmless once an aggregation closes (closed issues hold + no pending messages).""" + try: + c = rcdb() + rows = c.execute("SELECT issue_number FROM rc_agg").fetchall() + c.close() + except Exception as e: + print(f"classifier-board: boost read failed: {e}") + return + ids = [n for (n,) in rows if n] + if not ids: + return + for attempt in range(3): + try: + req = urllib.request.Request( + DAEMON_BOOST_URL, + data=json.dumps({"issue_ids": ids}).encode(), + headers={"Content-Type": "application/json"}, + method="POST", + ) + with urllib.request.urlopen(req, timeout=30) as r: + print(f"classifier-board: boost -> {r.read().decode()[:200]}") + break + except Exception as e: + print(f"classifier-board: boost POST failed (attempt {attempt+1}/3): {e}") + if attempt < 2: + time.sleep(5 * (attempt + 1)) + def mirror_row(n): c = sqlite3.connect(f"file:{DB}?mode=ro", uri=True) row = c.execute("""SELECT title, state, upstream_issue_number, upstream_ci_state, @@ -673,6 +741,8 @@ def main(): # issues and post member marks — so no member comment can wake a worker. write_suppression(merged, open_set) agg_by_cat = update_agg(merged, open_set) + boost_rc() + boost_rc() ensure_label(ABSORBED_LABEL, "d9d9d9") mark_members(agg_by_cat, merged, open_set) ensure_label(AGG_LABEL) From 20d804cfe484ceb82b03e3b6b45f6ceb4f48b617 Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Fri, 13 Nov 2026 09:44:14 +0800 Subject: [PATCH 2/4] feat(rc): 8-question contract in initial prompt + root-cause label on RC PRs with queue boost (owner policy 2026-11-13) --- packages/daemon/src/opencode.ts | 5 + .../daemon/tests/incorporated-stop.test.ts | 23 ++++ scripts/classifier-board.py | 102 +++++++++++++++++- 3 files changed, 128 insertions(+), 2 deletions(-) diff --git a/packages/daemon/src/opencode.ts b/packages/daemon/src/opencode.ts index c42d14d..78d93f1 100644 --- a/packages/daemon/src/opencode.ts +++ b/packages/daemon/src/opencode.ts @@ -4222,6 +4222,11 @@ Check states: read the mirror cache (see AGENTS.md), do not poll gh for check st `If it's empty, clone the repo: \`${instructions.clone}\``, ``, `Read the issue, work on it, and reply via the \`reply\` tool — every reply starts with \`[bot] 🏷\`. Post the reply as soon as possible, then continue working if needed.`, + // 8-question contract must be in the INITIAL prompt too (owner 2026-11-13): + // [根因]/[Root Cause] aggregation tickets are dispatched by issue_opened — + // the forward/nudge-only injection meant the worker's main run never saw + // the verdict format (2026-11-12: RC threads answered with a bare 结论). + this.rcEightQuestionRule(title), ].filter(Boolean).join("\n"); } diff --git a/packages/daemon/tests/incorporated-stop.test.ts b/packages/daemon/tests/incorporated-stop.test.ts index 56d5af6..e1d9e35 100644 --- a/packages/daemon/tests/incorporated-stop.test.ts +++ b/packages/daemon/tests/incorporated-stop.test.ts @@ -142,4 +142,27 @@ describe("incorporated-issue auto-stop (owner policy 2026-11-12)", () => { expect(Engine.prototype.rcEightQuestionRule.call(self, "普通 issue 标题")).toBe(""); expect(Engine.prototype.rcEightQuestionRule.call(self, undefined)).toBe(""); }); + + test("initial prompt carries the 8问 contract for [Root Cause] tickets (issue_opened path)", () => { + // RC aggregations are dispatched by issue_opened — the worker's first run + // only ever saw the forward/nudge rules, which is why 2026-11-13 RC threads + // answered with a bare 结论 and no 8-question verdict (owner: 「我发现root的8问没有了」). + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const self = Object.create(Engine.prototype) as Record; + self.cfg = { daemon: { wakeLogins: [], noWakeLogins: [], nonWakingAuthors: [] } }; + const args = ["body", "ranxianglei", "/w", { clone: "git clone x .", issueRef: "o/r#6453" }] as const; + const rcPrompt = Engine.prototype.buildInitialPrompt.call( + self, "bot", "[Root Cause] compression cache eviction (6 items)", ...args, + ) as string; + expect(rcPrompt).toContain("8-question checklist"); + expect(rcPrompt).toContain("待验证"); + const zhPrompt = Engine.prototype.buildInitialPrompt.call( + self, "bot", "[根因] 压缩链路三连断(6090/6091/6092)", ...args, + ) as string; + expect(zhPrompt).toContain("8-question checklist"); + const plainPrompt = Engine.prototype.buildInitialPrompt.call( + self, "bot", "普通 issue 标题", ...args, + ) as string; + expect(plainPrompt).not.toContain("8-question checklist"); + }); }); diff --git a/scripts/classifier-board.py b/scripts/classifier-board.py index 2d418cb..41b849d 100644 --- a/scripts/classifier-board.py +++ b/scripts/classifier-board.py @@ -35,6 +35,10 @@ DB = "/var/lib/ework-web/share/ework-web/ework.db" BOARD_TITLE = "Issue 根因归类板(自动维护,勿手编)" AGG_LABEL = "root-cause-batch" +# Label for PRs delivered from a [Root Cause] aggregation ticket (owner policy +# 2026-11-13): the board re-checks it every round and boosts the PR so RC work +# always jumps the queue. Distinct from root-cause-batch (umbrella issues only). +RC_PR_LABEL = "root-cause" # owner policy 2026-11-11: >=2 open issues of the same root cause get a # [Root Cause] aggregation issue that goes through the normal pipeline. AGG_THRESHOLD = 2 @@ -530,8 +534,8 @@ def update_agg(merged, open_set): + "对本批 issue 做**一个**根本性修复 PR:\n" + "- PR 描述里用 `Fixes #...` 逐个列出上面每一个 GitHub issue 号(没有 GitHub 号的写镜像号)\n" + "- 若某个 issue 已有自己的 PR 且方向一致,cherry-pick 其 commit 并保留原作者署名(`-x`);由你判断是否值得\n" - + "- 标签按本 PR 的 diff 独立判断(类别 + 优先级),不要抄任何来源 issue\n" - + "- 修完后回帖本线程:改了什么、为什么这样修\n" + + "- PR 必须打标签:`root-cause`(固定,来自根因汇聚单)+ 按本 PR 的 diff 独立判断的类别和优先级标签(最高优先用 p1),不要抄任何来源 issue\n" + + "- 回帖本线程必须是**最终裁决**,结尾固定用中文 8问 清单逐行回答:1 这是啥问题(大白话+触发条件)2 根本原因是啥(组件+机制)3 如何修复(已做的修复或建议修法)4 能否合并/关闭(结论+依据:测试/CI/回归分析)5 URL(相关线程/PR 链接)6 影响面(哪些代码路径/用户)7 测试(什么钉住它)8 风险(还可能坏在哪)。答不实的行写「待验证:原因」,不许漏行\n" ) if len(nums) < AGG_THRESHOLD: # below threshold: never create; but keep an existing ticket's body @@ -577,6 +581,98 @@ def update_agg(merged, open_set): ensured[cat] = {"number": it.get("number"), "title": title} return ensured +BOOST_ENDPOINT_GONE = False + +def boost_issues(numbers, why): + """Mark mirrored issues/PRs top-of-queue (daemon dispatch_priority, PR#63). + Numbers are MIRROR numbers (daemon ids), not GitHub numbers. Tolerates the + endpoint 404-ing until PR#63 deploys (then stops retrying for this process + — no point burning 15s of the 500s budget every round). Never crashes a + board round.""" + global BOOST_ENDPOINT_GONE + if BOOST_ENDPOINT_GONE: + return + nums = sorted({int(n) for n in numbers if str(n).isdigit()}) + if not nums: + return + for attempt in range(3): + try: + req = urllib.request.Request( + "http://127.0.0.1:3101/api/admin/boost", + data=json.dumps({"issue_ids": [str(n) for n in nums]}).encode(), + method="POST", + headers={"Content-Type": "application/json"}) + resp = json.load(urllib.request.urlopen(req, timeout=30)) + print(f"classifier-board: boost {why} -> {resp}") + return + except urllib.error.HTTPError as e: + if e.code == 404: + BOOST_ENDPOINT_GONE = True + print(f"classifier-board: boost endpoint not deployed yet (404) — skipping until daemon updates") + return + print(f"classifier-board: boost {why} attempt {attempt+1} failed: {e}") + time.sleep(5 if attempt else 10) + except Exception as e: + print(f"classifier-board: boost {why} attempt {attempt+1} failed: {e}") + time.sleep(5 if attempt else 10) + +def ensure_rc_pr_labels(merged, open_set): + """PRs that close an RC umbrella or a current member must carry the + root-cause label + be boosted (owner policy 2026-11-13: 最高优先级). The + worker is instructed to label its own PR; this is the safety net for the + ones that forget (the label is the merge-priority handle for the owner). + Matching: umbrella GH numbers from rc-agg.db + current members' GitHub + numbers, word-boundary matched in PR body/title.""" + gh_nums = set() + try: + c = rcdb() + for (num,) in c.execute("SELECT issue_number FROM rc_agg"): + gh_nums.add(int(num)) + c.close() + except Exception: + pass + for n in open_set: + cat = ((merged.get(n) or {}).get("category") or "").strip() + if not cat or cat == "tinyfix": + continue + up = up_num_of(n) + if up: + gh_nums.add(int(up)) + if not gh_nums: + return + rx = re.compile(r"(? Date: Fri, 13 Nov 2026 09:50:40 +0800 Subject: [PATCH 3/4] fix(classifier-board): dedupe boost_rc (double def + double call) left by PR#63, reuse DAEMON_BOOST_URL in boost_issues --- scripts/classifier-board.py | 33 +-------------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/scripts/classifier-board.py b/scripts/classifier-board.py index 41b849d..898c341 100644 --- a/scripts/classifier-board.py +++ b/scripts/classifier-board.py @@ -294,7 +294,6 @@ def open_numbers(): # and stop-work stops any live/queued work on each render (idempotent, silent). SUPPRESSION_PATH = "/var/lib/ework-daemon/share/classifier/suppressed.json" DAEMON_STOP_URL = "http://127.0.0.1:3101/api/admin/stop-work" -DAEMON_BOOST_URL = "http://127.0.0.1:3101/api/admin/boost" def incorporated_numbers(merged, open_set): """{mirror number: reason} for every open issue absorbed into a root-cause @@ -340,35 +339,6 @@ def write_suppression(merged, open_set): time.sleep(5 * (attempt + 1)) print(f"classifier-board: suppression set = {len(nums)} issue(s) -> {SUPPRESSION_PATH}") -def boost_rc(): - """Stamp the live [Root Cause] aggregation issues top-of-queue in the - daemon drain (idempotent; re-applied every round, also covers issues - created earlier in the same round).""" - try: - c = sqlite3.connect(f"file:{RCAGG_DB}?mode=ro", uri=True) - rows = c.execute("SELECT issue_number FROM rc_agg").fetchall() - c.close() - except sqlite3.OperationalError: - return # no rc-agg.db yet (nothing aggregated) — nothing to boost - ids = [n for (n,) in rows if n] - if not ids: - return - for attempt in range(3): - try: - req = urllib.request.Request( - DAEMON_BOOST_URL, - data=json.dumps({"issue_ids": ids}).encode(), - headers={"Content-Type": "application/json"}, - method="POST", - ) - with urllib.request.urlopen(req, timeout=30) as r: - print(f"classifier-board: boost -> {r.read().decode()[:200]}") - break - except Exception as e: - print(f"classifier-board: boost POST failed (attempt {attempt+1}/3): {e}") - if attempt < 2: - time.sleep(5 * (attempt + 1)) - def boost_rc(): """Top-of-queue for the root-cause aggregations themselves (owner policy 2026-11-12): the daemon drains their pending work ahead of the normal @@ -598,7 +568,7 @@ def boost_issues(numbers, why): for attempt in range(3): try: req = urllib.request.Request( - "http://127.0.0.1:3101/api/admin/boost", + DAEMON_BOOST_URL, data=json.dumps({"issue_ids": [str(n) for n in nums]}).encode(), method="POST", headers={"Content-Type": "application/json"}) @@ -838,7 +808,6 @@ def main(): write_suppression(merged, open_set) agg_by_cat = update_agg(merged, open_set) boost_rc() - boost_rc() ensure_label(ABSORBED_LABEL, "d9d9d9") mark_members(agg_by_cat, merged, open_set) ensure_label(AGG_LABEL) From 2b4074bab7c4a56c6ffcbbda44defc7cbd1bde46 Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Fri, 13 Nov 2026 16:46:41 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat(classifier-board):=20rcagg=20PR-body?= =?UTF-8?q?=20marker=20=E2=80=94=20spin-off=20PRs=20get=20root-cause=20lab?= =?UTF-8?q?el=20+=20boost=20(closes=20the=206492-batch=20blind=20spot)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/classifier-board.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/classifier-board.py b/scripts/classifier-board.py index 898c341..a5e223c 100644 --- a/scripts/classifier-board.py +++ b/scripts/classifier-board.py @@ -505,6 +505,7 @@ def update_agg(merged, open_set): + "- PR 描述里用 `Fixes #...` 逐个列出上面每一个 GitHub issue 号(没有 GitHub 号的写镜像号)\n" + "- 若某个 issue 已有自己的 PR 且方向一致,cherry-pick 其 commit 并保留原作者署名(`-x`);由你判断是否值得\n" + "- PR 必须打标签:`root-cause`(固定,来自根因汇聚单)+ 按本 PR 的 diff 独立判断的类别和优先级标签(最高优先用 p1),不要抄任何来源 issue\n" + + "- PR 描述末尾必须加标记行 ``(汇聚板靠它自动识别根因 PR 补标签/插队;即使修复拆成多个子单各自提 PR,每个 PR 都要带这行)\n" + "- 回帖本线程必须是**最终裁决**,结尾固定用中文 8问 清单逐行回答:1 这是啥问题(大白话+触发条件)2 根本原因是啥(组件+机制)3 如何修复(已做的修复或建议修法)4 能否合并/关闭(结论+依据:测试/CI/回归分析)5 URL(相关线程/PR 链接)6 影响面(哪些代码路径/用户)7 测试(什么钉住它)8 风险(还可能坏在哪)。答不实的行写「待验证:原因」,不许漏行\n" ) if len(nums) < AGG_THRESHOLD: @@ -608,9 +609,14 @@ def ensure_rc_pr_labels(merged, open_set): up = up_num_of(n) if up: gh_nums.add(int(up)) - if not gh_nums: - return - rx = re.compile(r"(? marker — that is the + # authoritative signal (category name is the authority, per the token design). + rc_marker = re.compile(r"rcagg:[a-z0-9][a-z0-9-]*") added = 0 boosted = [] for page in range(1, 4): @@ -625,7 +631,8 @@ def ensure_rc_pr_labels(merged, open_set): num = pr.get("number") if num is None: continue - if not rx.search((pr.get("body") or "") + "\n" + (pr.get("title") or "")): + text = (pr.get("body") or "") + "\n" + (pr.get("title") or "") + if not ((rx and rx.search(text)) or rc_marker.search(pr.get("body") or "")): continue boosted.append(num) # mirror number == GH number (1:1 sync) if issue_has_label(pr, RC_PR_LABEL):