                             cb(true)  # successful connect, but we still need to return error so sync happens
             else
                 winston.debug("codemirror session local hub sync -- pushed edits, thus completing cycle")
-                if before != @diffsync_server.live
+                @_last_sync = after # what was the last successful sync with upstream.
+                if before != after
                     @_tell_clients_to_sync()
                 cb()
 

                opts.cb(false, @)

    _connect: (cb) =>
        delete codemirror_sessions.by_path[@project_id + @path]
        delete codemirror_sessions.by_uuid[@session_uuid]
        delete @_sync_lock
        @local_hub.call
            mesg : message.codemirror_get_session(path:@path, project_id:@project_id, session_uuid:@session_uuid)
            cb   : (err, resp) =>

                else
                    @session_uuid = resp.session_uuid
                    @chat         = resp.chat

                    codemirror_sessions.by_uuid[@session_uuid] = @

                    if @_last_sync?
                        # We have sync'd before.
                        patch = @diffsync_server._compute_edits(@_last_sync, @diffsync_server.live)

                    # Reconnect to the upstream (local_hub) server
                    @diffsync_server = new diffsync.DiffSync(doc:resp.content)

                    if @_last_sync?
                        # applying missed patches to the new upstream version that we just got from the hub.
                        @_apply_patch_to_live(patch)
                    else
                        # This initialiation is the first.
                        @_last_sync   = resp.content

                    @diffsync_server.connect(new CodeMirrorDiffSyncLocalHub(@))

                    #
