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
perf(presence): throttle private heartbeat writes each minute [B3,C7]
Corey Olson61545c4844f9
diff --git a/src/cli-presence.js b/src/cli-presence.jsindex 732e78ee..d35e1045 100644--- a/src/cli-presence.js+++ b/src/cli-presence.js@@ -1,7 +1,6 @@/** One authenticated, machine-local heartbeat per command, independent of shared-board write locks [B3]. */import { context } from './cli-read-context.js';import {- agentAt,closeBoard,openBoardForRead,} from './board-query.js';@@ -17,7 +16,8 @@ export function heartbeatCommand(io) {const ctx = context(io);board = openBoardForRead(ctx.file, ctx.clock);if (!board) return;- const seat = agentAt(board, ctx.info.root);+ // Only the registered id is needed: projecting model/presence would reopen this same sidecar.+ const seat = board.db.prepare('SELECT agent_id FROM agent WHERE agent_path=?').get(ctx.info.root);if (seat && heartbeatSeat(board, seat.agent_id)) recorded.add(io);} catch (error) {if (!['NO_CONFIG', 'NOT_A_REPO'].includes(error.code)) io.err(`presence heartbeat unavailable: ${error.message}`);diff --git a/src/seat-presence.js b/src/seat-presence.jsindex ee65e896..eda1052c 100644--- a/src/seat-presence.js+++ b/src/seat-presence.js@@ -3,6 +3,7 @@ import { existsSync } from 'node:fs';import { DatabaseSync } from 'node:sqlite';const memory = new WeakMap();+const HEARTBEAT_INTERVAL_MS = 60_000;/** Read the native board identity once; an unidentifiable board supplies no local liveness. */function observationIdentity(board) {@@ -16,7 +17,24 @@ function observationFile(board) {return file ? `${file}.presence.sqlite` : null;}-/** Update exactly one local seat row; registration and command activity are observations, not moves. */+/** Keep a persisted observation fresh for one minute; clock rollback must replace a future value. */+function observationIsFresh(at, now) {+ const elapsed = now - Date.parse(at);+ return Number.isFinite(elapsed) && elapsed >= 0 && elapsed < HEARTBEAT_INTERVAL_MS;+}++/** Read one existing observation without opening a writer or creating any sidecar schema. */+function persistedObservation(file, key) {+ if (!existsSync(file)) return null;+ const db = new DatabaseSync(file, { readOnly: true });+ try {+ db.exec('PRAGMA busy_timeout=250');+ if (!db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='heartbeat'").get()) return null;+ return db.prepare('SELECT at FROM heartbeat WHERE seat=?').get(key)?.at ?? null;+ } finally { db.close(); }+}++/** Observe authenticated activity, persisting at most once per seat/minute, never as a shared move. */export function heartbeatSeat(board, id) {if (!board.db.prepare('SELECT 1 FROM agent WHERE agent_id=?').get(id)) return false;const identity = observationIdentity(board);@@ -26,14 +44,17 @@ export function heartbeatSeat(board, id) {const file = observationFile(board);if (!file) {const rows = memory.get(board.db) ?? new Map();- rows.set(key, at);+ if (!observationIsFresh(rows.get(key), Date.parse(at))) rows.set(key, at);memory.set(board.db, rows);return true;}+ if (observationIsFresh(persistedObservation(file, key), Date.parse(at))) return true;const db = new DatabaseSync(file);try {db.exec('PRAGMA busy_timeout=250; CREATE TABLE IF NOT EXISTS heartbeat(seat TEXT PRIMARY KEY, at TEXT NOT NULL)');- db.prepare('INSERT INTO heartbeat(seat,at) VALUES (?,?) ON CONFLICT(seat) DO UPDATE SET at=excluded.at').run(key, at);+ // A peer may have refreshed after the read: recheck under this write transaction.+ db.prepare('INSERT INTO heartbeat(seat,at) VALUES (?,?) ON CONFLICT(seat) DO UPDATE SET at=excluded.at WHERE heartbeat.at<=? OR heartbeat.at>?')+ .run(key, at, new Date(Date.parse(at) - HEARTBEAT_INTERVAL_MS).toISOString(), at);return true;} finally { db.close(); }}