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
gate unattended routing on a tailnet peer, per the visual-prompts ADR
[._.]/ Adam Eivy649d5fd5a37b
diff --git a/client/src/components/instances/UnattendedRenderRouting.jsx b/client/src/components/instances/UnattendedRenderRouting.jsxindex 39b22fdbb6..0837a181ed 100644--- a/client/src/components/instances/UnattendedRenderRouting.jsx+++ b/client/src/components/instances/UnattendedRenderRouting.jsx@@ -17,6 +17,21 @@ const isRecord = (value) => value && typeof value === 'object' && !Array.isArrayconst optionValue = ({ peerId, engine, modelId }) => JSON.stringify([peerId, engine, modelId]);const modelKey = ({ engine, modelId }) => `${engine}\u0000${modelId}`;+// Mirrors the server's fail-closed `isTailnetPeer` gate (server/lib/tailnetPeer.js).+// A standing route exports every future prompt of its kind unreviewed, so ADR+// 2026-08-20-federated-visual-prompts (rule 5) refuses a non-tailnet peer. The+// server is authoritative; this only keeps the UI from offering a choice it+// would reject on the first job.+const isTailnetPeer = (peer) => {+ const host = typeof peer?.host === 'string' ? peer.host.trim() : '';+ if (host) return /\.ts\.net$/i.test(host);+ const address = (typeof peer?.address === 'string' ? peer.address : '').trim().replace(/^\[|\]$/g, '');+ if (!address) return false;+ if (/\.ts\.net$/i.test(address) || /^fd7a:115c:a1e0:/i.test(address)) return true;+ const v4 = address.match(/^100\.(\d{1,3})\.\d{1,3}\.\d{1,3}$/);+ return !!v4 && Number(v4[1]) >= 64 && Number(v4[1]) <= 127;+};+// One option per (peer, allowlisted model) pair that the peer currently// advertises as a capability. A model the user allowlisted but the peer no// longer advertises is deliberately absent: routing unattended work at it would@@ -30,6 +45,9 @@ function routeOptions(peers, kind, field) {// MEDIA_PROVIDER_PEER_DISABLED.if (peer?.enabled === false) continue;if (peer?.mediaProvider?.enabled !== true) continue;+ // Offering a non-tailnet peer here would save a route the server refuses on+ // every job with MEDIA_ROUTING_PEER_NOT_TAILNET.+ if (!isTailnetPeer(peer)) continue;const allowed = new Set((peer.mediaProvider[field] || []).filter((model) => model?.engine && model?.modelId).map(modelKey));@@ -154,7 +172,8 @@ export default function UnattendedRenderRouting({ peers }) {<p className="text-[11px] text-gray-500 mb-2">Where Creative Director and Creative Commission send their renders. Agents never choose a peer;this instance does. A routed kind fails with the peer’s reason rather than quietly rendering- locally, so unavailable capacity is visible instead of silent.+ locally, so unavailable capacity is visible instead of silent. Only Tailscale peers can be+ chosen — a standing route exports every future prompt of its kind without review.</p><div className="grid grid-cols-1 sm:grid-cols-2 gap-2">{KINDS.map(({ kind, label }) => {diff --git a/client/src/components/instances/UnattendedRenderRouting.test.jsx b/client/src/components/instances/UnattendedRenderRouting.test.jsxindex dc3f0aeaf2..f924e445d2 100644--- a/client/src/components/instances/UnattendedRenderRouting.test.jsx+++ b/client/src/components/instances/UnattendedRenderRouting.test.jsx@@ -20,6 +20,9 @@ const capability = (overrides) => ({ ready: true, unavailableReason: null, ...ovconst peerWith = (overrides = {}) => ({id: 'peer-1',name: 'Render Box',+ // A standing route refuses a non-tailnet peer (ADR rule 5), so the shared+ // fixture has to be a tailnet host or nothing is offerable.+ host: 'render-box.tailnet-example.ts.net',mediaProvider: {enabled: true,imageModels: [{ engine: 'comfy', modelId: 'sdxl-base' }],@@ -203,3 +206,20 @@ describe('UnattendedRenderRouting — a failed read is not an empty configuratioexpect(await screen.findByText(/could not load this instance/i)).toBeInTheDocument();});});++describe('UnattendedRenderRouting — tailnet gate', () => {+ it('does not offer a peer reachable outside the tailnet', async () => {+ // The server refuses such a route on every job; offering it here would only+ // let the user save a configuration that can never run.+ const lanPeer = peerWith({ host: undefined, address: '192.0.2.10', name: 'LAN Box' });+ const { container } = render(<UnattendedRenderRouting peers={[lanPeer]} />);+ await waitFor(() => expect(getSettings).toHaveBeenCalled());+ expect(container).toBeEmptyDOMElement();+ });++ it('offers a CGNAT-addressed peer', async () => {+ const cgnatPeer = peerWith({ host: undefined, address: '100.64.0.5' });+ render(<UnattendedRenderRouting peers={[cgnatPeer]} />);+ expect(await screen.findByLabelText('Image')).toBeInTheDocument();+ });+});diff --git a/docs/FEDERATED_MEDIA_PROVIDERS.md b/docs/FEDERATED_MEDIA_PROVIDERS.mdindex 32eef6489e..ab90588006 100644--- a/docs/FEDERATED_MEDIA_PROVIDERS.md+++ b/docs/FEDERATED_MEDIA_PROVIDERS.md@@ -178,6 +178,20 @@ where a local one could not (busy/stale/unauthorized provider); the scene runnersettles the scene through its normal failure path instead of leaving it stuck in`rendering`.+**A standing route requires a Tailscale peer.** A non-tailnet peer is refused+with `403 MEDIA_ROUTING_PEER_NOT_TAILNET`, and the Instances picker does not+offer one. Interactive routing is unchanged — the difference is review cadence:+a standing route exports every future prompt of its kind with nobody looking, so+a misconfigured counterparty is a permanent leak rather than a one-time mistake,+and `peerFetch`'s `rejectUnauthorized: false` leaves a plain-LAN or non-`.ts.net`+hop with no server authentication at all. Authentication would not save it+either: the prompt rides the request body, so an impostor holding the connection+reads it before failing to answer. Required by ADR+[federated visual prompts](./decisions/2026-08-20-federated-visual-prompts.md)+(rule 5); the gate is its own fail-closed predicate (`server/lib/tailnetPeer.js`)+rather than a re-export of the probe-deferral heuristic, so tuning that heuristic+can never widen this boundary.+Three properties are worth stating explicitly:- **Every unattended path routes, or none does.** The Creative Director plannerdiff --git a/scripts/tailnet-identity-leak.test.js b/scripts/tailnet-identity-leak.test.jsindex 0c34526cd5..d937313e15 100644--- a/scripts/tailnet-identity-leak.test.js+++ b/scripts/tailnet-identity-leak.test.js@@ -66,6 +66,7 @@ const ALLOWED_CGNAT_IPS = new Set(['100.100.42.7','100.100.50.1','100.100.100.200', // documented Alibaba Cloud metadata endpoint, not a peer+ '100.127.255.254', // synthetic top-of-CGNAT boundary value in tailnetPeer.test.js]);const CGNAT_IP_SOURCE = '\\b100\\.(6[4-9]|[7-9]\\d|1[01]\\d|12[0-7])\\.\\d{1,3}\\.\\d{1,3}\\b';const CGNAT_IP_RE = /\b100\.(6[4-9]|[7-9]\d|1[01]\d|12[0-7])\.\d{1,3}\.\d{1,3}\b/g;diff --git a/server/lib/README.md b/server/lib/README.mdindex 478cb0c8dc..40dc1e1663 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -239,6 +239,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `httpClient.js` | Fetch-based HTTP client factory (axios.create replacement). || `abortTimeout.js` | `withAbortTimeout(timeoutMs, fn)` — runs `fn(signal)` under an `AbortController` that aborts after `timeoutMs` and always clears the timer on settle. Generic lifecycle helper for callers that need the insecure-agent `peerFetch` (so can't use `fetchWithTimeout`) or one signal across parallel fetches. || `fetchWithTimeout.js` | `fetch` wrapper with AbortController timeout. |+| `tailnetPeer.js` | `isTailnetPeer(peer)` — fail-closed security predicate for "is this peer reachable only over the tailnet". Deliberately separate from `instances.js`'s `peerRequiresTailscale()` probe-deferral heuristic so a polling-noise tweak can't widen a privacy boundary; required by the unattended-routing gate in ADR 2026-08-20-federated-visual-prompts. || `federatedMediaRequest.js` | Builds and validates the versioned federated-media submission body for a visual kind, so every call site that persists a remote-job marker projects local params onto the wire identically. || `federatedMediaWire.js` | Versioned federated-media status schema/constants plus fail-closed consumer freshness checks (stale and clock-skewed snapshots are never assignable). || `connectivity.js` | `isMachineOnline({timeoutMs?, hosts?})` — internet-reachability probe: bare TCP `connect` to public anycast resolvers on :443 (no DNS, no HTTP), resolves `true` on the first connect and `false` only after all fail; never rejects. Reuse when a caller needs a best-effort local reachability signal. |diff --git a/server/lib/index.js b/server/lib/index.jsindex dd1b1d8733..9d053a91ae 100644--- a/server/lib/index.js+++ b/server/lib/index.js@@ -232,6 +232,7 @@ export * from './abortTimeout.js';export * from './connectivity.js';export * from './fetchWithTimeout.js';export * from './federatedMediaRequest.js';+export * from './tailnetPeer.js';export * from './federatedMediaWire.js';export * from './requestAbort.js';export * from './httpClient.js';diff --git a/server/lib/tailnetPeer.js b/server/lib/tailnetPeer.jsnew file mode 100644index 0000000000..a0db40fdb6--- /dev/null+++ b/server/lib/tailnetPeer.js@@ -0,0 +1,63 @@+/**+ * Is a peer reachable ONLY over the tailnet — as a security gate.+ *+ * This deliberately duplicates the shape of `peerRequiresTailscale()` in+ * `server/services/instances.js` instead of re-exporting it, because the two+ * answer different questions and must be free to diverge:+ *+ * - That one is an **availability heuristic** driving probe deferral ("don't+ * spam DNS failures for a tailnet-only peer while Tailscale is down"). It is+ * tuning, and a future polling-noise fix is entitled to loosen it.+ * - This one is a **security boundary**. ADR+ * `docs/decisions/2026-08-20-federated-visual-prompts.md` (rule 5) requires an+ * unattended standing route to refuse a peer that is not a tailnet host: a+ * standing route exports every future prompt of its kind with nobody+ * reviewing, so a misconfigured counterparty is a permanent leak rather than a+ * one-time mistake. Authentication does not save it — the prompt rides the+ * request body, so an impostor holding the connection reads it before failing+ * to answer — and `peerFetch` sets `rejectUnauthorized: false`, so a plain-LAN+ * or non-`.ts.net` peer gets no server authentication at all.+ *+ * Borrowing the heuristic would let a tuning change silently widen a privacy+ * boundary, which is precisely what that ADR ruled out.+ *+ * FAIL-CLOSED, and that is the other real difference: an address this cannot+ * positively recognize as tailnet is treated as NOT tailnet. The heuristic's+ * `false` means "probe it now" (harmless if wrong); this one's `false` means+ * "refuse to export prompts to it" (safe if wrong).+ */++// Tailscale's MagicDNS suffix.+const MAGIC_DNS = /\.ts\.net$/i;+// Tailscale's IPv6 ULA prefix, fd7a:115c:a1e0::/48.+const TAILSCALE_ULA = /^fd7a:115c:a1e0:/i;++const trimmed = (value) => (typeof value === 'string' ? value.trim() : '');++// 100.64.0.0/10 — the CGNAT range Tailscale assigns IPv4 addresses from. The+// second octet must be 64-127; 100.0.0.0/10 and 100.128.0.0/9 are ordinary+// public space and must NOT read as tailnet.+function isCgnatV4(address) {+ const match = address.match(/^100\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);+ if (!match) return false;+ const octets = match.slice(1).map(Number);+ if (octets.some((octet) => octet > 255)) return false;+ return octets[0] >= 64 && octets[0] <= 127;+}++/**+ * @param {object} peer - Registered peer record (`host` and/or `address`).+ * @returns {boolean} True only when the peer is positively recognized as a+ * tailnet host.+ */+export function isTailnetPeer(peer) {+ const host = trimmed(peer?.host);+ // An explicit host wins: it is what `peerBaseUrl` actually dials, so a+ // non-tailnet hostname is not rescued by a tailnet-looking `address`.+ if (host) return MAGIC_DNS.test(host);+ const address = trimmed(peer?.address);+ if (!address) return false;+ // Strip brackets from a literal IPv6 address (`[fd7a:…]`).+ const bare = address.replace(/^\[|\]$/g, '');+ return MAGIC_DNS.test(bare) || isCgnatV4(bare) || TAILSCALE_ULA.test(bare);+}diff --git a/server/lib/tailnetPeer.test.js b/server/lib/tailnetPeer.test.jsnew file mode 100644index 0000000000..f3c737fd65--- /dev/null+++ b/server/lib/tailnetPeer.test.js@@ -0,0 +1,47 @@+import { describe, it, expect } from 'vitest';+import { isTailnetPeer } from './tailnetPeer.js';++// A security gate, not the probe-deferral heuristic it resembles: `false` here+// means "refuse to export prompts to this peer", so anything not positively+// recognized as tailnet must come back false.+describe('isTailnetPeer', () => {+ it('accepts a MagicDNS host', () => {+ expect(isTailnetPeer({ host: 'example-host.tailnet-example.ts.net' })).toBe(true);+ expect(isTailnetPeer({ host: ' example-host.tailnet-example.ts.net ' })).toBe(true);+ });++ it('accepts a Tailscale CGNAT v4 address across the whole 100.64.0.0/10 range', () => {+ for (const address of ['100.64.0.1', '100.64.0.5', '100.127.255.254']) {+ expect(isTailnetPeer({ address })).toBe(true);+ }+ });++ it('rejects 100.x addresses OUTSIDE the CGNAT range, which are ordinary public space', () => {+ for (const address of ['100.63.0.1', '100.128.0.1', '100.255.255.1']) {+ expect(isTailnetPeer({ address })).toBe(false);+ }+ });++ it('accepts the Tailscale IPv6 ULA, bracketed or bare', () => {+ expect(isTailnetPeer({ address: 'fd7a:115c:a1e0::1' })).toBe(true);+ expect(isTailnetPeer({ address: '[fd7a:115c:a1e0::1]' })).toBe(true);+ });++ it('rejects a plain LAN address, a public host, and a lookalike suffix', () => {+ for (const address of ['192.0.2.10', '10.0.0.5', 'example.com', 'notreally-ts.net.example.com']) {+ expect(isTailnetPeer({ address })).toBe(false);+ }+ });++ // `host` is what peerBaseUrl actually dials, so a tailnet-looking address+ // must not rescue a peer configured to reach a non-tailnet hostname.+ it('lets an explicit non-tailnet host override a tailnet-looking address', () => {+ expect(isTailnetPeer({ host: 'render.example.com', address: '100.64.0.1' })).toBe(false);+ });++ it('fails closed on missing, empty, or malformed input', () => {+ for (const peer of [undefined, null, {}, { host: ' ' }, { address: '' }, { address: '100.64.0' }, { address: '100.999.0.1' }]) {+ expect(isTailnetPeer(peer)).toBe(false);+ }+ });+});diff --git a/server/services/creative/tools/media.test.js b/server/services/creative/tools/media.test.jsindex 91de4c40c3..9c9741df77 100644--- a/server/services/creative/tools/media.test.js+++ b/server/services/creative/tools/media.test.js@@ -462,7 +462,7 @@ describe('federated default provider routing (#4348)', () => {beforeEach(() => {prepareRemoteMediaJob.mockReset();prepareRemoteMediaJob.mockImplementation(async ({ peerId, kind, request }) => ({- peer: { id: peerId },+ peer: { id: peerId, name: 'Render Box', host: 'render-box.tailnet-example.ts.net' },remoteMedia: { wireVersion: 1, peerId, reconcile: false, cancelRequested: false, request },}));});diff --git a/server/services/federatedMedia/defaultRouting.js b/server/services/federatedMedia/defaultRouting.jsindex 0009e46c9e..583a3344cc 100644--- a/server/services/federatedMedia/defaultRouting.js+++ b/server/services/federatedMedia/defaultRouting.js@@ -28,6 +28,7 @@import { ServerError } from '../../lib/errorHandler.js';import { buildFederatedMediaRequest } from '../../lib/federatedMediaRequest.js';import { getSettings } from '../settings.js';+import { isTailnetPeer } from '../../lib/tailnetPeer.js';import { CLOUD_VIDEO_GEN_MODES, VIDEO_GEN_MODES } from '../videoGen/modes.js';// Only the visual kinds. See the audio note in the module docblock.@@ -224,6 +225,23 @@ export async function resolveDefaultMediaRoute({ kind, params }) {kind,request,});+ // ADR docs/decisions/2026-08-20-federated-visual-prompts.md, rule 5: a+ // STANDING route must refuse a non-tailnet peer. It exports every future+ // prompt of its kind with nobody reviewing, so a misconfigured counterparty+ // is a permanent leak where an interactive mistake is a one-time one — and+ // peerFetch's rejectUnauthorized:false leaves a plain-LAN or non-.ts.net peer+ // with no server authentication, so an impostor reads the prompt out of the+ // request body before failing to answer. Interactive routing is unchanged.+ //+ // Checked AFTER prepareRemoteMediaJob so the peer record is the registry's,+ // not one reconstructed from the route.+ if (!isTailnetPeer(peer)) {+ throw new ServerError(+ `Unattended ${kind} routing requires a Tailscale peer — "${peer.name || peer.id}" is reachable outside the tailnet, `+ + 'so a standing route would export every future prompt over an unauthenticated hop.',+ { status: 403, code: 'MEDIA_ROUTING_PEER_NOT_TAILNET' },+ );+ }// NOTE: the geometry forwarded here was snapped to the LOCAL model catalog by// the enqueue path ahead of this resolver, and wire v1's capability payload// publishes no frame-stride/canvas constraints to re-snap it against. Adiff --git a/server/services/federatedMedia/defaultRouting.test.js b/server/services/federatedMedia/defaultRouting.test.jsindex 2b26a98aa5..5229e766bf 100644--- a/server/services/federatedMedia/defaultRouting.test.js+++ b/server/services/federatedMedia/defaultRouting.test.js@@ -24,7 +24,7 @@ beforeEach(() => {enqueueJob.mockClear();prepareRemoteMediaJob.mockReset();prepareRemoteMediaJob.mockImplementation(async ({ peerId, kind, request }) => ({- peer: { id: peerId },+ peer: { id: peerId, name: 'Render Box', host: 'render-box.tailnet-example.ts.net' },remoteMedia: { wireVersion: 1, peerId, reconcile: false, cancelRequested: false, request },}));});@@ -334,3 +334,46 @@ describe('unreadable settings are not "no route"', () => {expect(enqueueJob).not.toHaveBeenCalled();});});++// ADR docs/decisions/2026-08-20-federated-visual-prompts.md rule 5: a STANDING+// route exports every future prompt of its kind with nobody reviewing, and+// peerFetch's rejectUnauthorized:false leaves a non-tailnet hop unauthenticated.+describe('standing routes are gated on a tailnet peer', () => {+ const route = { peerId: 'peer-1', engine: 'comfy', modelId: 'sdxl-remote' };++ beforeEach(() => {+ getSettings.mockResolvedValue({ federation: { mediaRouting: { image: route } } });+ });++ it('refuses a route whose peer is reachable outside the tailnet', async () => {+ prepareRemoteMediaJob.mockImplementation(async ({ peerId, request }) => ({+ peer: { id: peerId, name: 'LAN Box', address: '192.0.2.10' },+ remoteMedia: { peerId, request },+ }));+ await expect(resolveDefaultMediaRoute({ kind: 'image', params: { prompt: 'p' } }))+ .rejects.toMatchObject({ code: 'MEDIA_ROUTING_PEER_NOT_TAILNET', status: 403 });+ });++ it('names the peer and the reason so the refusal is actionable', async () => {+ prepareRemoteMediaJob.mockImplementation(async ({ peerId, request }) => ({+ peer: { id: peerId, name: 'LAN Box', address: '192.0.2.10' },+ remoteMedia: { peerId, request },+ }));+ await expect(resolveDefaultMediaRoute({ kind: 'image', params: { prompt: 'p' } }))+ .rejects.toThrow(/LAN Box.*outside the tailnet/s);+ });++ it('allows a MagicDNS peer', async () => {+ await expect(resolveDefaultMediaRoute({ kind: 'image', params: { prompt: 'p' } }))+ .resolves.toMatchObject({ peer: { id: 'peer-1' } });+ });++ it('allows a CGNAT-addressed peer', async () => {+ prepareRemoteMediaJob.mockImplementation(async ({ peerId, request }) => ({+ peer: { id: peerId, address: '100.64.0.5' },+ remoteMedia: { peerId, request },+ }));+ await expect(resolveDefaultMediaRoute({ kind: 'image', params: { prompt: 'p' } }))+ .resolves.toMatchObject({ peer: { id: 'peer-1' } });+ });+});