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: retire unused Brain and catalog sync write endpoints (#13096)
Adam Eivy06092147c32b
diff --git a/server/hostControlCoverage.test.js b/server/hostControlCoverage.test.jsindex 01ae78327b..97b31be664 100644--- a/server/hostControlCoverage.test.js+++ b/server/hostControlCoverage.test.js@@ -202,7 +202,6 @@ const REVIEWED_OPEN_MUTATIONS = [['DELETE /api/brain/songbook/:id/attachments/:filename', REMOVES_RECORD],['POST /api/brain/songbook/:id/practice', RECORDS],['POST /api/brain/songbook/import/url', PUBLIC_FETCH],- ['POST /api/brain/sync', RECORDS],['POST /api/brain/threads', RECORDS],['DELETE /api/brain/threads/:id', REMOVES_RECORD],['PUT /api/brain/threads/:id', RECORDS],@@ -265,7 +264,6 @@ const REVIEWED_OPEN_MUTATIONS = [['DELETE /api/catalog/scraps/:id', REMOVES_RECORD],['PATCH /api/catalog/scraps/:id', RECORDS],['POST /api/catalog/scraps/:id/commit', RECORDS],- ['POST /api/catalog/sync/apply', RECORDS],['POST /api/catalog/types', RECORDS],['DELETE /api/catalog/types/:id', REMOVES_RECORD],['PATCH /api/catalog/types/:id', RECORDS],diff --git a/server/lib/brainValidation.js b/server/lib/brainValidation.jsindex 64bb4231a5..77e075683b 100644--- a/server/lib/brainValidation.js+++ b/server/lib/brainValidation.js@@ -5,7 +5,6 @@ import { EFFORT_LEVELS } from './providerModels.js';import { canonicalThreadRefKind } from './threadRefKinds.js';import { THREAD_STATUSES, THREAD_PRIORITIES } from './brainThreads.js';import { MAX_QUALITY } from './spacedRepetition.js';-import { parseTsMs } from './lwwTimestamp.js';// Destination enum. `links` is reachable only from the bare-URL capture// short-circuit (a pasted URL is filed straight to the links collection) — the@@ -586,26 +585,6 @@ export const brainSyncQuerySchema = z.object({limit: z.coerce.number().int().min(1).max(1000).optional().default(100)});-// Brain sync change object schema-const brainSyncChangeSchema = z.object({- seq: z.number().int(),- op: z.enum(['create', 'update', 'delete']),- type: z.string(),- id: z.string(),- // Missing records/clocks retain the legacy skipped-change behavior. A clock- // that IS supplied must be parseable; keep other record fields for newer peers.- record: z.object({- updatedAt: z.string().refine(value => parseTsMs(value) !== null, 'Invalid record timestamp').optional(),- }).passthrough().nullable().optional(),- originInstanceId: z.string().optional(),- ts: z.string()-});--// Brain sync push schema (POST /api/brain/sync body)-export const brainSyncPushSchema = z.object({- changes: z.array(brainSyncChangeSchema).min(1).max(1000)-});-// Brain parity check body (POST /api/brain/reconcile/parity). `peerId` is the// LOCAL peer-registry id (the same id `/api/instances/peers/:id/sync` takes, so// the Instances card can pass the peer it already holds). Omitted runs the sweepdiff --git a/server/lib/brainValidation.test.js b/server/lib/brainValidation.test.jsindex d019800668..8c6f2a67cf 100644--- a/server/lib/brainValidation.test.js+++ b/server/lib/brainValidation.test.js@@ -37,7 +37,6 @@ import {bucketUpdateInputSchema,bucketReorderSchema,brainSyncQuerySchema,- brainSyncPushSchema,memoryInputSchema,songInputSchema,songUpdateSchema,@@ -798,48 +797,6 @@ describe('brainValidation.js', () => {});});- describe('brainSyncPushSchema', () => {- const validChange = {- seq: 1,- op: 'create',- type: 'people',- id: 'abc-123',- record: { name: 'Test' },- originInstanceId: 'inst-1',- ts: '2026-01-01T00:00:00Z'- };-- it('should accept valid push with one change', () => {- const result = brainSyncPushSchema.safeParse({ changes: [validChange] });- expect(result.success).toBe(true);- });-- it('should reject empty changes array', () => {- const result = brainSyncPushSchema.safeParse({ changes: [] });- expect(result.success).toBe(false);- });-- it('should reject invalid op values', () => {- const result = brainSyncPushSchema.safeParse({- changes: [{ ...validChange, op: 'upsert' }]- });- expect(result.success).toBe(false);- });-- it('should accept delete with null record', () => {- const result = brainSyncPushSchema.safeParse({- changes: [{ ...validChange, op: 'delete', record: null }]- });- expect(result.success).toBe(true);- });-- it('should accept change without optional fields', () => {- const { originInstanceId, record, ...minimal } = validChange;- const result = brainSyncPushSchema.safeParse({ changes: [minimal] });- expect(result.success).toBe(true);- });- });-describe('memoryInputSchema', () => {it('accepts a minimal hand-written memory', () => {expect(memoryInputSchema.safeParse({ title: 'A thought' }).success).toBe(true);diff --git a/server/lib/catalogValidation.js b/server/lib/catalogValidation.jsindex 2775fe538a..8c791a074a 100644--- a/server/lib/catalogValidation.js+++ b/server/lib/catalogValidation.js@@ -645,8 +645,8 @@ export const catalogExportQuerySchema = z.object({format: z.enum(['json', 'markdown', 'yaml']).optional(),}).strict();-// Sync envelope shape — used by POST /api/catalog/sync/apply when a peer-// forwards changes pulled from another instance. Each kind is optional so+// Catalog sync envelope shape. Receivers apply pulled changes in-process+// via catalogSync.applyRemoteChanges. Each kind is optional so// callers can apply a partial envelope (e.g. ingredients-only).//// Read-path caps MIRROR the create-path caps above: rawText 2MB, payloaddiff --git a/server/routes/brain.test.js b/server/routes/brain.test.jsindex 38fc83c6d5..c78f031b03 100644--- a/server/routes/brain.test.js+++ b/server/routes/brain.test.js@@ -119,11 +119,6 @@ vi.mock('../services/brainSyncLog.js', () => ({getChangesSince: vi.fn()}));-// Mock the brain sync service-vi.mock('../services/brainSync.js', () => ({- applyRemoteChanges: vi.fn()-}));-// Mock the brain anti-entropy reconcile service (#1077). Only the two read// endpoints are exposed over HTTP; applyBrainSnapshot is orchestrator-only.vi.mock('../services/brainReconcile.js', () => ({@@ -169,7 +164,6 @@ import { getBrainGraphSearchIndex, getBrainGraphOverview, getBrainGraphNeighborhimport { syncAllBrainData, getEmbeddingCoverage } from '../services/brainMemoryBridge.js';import { getChangesSince } from '../services/brainSyncLog.js';import { getBrainChecksum, getBrainSnapshot } from '../services/brainReconcile.js';-import { applyRemoteChanges } from '../services/brainSync.js';import * as journal from '../services/brainJournal.js';describe('Brain Routes', () => {@@ -1386,43 +1380,6 @@ describe('Brain Routes', () => {});});- describe('POST /api/brain/sync', () => {- it('should apply remote changes and return stats', async () => {- const mockResult = { inserted: 2, updated: 1, deleted: 0, skipped: 1 };- applyRemoteChanges.mockResolvedValue(mockResult);-- const response = await request(app)- .post('/api/brain/sync')- .send({- changes: [- { seq: 1, op: 'create', type: 'people', id: 'p1', record: { name: 'A' }, ts: '2026-01-01T00:00:00.000Z' },- { seq: 2, op: 'update', type: 'ideas', id: 'i1', record: { title: 'B' }, ts: '2026-01-01T00:00:00.000Z' }- ]- });-- expect(response.status).toBe(200);- expect(response.body.inserted).toBe(2);- expect(response.body.updated).toBe(1);- expect(applyRemoteChanges).toHaveBeenCalledTimes(1);- });-- it('should return 400 when changes array is empty', async () => {- const response = await request(app)- .post('/api/brain/sync')- .send({ changes: [] });-- expect(response.status).toBe(400);- });-- it('should return 400 when changes is missing', async () => {- const response = await request(app)- .post('/api/brain/sync')- .send({});-- expect(response.status).toBe(400);- });- });-// ===========================================================================// DAILY LOG// ===========================================================================diff --git a/server/routes/brainSync.js b/server/routes/brainSync.jsindex dbe60b4608..2c62055f3b 100644--- a/server/routes/brainSync.js+++ b/server/routes/brainSync.js@@ -10,13 +10,11 @@ import { asyncHandler } from '../lib/errorHandler.js';import { validateRequest } from '../lib/validation.js';import {brainSyncQuerySchema,- brainSyncPushSchema,brainBridgeSyncSchema,brainParityCheckSchema} from '../lib/brainValidation.js';import { syncAllBrainData, getEmbeddingCoverage } from '../services/brainMemoryBridge.js';import * as brainSyncLog from '../services/brainSyncLog.js';-import * as brainSync from '../services/brainSync.js';import * as brainReconcile from '../services/brainReconcile.js';import * as brainParity from '../services/brainParity.js';@@ -67,16 +65,6 @@ router.get('/sync', asyncHandler(async (req, res) => {res.json(result);}));-/**- * POST /api/brain/sync- * Receive remote brain changes from a peer- */-router.post('/sync', asyncHandler(async (req, res) => {- const { changes } = validateRequest(brainSyncPushSchema, req.body);- const result = await brainSync.applyRemoteChanges(changes);- res.json(result);-}));-/*** GET /api/brain/reconcile/checksum* Anti-entropy checksum over ALL brain records (incl. tombstones) — #1077.diff --git a/server/routes/brainSync.test.js b/server/routes/brainSync.test.jsindex 9a9f944813..30d1ca1c6e 100644--- a/server/routes/brainSync.test.js+++ b/server/routes/brainSync.test.js@@ -12,9 +12,6 @@ vi.mock('../services/brainMemoryBridge.js', () => ({vi.mock('../services/brainSyncLog.js', () => ({getChangesSince: vi.fn(),}));-vi.mock('../services/brainSync.js', () => ({- applyRemoteChanges: vi.fn(),-}));vi.mock('../services/brainReconcile.js', () => ({getBrainChecksum: vi.fn(),getBrainSnapshot: vi.fn(),@@ -38,7 +35,6 @@ vi.mock('../services/settings.js', async () => ({}));import * as brainParity from '../services/brainParity.js';-import * as brainSync from '../services/brainSync.js';import * as brainSyncLog from '../services/brainSyncLog.js';import * as brainReconcile from '../services/brainReconcile.js';import { PEER_INSTANCE_ID_HEADER, __resetPullWarnThrottleForTests } from '../services/sharing/peerPullAuthorization.js';@@ -109,32 +105,6 @@ describe('brain pulls honor the per-peer brain category', () => {});});-describe('POST /api/brain/sync', () => {- it.each(['not-a-date', 42, { value: '2026-10-15' }])('rejects malformed record clocks before applying changes: %j', async (updatedAt) => {- const res = await request(buildApp()).post('/api/brain/sync').send({ changes: [{- seq: 1, op: 'update', type: 'people', id: 'peer-person',- record: { name: 'Remote person', updatedAt }, ts: '2026-10-15T00:00:00Z',- }] });-- expect(res.status).toBe(400);- expect(brainSync.applyRemoteChanges).not.toHaveBeenCalled();- });-- it('preserves legacy clock formats and unknown record fields', async () => {- brainSync.applyRemoteChanges.mockResolvedValue({ updated: 1 });- const change = {- seq: 1, op: 'update', type: 'people', id: 'peer-person',- record: { name: 'Remote person', updatedAt: '2026-10-15T12:00:00+02:00', futureField: { keep: true } },- ts: '2026-10-15T10:00:00Z',- };-- const res = await request(buildApp()).post('/api/brain/sync').send({ changes: [change] });-- expect(res.status).toBe(200);- expect(brainSync.applyRemoteChanges).toHaveBeenCalledWith([change]);- });-});-describe('GET /api/brain/reconcile/manifest', () => {it('serves the parity manifest a peer audits against', async () => {brainParity.buildBrainManifest.mockResolvedValue({ types: { people: [{ id: 'p1', updatedAt: 'T1', deleted: false }] } });diff --git a/server/routes/catalog.js b/server/routes/catalog.jsindex a082aa4a31..d474f3bf32 100644--- a/server/routes/catalog.js+++ b/server/routes/catalog.js@@ -29,7 +29,6 @@ import {catalogIngredientQuerySchema,catalogTagQuerySchema,catalogScrapCommitSchema,- catalogSyncEnvelopeSchema,catalogExtractRequestSchema,catalogPruneRequestSchema,catalogEmbeddingsBackfillSchema,@@ -912,15 +911,6 @@ router.get('/sync', asyncHandler(async (req, res) => {});}));-router.post('/sync/apply', asyncHandler(async (req, res) => {- const body = validateRequest(catalogSyncEnvelopeSchema, req.body);- // applyRemoteChanges throws CatalogSyncVersionMismatchError (status 412)- // when the peer is ahead on the `catalog` schema; centralized error- // middleware translates `err.status` to the HTTP response.- const stats = await catalogSync.applyRemoteChanges(body);- res.json(stats);-}));-router.post('/embeddings/backfill', asyncHandler(async (req, res) => {const body = validateRequest(catalogEmbeddingsBackfillSchema, req.body || {});const limit = body.limit ?? 50;diff --git a/server/routes/catalogSyncPull.test.js b/server/routes/catalogSyncPull.test.jsindex 0a7385236d..c54d92d1a3 100644--- a/server/routes/catalogSyncPull.test.js+++ b/server/routes/catalogSyncPull.test.js@@ -21,7 +21,6 @@ vi.mock('../services/settings.js', async () => ({}));vi.mock('../services/catalogSync.js', () => ({getChangesSince: vi.fn(async () => ({ changes: {}, maxSequences: {}, hasMore: false })),- applyRemoteChanges: vi.fn(),}));import * as catalogSync from '../services/catalogSync.js';diff --git a/server/services/catalogSync.js b/server/services/catalogSync.jsindex e1397edd4c..a64840f150 100644--- a/server/services/catalogSync.js+++ b/server/services/catalogSync.js@@ -24,7 +24,9 @@* past its respective cursor — drain by re-pulling with the maxSequences from* the previous response.*- * Apply: receiver POSTs the envelope to /api/catalog/sync/apply. Conflict+ * Apply: syncOrchestrator applies pulled envelopes in-process via+ * applyRemoteChanges; sharing/peerSyncReceive uses the same function for+ * incoming catalog bundles. Conflict* resolution is LWW on `updated_at` for ingredient/scrap rows; source/ref* rows are tuple-unique and idempotent on conflict. Each row is wrapped in* its own try/catch so one malformed row can't poison the whole batch.diff --git a/server/services/dataSync.pipelineUniverse.test.js b/server/services/dataSync.pipelineUniverse.test.jsindex 512f9cba17..9e12c38b58 100644--- a/server/services/dataSync.pipelineUniverse.test.js+++ b/server/services/dataSync.pipelineUniverse.test.js@@ -1225,7 +1225,7 @@ describe('dataSync — per-category schema gate (cross-key isolation)', () => {'peerAuth',// Numeric PortOS quality uses its version-validated read-through endpoint, never snapshot writes.'appQuality',- // catalog → `POST /api/catalog/sync/apply` (server/services/catalogSync.js)+ // catalog → in-process applyRemoteChanges (server/services/catalogSync.js)'catalog',// authors → per-record peer-push only (no 60s file-snapshot category).// Gated at applyIncomingPush via compareSchemaVersions / RECORD_KIND_SCHEMA_CATEGORIES.author.