If it's OK for append_output to write output and flush the buffer, would it be better to ensure we don't lose any output, at the cost of potentially writing a line non-atomically when it's too long?