Repository navigation
Relay Linux desktops over a private socket and notice them without a restart (851-4484) - #1485
Merged
pondorasti merged 5 commits intoNov 26, 2026
Conversation
pondorasti
force-pushed
the
alexandru/851-4484-linux-desktop-step-1-relay-over-a-private
branch
2 times, most recently
from
November 26, 2026 05:21
73a3557 to
8382c5e
Compare
…restart (851-4484) The server's VNC relay connects to the Unix socket named in screen-sharing.json instead of a localhost port, and only when that socket is private to the server's own account. The config is read on every request, so a desktop appears or goes away while the server keeps running. A config that names a port is ignored. The dev container's desktop listens on a socket with no TCP port and locks X11 with a cookie. scripts/vnc-desktop.sh wrote the port config and is gone. A viewer's request to set a desktop's scale was rejected before it reached the desktop; it is accepted for the desktop's own display. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…r's VNC off TCP Review follow-ups for 851-4484. The socket check walks every folder up to the root and dials the path it checked, so a folder higher up that others can write to no longer passes. A refused connection's close reason says whether the desktop isn't running or is reachable by other accounts. The dev container's Xvnc keeps -localhost next to -rfbport -1, and the script stops without writing a config when a TCP port is open or the X11 socket is missing. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…nc when its checks fail Review follow-ups for 851-4484. A desktop whose config names a local port (set up for an older Codevisor) stays listed and tells viewers it has to be set up again, with one log line; the server never connects to the port. The socket check tells three things apart: nothing there, something that isn't this account's socket (a file, a link, another account's socket, or a path the server may not look at), and a socket or folder that other accounts can open or change. The dev container's desktop script stops Xvnc and removes its socket and cookie on every failure path, checks the TCP port with ss on any address and fails closed when ss can't answer, and reports a cookie that couldn't be written. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ner's TCP port twice Second review follow-ups for 851-4484. Only a config with no socket and a valid port is treated as set up for an older Codevisor. It no longer lists computer-use-stream-v1, and the log line is written each time such a config starts being seen. Only a denied path reads as another account's desktop; a path that can't be resolved reads as not running. The dev container's desktop script checks the TCP port again a second after Xvnc is up, and starts D-Bus only once the checks have passed, so a failed start leaves no daemon behind. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…desktop on any failed start Third review follow-ups for 851-4484. The server log names the path that keeps a desktop from being shared and what is wrong with it (for example a folder a group can write to, with its mode and owner), and a vnc section with no usable socket is logged instead of vanishing. Both are logged when the reason changes. /v1/info looks at the desktop once and derives both features from that look. The dev container's desktop script cleans up through an exit trap unless it reached its last line, reports a D-Bus session that didn't start, and writes the config last. A test shows a viewer that remembers the old display id (vnc:5901) opening the display the machine offers now. Co-Authored-By: Claude Fable 5.2 <[email protected]>
pondorasti
force-pushed
the
alexandru/851-4484-linux-desktop-step-1-relay-over-a-private
branch
from
November 26, 2026 05:47
e67642a to
0117fe5
Compare
pondorasti
deleted the
alexandru/851-4484-linux-desktop-step-1-relay-over-a-private
branch
November 26, 2026 05:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes 851-4484
Part of 851-4479 (Linux desktops: screen sharing that works after installing codevisor-server). Step 1 of the approved design.
What changes
screen-sharing.json({ "vnc": { "socket", "display", "xauthority", ... } }). It never connects to a port: any account on the machine can dial127.0.0.1:5901.vncsection with no usable socket that isn't such an old config is not offered, and is logged too. Replacing an old desktop is step 2./tmp) (routes/private-socket.ts). Links in the folder path are resolved first and the checked path is the one dialled. If not, nothing is relayed and the viewer is told which it is: "The desktop on this machine isn't running." (nothing at the path), "The desktop on this machine isn't run by the account Codevisor runs as, so Codevisor won't share it." (not a socket, another account's socket, or a path the server is denied access to: the old root-desktop case), or "Other accounts on this machine can reach its desktop, so Codevisor won't share it." (the socket or a folder above it is open to others).[desktop] not shared: /home/dev/.codevisor can be changed by other accounts (mode 775, belongs to uid 1000). It is written when the reason changes, not on every request./v1/info, so the two features it lists can't disagree)./v1/infolistsscreen-sharing-v1only while the config names a desktop, and a request to a machine with no desktop answers "This machine has no desktop to share".-rfbport -1 -localhost(no TCP port), and X11 itself needs a cookie (-auth). The script then asksss, twice a second apart, whether anything listens on the desktop's TCP port on any address. The config is written last, and an exit trap cleans up unless the script got that far: whatever stops it (an open port,ssfailing, the cookie, Xvnc, D-Bus, the config write), Xvnc and D-Bus are stopped and the socket, cookie and config are removed. The server gets the cookie through the config and its environment, so the clipboard bridge, 2× scaling and Computer Use keep working.scripts/vnc-desktop.shis deleted. It could only write the port config the server no longer reads. Its replacement is step 2 (851-4485,codevisor desktop setup).setScalerequest was rejected with "Invalid Screen Sharing display" before it reached the desktop, because the route only accepted Mac display ids. So 2× scaling of Linux desktops has not worked since the live picture-in-picture change (606acbd). The route now accepts the desktop's own display id.apps/server/README.mddocuments the config and the check.What a viewer sees
Nothing new. The display id changes from
vnc:<port>tovnc:desktop. A Mac that remembersvnc:5901for the machine opensvnc:desktopby itself: the connection picks the remembered display only if the machine still offers it, otherwise the first offered one, and the socket and scale requests use the offered id. A new Swift test shows this (ScreenSharingVNCRememberedDisplayTests). No Swift source changes.One gap left for step 2: the apps re-read a machine's features when they reconnect or come to the foreground, so a desktop that appears while the app is open and connected shows up at the next of those, not at once.
Tests
In
apps/serverunless noted, and they fail without the change:private-socket.test.ts: a private socket passes, also inside a sticky shared folder and through a linked folder (the real path is dialled). Refused as missing: nothing at the path. Refused as not this account's: another owner, a regular file, a link to a socket, a folder the server may not look into. Refused as exposed: modes 660/606/666, a folder others can write to at any level.screen-sharing-vnc.test.ts: the relay tests now run against a real Unix socket and the real config file. New: a socket opened to others is not dialled and the viewer is told why; a desktop is offered once its config is written and withdrawn once it is removed, on one running server; a config that names a port stays listed, answers "set it up again", is logged once and is never dialled; a stray file at the socket path gets the "isn't run by the account" message;setScalewith the desktop's display id reaches the desktop (400 before the fix).vnc-desktops.test.ts: scaling uses the desktop's own display and cookie; 2× is offered only for an Xfce desktop whose display is known.Checked by hand
In the dev container with
CODEVISOR_DEV_CONTAINER_DESKTOP=1 bun run dev:linux, against the container's real server:The only listening TCP port in the container is the server's own; Xvnc runs with the socket (mode 600, folder 700) and the cookie; X11 refuses a client without the cookie.
/v1/infolists screen sharing, capabilities answeravailable, and the WebSocket relays theRFB 003.008greeting.With the server left running: moving the config away removes the feature and answers 501; moving it back restores both;
chmod 666on the socket gives the "other accounts" message and closes the socket with 1011 (checked before the close reason carried the message);chmod 600restores it.setScale2 and 1 through the server change Xfce's UI scale (read back withxfconf-query).In the Mac dev app: the inspector's Desktop card shows the live desktop, the Desktop window opens, and a click in it launched the terminal in the container.
scripts/dev-container-desktop.shon its own in a throwawaynode:22-bookwormcontainer, thirteen runs: a normal start (no listening TCP socket at all); something listening on127.0.0.1:5901; something listening on[::1]:5901only; a port that opens just after Xvnc is up;ssfailing;xauthfailing;mcookiefailing; Xvnc unable to start;dbus-launchfailing; a config folder that can't be created; a read-only config folder; and a normal start after all that. Every failing run printed its own reason, exited 1, left no Xvnc process, no D-Bus daemon, no socket, no cookie and no config.Not checked by hand: typing and clipboard copy/paste through the viewer (the server's clipboard watcher was running against the desktop), Computer Use on the container desktop, the iPhone, and any machine outside the dev container.
Known limits, left as they are
"Without a restart" holds for new connections. A viewer that is already connected keeps streaming after the config is removed or the socket stops being private, until it disconnects. Closing live relays then is part of step 2 (851-4485).
The folder rule refuses a folder a group can write to. On Fedora and RHEL (own group per account, umask 002) a home-made folder is mode 775 and is refused even though the group has one member; the log names the folder. Whether to relax that is a step 3 question, noted in the design doc. A socket under
/run/user/<uid>is unaffected.A socket file left behind by an Xvnc that was killed still passes the check, so capabilities answer
availableand the viewer's connection then closes with "VNC server unavailable". Telling a dead socket from a live one means connecting to it, which is the relay's job.The config is read from disk, synchronously, on every
/v1/infoand screen sharing request. It is one small local file next to the server's database. If it ever shows up in a profile, cache it on the file's modification time.Reviews
First code review (medium), fixed with a test or a run: the dev container's Xvnc had lost
-localhost; the socket check looked only at the socket's own folder; the script's start-up check ignored a missing X11 socket; a refused connection always said "VNC server unavailable".Review of 73a3557, fixed:
/dev/tcpmissing looked like a closed port) and only probed IPv4. It now usesss, on any address, and fails closed whensscan't answer.iproute2is installed with the desktop.xauthandmcookiefailures.Code review (medium) of that delta (8382c5e), fixed:
computer-use-stream-v1. It listsscreen-sharing-v1only.Not fixed, as agreed: the stale socket file case under "Known limits".
Review of e67642a:
vnc:5901opens the offeredvnc:desktop. Shown by a Swift test./v1/infolooked at the config twice; it looks once.🤖 Generated with Claude Code