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: add Tailcat connection recovery controls (#8819)
[._.]/dca7894ad36c
diff --git a/client/src/components/instances/TailcatForwardStatus.jsx b/client/src/components/instances/TailcatForwardStatus.jsxindex 9ec3ec2a66..272cf62b43 100644--- a/client/src/components/instances/TailcatForwardStatus.jsx+++ b/client/src/components/instances/TailcatForwardStatus.jsx@@ -6,6 +6,7 @@* Never receives a full tc… capability — only the redacted listing fields.*/+import { useId, useState } from 'react';import { RefreshCw, Trash2, CheckCircle2, AlertCircle, Clock } from 'lucide-react';import { DEFAULT_TAILCAT_REMOTE_PORT } from '../../lib/ports';import Pill from '../ui/Pill';@@ -34,6 +35,10 @@ export function TailcatForwardStatus({compact = false,showForget = true,}) {+ const addressId = useId();+ const [editingAddress, setEditingAddress] = useState(false);+ const [replacementAddress, setReplacementAddress] = useState('');+if (!forward) {return (<div className="mt-2 text-[11px] text-gray-500 leading-snug">@@ -95,6 +100,33 @@ export function TailcatForwardStatus({</div>)}</div>+ {onRetry && (+ <div className="mt-2 text-[11px]">+ <button type="button" disabled={busy} className="text-port-accent underline disabled:opacity-50"+ onClick={() => { setEditingAddress(!editingAddress); setReplacementAddress(''); }}>+ {editingAddress ? 'Cancel address replacement' : 'Replace remote address'}+ </button>+ {editingAddress && (+ <form className="mt-2 space-y-2" onSubmit={async (event) => {+ event.preventDefault();+ const address = replacementAddress.trim();+ if (!address || busy) return;+ setReplacementAddress('');+ setEditingAddress(false);+ await onRetry(undefined, address);+ }}>+ <label htmlFor={addressId} className="block text-gray-400">New remote Tailcat address</label>+ <input id={addressId} type="password" autoComplete="off" spellCheck={false}+ value={replacementAddress} onChange={event => setReplacementAddress(event.target.value)}+ disabled={busy} required minLength={24} maxLength={2048}+ className="w-full min-w-0 bg-port-bg border border-port-border rounded px-2 py-1" />+ <p className="text-gray-500">Paste the address copied from the remote after a relay change. Keeps this peer and its pairing settings.</p>+ <button type="submit" disabled={busy || !replacementAddress.trim()}+ className="border border-port-border rounded px-2 py-1 disabled:opacity-50">Save address & retry</button>+ </form>+ )}+ </div>+ )}{failure && (<p className="text-[11px] text-port-error mt-2 leading-snug break-words">{failure.message}diff --git a/client/src/components/instances/TailcatForwardsPanel.jsx b/client/src/components/instances/TailcatForwardsPanel.jsxindex 8bde3df6ed..89497d53b9 100644--- a/client/src/components/instances/TailcatForwardsPanel.jsx+++ b/client/src/components/instances/TailcatForwardsPanel.jsx@@ -44,9 +44,9 @@ export default function TailcatForwardsPanel({ onChange, peerIds, renderPanel =});}, [forwards, peerIdSet]);- const retry = async (id, remotePort) => {+ const retry = async (id, remotePort, tcAddress) => {setBusyId(id);- const peer = await retryTailcatForward(id, remotePort ? { remotePort } : {}).catch(() => null);+ const peer = await retryTailcatForward(id, { ...(remotePort ? { remotePort } : {}), ...(tcAddress ? { tcAddress } : {}) }).catch(() => null);setBusyId(null);// Refetch rather than guess: status, liveness and the failure text are all// derived server-side, and a local guess would misreport a failed retry.@@ -88,7 +88,7 @@ export default function TailcatForwardsPanel({ onChange, peerIds, renderPanel =<TailcatForwardStatusforward={forward}busy={busyId === forward.id}- onRetry={(remotePort) => retry(forward.id, remotePort)}+ onRetry={(remotePort, tcAddress) => retry(forward.id, remotePort, tcAddress)}onForget={() => forget(forward.id)}/></li>diff --git a/client/src/components/instances/TailcatForwardsPanel.test.jsx b/client/src/components/instances/TailcatForwardsPanel.test.jsxindex 5ea3ae08bc..9bb938fc6a 100644--- a/client/src/components/instances/TailcatForwardsPanel.test.jsx+++ b/client/src/components/instances/TailcatForwardsPanel.test.jsx@@ -137,3 +137,19 @@ it('updates the remote port only when the operator chooses the upgraded ingress'await user.click(await screen.findByRole('button', { name: 'Retry on :5565' }));await waitFor(() => expect(retryTailcatForward).toHaveBeenCalledWith(failedForward.id, { remotePort: 5565 }));});++it('replaces a stale address on the existing forward without revealing the stored capability', async () => {+ getTailcatForwards.mockResolvedValue({ forwards: [failedForward] });+ retryTailcatForward.mockResolvedValue({ id: 'peer-example', port: 15555 });+ const user = userEvent.setup();+ render(<TailcatForwardsPanel />);+ await user.click(await screen.findByRole('button', { name: 'Replace remote address' }));+ const input = screen.getByLabelText('New remote Tailcat address');+ expect(input).toHaveValue('');+ expect(input).toHaveAttribute('type', 'password');+ const tcAddress = 'tcEXAMPLE' + 'B'.repeat(40);+ await user.type(input, tcAddress);+ await user.click(screen.getByRole('button', { name: 'Save address & retry' }));+ await waitFor(() => expect(retryTailcatForward).toHaveBeenCalledWith(failedForward.id, { tcAddress }));+ expect(screen.queryByLabelText('New remote Tailcat address')).not.toBeInTheDocument();+});diff --git a/client/src/components/instances/TailcatServePanel.jsx b/client/src/components/instances/TailcatServePanel.jsxindex 9b98968ff7..cd8eee608c 100644--- a/client/src/components/instances/TailcatServePanel.jsx+++ b/client/src/components/instances/TailcatServePanel.jsx@@ -1,5 +1,5 @@/**- * Machine-local Tailcat serve status — start/stop PortOS API :5555 over+ * Machine-local Tailcat serve status — start/stop the isolated PortOS ingress over* tailcat, and Copy the tc… address for the other node to Dial-them.** The full address is returned by the serve status API on purpose (our own@@ -79,6 +79,18 @@ export default function TailcatServePanel({ onChange, compact = false }) {{busy ? 'Working...' : (status?.status === 'failed' || status?.enabled ? 'Retry' : 'Start serve')}</button>)}+ {status?.live && (+ <button+ type="button"+ onClick={() => run(() => retryTailcatServe(), 'Tailcat serve restarted')}+ disabled={busy}+ title="Restart the serving process using the saved key"+ className="inline-flex items-center gap-1 text-[11px] text-gray-400 hover:text-white disabled:opacity-50 border border-port-border rounded px-2 py-1 transition-colors"+ >+ <RefreshCw size={11} className={busy ? 'animate-spin' : ''} />+ {busy ? 'Working...' : 'Restart serve'}+ </button>+ )}{status?.live && (<buttontype="button"diff --git a/client/src/components/instances/TailcatServePanel.test.jsx b/client/src/components/instances/TailcatServePanel.test.jsxindex 95fc114de1..62dd14fd46 100644--- a/client/src/components/instances/TailcatServePanel.test.jsx+++ b/client/src/components/instances/TailcatServePanel.test.jsx@@ -29,7 +29,7 @@ import socket from '../../services/socket';afterEach(() => vi.useRealTimers());-import { getTailcatServe, startTailcatServe, stopTailcatServe } from '../../services/api';+import { getTailcatServe, startTailcatServe, retryTailcatServe, stopTailcatServe } from '../../services/api';import TailcatServePanel from './TailcatServePanel';const stopped = {@@ -80,6 +80,22 @@ describe('TailcatServePanel', () => {expect(screen.getByText(/tcEX…EEEE/)).toBeInTheDocument();});+ it('restarts a live but stale serve without disabling it or replacing its address', async () => {+ getTailcatServe.mockResolvedValue(serving);+ let finishRestart;+ retryTailcatServe.mockImplementationOnce(() => new Promise(resolve => { finishRestart = resolve; }));+ const user = userEvent.setup();+ render(<TailcatServePanel />);+ await user.click(await screen.findByRole('button', { name: 'Restart serve' }));+ expect(screen.getByRole('button', { name: 'Working...' })).toBeDisabled();+ expect(screen.getByRole('button', { name: 'Stop' })).toBeDisabled();+ await act(async () => finishRestart(serving));+ expect(screen.getByRole('button', { name: 'Restart serve' })).toBeEnabled();+ expect(screen.getByText(/tcEX…EEEE/)).toBeInTheDocument();+ expect(stopTailcatServe).not.toHaveBeenCalled();+ expect(startTailcatServe).not.toHaveBeenCalled();+ });+it('stops a live serve', async () => {getTailcatServe.mockResolvedValue(serving);stopTailcatServe.mockResolvedValue(stopped);diff --git a/client/src/pages/Instances.jsx b/client/src/pages/Instances.jsxindex 287d93ff5b..0ae8cfe1b9 100644--- a/client/src/pages/Instances.jsx+++ b/client/src/pages/Instances.jsx@@ -1273,11 +1273,11 @@ export function PeerCard({ peer, onRefresh, syncStatus, tailnetInfo, parityRepor}};- const handleForwardRetry = async (remotePort) => {+ const handleForwardRetry = async (remotePort, tcAddress) => {const forwardId = peer.tailcatForward?.id;if (!forwardId) return;setForwardBusy(true);- const updated = await retryTailcatForward(forwardId, remotePort ? { remotePort } : {}).catch(() => null);+ const updated = await retryTailcatForward(forwardId, { ...(remotePort ? { remotePort } : {}), ...(tcAddress ? { tcAddress } : {}) }).catch(() => null);setForwardBusy(false);onRefresh();if (!updated) return;diff --git a/docs/features/tailcat-peers.md b/docs/features/tailcat-peers.mdindex 1f8542f848..1aaf57129d 100644--- a/docs/features/tailcat-peers.md+++ b/docs/features/tailcat-peers.md@@ -254,8 +254,8 @@ that started working again goes quiet — a latched "no route" would be the samelie as a permanently green "running", pointing the other way.**When an add reports the tunnel could not reach the remote, or a live forward-shows `no route`,** the tunnel — not PortOS — is what to look at. The-usual cause on macOS is a local network filter (Little Snitch and friends)+shows `no route`,** check both the remote ingress and the tunnel. One possible+cause on macOS is a local network filter (Little Snitch and friends)denying the `tailcat` binary itself: `tailcat forward --verbose` then logs arelay connect that dies the instant it is established, while `curl` to the samerelay from the same machine succeeds.@@ -273,6 +273,32 @@ the `tailcat` binary outbound in the filter, then Retry the forward. If outboundallow-listing is impractical on this host, switch to **They dial us**: servehere and have the sandbox (or other good initiator) Dial them toward this node.+### Restoring a lost connection++A running Tailcat process proves neither that the tunnel works nor that the+remote PortOS ingress is listening. Recover in this order:++1. On the remote machine, confirm that PortOS answers on its isolated ingress+ `:5565`, using the install's HTTP/HTTPS mode. A healthy main API on `:5555`+ alone does not establish that the ingress is ready.+2. In the remote **Tailcat serve (this node)** panel, use **Restart serve** even+ if the process still says **serving**. Restart uses the saved key and keeps+ restore-on-boot enabled. Do not generate a replacement key as a restart step.+3. On the dialing machine, use **Retry** on the saved forward. PortOS verifies+ an HTTP response through the tunnel, then immediately probes the peer rather+ than waiting for its previous failure backoff (which can reach 24 hours).+ If relay selection changed the address, use **Replace remote address** on that+ same forward and paste the new address copied privately from the remote. This+ preserves the peer, credentials and pairing; it does not require Forget/Add.+4. Check the peer's new health result. A reachable peer asking for credentials+ needs pairing/authentication; another tunnel timeout needs further transport+ diagnosis. Compare versions, the served port and saved address, then inspect+ relay/firewall diagnostics. A ping alone does not verify TCP forwarding.++The local Retry action cannot restart an unreachable remote process. Use the+remote machine's own UI or an already authorized out-of-band management channel.+Keep the existing private access boundary and dedicated ingress when recovering.+### The DERP map has to be reachable — by Gotailcat resolves a `tc…` address's relay region by fetching its DERP map@@ -365,6 +391,38 @@ tailcat forward <tcADDR> 15555:5565- [tailscale/tailcat](https://github.com/tailscale/tailcat) — CLI reference+### Separate authentication failures from relay TLS failures++The public health probe and Tailcat relay handshake do not require a paired+PortOS credential. A 401 or 403 response proves the tunnel carried HTTP; resolve+that response through the instance credential / pair-secret workflow. A saved+peer without a pair secret can remain unable to sync even after transport is+restored. Do not remove authentication or point Tailcat at the main API port to+work around a relay timeout.++A relay timeout alone does not prove that a hosting provider banned Tailcat.+Compare the same public relay URL from both endpoints, retaining certificate+verification and the hostname, then repeat a bounded TLS comparison:++```sh+curl --connect-timeout 5 --max-time 10 -v https://<relay-host>/derp/probe+curl --connect-timeout 5 --max-time 10 -v --curves X25519 https://<relay-host>/derp/probe+```++Some network paths fail with the larger post-quantum ClientHello while the same+host succeeds with classic X25519. Go documents this compatibility failure and+the diagnostic `GODEBUG=tlsmlkem=0` switch in its+[GODEBUG guidance](https://go.dev/doc/godebug). A successful relay connection+under that setting is useful evidence, but is not an end-to-end health check:+both the serve and forward must reach the relay. Inspect verbose connection+traces instead of inferring the failure stage from zero-valued curl timings.++Keep this a bounded diagnostic. Do not automatically persist a cryptographic+fallback, disable certificate verification, change firewall rules, or declare+a provider policy change from timeouts. A permanent compatibility setting is a+separate operator decision; the underlying path or middlebox defect remains+unidentified until additional network evidence establishes it.+## Code ownershipShared CLI discovery, version-gated installation, and DERP cache priming live indiff --git a/server/routes/instances.js b/server/routes/instances.jsindex 074c090968..984827f302 100644--- a/server/routes/instances.js+++ b/server/routes/instances.js@@ -289,9 +289,15 @@ router.get('/peers/tailcat/forwards', asyncHandler(async (_req, res) => {// using the stored capability, registering its peer if the original add never got// that far.router.post('/peers/tailcat/forwards/:id/retry', asyncHandler(async (req, res) => {- const data = validateRequest(z.object({ remotePort: z.number().int().min(1).max(65535).optional() }), req.body || {});+ const data = validateRequest(z.object({+ remotePort: z.number().int().min(1).max(65535).optional(),+ tcAddress: z.string().trim().min(24).max(2048).refine(tailcatPeer.isValidTcAddress, 'Invalid Tailcat address').optional(),+ }), req.body || {});const peer = await tailcatPeer.retryTailcatForward(req.params.id, data);- res.json(instances.sanitizePeerForClient(peer));+ // A repaired tunnel must not leave the peer in yesterday's probe backoff.+ // Probe also distinguishes a usable tunnel from missing peer credentials.+ const probed = await instances.probePeer(peer);+ res.json(instances.sanitizePeerForClient(probed || peer));}));// DELETE /api/instances/peers/tailcat/forwards/:id — stop the forward, drop thediff --git a/server/routes/instances.test.js b/server/routes/instances.test.jsindex 0cedfd050f..a6dec94727 100644--- a/server/routes/instances.test.js+++ b/server/routes/instances.test.js@@ -30,6 +30,7 @@ vi.mock('../services/instances.js', async (importOriginal) => ({sanitizePeerForClient: vi.fn((peer) => peer),getAssignableInstances: vi.fn(),getPeers: vi.fn(),+ probePeer: vi.fn(),}));// This suite's routes/instances.js import pulls getSelf/updateSelf from the// identity leaf (#6836) — double it too so an untested route (e.g. GET /@@ -344,13 +345,40 @@ describe('saved tailcat forward routes', () => {expect(res.body).toEqual({ forwards: rows });});- it('retries a saved forward and sanitizes the resulting peer', async () => {+ it('probes a repaired forward immediately instead of returning stale offline backoff', async () => {const peer = { id: 'peer-example', transport: 'tailcat', address: '127.0.0.1', port: 15556 };retryTailcatForward.mockResolvedValue(peer);+ const recovered = { ...peer, status: 'online', consecutiveFailures: 0, nextProbeAt: null };+ instances.probePeer.mockResolvedValue(recovered);const res = await request(buildApp()).post('/api/instances/peers/tailcat/forwards/fwd_1/retry');expect(res.status).toBe(200);expect(retryTailcatForward).toHaveBeenCalledWith('fwd_1', {});- expect(instances.sanitizePeerForClient).toHaveBeenCalledWith(peer);+ expect(instances.probePeer).toHaveBeenCalledWith(peer);+ expect(instances.sanitizePeerForClient).toHaveBeenCalledWith(recovered);+ expect(res.body).toEqual(recovered);+ });++ it('keeps a reachable but unpaired peer distinct from a recovered peer', async () => {+ const peer = { id: 'peer-example', transport: 'tailcat', port: 15555 };+ retryTailcatForward.mockResolvedValue(peer);+ instances.probePeer.mockResolvedValue({ ...peer, status: 'offline', authRequired: true });+ const res = await request(buildApp()).post('/api/instances/peers/tailcat/forwards/fwd_1/retry');+ expect(res.status).toBe(200);+ expect(res.body).toMatchObject({ authRequired: true, status: 'offline' });+ });++ it('validates replacement capabilities before restarting a saved forward', async () => {+ const tcAddress = 'tcEXAMPLE' + 'A'.repeat(40);+ const peer = { id: 'peer-example', port: 15555 };+ retryTailcatForward.mockResolvedValue(peer);+ instances.probePeer.mockResolvedValue(peer);+ const ok = await request(buildApp()).post('/api/instances/peers/tailcat/forwards/fwd_1/retry').send({ tcAddress });+ expect(ok.status).toBe(200);+ expect(retryTailcatForward).toHaveBeenCalledWith('fwd_1', { tcAddress });+ retryTailcatForward.mockClear();+ const bad = await request(buildApp()).post('/api/instances/peers/tailcat/forwards/fwd_1/retry').send({ tcAddress: 'x'.repeat(30) });+ expect(bad.status).toBe(400);+ expect(retryTailcatForward).not.toHaveBeenCalled();});it('forgets a saved forward', async () => {diff --git a/server/services/tailcatPeer.js b/server/services/tailcatPeer.jsindex 537d0789f1..f1807841f4 100644--- a/server/services/tailcatPeer.js+++ b/server/services/tailcatPeer.js@@ -607,8 +607,9 @@ async function startAndRegister({const detail = child.tailcatRuntimeError?.message || unreachable;throw new ServerError(`tailcat is forwarding 127.0.0.1:${localPort} but the tunnel could not reach the remote — ${detail}. `- + 'Check that the remote is still serving its tailcat address, and that a local firewall is not '- + 'blocking the `tailcat` binary itself.',+ + `On the remote, check that the PortOS ingress on :${remotePort} responds and restart Tailcat serve `+ + 'using its saved key, then retry this forward. If it still fails, compare Tailcat versions on both '+ + 'ends and check whether a firewall blocks the `tailcat` binary.',{ status: 502, code: 'TAILCAT_TUNNEL_UNREACHABLE' });}@@ -684,6 +685,7 @@ export function retryTailcatForward(id, options = {}) {async function retryForward(id, {remotePort,+ tcAddress,ensureInstalled = ensureTailcatInstalled,primeDerpMap = primeDerpMapCache,allocatePort = allocateLocalPort,@@ -699,13 +701,25 @@ async function retryForward(id, {const entry = entries.find((f) => f.id === id);if (!entry) throw new ServerError('Tailcat forward not found', { status: 404 });+ const patch = {};if (remotePort !== undefined) {if (!Number.isInteger(remotePort) || remotePort < 1 || remotePort > 65535) {throw new ServerError('Invalid remote Tailcat port', { status: 400, code: 'TAILCAT_BAD_PORT' });}- const patched = await patchForwardEntry(entry.id, { remotePort });- if (!patched) throw new ServerError('Could not update Tailcat remote port', { status: 503 });- entry.remotePort = remotePort;+ patch.remotePort = remotePort;+ }+ if (tcAddress !== undefined) {+ if (!isValidTcAddress(tcAddress)) {+ throw new ServerError('Invalid Tailcat address', { status: 400, code: 'TAILCAT_BAD_ADDRESS' });+ }+ patch.tcAddress = tcAddress.trim();+ }+ if (Object.keys(patch).length) {+ // Keep the replacement machine-local and retryable even if its first dial fails.+ // Never recreate the peer: credentials, pairing and sync choices belong to it.+ const patched = await patchForwardEntry(entry.id, patch);+ if (!patched) throw new ServerError('Could not update Tailcat forward', { status: 503 });+ Object.assign(entry, patch);}// A live child on a stale mapping would keep the port and mask the retry.diff --git a/server/services/tailcatPeer.test.js b/server/services/tailcatPeer.test.jsindex d793bd7599..4ab855724d 100644--- a/server/services/tailcatPeer.test.js+++ b/server/services/tailcatPeer.test.js@@ -504,6 +504,35 @@ describe('saved tailcat forwards', () => {expect(patches).toEqual([['fwd_1', expect.objectContaining({ peerId: 'peer-9', status: 'active', lastError: null })]]);});+ it('replaces a stale relay address without recreating its paired peer', async () => {+ const replacement = 'tcEXAMPLE' + 'B'.repeat(40);+ const savedPeer = { id: 'peer-1', transport: 'tailcat', port: 15555, syncSecret: 'example-pair-secret', syncCategories: { brain: true } };+ readJSONFile.mockResolvedValue({ version: 1, forwards: [{+ id: 'fwd_1', peerId: savedPeer.id, tcAddress: EXAMPLE_TC, localPort: 15555, remotePort: 5565,+ }] });+ const patches = [];+ const startForward = vi.fn(async () => fakeChild());+ const addPeerFn = vi.fn();+ const peer = await retryTailcatForward('fwd_1', {+ tcAddress: ` ${replacement} `,+ ensureInstalled: async () => ({ bin: 'tailcat' }),+ primeDerpMap: async () => ({}),+ allocatePort: async () => 15555,+ startForward, addPeerFn,+ patchForwardEntry: async (id, patch) => { patches.push(patch); return { id, ...patch }; },+ getPeersFn: async () => [savedPeer],+ });+ expect(patches[0]).toEqual({ tcAddress: replacement });+ expect(startForward).toHaveBeenCalledWith(expect.objectContaining({ tcAddress: replacement, remotePort: 5565 }));+ expect(peer).toBe(savedPeer);+ expect(addPeerFn).not.toHaveBeenCalled();++ const persist = vi.fn();+ await expect(retryTailcatForward('fwd_1', { tcAddress: 'invalid', patchForwardEntry: persist }))+ .rejects.toMatchObject({ code: 'TAILCAT_BAD_ADDRESS' });+ expect(persist).not.toHaveBeenCalled();+ });+it('repoints an existing peer when a retry has to bind a different port', async () => {readJSONFile.mockResolvedValue({ version: 1, forwards: [{id: 'fwd_1', peerId: 'peer-1', tcAddress: EXAMPLE_TC, localPort: 15555, remotePort: 5555,