Fix attach_session URL to match sprites-go and sprites-py#10
Open
jhgaylor wants to merge 1 commit intosuperfly:mainfrom
Open
Fix attach_session URL to match sprites-go and sprites-py#10jhgaylor wants to merge 1 commit intosuperfly:mainfrom
jhgaylor wants to merge 1 commit intosuperfly:mainfrom
Conversation
The attach_session function was building URLs of the form `/v1/sprites/:name/exec?session_id=X`, but the server expects the path-based form `/v1/sprites/:name/exec/:session_id` (also used by the Go and Python SDKs). Symptom: `Sprites.attach_session/3` would succeed the WebSocket upgrade because the server treated the request as a fresh exec with empty command. The original detached process would keep running on the sprite, but no output ever flowed to the new connection — making it impossible to recover an in-flight `detachable: true` command after a client-side crash. Fix: when `:session_id` is set in opts, build the attach URL with the session id in the path. Also skip the spawn-only query params (path/cmd/env/dir/detachable), since the server ignores them on attach. Verified end-to-end with a probe that: 1. spawns `bash -c "echo BEFORE; sleep 20; echo AFTER"` detachably 2. hard-kills the Command GenServer mid-sleep 3. lists sessions and reattaches via attach_session 4. observes BEFORE replayed from the session buffer, AFTER streamed live post-disconnect, and a clean exit code 0
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.
Summary
Sprites.attach_session/3was building URLs as/v1/sprites/:name/exec?session_id=X, but the server expects the path-based form/v1/sprites/:name/exec/:session_id— the same shape bothsprites-goandsprites-pyuse.Symptom
attach_sessionwould return{:ok, command}because the WebSocket upgrade succeeded — the server saw the bad URL as a fresh exec with empty command. The originally detached process kept running on the sprite, but no output ever flowed to the new connection. End result: it was impossible to recover an in-flightdetachable: truecommand after a client-side crash.Fix
When
:session_idis set in opts:path/cmd/env/dir/detachable) — the server ignores them on attach since they belong to the original spawn.stdin/ttyare still forwarded since they're meaningful for the attached side.Test plan
bash -c "echo BEFORE; sleep 20; echo AFTER"withdetachable: true.CommandGenServer mid-sleep.list_sessionsshows the detached session withis_active: false.attach_sessionto that id.BEFOREreplayed from the session buffer,AFTERstreamed live post-disconnect, cleanexit 0reported.🤖 Generated with Claude Code