         runtime.exportedEdges = []
         runtime.edgesForInspection = []
 
-        sendMessage runtime, { protocol: 'graph', command: command, payload: payload }
+        return sendMessage(runtime, request).then (response) ->
+          sendAck connection, response
     else if command is "addnode"
         graph.processes[payload.id] = payload
         graph.nodeMap[payload.id] = { id: graph.currentNodeId++ }
         graph.componentMap[payload.id] = payload.component
         # TODO: wait for nodeId from runtime, update nodeMap then
-        sendMessage runtime, { protocol: 'graph', command: command, payload: payload }
+        return sendMessage(runtime, request).then (response) ->
+          sendAck connection, response
+
     else if command is "removenode"
-        sendMessage runtime, { protocol: 'graph', command: command, payload: payload }
-        delete graph.processes[payload.id]
-        delete graph.nodeMap[payload.id]
-        delete graph.componentMap[payload.id]
+        return sendMessage(runtime, request).then (response) ->
+          delete graph.processes[payload.id]
+          delete graph.nodeMap[payload.id]
+          delete graph.componentMap[payload.id]
+          sendAck connection, response
+
     else if command is "renamenode"
         node = graph.processes[payload.from]
         graph.processes[payload.to] = node
-        sendAck connection, { protocol: 'graph', command: command, payload: payload }
+        return sendMessage(runtime, request).then (response) ->
+          sendAck connection, response
     else if command is "changenode"
         # FIXME: ignored
-        sendAck connection, { protocol: 'graph', command: command, payload: payload }
+        sendAck connection, request
+        return Promise.resolve()
     else if command is "addedge"
         graph.connections.push protocol.wsConnectionFormatToFbp(payload)
-        sendMessage runtime, { protocol: 'graph', command: command, payload: payload }
+        return sendMessage(runtime, request).then (response) ->
+          sendAck connection, response
     else if command is "removeedge"
         graph.connections = connectionsWithoutEdge(graph.connections, protocol.wsConnectionFormatToFbp(payload))
-        sendMessage runtime, { protocol: 'graph', command: command, payload: payload }
+        return sendMessage(runtime, request).then (response) ->
+          sendAck connection, response
     else if command is "changeedge"
         # FIXME: ignored
         sendAck connection, { protocol: 'graph', command: command, payload: payload }
+        return Promise.resolve()
     else if command is "addinitial"
         graph.connections.push protocol.wsConnectionFormatToFbp(payload)
-        sendMessage runtime, { protocol: 'graph', command: command, payload: payload }
-        sendAck connection, { protocol: 'graph', command: command, payload: payload } # TODO: receive from RT
+        return sendMessage(runtime, request).then (response) ->
+          sendAck connection, request # TODO: use response from RT
     else if command is "removeinitial"
         # TODO: send to runtime side, wait for response
         graph.connections = connectionsWithoutEdge(graph.connections, protocol.wsConnectionFormatToFbp(payload))
-        sendAck connection, { protocol: 'graph', command: command, payload: payload }
-
-    # PROTOCOL: Inconsistent that these don't ack on same format?
+        sendAck connection, request
+        return Promise.resolve()
+
     else if command is "addinport"
         graph.inports[payload.public] =
             process: payload.node
             port: payload.port
         sendExportedPorts connection, runtime
-        sendAck connection, { protocol: 'graph', command: command, payload: payload }
+        sendAck connection, request
+        return Promise.resolve()
     else if command is "removeinport"
         delete graph.inports[payload.public]
         sendExportedPorts connection, runtime
-        sendAck connection, { protocol: 'graph', command: command, payload: payload }
+        sendAck connection, request
+        return Promise.resolve()
     else if command is "addoutport"
         graph.outports[payload.public] =
             process: payload.node

        err.message = "Unexpected error: #{err.message}"
        p = Promise.reject(err)

    if p
        p.catch (err) ->
            payload = { message: err.message }
            connection.send { protocol: contents.protocol, command: 'error', payload: payload }

            console.error('FBP PROTOCOL error:', err)
            console.error(err.stack)

    return null


    connection.send msg

handleGraphCommand = (command, payload, connection, runtime) ->
    request = { protocol: 'graph', command: command, payload: payload }

    graph = runtime.graph
    if command is "clear"
        graph.inports = {}
