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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(api): deliver inactivity warnings through event polling [H18]
Corey Olson4451a33baf26
diff --git a/relay/README.md b/relay/README.mdindex f9a426e0..057b2e0b 100644--- a/relay/README.md+++ b/relay/README.md@@ -150,7 +150,9 @@ The activity timestamp survives compaction and restart. Links without a move uselink time; older unshipped auth databases receive a full grace period during migration.At sixty idle days, authorized `GET state` and `PUT state` responses include-`state.warning`; the board listing includes `warnings`. A warning contains only public board+`state.warning`; event polls include `warning`, live streams emit a named `warning` event,+and the board listing includes `warnings`. Streams send a warning once when it changes,+with normal authorization on every poll. A warning contains only public boardidentity, `BOARD_INACTIVE`, idle days, the ninety-day deletion deadline and next steps.Linked CLI and view consumers must display this on their next contact; this backend has nonotification delivery and never reads a seal. At ninety idle days, a contact or maintenancediff --git a/relay/retention.js b/relay/retention.jsindex 0ae49dfc..8e8363ca 100644--- a/relay/retention.js+++ b/relay/retention.js@@ -96,8 +96,8 @@ export function createRelayRetention({ directory, backupsDirectory = directory +if (age < WARN) return null;return { board: id, code: 'BOARD_INACTIVE', inactiveDays: Math.floor(age / DAY),deletesAt: new Date(activity + EXPIRE).toISOString(),- message: 'This linked board is inactive and will be deleted after 90 days without a new sealed move.',- next: 'Send a new move before the deadline, or unlink; the local board stays complete.' };+ message: 'This linked board is inactive and will be deleted after 90 days without new board activity.',+ next: 'Make a board move before the deadline, or unlink; the local board stays complete.' };}/** Validate all managed paths before any deletion, leaving unrelated files untouched. */diff --git a/relay/service.js b/relay/service.jsindex 28f3e61a..a0afcf95 100644--- a/relay/service.js+++ b/relay/service.js@@ -155,6 +155,7 @@ export function createRelayHandler({ directory, auth, pollMs = 200, publicOriginif (snapshot && after < snapshot.sequence) throw new Refused('SNAPSHOT_REQUIRED', 'fetch the latest sealed state, then resume after its sequence');return journal.after(after).map(event);}),+ warning: (board) => retention.notice(board.id),move: append,request: async (board, body, who) => (await append(board, body, who, 'request')).body,}, { pollMs });diff --git a/src/api-http.js b/src/api-http.jsindex 2eaf4b27..e8de44c1 100644--- a/src/api-http.js+++ b/src/api-http.js@@ -58,6 +58,7 @@ export function createApiHandler(adapter, { pollMs = 200 } = {}) {let closed = false;let busy = false;let blocked = false;+ let lastWarning = null;let timer;/** Remove this stream and its timer once the client disconnects or access is revoked. */function stop() {@@ -73,6 +74,12 @@ export function createApiHandler(adapter, { pollMs = 200 } = {}) {busy = true;try {who = await adapter.authenticate(req, { board: board.id, write: false });+ const warning = await adapter.warning?.(board, who);+ const serialized = warning ? JSON.stringify({ version: 1, warning }) : null;+ if (serialized !== lastWarning) {+ lastWarning = serialized;+ if (serialized && !res.write('event: warning\ndata: ' + serialized + '\n\n')) { blocked = true; return; }+ }const records = initial ?? await adapter.events(board, after, who);initial = null;for (const event of records) {@@ -121,7 +128,8 @@ export function createApiHandler(adapter, { pollMs = 200 } = {}) {const initial = await adapter.events(board, after, who);const live = String(req.headers.accept ?? '').split(',').some((part) => /^\s*text\/event-stream\s*(?:;|$)/i.test(part));if (live) return await stream(req, res, board, who, after, initial);- return json(res, 200, { events: initial });+ const warning = await adapter.warning?.(board, who);+ return json(res, 200, { events: initial, ...(warning ? { warning } : {}) });}if (req.method === 'POST' && route[2] === 'moves') {const moved = await adapter.move(board, await readBody(req), who);diff --git a/test/relay-retention.test.js b/test/relay-retention.test.jsindex 05325a6b..467bd9aa 100644--- a/test/relay-retention.test.js+++ b/test/relay-retention.test.js@@ -81,6 +81,25 @@ test('[H18] warnings begin at sixty days on authorized contact; compaction and rassert.equal(warned.body.state.warning.inactiveDays, 60);assert.equal(warned.body.state.warning.deletesAt, new Date(start + 90 * DAY).toISOString());assert.equal((await box.call(null)).body.warnings.length, 2);+ assert.equal((await box.call(A, { path: '/events?after=0' })).body.warning.code, 'BOARD_INACTIVE');+ const controller = new AbortController();+ const warningTimeout = setTimeout(() => controller.abort(), 10_000);+ warningTimeout.unref();+ t.after(() => { clearTimeout(warningTimeout); controller.abort(); });+ const stream = await fetch('http://127.0.0.1:' + box.relay.port + '/api/v1/boards/' + A + '/events?after=0', {+ headers: { authorization: 'Bearer ' + box.signed.token, accept: 'text/event-stream' }, signal: controller.signal,+ });+ const reader = stream.body.getReader();+ let delivered = '';+ try {+ while (!delivered.includes('BOARD_INACTIVE')) {+ const chunk = await reader.read();+ assert.equal(chunk.done, false);+ delivered += new TextDecoder().decode(chunk.value);+ }+ assert.ok(delivered.includes('BOARD_INACTIVE'), 'a live view receives the same authorized warning');+ } finally { clearTimeout(warningTimeout); controller.abort(); reader.releaseLock(); }+const snapshot = await box.call(A, { method: 'PUT', body: { sequence: 1, sealed: box.payload.toString('base64url') } });assert.equal(snapshot.body.state.warning.inactiveDays, 60, 'snapshot upload does not reset inactivity');assert.equal(box.journal(A, (db) => db.after(0).length), 0, 'all covered history is folded into the snapshot');