Add Go cloud session SDK API#1257
Conversation
Implement the Mission Control cloud task/client-control API for the Go SDK, matching the Node SDK behavior from PR #1256. New files: - cloud_types.go: CloudRepository, CloudSessionMetadata, CloudSessionOptions, CloudConnectOptions, MissionControlTask, MissionControlCommandType, CloudSessionError, and all steering payload types - cloud_mission_control_client.go: HTTP client for Mission Control (create task, list events, steer, get task, frontend URL) - cloud_session.go: CloudSession with event polling, deduplication, handler dispatch, steering helpers, and connect/disconnect lifecycle - cloud_client.go: CreateCloudSession and ConnectCloudSession methods on Client, env-var resolution for MC URLs/tokens - cloud_session_test.go: Unit tests covering task creation (with repo and repo-less), owner validation, steer API, event sorting/dedup, error responses, disconnect behavior, remote-steerable changes, handler subscribe/unsubscribe, and MC error extraction Updated: - README.md: CloudSession API reference, CloudSessionOptions docs, cloud session usage examples, environment variable docs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a Go SDK “cloud session” API for creating and remotely controlling Mission Control cloud sandbox tasks (no local CLI process), aligning with the previously added Node SDK behavior.
Changes:
- Introduces Go types for Mission Control tasks/events, steering command payloads, and structured cloud-session errors.
- Adds a Mission Control HTTP client plus
Client.CreateCloudSession/Client.ConnectCloudSessionhelpers that construct and connect aCloudSession. - Implements
CloudSessionevent polling, event dedupe/sorting, handler subscription, and steering helpers; adds focused unit tests and README documentation.
Show a summary per file
| File | Description |
|---|---|
| go/README.md | Documents the new CloudSession API surface, options, env vars, and examples. |
| go/cloud_types.go | Defines cloud session/task/event types, steering command constants, payload types, and CloudSessionError. |
| go/cloud_mission_control_client.go | Implements Mission Control HTTP requests for task create/get/events/steer and error extraction. |
| go/cloud_session.go | Implements CloudSession polling, event storage/dedupe, handler subscriptions, and steering methods. |
| go/cloud_client.go | Adds Client.CreateCloudSession / ConnectCloudSession and MC client/env-var plumbing + metadata builders. |
| go/cloud_session_test.go | Adds unit tests covering task creation/connection, steering, dedupe/sorting, errors, disconnect, and handlers. |
Copilot's findings
Comments suppressed due to low confidence (1)
go/cloud_session_test.go:469
capturereads the body usingr.ContentLengthand a singler.Body.Read, which can result in partial reads and can fail ifContentLength == -1. Usingio.ReadAll(r.Body)(with error handling) will make these request-capture assertions more robust.
func capture(r *http.Request) capturedRequest {
body := make([]byte, 0)
if r.Body != nil {
body = make([]byte, r.ContentLength)
r.Body.Read(body)
}
- Files reviewed: 6/6 changed files
- Comments generated: 6
| cs.seenEventIDs[e.ID] = true | ||
| cs.events = append(cs.events, e) | ||
| cs.markEventTimestamp(e) | ||
| cs.updateRemoteSteerable(e) | ||
| cs.dispatchEvent(e) |
| cs.mu.Unlock() | ||
| return errors.New("cloud session is disconnected") | ||
| } | ||
| cs.mu.Unlock() |
| } | ||
|
|
||
| // Connect fetches initial events and starts background polling. | ||
| // It must be called before sending messages or subscribing to events. |
|
|
||
| createdAt, _ := time.Parse(time.RFC3339, task.CreatedAt) | ||
| updatedAt, _ := time.Parse(time.RFC3339, task.UpdatedAt) | ||
|
|
| req.Header.Set(k, v) | ||
| } | ||
|
|
||
| client := &http.Client{Timeout: timeout} | ||
| resp, err := client.Do(req) |
| b := make([]byte, r.ContentLength) | ||
| r.Body.Read(b) | ||
| capturedBody = b |
Cross-SDK Consistency ReviewThis PR adds the ✅ Consistent with Node SDK
|
There was a problem hiding this comment.
Generated by SDK Consistency Review Agent for issue #1257 · ● 1.5M
|
|
||
| // On registers a handler that is called for every cloud session event. | ||
| // Returns an unsubscribe function. | ||
| func (cs *CloudSession) On(handler CloudSessionEventHandler) func() { |
There was a problem hiding this comment.
Cross-SDK consistency note: The Node SDK's CloudSession.on() supports a typed event-filter overload:
// Node SDK - typed subscription
session.on("assistant.message", (event) => {
console.log(event.data.content);
});
// Node SDK - wildcard
session.on((event) => { ... });The Go CloudSession only exposes the wildcard form. This is consistent with the existing pattern in the Go SDK's regular Session.On(), but it does diverge from what the Node README documents for CloudSession.
Consider adding an OnEventType(eventType string, handler CloudSessionEventHandler) func() method (mirroring the Client.OnEventType pattern already present in the Go SDK) so callers can subscribe to specific event types without filtering in every handler. This would bring the Go CloudSession API surface closer to Node's.
Implement the Mission Control cloud task/client-control API for the Go SDK, matching the Node SDK behavior from #1256.
What's new
Types (
cloud_types.go)CloudRepository,CloudSessionMetadata,CloudSessionOptions,CloudConnectOptionsMissionControlTask,MissionControlTaskSessionMissionControlCommandTypeconstants for all steering commandsCloudSessionErrorwith reason categorizationCloudPermissionResponsePayload,CloudAskUserResponsePayload,CloudElicitationResponsePayload,CloudPlanApprovalResponsePayload,CloudModeSwitchPayloadMission Control HTTP client (
cloud_mission_control_client.go)createCloudTask— POST/taskswith repo or owner bodylistTaskEvents— GET/tasks/:id/eventssteerTask— POST/tasks/:id/steergetTask— GET/tasks/:id(returns nil for 404)messagefield, status-based reason mappingCloudSession (
cloud_session.go)Send,SendAndWait,Abort,SubmitRemoteCommandRespondToPermission,RespondToAskUser,RespondToElicitation,RespondToPlanApproval,SwitchModeremote_steerable_changedevent trackingClient methods (
cloud_client.go)CreateCloudSession(options)— creates MC task and returns*CloudSessionConnectCloudSession(taskID, options)— attaches to existing taskX-Copilot-Agent-Slug: copilot-developer-sandboxTests (
cloud_session_test.go)11 test cases covering task creation, steering, event dedup, error handling, disconnect, remote-steerable, and handler lifecycle.
README updates
CloudSession API reference, usage examples, and env var docs.