missing serial data in communication

I have an arduino that is connected to an LCD and a PS/2 keyboard. It is connected to my PC via the USB cable, and it communicates with a python program I've made.

The issue I am having is when I send data and receive data concurrently on the serial, sometimes the data received on the python side isn't all there. For example, let's say I were to make an echo program for the arduino. If I continually send "HELLOWORLD" to the arduino, sometimes I will get "HELLOWORL" or "ELLOWORLD" back instead.

To fix this problem, I have to "pad" my protocol with extra characters and then use a regexp to extract the command out of it. Here is an example program which exhibits the problem:

Arduino:

char c;

void setup() {      
  Serial.begin(115200);
  Serial.flush();  
  delay(100);
}

void loop() {
  while (Serial.available())
    c = Serial.read(); 

  Serial.print("\x02HELLOTHERE\x03");
  delay(100);
}

Python:

import serial
import re

regex = re.compile(r'\x02(.*?)\x03')

s = serial.Serial('COM8', 115200)
buffer = ''

while True:
  data = s.read(1)
  n = s.inWaiting()
  if n:
    buffer += data + s.read(n)
    s.write('some long test that should surely screw things up. some long test that should surely screw things up.')
    
  if buffer:
    match = regex.search(buffer)
    if match:
      if match.group(1) != 'HELLOTHERE':
        print "ERROR"
      #print(match.group(1))
      buffer = buffer[match.end():]

If you run this setup, you will get a few "ERROR" print outs because sometimes it misses the beginning or ending of the "\x02HELLOTHERE\x03" string.

Now to fix this problem, all I have to do is change the "\x02HELLOTHERE\x03" to " \x02HELLOTHERE\x03 " in the arduino code. Now, it will never print out "ERROR".

Since I kinda have a solution to this, I was wondering if anyone knew what is occurring? Why when I'm receiving data on the python end, does it sometimes miss the beginning or ending of the string? Note that this only occurs if the python script is sending data as well. If you were to take out

s.write('some long test that should surely screw things up. some long test that should surely screw things up.')

It would work fine as well.

Just a side note, this problem is compounded when I'm using the Messenger library in arduino playground. I have to pad my string a lot more in this situation.