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: score arc repair model outcomes
[._.]/ Adam Eivy0f04c6379ac3
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex f6a0fb5027..4553b341de 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -4,7 +4,7 @@- **Daily Log no longer parks autosave when voice dictation lands mid-edit.** A spoken segment is merged into the textarea (append-at-end, caret restored) instead of leaving the user to Save or refresh, and full-content saves send the last-seen `updatedAt` as `ifMatchUpdatedAt`. When a concurrent append advances that clock, the server returns 409 `STALE_JOURNAL` with the current entry in `context.entry`; the client folds in any missing voice segments and retries a few times so an in-flight PUT cannot silently drop dictation.-- **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 plus a positive reliability threshold, 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, and internal structure-verification calls retain the judge role instead of inheriting their repairer's creative role. 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 plus a positive reliability threshold, 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, and internal structure-verification calls retain the judge role instead of inheriting their repairer's creative role. Foundation judges record contract-valid responses separately from true editorial approval, and foundation repairs automatically record accepted versus rolled-back outcomes. Arc repairs now do the same after normal rounds, corrective retries, and isolated-finding attempts, while canceled candidates remain deliberately unevaluated, so a model that finishes a long run but makes the story worse is not learned as a success.- **Series Autopilot can route individual steps to specialist models.** A run may now override provider, model, and reasoning effort for the creative or judge role of one named orchestration step, from either the start API or the Options panel. Stage routes survive pause/resume, take precedence over learned and run-wide choices, and remain soft defaults beneath exact prompt-stage pins, so a weak foundation repair model can be replaced without repointing episode drafting or independent verification.diff --git a/server/services/pipeline/seriesAutopilot.test.js b/server/services/pipeline/seriesAutopilot.test.jsindex beead7ad5a..295de5be81 100644--- a/server/services/pipeline/seriesAutopilot.test.js+++ b/server/services/pipeline/seriesAutopilot.test.js@@ -182,6 +182,9 @@ vi.mock('./foundationJudge.js', async (importOriginal) => {};});+const recordModelOutcome = vi.fn(async () => true);+vi.mock('./seriesAutopilot/modelPerformance.js', () => ({ recordModelOutcome }));+// Pause-escalation notifications (#1615) — spy on the notification center so a// test can assert a pause posts a banner (and a clean run / opt-out does not).const addNotification = vi.fn(async () => ({ id: 'notif-1' }));@@ -2285,6 +2288,9 @@ describe('autopilot conductor', () => {.mockImplementationOnce(async () => round(1)).mockImplementationOnce(async () => round(3)).mockImplementationOnce(async () => round(5));+ arcSpies.resolveVerifyIssues+ .mockImplementationOnce(async () => ({ applied: true, runId: 'arc-regression-1' }))+ .mockImplementationOnce(async () => ({ applied: true, runId: 'arc-regression-2' }));const { seriesId } = await seedComplete();await autopilot.startSeriesAutopilot(seriesId, { maxArcVerifyRounds: 6 });await waitFor(runFinished(seriesId));@@ -2307,6 +2313,12 @@ describe('autopilot conductor', () => {findings: [original],avoid: round(3).issues,});+ expect(recordModelOutcome).toHaveBeenCalledWith('arc-regression-1', expect.objectContaining({+ role: 'creative', stage: 'verifyArcSpine', outcome: 'rejected', scoreBefore: -1, scoreAfter: -3,+ }));+ expect(recordModelOutcome).toHaveBeenCalledWith('arc-regression-2', expect.objectContaining({+ role: 'creative', stage: 'verifyArcSpine', outcome: 'rejected', scoreBefore: -1, scoreAfter: -5,+ }));const last = autopilot.__testing.runs.get(seriesId)?.lastPayload;expect(last?.type).toBe('paused');@@ -2335,6 +2347,9 @@ describe('autopilot conductor', () => {.mockImplementationOnce(async () => ({ issues: holes(3, 'initial') })).mockImplementationOnce(async () => ({ issues: holes(6, 'regressed') })).mockImplementationOnce(async () => ({ issues: [] }));+ arcSpies.resolveVerifyIssues+ .mockImplementationOnce(async () => ({ applied: true, runId: 'arc-rejected' }))+ .mockImplementationOnce(async () => ({ applied: true, runId: 'arc-accepted' }));const { seriesId } = await seedComplete();const frames = [];const handler = (p) => frames.push(p);@@ -2356,6 +2371,12 @@ describe('autopilot conductor', () => {expect(rollback).toMatchObject({ before: 3, after: 6, best: 3, retrying: true });expect(frames.some((f) => f.type === 'resolve:round' && f.retry === true)).toBe(true);expect(frames.some((f) => f.type === 'paused' && f.pauseKind === 'regression')).toBe(false);+ expect(recordModelOutcome).toHaveBeenCalledWith('arc-rejected', expect.objectContaining({+ outcome: 'rejected', scoreBefore: -3, scoreAfter: -6,+ }));+ expect(recordModelOutcome).toHaveBeenCalledWith('arc-accepted', expect.objectContaining({+ outcome: 'accepted', scoreBefore: -3, scoreAfter: 0,+ }));const series = await seriesSvc.getSeries(seriesId);expect(series.autopilot?.pauseKind).not.toBe('regression');});@@ -2571,7 +2592,7 @@ describe('autopilot conductor', () => {for (let i = 0; i < 6; i += 1) {arcSpies.resolveVerifyIssues.mockImplementationOnce(async () => {billed.push('resolve');- return { applied: true };+ return { applied: true, runId: `arc-isolation-${i + 1}` };});}@@ -2595,6 +2616,12 @@ describe('autopilot conductor', () => {expect(isolated).toHaveLength(2);expect(isolated[0]).toMatchObject({ scope: 'arcSpine', attempt: 1, before: 2, after: 1, kept: true });expect(isolated[1]).toMatchObject({ attempt: 2, before: 1, after: 2, kept: false });+ expect(recordModelOutcome).toHaveBeenCalledWith('arc-isolation-3', expect.objectContaining({+ outcome: 'accepted', scoreBefore: -2, scoreAfter: -1,+ }));+ expect(recordModelOutcome).toHaveBeenCalledWith('arc-isolation-4', expect.objectContaining({+ outcome: 'rejected', scoreBefore: -1, scoreAfter: -2,+ }));// Two whole-round rollbacks plus the one rejected isolated patch.expect(arcSpies.restoreArcState).toHaveBeenCalledTimes(3);// Round 3's verify, then the two isolated attempts (resolve→verify each),diff --git a/server/services/pipeline/seriesAutopilot/childRuns.js b/server/services/pipeline/seriesAutopilot/childRuns.jsindex 4df3b4e50a..4e1a7cddc8 100644--- a/server/services/pipeline/seriesAutopilot/childRuns.js+++ b/server/services/pipeline/seriesAutopilot/childRuns.js@@ -71,6 +71,32 @@ async function resolveArcFindings(seriesId, record, { findings, avoid, spineOnly// Episode synopses one resolve pass actually rewrote, for the telemetry frames.const editedCount = (resolved) => (Array.isArray(resolved?.episodesResolved) ? resolved.episodesResolved.length : 0);+// A resolver's provider run is only a TECHNICAL success until the next+// independent arc verification decides whether its candidate remains in the+// plan. Keep quality scores "higher is better" across every pipeline stage by+// representing an arc result as the negative blocker count: 3 → 2 blockers is+// a +1 quality delta, while 3 → 4 is -1. The raw before/after blocker counts+// remain available in the verify/rollback telemetry frames.+const arcResolveRunIds = (resolved) => (typeof resolved?.runId === 'string' && resolved.runId ? [resolved.runId] : []);+const arcQualityScore = (blocking) => (blocking.length === 0 ? 0 : -blocking.length);++async function recordArcResolveOutcome(candidate, record, { outcome, after, target }) {+ const runIds = Array.isArray(candidate?.runIds) ? candidate.runIds : [];+ if (runIds.length === 0) return;+ await Promise.all(runIds.map((runId) => recordModelOutcome(runId, {+ role: 'creative',+ stage: record.currentStep || 'verifyArc',+ outcome,+ target,+ scoreBefore: arcQualityScore(candidate.blocking),+ scoreAfter: arcQualityScore(after),+ }).catch(() => {})));+ // The same checkpoint can remain `lastResolve` for comparison after its+ // verdict. Consume its evidence once so later seeded/re-confirmation rounds+ // cannot count one provider run twice.+ candidate.runIds = [];+}+function finishPlanningMutation(record, peerLatch) {record.runState[peerLatch] = false;record.runState.planningGateHandoffs = (record.runState.planningGateHandoffs || 0) + 1;@@ -189,6 +215,15 @@ async function isolateArcFindings(seriesId, record, { scope, round, spineOnly, breturn { accepted, attempts, verified: standing, outcome: verified.outcome };}const kept = isIsolatedFixSafe(target, blocking(), verified.blocking);+ await recordArcResolveOutcome(+ { blocking: blocking(), runIds: arcResolveRunIds(resolved) },+ record,+ {+ outcome: kept ? 'accepted' : 'rejected',+ after: verified.blocking,+ target: typeof target.location === 'string' ? target.location : scope,+ },+ );if (kept) {accepted += 1;standing = verified;@@ -260,6 +295,7 @@ export async function runArcVerify(seriesId, record, { spineOnly = false } = {})blocking: blocking.length, volumesChecked: verified.volumesChecked,});if (blocking.length === 0) {+ await recordArcResolveOutcome(lastResolve, record, { outcome: 'accepted', after: blocking, target: scope });record.runState[spineOnly ? 'arcSpineVerified' : 'arcVerified'] = true;if (!spineOnly && changed && !finishPlanningMutation(record, 'foundationGated')) {return {@@ -281,6 +317,7 @@ export async function runArcVerify(seriesId, record, { spineOnly = false } = {})// before maxRounds/divergence so no worse baseline survives.// Reverting is unconditional; PAUSING is not — see the corrective pass below.if (lastResolve && isBlockingSetRegression(lastResolve.blocking, blocking)) {+ await recordArcResolveOutcome(lastResolve, record, { outcome: 'rejected', after: blocking, target: scope });const rollbackTarget = bestVerified || lastResolve;const rollback = await restoreArcState(seriesId, rollbackTarget.snapshot);const discarded = discardedSet(blocking);@@ -327,7 +364,7 @@ export async function runArcVerify(seriesId, record, { spineOnly = false } = {})// The restored state is what the retry has to beat, so the next round// compares against ITS count — not the rejected candidate's, which// would let the retry regress back to the discarded draft for free.- lastResolve = rollbackTarget;+ lastResolve = { ...rollbackTarget, runIds: arcResolveRunIds(retried) };broadcast(seriesId, {type: 'resolve:round', scope, round, retry: true, episodesEdited: editedCount(retried),});@@ -373,6 +410,10 @@ export async function runArcVerify(seriesId, record, { spineOnly = false } = {})discarded,};}+ // The previous resolver candidate survived an independent verification and+ // remains the live checkpoint. It is quality-accepted even when the count+ // ties (the gate separately rejects a worse severity mix above).+ await recordArcResolveOutcome(lastResolve, record, { outcome: 'accepted', after: blocking, target: scope });// Equal-count drafts may still represent real causal progress when their// severity mix is not worse: a resolver can close broad structural findings// and expose the same number of narrower handoff problems. Treat that latest@@ -419,7 +460,7 @@ export async function runArcVerify(seriesId, record, { spineOnly = false } = {})// only place they can actually close a finding.const resolved = await resolveArcFindings(seriesId, record, { findings: blocking, spineOnly });if (resolved?.applied !== false) changed = true;- lastResolve = { blocking, snapshot };+ lastResolve = { blocking, snapshot, runIds: arcResolveRunIds(resolved) };broadcast(seriesId, {type: 'resolve:round', scope, round, episodesEdited: editedCount(resolved),});