Is there another unique identifier, like a line number, for the output G-code? I assume you are ''watching'' the machine running in real time. If both of these items are true, then you could look up the input G-code and grab the comment from the original rather than trying to make changes to the machine controller. Might be much safer to do.
Maybe you could post a code snippet of the output G-code, might be helpful.