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: scope series autopilot outcome corrections to owned runs (#13094)
Adam Eivydfa42af3c768
diff --git a/server/routes/pipeline/autopilot.js b/server/routes/pipeline/autopilot.jsindex 563b12f3af..f5f4d70ccc 100644--- a/server/routes/pipeline/autopilot.js+++ b/server/routes/pipeline/autopilot.js@@ -280,7 +280,7 @@ router.get('/series/:id/autopilot/model-metrics', asyncHandler(async (req, res)router.post('/series/:id/autopilot/model-outcomes', asyncHandler(async (req, res) => {await seriesSvc.getSeries(req.params.id).catch((err) => { throw mapServiceError(err); });const body = validateRequest(modelOutcomeSchema, req.body ?? {});- const recorded = await recordModelOutcome(body.runId, body);+ const recorded = await recordModelOutcome(body.runId, body, req.params.id);if (!recorded) throw new ServerError('AI run not found', { status: 404, code: 'RUN_NOT_FOUND' });res.json({ success: true, runId: body.runId });}));diff --git a/server/routes/pipeline/autopilot.test.js b/server/routes/pipeline/autopilot.test.jsnew file mode 100644index 0000000000..79e5a58818--- /dev/null+++ b/server/routes/pipeline/autopilot.test.js@@ -0,0 +1,83 @@+import { beforeEach, describe, expect, it, vi } from 'vitest';+import express from 'express';+import { request } from '../../lib/testHelper.js';+import { errorMiddleware } from '../../lib/errorHandler.js';++const { runs, patchRunMetadata } = vi.hoisted(() => {+ const runs = new Map();+ return {+ runs,+ patchRunMetadata: vi.fn(async (id, patch) => Object.assign(runs.get(id), patch)),+ };+});++vi.mock('../../services/runner.js', () => ({+ getRun: vi.fn(async (id) => runs.get(id) || null),+ listRuns: vi.fn(),+ patchRunMetadata,+}));+vi.mock('../../services/providers.js', () => ({ getAllProviders: vi.fn() }));+vi.mock('../../services/pipeline/series.js', () => ({+ AUTOPILOT_LLM_STAGE_KINDS: ['foundationGate'],+ getSeries: vi.fn(async (id) => ({ id })),+}));+vi.mock('../../services/pipeline/seriesAutopilot.js', () => ({}));+vi.mock('../../services/pipeline/editorialScore.js', () => ({ READINESS_GATES: ['story'] }));+vi.mock('./shared.js', () => ({+ mapServiceError: (err) => err,+ providerOverrideShape: {},+}));++const autopilotRoutes = (await import('./autopilot.js')).default;+const app = express();+app.use(express.json());+app.use('/api/pipeline', autopilotRoutes);+app.use(errorMiddleware);++const runId = '11111111-1111-4111-8111-111111111111';+const outcome = {+ runId, role: 'creative', stage: 'foundationGate', outcome: 'accepted',+ effort: 'max', scoreBefore: 0.4, scoreAfter: 0.8,+};++beforeEach(() => {+ runs.clear();+ patchRunMetadata.mockClear();+ runs.set(runId, { id: runId, seriesId: 'series-a', qualityOutcome: 'rejected' });+});++describe('Series autopilot model outcomes', () => {+ it('refuses another series run without changing its evidence', async () => {+ const original = { ...runs.get(runId), seriesId: 'series-b' };+ runs.set(runId, { ...original });+ const res = await request(app)+ .post('/api/pipeline/series/series-a/autopilot/model-outcomes').send(outcome);+ expect(res.status).toBe(404);+ expect(res.body.code).toBe('RUN_NOT_FOUND');+ expect(patchRunMetadata).not.toHaveBeenCalled();+ expect(runs.get(runId)).toEqual(original);+ });++ it('records an outcome on the series own run', async () => {+ const res = await request(app)+ .post('/api/pipeline/series/series-a/autopilot/model-outcomes').send(outcome);+ expect(res.status).toBe(200);+ expect(res.body).toEqual({ success: true, runId });+ expect(runs.get(runId)).toMatchObject({+ seriesId: 'series-a', qualityOutcome: 'accepted', effort: 'max',+ qualityScoreBefore: 0.4, qualityScoreAfter: 0.8, qualityScoreDelta: 0.4,+ pipelineRole: 'creative', pipelineStage: 'foundationGate',+ qualityEvaluatedAt: expect.any(String),+ });+ });++ it.each(['missing', 'unowned'])('refuses a %s run without writing evidence', async (kind) => {+ if (kind === 'missing') runs.delete(runId);+ else delete runs.get(runId).seriesId;+ const res = await request(app)+ .post('/api/pipeline/series/series-a/autopilot/model-outcomes').send(outcome);+ expect(res.status).toBe(404);+ expect(res.body.code).toBe('RUN_NOT_FOUND');+ expect(patchRunMetadata).not.toHaveBeenCalled();+ });+});diff --git a/server/services/pipeline/seriesAutopilot.test.js b/server/services/pipeline/seriesAutopilot.test.jsindex 9ab4f3ce9b..eb3943fc1e 100644--- a/server/services/pipeline/seriesAutopilot.test.js+++ b/server/services/pipeline/seriesAutopilot.test.js@@ -5,6 +5,11 @@ import { SERIES_AUTOPILOT_DEFAULTS } from '../../lib/seriesAutopilotDefaults.js'// ---- File-backed store (like autoRunner.test.js) so the REAL series/issues// services run against an in-memory map instead of Postgres. ------------------const fileStore = new Map();+const patchRunMetadata = vi.fn(async () => {});+vi.mock('../runner.js', async (importOriginal) => ({+ ...(await importOriginal()),+ patchRunMetadata,+}));vi.mock('../../lib/fileUtils.js', () => ({sleep: vi.fn().mockResolvedValue(undefined),tryReadFile: vi.fn().mockResolvedValue(null),@@ -2724,6 +2729,9 @@ describe('autopilot conductor', () => {const last = autopilot.__testing.runs.get(seriesId)?.lastPayload;expect(last?.pauseKind).toBe('inapplicable');expect(last?.discardedFindings).toEqual(blockers);+ expect(patchRunMetadata).toHaveBeenCalledWith('structure-reverted', expect.objectContaining({+ seriesId, autopilotSystem: 'series', pipelineRole: 'creative',+ }));expect(recordModelOutcome).toHaveBeenCalledWith('structure-reverted', expect.objectContaining({role: 'creative', stage: 'foundationGate', outcome: 'rejected', target: 'structure',}));diff --git a/server/services/pipeline/seriesAutopilot/modelPerformance.js b/server/services/pipeline/seriesAutopilot/modelPerformance.jsindex a189572426..eec73ceb97 100644--- a/server/services/pipeline/seriesAutopilot/modelPerformance.js+++ b/server/services/pipeline/seriesAutopilot/modelPerformance.js@@ -171,8 +171,11 @@ export async function getModelPerformanceReport() {};}-export async function recordModelOutcome(runId, patch = {}) {- if (!runId || !await getRun(runId)) return false;+// HTTP corrections require recorded series ownership; internal lifecycle callers+// already own their run ids and may annotate legacy evidence without this scope.+export async function recordModelOutcome(runId, patch = {}, seriesId) {+ const run = runId ? await getRun(runId) : null;+ if (!run || (seriesId !== undefined && run.seriesId !== seriesId)) return false;const scoreBefore = finiteOrNull(patch.scoreBefore);const scoreAfter = finiteOrNull(patch.scoreAfter);await patchRunMetadata(runId, {diff --git a/server/services/pipeline/seriesAutopilot/orchestrator.js b/server/services/pipeline/seriesAutopilot/orchestrator.jsindex e73e6fd650..c0874a7651 100644--- a/server/services/pipeline/seriesAutopilot/orchestrator.js+++ b/server/services/pipeline/seriesAutopilot/orchestrator.js@@ -154,6 +154,7 @@ export async function startSeriesAutopilot(sId, options = {}) {const runId = randomUUID();const record = {runId,+ seriesId: sId,clients: [],lastPayload: null,cancelRequested: false,diff --git a/server/services/pipeline/seriesAutopilot/session.js b/server/services/pipeline/seriesAutopilot/session.jsindex 0772b90138..fa34d02468 100644--- a/server/services/pipeline/seriesAutopilot/session.js+++ b/server/services/pipeline/seriesAutopilot/session.js@@ -418,6 +418,7 @@ const runLifecycle = (record, role) => ({record.activeLlmRunId = runId;patchRunMetadata(runId, {autopilotSystem: 'series',+ seriesId: record.seriesId,autopilotRunId: record.runId || null,pipelineStage: record.currentStep || 'unknown',pipelineRole: role,