Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: serialize AI run metadata attribution
[._.]/ Adam Eivy8637d0830918
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 5f2b1b83b6..9c1e4de466 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -2,7 +2,7 @@## Changed-- **Series Autopilot can learn which models actually work at each step.** AI run history now distinguishes technical completion from a later editorial keep/revert decision and aggregates evidence by orchestration step, creative-versus-judge role, provider, model, and reasoning effort. The new opt-in selector requires multiple quality-reviewed samples, ignores disabled providers and removed models, and remains a soft default beneath explicit run choices and exact prompt-stage pins. The Options panel reports how much attributed and quality-reviewed evidence exists, while local APIs expose the full metrics and allow an operator to correct or backfill a historical outcome, including its effort when the older run predates effort telemetry. Foundation judges record contract-valid responses separately from true editorial approval, and foundation repairs automatically record accepted versus rolled-back outcomes, so a model that finishes a long run but makes the story worse is not learned as a success.+- **Series Autopilot can learn which models actually work at each step.** AI run history now distinguishes technical completion from a later editorial keep/revert decision and aggregates evidence by orchestration step, creative-versus-judge role, provider, model, and reasoning effort. The new opt-in selector requires multiple quality-reviewed samples, ignores disabled providers and removed models, and remains a soft default beneath explicit run choices and exact prompt-stage pins. The Options panel reports how much attributed and quality-reviewed evidence exists, while local APIs expose the full metrics and allow an operator to correct or backfill a historical outcome, including its effort when the older run predates effort telemetry. Concurrent metadata updates for one run are serialized so provider telemetry cannot overwrite its Autopilot step/role attribution. Foundation judges record contract-valid responses separately from true editorial approval, and foundation repairs automatically record accepted versus rolled-back outcomes, so a model that finishes a long run but makes the story worse is not learned as a success.- **Completed CoS agents no longer strand a worktree because of their own completion marker.** The `.agent-done` sentinel is consumed before worktree cleanup, but Git still reported the untracked file as ordinary authored work and the safety gate preserved the otherwise-clean checkout with a high-priority warning. Cleanup now ignores only that runtime marker: sentinel-only trees are removed normally, while any real source change still preserves the worktree and is named in the warning.diff --git a/server/services/runner.js b/server/services/runner.jsindex 3b896c06ec..ef49797caf 100644--- a/server/services/runner.js+++ b/server/services/runner.js@@ -36,6 +36,7 @@ export { buildCliArgs };// `runnerConfig` (dataDir + hooks) is captured here because only the runner// needs it.let runnerConfig = { dataDir: './data', hooks: {} };+const metadataPatchTails = new Map();export function setAIToolkit(toolkit, config = {}) {setAIToolkitInstance(toolkit);@@ -203,13 +204,20 @@ export function emitRunStarted({ runId, provider, model }) {*/export async function patchRunMetadata(runId, patch) {if (!patch || typeof patch !== 'object') return;- const metadataPath = join(getRunsPath(), runId, 'metadata.json');- const metadataStr = await tryReadFile(metadataPath);- if (!metadataStr) return;- let metadata;- try { metadata = JSON.parse(metadataStr); } catch { return; }- Object.assign(metadata, patch);- await atomicWrite(metadataPath, metadata).catch(() => {});+ const previous = metadataPatchTails.get(runId) || Promise.resolve();+ const operation = previous.catch(() => {}).then(async () => {+ const metadataPath = join(getRunsPath(), runId, 'metadata.json');+ const metadataStr = await tryReadFile(metadataPath);+ if (!metadataStr) return;+ let metadata;+ try { metadata = JSON.parse(metadataStr); } catch { return; }+ Object.assign(metadata, patch);+ await atomicWrite(metadataPath, metadata).catch(() => {});+ });+ metadataPatchTails.set(runId, operation);+ await operation.finally(() => {+ if (metadataPatchTails.get(runId) === operation) metadataPatchTails.delete(runId);+ });}/**diff --git a/server/services/runner.test.js b/server/services/runner.test.jsindex b52907e233..9e817965de 100644--- a/server/services/runner.test.js+++ b/server/services/runner.test.js@@ -53,10 +53,13 @@ vi.mock('fs/promises', () => ({const { spawn } = await import('child_process');const { writeFile, readFile } = await import('fs/promises');-const { atomicWrite } = await import('../lib/fileUtils.js');+const { atomicWrite, tryReadFile } = await import('../lib/fileUtils.js');const runner = await import('./runner.js');const { analyzeError, ERROR_CATEGORIES } = await import('../lib/aiToolkit/errorDetection.js');-const { setAIToolkit, executeCliRun, buildCliArgs, hasModelFlag, extractBakedModel, emitRunStarted, finalizeRunRecord } = runner;+const {+ setAIToolkit, executeCliRun, buildCliArgs, hasModelFlag, extractBakedModel,+ emitRunStarted, finalizeRunRecord, patchRunMetadata,+} = runner;// Minimal toolkit stub that satisfies executeCliRun's expectations. Mirrors the// real toolkit runner's declared external-run registry (registerExternalRun /@@ -164,6 +167,31 @@ describe('finalizeRunRecord — authoritative timeout classification', () => {});});+describe('patchRunMetadata — serialized merges', () => {+ it('preserves fields from concurrent attribution patches to the same run', async () => {+ let stored = JSON.stringify({ id: 'run-attribution' });+ tryReadFile.mockImplementation(async () => stored);+ atomicWrite.mockImplementation(async (_path, data) => {+ await Promise.resolve();+ stored = JSON.stringify(data);+ });++ await Promise.all([+ patchRunMetadata('run-attribution', { pipelineStage: 'verifyArc' }),+ patchRunMetadata('run-attribution', { effort: 'high' }),+ ]);++ expect(JSON.parse(stored)).toMatchObject({+ id: 'run-attribution', pipelineStage: 'verifyArc', effort: 'high',+ });+ tryReadFile.mockResolvedValue(null);+ atomicWrite.mockImplementation(async (filePath, data) => {+ const payload = (typeof data === 'string' || Buffer.isBuffer(data)) ? data : JSON.stringify(data, null, 2);+ return writeFile(filePath, payload);+ });+ });+});+describe('executeCliRun — wall-clock timeout classification', () => {// The CLI runner kills its own child on timeout, so the close event carries// `exitCode: null` rather than the 124 finalizeRunRecord keys on. Without the