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.

feat(inbox): retain bounded legacy delivery [R2,N26,H16]

Corey Olson7595a5b60eeb
diff --git a/docs/api.md b/docs/api.md
index f558378b..abc19a9f 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -657,6 +657,7 @@ The incoming agent joins a new worktree and runs `pullboard handoff --take <id>`
`activity: { entries, digests, cursor }`. Entries carry their original event id, timestamp, kind
and item reference where relevant. They select the caller's active builds/reviews and their
upstream/downstream dependencies, files from its plan or actual Git diff, cited row decisions,
+drafts/applications and committed row-content changes,
and addressed messages. Other lane activity is summarized. Explicit coordinator/person
`shout all <text> --news` announcements appear in a one-line digest at session start;
untyped broadcasts are direct. A missing Git object reports unknown overlap, never zero.
diff --git a/src/activity-feed.js b/src/activity-feed.js
index 7c3e812b..5bdd45ef 100644
--- a/src/activity-feed.js
+++ b/src/activity-feed.js
@@ -69,6 +69,15 @@ function activityEntry(event, text, extra = {}) {
...(event.item_id === null ? {} : { item: event.item_id }), text, ...extra };
}
+/** Treat only a versioned authorized announcement as news; old arbitrary metadata stays direct. */
+export function isActivityNews(event, message) {
+ const detail = activityEventDetail(event);
+ return event.event_kind === 'shout' && detail?.news === true && detail.newsFormat === 1
+ && event.item_id === null && ['coordinator', 'person'].includes(message?.shout_from)
+ && event.event_by === message.shout_from && message.shout_to === 'all'
+ && !message.shout_decision && !message.shout_request && message.shout_answers === null;
+}
+
/** Select one read-only activity stream and compact digests without changing native history or audiences. */
export function projectAgentActivity({ agent, interests, events, shouts, changesForMain,
sessionStart = false, after = 0, newsAfter = 0, cursor }) {
@@ -83,7 +92,7 @@ export function projectAgentActivity({ agent, interests, events, shouts, changes
} else if (interests.byId.get(event.item_id)?.item_lane === interests.lane) { laneCount++; laneItems.add(event.item_id); }
continue;
}
- if (event.event_kind === 'shout' && detail.news === true && detail.newsFormat === 1) {
+ if (isActivityNews(event, messages.get(detail.shout))) {
if (sessionStart && event.event_id > newsAfter && messages.has(detail.shout)) announcements.push(messages.get(detail.shout));
continue;
}
diff --git a/src/board-query.js b/src/board-query.js
index 87110165..6c2e4c21 100644
--- a/src/board-query.js
+++ b/src/board-query.js
@@ -2,6 +2,7 @@ import { itemById } from './board-item-read.js';
import {
activityEventDetail,
activityInterests,
+ isActivityNews,
itemActivity,
projectAgentActivity,
} from './activity-feed.js';
@@ -459,7 +460,9 @@ export function agentActivity(board, agentId, { after = 0, newsAfter = 0, workin
throw new Refused('BAD_ACTIVITY_CURSOR', 'activity cursors are nonnegative event ids; remove the damaged local inbox cursor and read inbox again');
}
// Freeze a high-water mark before any Git seam or other query; later events must remain pending.
- const cursor = board.db.prepare('SELECT COALESCE(MAX(event_id),0) AS id FROM event').get().id;
+ const { cursor, shoutCursor } = board.db.prepare(`SELECT
+ (SELECT COALESCE(MAX(event_id),0) FROM event) AS cursor,
+ (SELECT COALESCE(MAX(shout_id),0) FROM shout) AS shoutCursor`).get();
const items = listItems(board, { all: true });
const builds = items.filter(item => item.item_status === 'claimed' && item.item_owner === agentId);
const observed = typeof workingFiles === 'function' ? workingFiles(builds) : workingFiles;
@@ -476,21 +479,22 @@ export function agentActivity(board, agentId, { after = 0, newsAfter = 0, workin
for (const event of board.db.prepare(`SELECT * FROM event WHERE event_id>? AND event_id<=?
AND event_kind IN ('main-moved','row_decision','row_apply','row_draft','shout','pass','answer') ORDER BY event_id`).all(after, cursor)) rows.set(event.event_id, event);
if (sessionStart) for (const event of board.db.prepare(`SELECT * FROM event WHERE event_id>? AND event_id<=? AND event_kind='shout'
- AND json_valid(event_detail) AND json_extract(event_detail,'$.news')=1
- AND json_extract(event_detail,'$.newsFormat')=1 ORDER BY event_id`).all(newsAfter, cursor)) rows.set(event.event_id, event);
- const shoutCursor = Math.max(0, ...['shout', 'answer', 'pass'].map(kind => board.db.prepare(
- `SELECT json_extract(event_detail,'$.shout') AS id FROM event WHERE event_kind=? AND event_id<=? ORDER BY event_id DESC LIMIT 1`)
- .get(kind, cursor)?.id ?? 0));
+ AND json_extract(CASE WHEN json_valid(event_detail) THEN event_detail ELSE '{}' END,'$.news')=1
+ AND json_extract(CASE WHEN json_valid(event_detail) THEN event_detail ELSE '{}' END,'$.newsFormat')=1
+ ORDER BY event_id`).all(newsAfter, cursor)) rows.set(event.event_id, event);
const messages = board.db.prepare(`SELECT * ${UNREAD_SQL} AND shout_id<=? ORDER BY shout_id`)
.all(...unreadShoutBindings(agent.agent_last_shout_id, agentId, agent.agent_lane), shoutCursor);
// News delivery uses its own cursor so ordinary inbox reads cannot consume a future session's digest.
- const newsIds = [...rows.values()].filter(event => event.event_kind === 'shout'
+ const possibleNewsIds = [...rows.values()].filter(event => event.event_kind === 'shout'
&& activityEventDetail(event)?.news === true && activityEventDetail(event)?.newsFormat === 1)
- .map(event => activityEventDetail(event).shout);
- for (let offset = 0; offset < newsIds.length; offset += 500) {
- const ids = newsIds.slice(offset, offset + 500);
+ .map(event => activityEventDetail(event).shout).filter(id => Number.isSafeInteger(id) && id > 0);
+ for (let offset = 0; offset < possibleNewsIds.length; offset += 500) {
+ const ids = possibleNewsIds.slice(offset, offset + 500);
messages.push(...board.db.prepare(`SELECT * FROM shout WHERE shout_id IN (${ids.map(() => '?').join(',')}) AND shout_to='all'`).all(...ids));
}
+ const byShout = new Map(messages.map(message => [message.shout_id, message]));
+ const newsIds = [...rows.values()].filter(event => isActivityNews(event, byShout.get(activityEventDetail(event)?.shout)))
+ .map(event => activityEventDetail(event).shout);
for (const event of rows.values()) if (event.event_kind === 'main-moved') event.activityBase = activityBatchBase(board, event);
for (const event of rows.values()) if (event.event_kind === 'row_apply') {
const ids = activityEventDetail(event)?.events;
diff --git a/test/activity-feed.test.js b/test/activity-feed.test.js
index b971dce5..01dc71c5 100644
--- a/test/activity-feed.test.js
+++ b/test/activity-feed.test.js
@@ -217,6 +217,12 @@ test('activity cursors leave events arriving during an observation pending [N26]
assert.equal(unknown.entries.some(entry => entry.text === 'Governing messages survive unknown old detail'), true);
assert.deepEqual(exportBoard(board), intact, 'unknown legacy detail is reported without rewriting it');
assert.throws(() => store.inbox(board, 'web-1', { through: -1 }), error => error.code === 'BAD_ACTIVITY_CURSOR');
+ const oldMessage = store.shout(board, { from: 'coordinator', to: 'all', text: 'A legacy message still has its body', lanes: ['web'] });
+ const oldEvent = board.db.prepare("SELECT event_id FROM event WHERE event_kind='shout' ORDER BY event_id DESC LIMIT 1").get();
+ board.db.prepare('UPDATE event SET event_detail=? WHERE event_id=?').run('{broken legacy message event', oldEvent.event_id);
+ const legacy = store.agentActivity(board, 'web-1', { after: unknown.cursor });
+ assert.ok(store.inbox(board, 'web-1', { through: legacy.shoutCursor }).some(shout => shout.shout_id === oldMessage),
+ 'a corrupt old event cannot block delivery from the canonical message table');
});
test('inbox delivery uses real Git paths and board-bound cursors without consuming later news [R2,N26,H16]', () => {
@@ -296,7 +302,14 @@ test('old ordinary shout replay does not become newly typed news [H16,N26]', (t)
const move = prepareEngineMove(board, 'shout', [{ from: 'coordinator', to: 'all', lanes: ['web'],
text: 'Historical metadata is not a new delivery instruction.', detail: { news: true } }]);
applyEngineMove(board, { ...move, engine: 1 }, { sequence: 1, at: new Date().toISOString() });
+ const agentMove = prepareEngineMove(board, 'shout', [{ from: 'web-1', to: 'all', lanes: ['web'],
+ text: 'Legacy agent metadata cannot hide a direct message.', detail: { news: true, newsFormat: 1 } }]);
+ applyEngineMove(board, { ...agentMove, engine: 1 }, { sequence: 2, at: new Date().toISOString() });
const feed = store.agentActivity(board, 'web-1', { sessionStart: true });
assert.ok(feed.entries.some(entry => entry.text === 'Historical metadata is not a new delivery instruction.'));
assert.deepEqual(feed.digests, [], 'only the new versioned explicit representation is digested');
+ // The sender does not read its own broadcast; the coordinator must still receive it directly.
+ const coordinator = store.agentActivity(board, 'coordinator', { sessionStart: true });
+ assert.ok(coordinator.entries.some(entry => entry.text === 'Legacy agent metadata cannot hide a direct message.'));
+ assert.deepEqual(coordinator.digests, []);
});