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: derive the facade's forbidden-importer set from the graph, and match dynamic imports without `await` (#3450)
[._.]/ Adam Eivy29e7318056e2
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 7a395aeba7..eb5100e736 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -2,7 +2,7 @@## Changed-- **The agent lifecycle has a named entry point instead of seven mutually-recursive modules.** The `cos.js → cosAgents.js → cosAgentLifecycle.js → agentManagement.js → agents.js → subAgentSpawner.js → agentLifecycle.js` cluster has no owner, so reasoning about one transition — pause, kill, complete, spawn — means holding all seven files in mind, and several of the back-edges are `await import(...)` calls that exist only to dodge a load-time cycle. `server/services/agentOrchestrator.js` is the facade above that cluster: it imports the transition owners one-directionally, carries the transition-vs-leaf classification in its header so later passes start from it, and renames apart the two different functions both called `terminateAgent` — `requestAgentTermination` only emits the event and returns, while `terminateAgent` keeps the name for the real SIGTERM/SIGKILL sequence. The four agent routes (terminate, pause, kill, stats) now go through it, one hop instead of three. `agentImportCycles.test.js` gains a guard that fails if any of the seven imports the facade back, statically *or* via `await import(...)` — the dynamic form matters because reaching across a blocked layer that way is exactly this cluster's habit. Widening that suite's graph builder to walk subdirectories closed a hole in the pre-existing cycle guard too: it read only top-level `server/services/*.js`, so a cycle routed through one subdirectory hop (`agentTuiSpawning/outputSpooler.js` already imports back up to `../cosAgents.js`) was invisible to it. The remaining call sites and the dynamic-import workarounds follow in later PRs (#3450).+- **The agent lifecycle has a named entry point instead of seven mutually-recursive modules.** The `cos.js → cosAgents.js → cosAgentLifecycle.js → agentManagement.js → agents.js → subAgentSpawner.js → agentLifecycle.js` cluster has no owner, so reasoning about one transition — pause, kill, complete, spawn — means holding all seven files in mind, and several of the back-edges are `await import(...)` calls that exist only to dodge a load-time cycle. `server/services/agentOrchestrator.js` is the facade above that cluster: it imports the transition owners one-directionally, carries the transition-vs-leaf classification in its header so later passes start from it, and renames apart the two different functions both called `terminateAgent` — `requestAgentTermination` only emits the event and returns, while `terminateAgent` keeps the name for the real SIGTERM/SIGKILL sequence. The four agent routes (terminate, pause, kill, stats) now go through it, one hop instead of three. `agentImportCycles.test.js` gains a guard that fails if anything reachable from the facade imports it back, statically *or* via `import(...)` — the dynamic form matters because reaching across a blocked layer that way is exactly this cluster's habit, and the forbidden set is derived from the graph rather than listed so it can't fall behind. Widening that suite's graph builder to walk subdirectories closed a hole in the pre-existing cycle guard too: it read only top-level `server/services/*.js`, so a cycle routed through one subdirectory hop (`agentTuiSpawning/outputSpooler.js` already imports back up to `../cosAgents.js`) was invisible to it. The remaining call sites and the dynamic-import workarounds follow in later PRs (#3450).- **Every view that used to show a bare "Loading…" text node now uses the shared loading affordances.** ~35 views across Music, MeatSpace, Media, Pipeline, Sprites, Writers Room, Sync, Catalog and a dozen pages rendered unstyled text while fetching, which read as broken content rather than a deliberate loading state. Small inline loads (buttons, side lists, drawer subtitles, popover menus) now render `BrailleSpinner`; full-page and card-grid loads render `PageSkeleton`, which reserves the eventual content's dimensions so the first paint doesn't reflow and announces itself via `role="status"`/`aria-busy`. Several hand-rolled `Loader2 + animate-spin` one-offs collapsed onto the same two components, and the pipeline audio music-library panel lost its duplicate second spinner.diff --git a/server/services/agentImportCycles.test.js b/server/services/agentImportCycles.test.jsindex b2dca91bfc..bc177f0ad9 100644--- a/server/services/agentImportCycles.test.js+++ b/server/services/agentImportCycles.test.js@@ -124,27 +124,39 @@ describe('agent lifecycle cluster — no static import cycles (#2837)', () => {}});- it('keeps the agentOrchestrator facade outside the cluster it fronts (#3450)', () => {+ it('keeps the agentOrchestrator facade outside the graph it fronts (#3450)', () => {// The facade only stays a facade while its edges point one way: it imports- // the cluster, the cluster never imports it back. Checked against the SEVEN- // named modules rather than all of `server/services` on purpose — a service- // that is NOT in the cluster can import the facade without closing any loop,- // and forbidding that would freeze the remaining call-site migrations.+ // the cluster, the cluster never imports it back.//- // Both forms are checked. The graph above is static-only (correct for cycle- // detection), but this cluster's established habit is to reach across a- // blocked layer with `await import()` — so a dynamic import of the facade- // from inside the cluster would violate the layering with the cycle walk- // fully green, which is the failure mode this module exists to end.- const CLUSTER_SEVEN = [- 'cos.js', 'cosAgents.js', 'cosAgentLifecycle.js', 'agentManagement.js',- 'agents.js', 'subAgentSpawner.js', 'agentLifecycle.js',- ];- const offenders = CLUSTER_SEVEN.filter(file => {- if ((graph.get(file) || []).includes('agentOrchestrator.js')) return true;- return /await import\(\s*['"]\.\/agentOrchestrator\.js['"]\s*\)/- .test(readFileSync(join(SERVICES_DIR, file), 'utf-8'));- });+ // The forbidden set is derived, not listed. It is everything reachable FROM+ // the facade — an import back from any of those closes a loop, and the set+ // grows on its own as the cluster does, so it can't fall behind the way a+ // hand-maintained list of seven names would (that list omitted+ // agentCliSpawning/agentTuiSpawning, both reachable via agentLifecycle).+ // Modules outside the closure may import the facade freely: they close no+ // loop, and forbidding them would freeze the remaining call-site migrations.+ const reachable = new Set();+ const walk = (node) => {+ for (const dep of graph.get(node) || []) {+ if (reachable.has(dep)) continue;+ reachable.add(dep);+ walk(dep);+ }+ };+ walk('agentOrchestrator.js');+ expect(reachable.size, 'facade closure looks empty — did the module move?').toBeGreaterThan(3);++ // Dynamic imports are matched too, and WITHOUT requiring `await`: the static+ // graph deliberately ignores `import()` (correct for cycle detection), but+ // reaching across a blocked layer with a deferred import is exactly this+ // cluster's habit, so a `return import(...).then(...)` back-edge would+ // violate the layering with the cycle walk fully green. Any relative+ // specifier ending in `agentOrchestrator.js` counts, from any depth.+ const DYNAMIC_FACADE_IMPORT = /\bimport\(\s*['"][^'"]*\bagentOrchestrator\.js['"]\s*\)/;+ const offenders = [...reachable].filter(file =>+ (graph.get(file) || []).includes('agentOrchestrator.js') ||+ DYNAMIC_FACADE_IMPORT.test(readFileSync(join(SERVICES_DIR, file), 'utf-8'))+ ).sort();expect(offenders, `agentOrchestrator.js must not be imported by ${offenders.join(', ')}`).toEqual([]);});diff --git a/server/services/agentOrchestrator.js b/server/services/agentOrchestrator.jsindex cb7834a304..8b82a54af6 100644--- a/server/services/agentOrchestrator.js+++ b/server/services/agentOrchestrator.js@@ -25,15 +25,16 @@* `await import(...)`), and it re-exports ~40 symbols as a back-compat barrel.* A facade has to be small, complete, and outside the graph it fronts.*- * **Invariant, enforced by `agentImportCycles.test.js`: none of those seven- * modules may import this one — statically OR via `await import(...)`.** One- * such edge closes the loop and puts every dynamic-import workaround back on the- * table, and this cluster's habit is to reach across a blocked layer with- * `await import()`, so the guard checks both forms. Anything *outside* the seven- * may import the facade freely — routes, socket handlers, and any service the- * cluster does not depend on. That is the migration path for the exports below- * whose current callers are still inside the cluster: the caller moves out, it- * does not import back in.+ * **Invariant, enforced by `agentImportCycles.test.js`: no module reachable+ * FROM this one may import it back — statically OR via `import(...)`.** One such+ * edge closes the loop and puts every dynamic-import workaround back on the+ * table, and this cluster's habit is to reach across a blocked layer with a+ * deferred import, so the guard checks both forms. The forbidden set is derived+ * from the graph rather than listed, so it grows as the cluster does. Anything+ * *outside* that closure may import the facade freely — routes, socket handlers,+ * and any service the cluster does not depend on. That is the migration path for+ * the exports below whose current callers are still inside the cluster: the+ * caller moves out, it does not import back in.** ## Transition vs leaf (step 1 of the #3450 sequencing)*