From 8ff8aeee7e7e649f18902fddf1127c8a9b365b2e Mon Sep 17 00:00:00 2001 From: Keaton Hoskins Date: Mon, 2 Nov 2026 16:16:07 -0800 Subject: [PATCH] fix(T768): unanswered mail with no lead alerts each sender; report long backlogs 20 at a time; release v0.5.57 When an agent has no other lead (no project lead, or it is the lead), each sender gets one alert naming only its own unanswered messages. The sweep skips copies already reported, so a backlog over 20 is reported across sweeps, and every reported message is named (0.5.56 named only the first 10 of each alert). Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 3 ++ dist/unanswered.js | 49 +++++++++++++++------- package-lock.json | 4 +- package.json | 2 +- plugins/claude/.claude-plugin/plugin.json | 2 +- src/unanswered.ts | 51 ++++++++++++++++------- test/unanswered.test.ts | 31 +++++++++++--- 7 files changed, 101 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0feb31b3..0fa79d4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +## 0.5.57 (2026-11-02) + +- **Unanswered mail reaches someone even without a project lead (T768, owner decision 2026-11-02).** The 2-hour alert from 0.5.56 went only to a project lead, and most projects have none, so it told nobody. Now, when an agent has no other lead (its project has none, or it is the lead), each sender gets one alert naming only its own unanswered messages. A backlog longer than 20 messages is reported across sweeps, and each message is named exactly once (0.5.56 named only the first 10 of each alert). - **Faster CI and releases (T766, T767, owner decisions 2026-11-02).** The suite (about 26 minutes per platform, run one test at a time) now runs as 4 parallel shards per platform, in pull requests and on release tags. Pushes to main run CI only when a workflow file changes or when started by hand, so a merge of a PR that already passed is not tested again. The required check `test (ubuntu-24.04)` keeps its name and turns green only when every shard passed. ## 0.5.56 (2026-11-02) diff --git a/dist/unanswered.js b/dist/unanswered.js index d746c27a..59442fc6 100644 --- a/dist/unanswered.js +++ b/dist/unanswered.js @@ -21,11 +21,12 @@ export function autoAckRead(store, ids, agent, now = Date.now()) { store.audit("auto_ack", { ...(agent ? { agent } : {}), count: n, why: "auto: read (informational mail)" }); return n; } -/** Work mail `agent` read at least `age` ago (within the lookback), still unacked and with no reply from it. Newest first. */ -export function unansweredMail(node, agent, age, now = Date.now()) { +/** Work mail `agent` read at least `age` ago (within the lookback), still unacked and with no reply from it. Newest first, + * at most 20; `unreported` leaves out copies already reported, so a longer backlog is reported 20 at a time. */ +export function unansweredMail(node, agent, age, now = Date.now(), o = {}) { return node.store.db.prepare(`SELECT m.id id, m.kind kind, m.from_addr "from", d.updated_at read_at, d.note note FROM deliveries d JOIN messages m ON m.id=d.msg_id - WHERE d.agent=? AND d.state='read' AND d.updated_at<=? AND d.updated_at>=? AND m.from_addr NOT LIKE 'mbx@%' AND ${WORK} + WHERE d.agent=? AND d.state='read' ${o.unreported ? "AND coalesce(d.note,'')<>'unanswered'" : ""} AND d.updated_at<=? AND d.updated_at>=? AND m.from_addr NOT LIKE 'mbx@%' AND ${WORK} AND NOT EXISTS (SELECT 1 FROM messages r WHERE r.reply_to=m.id AND r.from_addr=?) ORDER BY d.updated_at DESC LIMIT 20`).all(agent, iso(now - age), iso(now - LOOKBACK_MS), `${agent}@${node.host}`); } @@ -47,7 +48,8 @@ export function leadToAlert(node, agent, now = Date.now()) { const lead = project ? activeLead(node, project, new Date(now)) : null; return lead && lead.host === node.host && lead.agent !== agent ? lead.agent : null; } -/** Daemon sweep: close informational mail already read, then alert each lead once per message unanswered 2 h after read. +/** Daemon sweep: close informational mail already read, then report each message unanswered 2 h after read, once: to + * the project lead, or (no lead) to its sender. * The alerted copies carry note 'unanswered', which the sender's receipts show. Returns the agents reported. */ export function sweepUnanswered(node, now = Date.now()) { autoAckRead(node.store, undefined, undefined, now); @@ -57,22 +59,37 @@ export function sweepUnanswered(node, now = Date.now()) { .map((r) => r.agent); const out = []; for (const agent of agents) { - const due = unansweredMail(node, agent, ALERT_AFTER_MS, now).filter((u) => u.note !== "unanswered"); - const lead = due.length ? leadToAlert(node, agent, now) : null; - if (!lead) + const due = unansweredMail(node, agent, ALERT_AFTER_MS, now, { unreported: true }); + if (!due.length) continue; - const list = due.slice(0, 10).map((u) => `${u.id} (${u.kind} from ${u.from})`).join(", "); - try { - node.send({ from: "mbx", to: [lead], kind: "alert", subject: `Unanswered mail: ${agent} read work and did not reply or ack`.slice(0, 200), - body: `${agent} read ${due.length} work message(s) over 2 h ago and has neither replied nor acked them: ${list}${due.length > 10 ? ", …" : ""}. ` - + `Check on ${agent} (it may have moved on mid-task), or reassign the work.` }); + // T768 (owner decision 2026-11-02): with no other lead to tell (no project lead, or the agent is the lead), each + // sender hears about its own requests instead: they asked, so they are the ones waiting. + const lead = leadToAlert(node, agent, now); + const groups = lead ? [{ to: lead, rows: due }] + : [...Map.groupBy(due.filter((u) => u.from !== `${agent}@${node.host}` && !u.from.startsWith("owner@")), (u) => u.from)] + .map(([to, rows]) => ({ to, rows })); + const told = []; + for (const g of groups) { + // Every message it marks reported is named (at most 20 per sweep), so none is reported without its id. + const list = g.rows.map((u) => `${u.id} (${u.kind}${lead ? ` from ${u.from}` : ""})`).join(", "); + try { + node.send({ from: "mbx", to: [g.to], kind: "alert", subject: `Unanswered mail: ${agent} read work and did not reply or ack`.slice(0, 200), + body: lead + ? `${agent} read ${g.rows.length} work message(s) over 2 h ago and has neither replied nor acked them: ${list}. ` + + `Check on ${agent} (it may have moved on mid-task), or reassign the work.` + : `${agent} read ${g.rows.length} of your work message(s) over 2 h ago and has neither replied nor acked them: ${list}. ` + + `Its project has no lead to tell. Follow up with ${agent}, or send the work to another agent.` }); + told.push(g.to); + } + catch { /* that recipient is retried on the next sweep */ } } - catch { + const done = new Set(told); + const marked = lead ? (told.length ? due : []) : due.filter((u) => done.has(u.from) || u.from === `${agent}@${node.host}` || u.from.startsWith("owner@")); + if (!marked.length) continue; - } - node.store.tx(() => { for (const u of due) + node.store.tx(() => { for (const u of marked) node.store.db.prepare("UPDATE deliveries SET note='unanswered' WHERE msg_id=? AND agent=? AND state='read'").run(u.id, agent); }); - node.store.audit("unanswered.alert", { agent, lead, count: due.length }); + node.store.audit("unanswered.alert", { agent, ...(lead ? { lead } : { senders: told }), count: marked.length }); out.push(agent); } return out; diff --git a/package-lock.json b/package-lock.json index bf2f663d..9168f577 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "agentmbx", - "version": "0.5.56", + "version": "0.5.57", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "agentmbx", - "version": "0.5.56", + "version": "0.5.57", "license": "BUSL-1.1", "dependencies": { "@modelcontextprotocol/sdk": "^1.30.1", diff --git a/package.json b/package.json index 1613f47e..afe1a0cf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "agentmbx", - "version": "0.5.56", + "version": "0.5.57", "description": "AgentMBX: signed messages between AI coding agents (Claude, Codex, Kimi, OpenCode, Hermes, Antigravity) on one machine and across a LAN, with wake-up adapters and an owner-authority master agent.", "type": "module", "bin": { diff --git a/plugins/claude/.claude-plugin/plugin.json b/plugins/claude/.claude-plugin/plugin.json index 6a3016b3..2732050c 100644 --- a/plugins/claude/.claude-plugin/plugin.json +++ b/plugins/claude/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "agentmbx", - "version": "0.5.56", + "version": "0.5.57", "description": "Renders this Claude Code session's AgentMBX status. It does not compute status itself.", "author": { "name": "AgentMBX" diff --git a/src/unanswered.ts b/src/unanswered.ts index 56642de1..852cc90d 100644 --- a/src/unanswered.ts +++ b/src/unanswered.ts @@ -1,7 +1,8 @@ // T765 (owner decision 2026-11-02): read-but-unanswered mail. Mail that asks for nothing (message, reply or status, no // needs_reply, no owner authority) closes when it is read. Work mail (request, task, decision, alert, or anything with // needs_reply) an agent read but neither answered nor acked is named again after 30 min, at the next prompt or before -// the session goes idle, and after 2 h its project lead gets one alert. Ids and senders only, never content. +// the session goes idle, and after 2 h its project lead (or, with none, each sender: T768) gets one alert. Ids and +// senders only, never content. import type { MbxNode } from "./node.ts"; import type { Store } from "./store.ts"; import { activeLead } from "./lead-record.ts"; @@ -31,11 +32,12 @@ export function autoAckRead(store: Store, ids?: string[], agent?: string, now = export interface Unanswered { id: string; kind: string; from: string; read_at: string; note: string | null } -/** Work mail `agent` read at least `age` ago (within the lookback), still unacked and with no reply from it. Newest first. */ -export function unansweredMail(node: MbxNode, agent: string, age: number, now = Date.now()): Unanswered[] { +/** Work mail `agent` read at least `age` ago (within the lookback), still unacked and with no reply from it. Newest first, + * at most 20; `unreported` leaves out copies already reported, so a longer backlog is reported 20 at a time. */ +export function unansweredMail(node: MbxNode, agent: string, age: number, now = Date.now(), o: { unreported?: boolean } = {}): Unanswered[] { return node.store.db.prepare(`SELECT m.id id, m.kind kind, m.from_addr "from", d.updated_at read_at, d.note note FROM deliveries d JOIN messages m ON m.id=d.msg_id - WHERE d.agent=? AND d.state='read' AND d.updated_at<=? AND d.updated_at>=? AND m.from_addr NOT LIKE 'mbx@%' AND ${WORK} + WHERE d.agent=? AND d.state='read' ${o.unreported ? "AND coalesce(d.note,'')<>'unanswered'" : ""} AND d.updated_at<=? AND d.updated_at>=? AND m.from_addr NOT LIKE 'mbx@%' AND ${WORK} AND NOT EXISTS (SELECT 1 FROM messages r WHERE r.reply_to=m.id AND r.from_addr=?) ORDER BY d.updated_at DESC LIMIT 20`).all(agent, iso(now - age), iso(now - LOOKBACK_MS), `${agent}@${node.host}`) as unknown as Unanswered[]; } @@ -59,7 +61,8 @@ export function leadToAlert(node: MbxNode, agent: string, now = Date.now()): str return lead && lead.host === node.host && lead.agent !== agent ? lead.agent : null; } -/** Daemon sweep: close informational mail already read, then alert each lead once per message unanswered 2 h after read. +/** Daemon sweep: close informational mail already read, then report each message unanswered 2 h after read, once: to + * the project lead, or (no lead) to its sender. * The alerted copies carry note 'unanswered', which the sender's receipts show. Returns the agents reported. */ export function sweepUnanswered(node: MbxNode, now = Date.now()): string[] { autoAckRead(node.store, undefined, undefined, now); @@ -69,17 +72,33 @@ export function sweepUnanswered(node: MbxNode, now = Date.now()): string[] { .map((r) => r.agent); const out: string[] = []; for (const agent of agents) { - const due = unansweredMail(node, agent, ALERT_AFTER_MS, now).filter((u) => u.note !== "unanswered"); - const lead = due.length ? leadToAlert(node, agent, now) : null; - if (!lead) continue; - const list = due.slice(0, 10).map((u) => `${u.id} (${u.kind} from ${u.from})`).join(", "); - try { - node.send({ from: "mbx", to: [lead], kind: "alert", subject: `Unanswered mail: ${agent} read work and did not reply or ack`.slice(0, 200), - body: `${agent} read ${due.length} work message(s) over 2 h ago and has neither replied nor acked them: ${list}${due.length > 10 ? ", …" : ""}. ` - + `Check on ${agent} (it may have moved on mid-task), or reassign the work.` }); - } catch { continue; } - node.store.tx(() => { for (const u of due) node.store.db.prepare("UPDATE deliveries SET note='unanswered' WHERE msg_id=? AND agent=? AND state='read'").run(u.id, agent); }); - node.store.audit("unanswered.alert", { agent, lead, count: due.length }); + const due = unansweredMail(node, agent, ALERT_AFTER_MS, now, { unreported: true }); + if (!due.length) continue; + // T768 (owner decision 2026-11-02): with no other lead to tell (no project lead, or the agent is the lead), each + // sender hears about its own requests instead: they asked, so they are the ones waiting. + const lead = leadToAlert(node, agent, now); + const groups = lead ? [{ to: lead, rows: due }] + : [...Map.groupBy(due.filter((u) => u.from !== `${agent}@${node.host}` && !u.from.startsWith("owner@")), (u) => u.from)] + .map(([to, rows]) => ({ to, rows })); + const told: string[] = []; + for (const g of groups) { + // Every message it marks reported is named (at most 20 per sweep), so none is reported without its id. + const list = g.rows.map((u) => `${u.id} (${u.kind}${lead ? ` from ${u.from}` : ""})`).join(", "); + try { + node.send({ from: "mbx", to: [g.to], kind: "alert", subject: `Unanswered mail: ${agent} read work and did not reply or ack`.slice(0, 200), + body: lead + ? `${agent} read ${g.rows.length} work message(s) over 2 h ago and has neither replied nor acked them: ${list}. ` + + `Check on ${agent} (it may have moved on mid-task), or reassign the work.` + : `${agent} read ${g.rows.length} of your work message(s) over 2 h ago and has neither replied nor acked them: ${list}. ` + + `Its project has no lead to tell. Follow up with ${agent}, or send the work to another agent.` }); + told.push(g.to); + } catch { /* that recipient is retried on the next sweep */ } + } + const done = new Set(told); + const marked = lead ? (told.length ? due : []) : due.filter((u) => done.has(u.from) || u.from === `${agent}@${node.host}` || u.from.startsWith("owner@")); + if (!marked.length) continue; + node.store.tx(() => { for (const u of marked) node.store.db.prepare("UPDATE deliveries SET note='unanswered' WHERE msg_id=? AND agent=? AND state='read'").run(u.id, agent); }); + node.store.audit("unanswered.alert", { agent, ...(lead ? { lead } : { senders: told }), count: marked.length }); out.push(agent); } return out; diff --git a/test/unanswered.test.ts b/test/unanswered.test.ts index 87ca1a50..8e6445cd 100644 --- a/test/unanswered.test.ts +++ b/test/unanswered.test.ts @@ -84,10 +84,31 @@ test("T765: the sweep closes informational backlog and alerts the lead once per assert.equal(alerts().length, 1); }); -test("T765: the lead's own unanswered mail alerts no one", (t) => { +test("T768: with no other lead to tell, each sender hears about its own unanswered requests, once", (t) => { const { n, alerts } = world(t); - const id = n.send({ from: "boss", to: ["alpha-lead"], subject: "s", body: "b", kind: "request" }).envelope.id; - n.setDelivery(id, "alpha-lead", "read"); - assert.deepEqual(sweepUnanswered(n, Date.now() + ALERT_AFTER_MS + 1), []); - assert.equal(alerts().filter((a) => a.subject.startsWith("Unanswered")).length, 0); + // alpha-lead is its project's lead: there is no one above it, so the senders are told. + const a = n.send({ from: "boss", to: ["alpha-lead"], subject: "secret-subject", body: "secret-body", kind: "request" }).envelope.id; + const b = n.send({ from: "peer", to: ["alpha-lead"], subject: "s", body: "b", kind: "task" }).envelope.id; + for (const id of [a, b]) n.setDelivery(id, "alpha-lead", "read"); + const later = Date.now() + ALERT_AFTER_MS + 1; + assert.deepEqual(sweepUnanswered(n, later), ["alpha-lead"]); + const to = (who: string) => (n.store.db.prepare("SELECT m.envelope FROM deliveries d JOIN messages m ON m.id=d.msg_id WHERE d.agent=?").all(who) as { envelope: string }[]) + .map((r) => JSON.parse(r.envelope) as { kind: string; subject: string; body: string }).filter((e) => e.subject.startsWith("Unanswered")); + const [toBoss] = to("boss"), [toPeer] = to("peer"); + assert.match(toBoss.body, new RegExp(a)); assert.doesNotMatch(toBoss.body, new RegExp(b), "a sender sees only its own requests"); + assert.match(toPeer.body, new RegExp(b)); + assert.ok(!toBoss.body.includes("secret")); + assert.equal(alerts().filter((e) => e.subject.startsWith("Unanswered")).length, 0, "the lead is not told about itself"); + assert.deepEqual(sweepUnanswered(n, later + 60_000), [], "once per message"); +}); + +test("T768: a backlog longer than one alert is reported 20 at a time, never repeating a message", (t) => { + const { n, send, alerts } = world(t); + const ids = Array.from({ length: 25 }, () => send("request")); + for (const id of ids) n.setDelivery(id, "alpha-worker", "read"); + const later = Date.now() + ALERT_AFTER_MS + 1; + sweepUnanswered(n, later); sweepUnanswered(n, later + 60_000); sweepUnanswered(n, later + 120_000); + const bodies = alerts().filter((a) => a.subject.startsWith("Unanswered")).map((a) => a.body); + assert.equal(bodies.length, 2); + for (const id of ids) assert.equal(bodies.filter((b) => b.includes(id)).length, 1, `${id} reported exactly once`); });