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.

test(core): trace resume diagnostic costs [N19,N26]

Corey Olson4be35c1d11f2
diff --git a/src/commands/resume.js b/src/commands/resume.js
index e2a2431b..43cafa64 100644
--- a/src/commands/resume.js
+++ b/src/commands/resume.js
@@ -105,6 +105,14 @@ import {
worktreeLocation,
} from '../cli.js';
+/** Temporary bounded observation for coordinator25919; never a submitted product API. */
+const RESUME_OBSERVATIONS = [];
+
+/** Drain the private diagnostic spans after the measured fixture command. */
+export function takeResumeObservations() {
+ return RESUME_OBSERVATIONS.splice(0);
+}
+
/**
* Resume's one compatibility move (the approval baseline) is bookkeeping: a session that cannot
* reach the board key (SSH, a scheduled job, a locked keychain) still reads the whole card, and the moves wait for a
@@ -136,7 +144,15 @@ function keylessBookkeeping(send) {
* @returns {number}
*/
export async function resumeHere(io, view, diagnostics = false) {
+ let observedAt = performance.now();
+ /** Record disjoint observational spans; no result, authority or command input changes. */
+ const observed = (phase) => {
+ const now = performance.now();
+ if (RESUME_OBSERVATIONS.length < 80) RESUME_OBSERVATIONS.push({ phase, ms: now - observedAt });
+ observedAt = performance.now();
+ };
const ctx = context(io);
+ observed('context');
const ordered = keylessBookkeeping(sendOrdered);
const initialBaseline = withBoardRead(ctx, board => {
whoAmI(ctx, board);
@@ -149,10 +165,13 @@ export async function resumeHere(io, view, diagnostics = false) {
agentId: COORDINATOR, baseline: initialBaseline,
}]));
}
+ observed('baseline bookkeeping');
resumeSentinels({ ctx, withBoard: withBoardRead });
+ observed('due sentinel notice');
const { root, isMain } = ctx.info;
const mainRoot = diagnostics ? primaryCheckoutRoot(ctx.info) : null;
const worktreeConfig = mainRoot ? (isMain ? ctx.config : loadConfig(mainRoot)) : null;
+ observed('primary identity + actual working config');
let setupScope;
let doctrine;
let sources;
@@ -160,6 +179,7 @@ export async function resumeHere(io, view, diagnostics = false) {
setupScope = diagnostics ? setupIdentity(board) : null;
sources = diagnostics ? null : await readResumeSources(ctx, board);
doctrine = diagnostics ? agentDoctrine(ctx, board) : sources.doctrine;
+ observed('shared doctrine preparation');
const me = whoAmI(ctx, board);
const projector = diagnostics ? verdictProjector(root, board) : null;
const all = store.listItems(board, { all: true }).map(item => projector ? projector.project(item) : item);
@@ -167,9 +187,11 @@ export async function resumeHere(io, view, diagnostics = false) {
.map(item => ({ ...item, item_checked_commit: store.checkedLandingCommit(board, item) }));
const toMerge = pendingMerges.filter(item => !item.item_verdict_state);
const staleVerdicts = pendingMerges.filter(item => item.item_verdict_state);
+ observed('toMerge + stale verdict projection');
const decisionSections = isMain ? coordinatorDecisionSections(board, ctx) : null;
const { shouts = [], ...decisions } = decisionSections ?? {};
const needsState = resumeNeeds(root, { board, config: ctx.config, includeRigorUndrafted: me.id === COORDINATOR });
+ observed('decisions + personNeeds + fit');
return {
me,
health: recordedHealthFindings(board),
@@ -200,16 +222,21 @@ export async function resumeHere(io, view, diagnostics = false) {
...(diagnostics ? { viewOpened: viewSetupComplete(ctx, board) } : {}),
};
});
+ observed('remaining board card');
card.relayProblems = unlinkedRelayProjects();
+ observed('relay problems');
if (diagnostics) {
card.hookProblems = unwiredHookProblems(root);
+ observed('hook diagnostics');
card.newWorktreeLocation = mainRoot
? worktreeLocation(mainRoot, worktreeConfig)
: unavailableWorktreeLocation();
+ observed('newWorktreeLocation');
}
const { me } = card;
const name = (id) => agentDisplayName(card.agents, ctx.config, id);
if (diagnostics) card.stale = staleFrozenItems(card.all, loadSpec(root, ctx.config).rows, staleDoctrineRows(ctx, doctrine)).map((item) => ({ ...item, ...staleItemFinding(item) }));
+ observed('stale frozen + HEAD doctrine overlay');
if (isMain && diagnostics) {
card.staleFollowUps = { count: card.stale.length + card.staleIntegrations.length,
list: 'pullboard resume --diagnostics --json', items: card.stale, integrations: card.staleIntegrations };
@@ -237,10 +264,12 @@ export async function resumeHere(io, view, diagnostics = false) {
// A view left running needs no line at every session start; a start, a busy port or a failure does.
if (view.state !== 'running' && backgroundViewLine(view)) say(backgroundViewLine(view));
if (card.inbox) for (const line of coordinatorInboxLines(card.inbox, name, (at) => span(ctx, at), firstLine)) say(line);
+ observed('common doctrine/release/view rendering');
if (diagnostics) {
say(`New agent worktrees: ${card.newWorktreeLocation}`);
card.setup = withBoardRead(ctx, board => withStarterWork(boardSetup(ctx, card, setupScope), { board, me, main: isMain, config: ctx.config, root, seat: ctx.io.callerRole() === 'seat' }));
} else say('Setup, hook and stale-work diagnostics: pullboard resume --diagnostics.');
+ observed('setup projection');
if (!loadSpec(root, ctx.config).rows.length && card.all.length) say('Spec rows are optional; add a requirement later: pullboard spec draft "<text>".');
if (card.setup) {
say(`Setting up: step ${card.setup.step} of 5`);
@@ -249,7 +278,9 @@ export async function resumeHere(io, view, diagnostics = false) {
if (card.setup.afterAnswer) say(card.setup.afterAnswer);
if (card.setup.meanwhile) say(card.setup.meanwhile);
}
+ observed('setup rendering');
const dirty = diagnostics ? dirtyFiles(root).length : undefined;
+ observed('dirty actual status');
if (!isMain) {
const branch = diagnostics ? tryGit(root, ['rev-parse', '--abbrev-ref', 'HEAD']).stdout || 'HEAD' : sources.branch;
// Against the main checkout's branch, not its HEAD, which is detached while the coordinator verifies.
@@ -262,6 +293,7 @@ export async function resumeHere(io, view, diagnostics = false) {
} else if (dirty) {
say(`${plural(dirty, 'file')} uncommitted in the main checkout`);
}
+ observed('branch + ahead/behind');
if (isMain && diagnostics) {
card.commits = commitOwners(uncommittedSetup(root, ctx.config)?.differ ?? [], [ctx.config.spec, ctx.config.practice], root);
for (const line of commitOwnerLines(card.commits)) say(line);
@@ -336,10 +368,12 @@ export async function resumeHere(io, view, diagnostics = false) {
if (card.setup) next = card.setup.agentNext ?? card.setup.command;
if (card.commits) next = commitFirst(card.commits, next);
if (card.inbox) next = inboxFirst(card.inbox, next);
+ observed('remaining notices + next');
io.result?.({ ...card, root, ...(diagnostics ? { dirty } : {}), next });
say(`next: ${next}`);
const flowAlert = isMain ? flowAlertLine(card.flow) : null;
if (flowAlert) say(flowAlert);
+ observed('result serialization + final line');
return 0;
}
diff --git a/test/sentinels.test.js b/test/sentinels.test.js
index 2e3a1b52..55460680 100644
--- a/test/sentinels.test.js
+++ b/test/sentinels.test.js
@@ -1,5 +1,8 @@
/** Real board watches: exact person approval, automatic execution, owner notices and replay [A6,D1,D3,H16]. */
import assert from 'node:assert/strict';
+import childProcess from 'node:child_process';
+import { syncBuiltinESMExports } from 'node:module';
+import { takeResumeObservations } from '../src/commands/resume.js';
import { existsSync } from 'node:fs';
import { mkdirSync } from 'node:fs';
import { mkdtempSync } from 'node:fs';
@@ -46,6 +49,34 @@ import { loadSpec } from '../src/spec.js';
import { parseProcessCensus } from '../src/process-census.js';
import { requireSupportedEngine as requirePublished55Engine } from './fixtures/engine-55-reader.js';
+/** Observe only controlled private fixture Git costs, preserving original process calls. */
+function observePrivateResumeProcesses() {
+ const methods = ['spawnSync', 'execFileSync'];
+ const originals = Object.fromEntries(methods.map(method => [method, childProcess[method]]));
+ const calls = [];
+ for (const method of methods) {
+ /** Delegate identical inputs and retain bounded diagnostic durations, not process output or environment. */
+ childProcess[method] = function (...args) {
+ const started = performance.now();
+ const caller = new Error().stack?.split('\n').slice(2, 7).map(line => line.replace(/file:\/\/[^)]*\/src\//u, 'src/'));
+ try { return Reflect.apply(originals[method], this, args); }
+ finally {
+ if (calls.length < 80) calls.push({ method, program: String(args[0]),
+ ...(String(args[0]).split('/').at(-1) === 'git' ? { args: args[1] } : {}),
+ caller, ms: performance.now() - started });
+ }
+ };
+ }
+ syncBuiltinESMExports();
+ return { calls,
+ /** Restore builtin exports before assertions, output and cleanup. */
+ stop() {
+ for (const method of methods) childProcess[method] = originals[method];
+ syncBuiltinESMExports();
+ },
+ };
+}
+
/** Isolate actual SQLite, Git, settings and subprocess files; due time is explicitly injected. */
function fixture(t, { agentRoute } = {}) {
const directory = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-board-watch-')));
@@ -77,8 +108,22 @@ function fixture(t, { agentRoute } = {}) {
/** Run the actual CLI against this real board; view means the explicit test person adapter. */
const cli = async (args, personChannel, cwd = root) => {
let output = ''; let error = '';
- const code = await main([...args, '--json'], { cwd, clock, personChannel,
- stdout: { isTTY: false, write: text => { output += text; } }, stderr: { write: text => { error += text; } } });
+ const observing = args[0] === 'resume';
+ if (observing) takeResumeObservations();
+ const processObserver = observing ? observePrivateResumeProcesses() : null;
+ let code;
+ const observedStarted = performance.now();
+ try {
+ code = await main([...args, '--json'], { cwd, clock, personChannel,
+ stdout: { isTTY: false, write: text => { output += text; } }, stderr: { write: text => { error += text; } } });
+ } finally {
+ processObserver?.stop();
+ if (observing) {
+ const observation = { mainWallMs: performance.now() - observedStarted, spans: takeResumeObservations(), calls: processObserver.calls,
+ qualification: 'ONE coordinator25919 observation; exact args/options/results delegated; observer overhead included; spans disjoint, child calls nested; output after measured command' };
+ t.after(() => t.diagnostic(JSON.stringify(observation)));
+ }
+ }
return { code, document: output ? JSON.parse(output) : null, error };
};
t.after(() => {