Fix CLI handshake on Windows named pipes with newline framing - #31
Open
freetag369 wants to merge 1 commit into
Open
Fix CLI handshake on Windows named pipes with newline framing#31freetag369 wants to merge 1 commit into
freetag369 wants to merge 1 commit into
Conversation
The CLI handshake framed its messages by half-closing the socket: the client wrote the handshake and called sock.end(), then parsed the reply on 'end'. Windows named pipes (\\.\pipe\diffusion-studio) do not support half-open connections, so end() tears the whole pipe down before the app can reply, the client reads an empty buffer, and every dapi command that connects to the app fails with "Unexpected end of JSON input". Frame the handshake with a newline instead: the client writes the JSON followed by "\n" and keeps the socket open; the server answers as soon as the first line arrives and terminates its reply with "\n". Peers that still frame by half-closing are handled on 'end' on both sides, so new clients and servers stay compatible with old ones on Unix sockets. Repro (Windows 11, Node 22): launch the desktop app, then run any dapi command that talks to it (e.g. `dapi mount <file>`). Before this change the handshake always fails; after it, it succeeds. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
@freetag369 is attempting to deploy a commit to the Diffusion Studio Team on Vercel. A member of the Team first needs to authorize it. |
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.
Problem
On Windows, every
dapicommand that connects to the desktop app fails with:The CLI handshake frames its messages by half-closing the socket:
apps/cli/src/cli-client.ts) writes the handshake JSON, callssock.end(), and parses the reply on'end';apps/desktop/src/cli-server.ts) buffers until'end', then handles the handshake and replies.On Unix domain sockets this works because the connection stays half-open after
end(). Windows named pipes (\\.\pipe\diffusion-studio) do not support half-open connections: the client'send()tears the whole pipe down, the reply never arrives, and the client parses an empty buffer.Fix
Switch the handshake to newline framing, keeping the old half-close path working:
JSON + "\n"without half-closing, and resolve as soon as a newline-terminated reply arrives. If the peer closes without a trailing newline (an older server on Unix), fall back to parsing the buffered data on'end'as before."\n". Clients that still frame by half-closing are handled on'end'as before.So new and old peers interoperate in both directions on Unix, and on Windows — where both sides ship together (app + bundled CLI) — the handshake now completes.
Testing
dapi mount <file>(or any command that connects to the app) always failed withUnexpected end of JSON input; with it, the full mount →node capture→node renderflow works against a real project.npm run check(tsc --noEmit) passes inapps/desktop;apps/clibundles cleanly with esbuild.Notes
There are a couple of further Windows papercuts in the dev tooling (
scripts/dev-desktop.mjsspawnSync npm ENOENT,chmodin the CLI build script) — reported separately in #30 since they're independent of this fix.🤖 Generated with Claude Code