feat(ws): handle shutdown message for graceful destroy#30
Open
feat(ws): handle shutdown message for graceful destroy#30
Conversation
Adds a new protocol.MessageTypeShutdown and a matching Handler.handleShutdown so Safari can cleanly tear down a cloud sandbox's runner without waiting on the 5s force-unregister timeout. Flow when CloudManager.disconnectRunner sends a shutdown message: 1. Handler cancels all in-flight tasks via CancelAllTasks. 2. Waits up to 2s for in-flight tool results to flush via WaitForTasks — well inside Safari's 5s force-unregister window. 3. Closes the WebSocket client, which sets c.closed so RunWithReconnect returns nil instead of entering the reconnect loop. Before this change, every cloud sandbox destroy hit the 5s timeout because the runner silently ignored the shutdown message and stayed in its reconnect loop until the server-side unregister finally fired. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
protocol.MessageTypeShutdownand matchingHandler.handleShutdownso Safari can tell a runner to drop everything and exit cleanly, without waiting on the 5s force-unregister timeout.handleShutdowncancels all in-flight tasks, waits up to 2s for tool results to flush, then closes the WebSocket client soRunWithReconnectreturnsnilinstead of entering the reconnect loop.Why
Sibling PR:
fc-safarifeat/ai-srebranch, commitd505589 feat(cloud-sandbox): end-to-end provisioning + auto-pause lifecycle. Safari'sCloudManager.disconnectRunnersends this message whenever a cloud sandbox is torn down (session end, idle recycle, eviction). Before this change every cloud sandbox destroy hit the 5s timeout because the runner silently ignored the unknownshutdowntype and stayed in its reconnect loop until the server-side unregister finally fired.Test plan
go build ./...— cleango vet ./...— cleanCloudManager.GracefulShutdown→disconnectRunnernow completes in ~2s instead of hitting the 5s warn-and-force-unregister path. Recycle log showskind=clouddisconnect with no warning.WaitForTaskswindow is compatible with the longest-running in-flight tool (bash scripts, MCP calls).🤖 Generated with Claude Code