Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
49 changes: 33 additions & 16 deletions dist/unanswered.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand All @@ -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);
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion plugins/claude/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
51 changes: 35 additions & 16 deletions src/unanswered.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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[];
}
Expand All @@ -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);
Expand All @@ -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;
Expand Down
31 changes: 26 additions & 5 deletions test/unanswered.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
});
Loading