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: pass io into startBackgroundServices so the sweeper can arm (#5660)
Adam Eivy4df1c0180360
diff --git a/server/services/bootstrap.hostedSessionSweep.test.js b/server/services/bootstrap.hostedSessionSweep.test.jsnew file mode 100644index 0000000000..e338ac6efc--- /dev/null+++ b/server/services/bootstrap.hostedSessionSweep.test.js@@ -0,0 +1,47 @@+/**+ * Source contract for the FableLoom hosted-session sweeper's boot wiring (#5660).+ *+ * `startBackgroundServices` and `runBootSequence` have no unit harness — running+ * either would spin up every scheduler, hook and PTY the real boot arms — so the+ * wiring facts the sweeper depends on are asserted against the source instead.+ * Both are things a plausible edit silently breaks, and neither shows up until+ * the server actually boots:+ *+ * 1. `startBackgroundServices` must destructure `io`. It is a module-scope+ * arrow, so a body that reads `io` without receiving it is a ReferenceError+ * thrown mid-boot, not a lint-time typo (ESM is strict mode — there is no+ * implicit global to fall back on).+ * 2. The shutdown handler must disarm the sweeper. A tick that fires mid+ * -shutdown emits into a namespace the process is about to close.+ */++import { describe, it, expect } from 'vitest';+import { readFileSync } from 'fs';+import { fileURLToPath } from 'url';+import { dirname, join } from 'path';+import { extractDeclaration, stripCommentsAndNormalize } from '../lib/mirrorParity.js';++const __dirname = dirname(fileURLToPath(import.meta.url));+const SRC = readFileSync(join(__dirname, 'bootstrap.js'), 'utf-8').replace(/\r\n/g, '\n');++describe('hosted-session sweeper boot wiring (#5660)', () => {+ const startBody = stripCommentsAndNormalize(extractDeclaration(SRC, 'startBackgroundServices') || '');++ it('arms the sweeper from startBackgroundServices with an io it actually receives', () => {+ expect(startBody, 'startBackgroundServices not found in bootstrap.js').toBeTruthy();+ expect(startBody).toContain('startHostedSessionSweep({ io })');+ // The destructured parameter list, i.e. everything up to the arrow.+ const params = startBody.slice(0, startBody.indexOf('=>'));+ expect(params, 'startBackgroundServices reads `io` but never destructures it').toMatch(/\bio\b/);+ });++ it('passes io down from runBootSequence, which is where the Socket.IO server lives', () => {+ const bootBody = stripCommentsAndNormalize(extractDeclaration(SRC, 'runBootSequence') || '');+ expect(bootBody).toContain('startBackgroundServices({ spawnerReady, io })');+ });++ it('disarms the sweeper during graceful shutdown', () => {+ const shutdownBody = stripCommentsAndNormalize(extractDeclaration(SRC, 'shutdown') || '');+ expect(shutdownBody).toContain('stopHostedSessionSweep()');+ });+});diff --git a/server/services/bootstrap.js b/server/services/bootstrap.jsindex 09b1ec3013..22302f2e8c 100644--- a/server/services/bootstrap.js+++ b/server/services/bootstrap.js@@ -315,7 +315,7 @@ export const bootstrapServices = async ({ io, dataDir, dataReferenceDir, serverD* Fire-and-forget service inits + scheduler arming. None of these block the* server from listening; each logs its own failure and the boot continues.*/-const startBackgroundServices = ({ spawnerReady }) => {+const startBackgroundServices = ({ spawnerReady, io }) => {// Explicit call (not a module-level side effect) so test imports of cos.js// don't spin up its event listeners and timers. The spawner gate itself lives// in bootstrapSequence.js.@@ -739,7 +739,7 @@ const announceListening = ({ io, httpServer, localHttpServer, httpsEnabled, port*/export const runBootSequence = ({ io, httpServer, localHttpServer, httpsEnabled, port, host, spawnerReady }) =>runPostRouteSequence({- startBackgroundServices: () => startBackgroundServices({ spawnerReady }),+ startBackgroundServices: () => startBackgroundServices({ spawnerReady, io }),// Instance identity + sync log come up before requests are accepted, so a// brain mutation can't arrive before the sync log is ready.