Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(inbox): retain unread obligations until recorded [E9,E18,N26]

Corey Olson03520482a7f4
diff --git a/src/activity-delivery-cli.js b/src/activity-delivery-cli.js
index caf7433f..00d7e143 100644
--- a/src/activity-delivery-cli.js
+++ b/src/activity-delivery-cli.js
@@ -60,8 +60,6 @@ export async function deliverActivity(ctx, { actedIds = [], afterSubmit = false,
changesForMain: (commit, detail) => activityMainFiles(ctx.info.root, commit, detail,
{ rowFiles: [ctx.config.spec, ctx.config.practice] }) });
const { observation, newsShouts, shoutCursor, ...activity } = projected;
- const shouts = directShouts ? store.inbox(board, me.id, { through: shoutCursor })
- .filter(shout => !newsShouts.includes(shout.shout_id)) : [];
// Pending obligations survive an output failure: delivery is not acknowledgement.
const retired = handoffMoveProblem(board, me.id, 'recordActivityDelivery', [{ agentId: me.id }]);
if (retired) activity.receipt = { recorded: false, code: retired.code, message: retired.message };
@@ -73,6 +71,8 @@ export async function deliverActivity(ctx, { actedIds = [], afterSubmit = false,
activity.receipt = { recorded: false, code: error.code, message: error.message };
}
}
+ const shouts = directShouts ? store.inbox(board, me.id, { through: shoutCursor, markRead: activity.receipt?.recorded !== false })
+ .filter(shout => !newsShouts.includes(shout.shout_id)) : [];
return { shouts, agents: store.listAgents(board), activity, local };
});
if (delivered.activity.receipt?.recorded !== false && !saveActivityCursor(delivered.local, delivered.activity.cursor)) {
diff --git a/src/inbox-store.js b/src/inbox-store.js
index ca3aa064..020a2720 100644
--- a/src/inbox-store.js
+++ b/src/inbox-store.js
@@ -9,13 +9,13 @@ import {
} from './shout-audience.js';
/**
- * Unread shouts for an agent, oldest first, then marked read.
+ * Unread shouts for an agent, oldest first; an unrecorded delivery can inspect them without consuming them.
*
* @param {any} board
* @param {string} agentId
* @returns {any[]}
*/
-export function inbox(board, agentId, { through } = {}) {
+export function inbox(board, agentId, { through, markRead = true } = {}) {
if (through !== undefined && (!Number.isSafeInteger(through) || through < 0)) {
throw new Refused('BAD_ACTIVITY_CURSOR', 'the inbox high-water mark is a nonnegative shout id; read inbox again');
}
@@ -26,7 +26,7 @@ export function inbox(board, agentId, { through } = {}) {
.prepare(`SELECT * ${UNREAD_SQL}${through === undefined ? '' : ' AND shout_id<=?'} ORDER BY shout_id`)
.all(...unreadShoutBindings(agent.agent_last_shout_id, agentId, agent.agent_lane), ...(through === undefined ? [] : [through]));
const last = shouts.at(-1)?.shout_id ?? agent.agent_last_shout_id;
- board.db.prepare('UPDATE agent SET agent_last_shout_id = ? WHERE agent_id = ?').run(last, agentId);
+ if (markRead) board.db.prepare('UPDATE agent SET agent_last_shout_id = ? WHERE agent_id = ?').run(last, agentId);
if (agentId !== COORDINATOR) return shouts;
const requests = openRequests(board);
const ids = new Set(requests.map((shout) => shout.shout_id));
diff --git a/test/inbox-key-fixture.js b/test/inbox-key-fixture.js
index 1fcce917..21828545 100644
--- a/test/inbox-key-fixture.js
+++ b/test/inbox-key-fixture.js
@@ -14,6 +14,13 @@ function receipts(box) {
finally { board.db.close(); }
}
+/** Observe the inbox's separate unread projection, which must not consume an unrecorded interrupt. */
+function shoutCursors(box) {
+ const board = openBoardForRead(join(box.root, '.git', 'pullboard', 'board.sqlite'));
+ try { return board.db.prepare('SELECT agent_id, agent_last_shout_id FROM agent ORDER BY agent_id').all(); }
+ finally { board.db.close(); }
+}
+
/** Read an optional local cursor without creating it. */
function cursor(box) {
const file = join(box.root, '.git', 'pullboard-activity.json');
@@ -41,6 +48,7 @@ export async function prepareKeylessInbox(box) {
/** Preserve both cursors while displaying a real obligation and refusing explicit acknowledgement. */
export async function readKeylessInbox(box, state) {
const beforeCursor = cursor(box), beforeReceipts = receipts(box);
+ const beforeShouts = shoutCursors(box);
const read = await box.cli('inbox');
assert.equal(read.code, 0, `inbox reads without the key: ${JSON.stringify(read.document?.error ?? null)}`);
assert.equal(read.document.activity.receipt.recorded, false, 'an unavailable canonical receipt is never claimed');
@@ -50,6 +58,7 @@ export async function readKeylessInbox(box, state) {
state.interrupt = interrupt.id;
assert.equal(cursor(box), beforeCursor, 'unrecorded delivery never advances the local cursor');
assert.deepEqual(receipts(box), beforeReceipts, 'the read cannot forge a canonical delivery');
+ assert.deepEqual(shoutCursors(box), beforeShouts, 'an unrecorded read cannot consume its answer through the unread projection');
const acted = await box.cli('inbox', '--acted-on', state.interrupt);
assert.equal(acted.document?.error?.code, 'RELAY_KEY_MISSING', 'explicit acknowledgement stays an authenticated write');
assert.deepEqual(receipts(box), beforeReceipts, 'a refused acknowledgement changes no receipt');