Repository navigation
feat: apps add linked environments automatically - #88
Conversation
A machine a connected server links, but this app lacks, is added without a click once its link is reachable, at no more than the link's access. A failed add waits for the link's status, addresses or session to change, so a down peer never burns single-use codes. Removing a linked machine from the app keeps it out until the user chooses Add to this app. Model: claude-opus-5-5 Task: feature Agent: claude-code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bot review round 1 (Claude Opus 5.5, independent) @ 7b23515Scope: Verdict: blocking. Finding 1 means the founder's main requirement, that offline machines appear once they come online, is not met. Finding 2 lets a removed machine come back on its own. Findings 3 to 7 are non-blocking. 1. High (blocking): nothing adds a machine when it comes online; it waits for an unrelated event
The auto-add only runs when its snapshot changes. The snapshot includes
None of these fires because the peer machine came online. The docstring "Runs when a host's list changes, which includes its reconnecting" is true, but the list does not change when the peer comes online. Failure scenario: the desktop app is open with host H connected. H links VPS M, which is off. M boots an hour later. Nothing happens until the user opens Settings → Linked environments or some other app connection changes. That is "Add to this app" with extra steps, which is the click the founder wanted to avoid. Suggested fix (no timers): decide which event means "the peer is back", then wire it in.
My view: (a) is enough for the first cut if the PR text and docs stop saying "once their link is reachable" and say "the next time you return to the app". Otherwise it needs (b). Either way, this is the founder's call. 2. High (blocking): removing from Settings → Connections does not record a dismissal when the linking host is offline or not loaded
const linkingHosts = hostsLinking(peerLinkHosts, environmentId);
if (linkingHosts.length > 0) void dismissLinkedEnvironment(environmentId);
Failure scenario: host H links M. H is offline, or its list has not loaded yet. The user removes M under Connections, Suggested fix: dismiss unconditionally on every user-initiated remove. It costs one ID in client settings. Keep 3. Medium: a manual "Add to this app" can race an in-flight auto-add, spending two single-use codes and leaving two authorized clients
The Failure scenario: at app start the auto-add for M tries M's first address, which hangs until it times out. The user opens Settings and clicks "Add to this app". M mints a second code, both pairings can succeed, Suggested fix: move single-flight into 4. Medium: dismissal is cleared only by the Linked environments button, not by other ways of adding the machine back
Failure scenario: the user removes M (now dismissed), then adds it back through Connections → Add environment or a pairing URL. M stays dismissed. If it is removed again later by a non-user path (for example Suggested fix: clear the dismissal whenever an environment successfully enters the catalog through a user action, for example on 5. Medium (performance): the app now starts with one
|
… removed Repair round 1 for the auto-add review on 7b23515. - Each writable host's linked-environment list is read again on window focus, the document becoming visible, the browser online event and a network path change (useLiveRefresh refreshOnReconnect), with the existing 10 s floor and no timer. The key is shared with the Linked environments panel. - Removing under Connections always records the dismissal, whether or not a host's list is loaded. A remove that fails rolls it back. - addLinkedEnvironmentToApp is single-flight per linked environment across the button and the auto-add; the row shows "Adding…" while one runs. - Adding a machine back by any path (pairing, SSH, T3 Connect, Add to this app) clears its dismissal. - Docs no longer claim a machine appears as soon as its link is reachable. Model: claude-opus-5-5 Task: fix Agent: claude-code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Repair round 1 @ 6002bddFixes the bot review round 1 findings on 7b23515. One commit on top: Finding 1: a machine that comes online later is not addedFix (a), events only, with no interval, polling or server push.
Bursts are limited by the existing 10 s floor ( Finding 2: removing under Connections does not always record a dismissal
Finding 3: a button click can race an auto-add
Finding 4: only the button clears a dismissal; a failed remove keeps itDismissal helpers moved to
Setting a value it already has is a no-op, so this writes nothing in the common case. Finding 7: docs
Not fixed
What I ran (Node 26.13.1,
|
….10-auto-add-linked
|
Fleet build artifacts from
R720 build inputs were copied from the ASUS builds: Node 26.13.1, the noble gcc-13 sysroot from |
Stacked on #80 (the app and its server see the same environments). Base:
feat/app-server-same-environments.A machine that a connected server links, but this app lacks, only showed Add to this app in Settings → Linked environments. You had to click it on every device, and again for each machine that came online later.
How it works
linkedEnvironmentsToAutoAddinpackages/client-runtime/src/linkRequest.tsis a pure selector. From one host's known-environments rows, it returns the entries to add now: actionadd-to-app, linkreachable, a usable app address, not in the catalog, not dismissed, and not already being added from any host. An entry that failed is skipped until its link state changes. That state is status, addresses and session (linkedAt); a newlastReachedAtalone does not count. The selector also returns failures whose state has moved, so a peer that goes down and comes back is tried again. Each try spends a single-use code, so a down peer is never retried in a loop.AutoAddLinkedEnvironments(apps/web/src/state/knownEnvironments.tsx, mounted in the root route) renders one child per connected host where this client holds access:write. Each child reads that host'speerLinks.environmentslist and runs the selector when the list, the catalog or the dismissals change. The query reruns when the host reconnects. There are no timers or polling. It waits for client settings to hydrate and for the catalog to be ready, so a machine that is already held or dismissed never looks addable at startup.addLinkedEnvironmentToApp(apps/web/src/state/peerLinks.ts), which is the button's old flow moved out of the component. On success there is one toast: " added from 's links", noting read-only when the link caps it there. A failure shows no toast; the row keeps offering Add to this app.Reverse path
dismissedLinkedEnvironmentIds, in the existingClientSettingsschema and persistence:apps/mobile/src/state/peerLinks.tssays so.docs/user/remote-access.md.Tests
Run with the pinned Node 26.13.1:
vp test run packages/client-runtime/src/linkRequest.test.ts packages/contracts/src/settings.test.ts: 59 passed across 2 files. This includes 8 newlinkedEnvironmentsToAutoAddtests: addable, read-only link, dismissed, already in catalog, unreachable / can't pair / loopback-only address, in flight, failed at the same state vs. changed addresses or session (and not changed bylastReachedAt), and down-then-up.vp test run --project browser src/components/settings/LinkedEnvironmentsSettings.browser.test.tsx: 2 passed.effect-tsgo tsrs --noEmitpasses inpackages/client-runtimeandapps/web.vp lintis clean on the touched files.Model: claude-opus-5-5
Task: feature
🤖 Generated with Claude Code