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: honor the Signal sync off switch before accessing chats (#13091)
Adam Eivy954908b6660f
diff --git a/server/services/signalSync.js b/server/services/signalSync.jsindex 2626baee0d..5f4da4868d 100644--- a/server/services/signalSync.js+++ b/server/services/signalSync.js@@ -48,6 +48,7 @@ import { decryptSafeStorageValue, isRawHexKey } from '../lib/signalCrypto.js';import { shortSummary, localDayKey } from './humanActivity.js';import { captureConsistentSnapshot } from './signalSnapshot.js';import { getSettings } from './settings.js';+import { ServerError } from '../lib/errorHandler.js';const execFileAsync = promisify(execFile);@@ -392,6 +393,9 @@ function readMessages(db, cursorRowid, limit) {* render an actionable error (missing install, key failure, unsupported schema).*/export async function checkSetup() {+ const config = await getSignalConfig();+ if (config.enabled !== true) return { enabled: false };+const keyResult = await resolveDbKey();if (!keyResult.ok) {return { ok: false, dbPath: dbPath(), error: keyResult.error, remediation: keyResult.remediation };@@ -423,13 +427,19 @@ export async function checkSetup() {* touchpoints, and advance the cursor. Returns a summary. Safe to call repeatedly* — dedupe keys make re-ingestion a no-op. Runs outside the request lifecycle* (scheduler / explicit endpoint), so every failure is try/catch-guarded and- * returns an error report instead of throwing.+ * returns an error report instead of throwing. Disabled sync rejects with+ * SIGNAL_DISABLED before reading Signal files or the keychain.** Re-entrancy guarded: a manual "Sync now" overlapping a scheduler tick would* double-read the same cursor — so concurrent callers share the in-flight pass.*/let syncInFlight = null;export async function runSync() {+ const config = await getSignalConfig();+ if (config.enabled !== true) {+ throw new ServerError('Enable Signal sync in Settings before syncing.', { status: 409, code: 'SIGNAL_DISABLED' });+ }+if (syncInFlight) return syncInFlight;syncInFlight = doRunSync().finally(() => { syncInFlight = null; });return syncInFlight;diff --git a/server/services/signalSync.runSync.test.js b/server/services/signalSync.runSync.test.jsindex 60fed5e9f4..57e32b2f6f 100644--- a/server/services/signalSync.runSync.test.js+++ b/server/services/signalSync.runSync.test.js@@ -10,11 +10,14 @@ import { decryptSqlcipherDatabase, deriveSqlcipherKeys, sqlcipherPageHmac,const mocks = vi.hoisted(() => ({root: '', snapshots: [], recordEvents: vi.fn(), autoLogTouchpoints: vi.fn(),+ readFile: vi.fn(), execFile: vi.fn(),}));-vi.mock('../lib/fileUtils.js', async (importOriginal) => ({- ...await importOriginal(),- dataPath: (...parts) => join(mocks.root, ...parts),-}));+vi.mock('../lib/fileUtils.js', async (importOriginal) => {+ const actual = await importOriginal();+ mocks.readFile.mockImplementation(actual.tryReadFile);+ return { ...actual, tryReadFile: mocks.readFile, dataPath: (...parts) => join(mocks.root, ...parts) };+});+vi.mock('../lib/childProcess.js', () => ({ execFile: mocks.execFile }));vi.mock('node:fs/promises', async (importOriginal) => {const actual = await importOriginal();return { ...actual, mkdtemp: async (...args) => {@@ -23,7 +26,7 @@ vi.mock('node:fs/promises', async (importOriginal) => {return path;} };});-vi.mock('./settings.js', () => ({ getSettings: vi.fn(async () => ({})) }));+vi.mock('./settings.js', () => ({ getSettings: vi.fn(async () => ({ signal: { enabled: true } })) }));vi.mock('./userTimezone.js', () => ({ getUserTimezone: vi.fn(async () => 'UTC') }));vi.mock('./humanActivity.js', async (importOriginal) => ({...await importOriginal(), recordEvents: mocks.recordEvents,@@ -31,6 +34,8 @@ vi.mock('./humanActivity.js', async (importOriginal) => ({vi.mock('./tribe.js', () => ({ autoLogTouchpoints: mocks.autoLogTouchpoints }));import { checkSetup, runSync, readSyncState } from './signalSync.js';+import { getSettings } from './settings.js';+import { ServerError } from '../lib/errorHandler.js';const KEY = 'ab'.repeat(32); // invented fixture key; never reads the keychainconst BODY = 'x'.repeat(512);@@ -86,6 +91,9 @@ function encrypt(plain) {}beforeEach(() => {+ getSettings.mockResolvedValue({ signal: { enabled: true } });+ mocks.readFile.mockClear();+ mocks.execFile.mockReset().mockImplementation((...args) => args.at(-1)(new Error('Unexpected keychain access')));mocks.root = createTempDataRoot('signal-auth-test-');mocks.snapshots = [];mkdirSync(join(mocks.root, 'sql'));@@ -111,6 +119,22 @@ function expectSnapshotsRemoved() {}describe('Signal authenticated snapshot ingestion', () => {+ it.each([{}, { signal: { enabled: false } }])('refuses disabled sync and setup before any Signal file or keychain access (%j)', async (settings) => {+ getSettings.mockResolvedValue(settings);+ vi.stubEnv('SIGNAL_KEYCHAIN_PASSWORD', '');+ writeFileSync(join(mocks.root, 'config.json'), JSON.stringify({ encryptedKey: 'fixture-wrapped-key' }));++ const refusal = await runSync().catch((error) => error);+ expect(refusal).toBeInstanceOf(ServerError);+ expect(refusal).toMatchObject({ status: 409, code: 'SIGNAL_DISABLED' });+ expect(await checkSetup()).toEqual({ enabled: false });+ expect(mocks.readFile).not.toHaveBeenCalled();+ expect(mocks.execFile).not.toHaveBeenCalled();+ expect(mocks.snapshots).toEqual([]);+ expect(mocks.recordEvents).not.toHaveBeenCalled();+ expect(mocks.autoLogTouchpoints).not.toHaveBeenCalled();+ });+it('accepts a multipage database and does not reingest messages on replay', async () => {expect(plaintext.length).toBeGreaterThan(SQLCIPHER_PAGE_SIZE);expect(await checkSetup()).toMatchObject({ ok: true, messageCount: 1 });diff --git a/server/services/signalSync.wal.test.js b/server/services/signalSync.wal.test.jsindex 3d9848cd8f..a99698cd6c 100644--- a/server/services/signalSync.wal.test.js+++ b/server/services/signalSync.wal.test.js@@ -38,6 +38,8 @@ vi.mock('./humanActivity.js', async () => {return { ...actual, recordEvents: recordEventsMock };});+vi.mock('./settings.js', () => ({ getSettings: vi.fn(async () => ({ signal: { enabled: true } })) }));+vi.mock('./tribe.js', () => ({autoLogTouchpoints: autoLogTouchpointsMock,}));