Command and first line of output are printed on the same line with FF_SCRIPT_SECTIONS

Summary

When the flag FF_SCRIPT_SECTIONS is enabled, the first line of the output of a command is printed on the same line.

This is happening since updating to 14.9.0. No issues with 14.8.2.

Steps to reproduce

.gitlab-ci.yml
test_script-section:
  script:
    - echo foo
  needs: []
  variables:
    FF_SCRIPT_SECTIONS: "true"

Actual behavior

runner-14.9.0-FF_SCRIPT_SECTIONS

[0Ksection_start:1648024230:step_script
[0K[0K[36;1mExecuting "step_script" stage of the job script[0;m[0;m
[0KUsing docker image sha256:b0757c55a1fdbb59c378fd34dde3e12bd25f68094dd69546cf5ca00ddbaa7a33 for docker:stable with digest docker@sha256:fd4d028713fd05a1fb896412805daed82c4a0cc84331d8dad00cb596d7ce3e3a ...[0;m
[0Ksection_start:1648024236:section_script_step_0
[0K[32;1m$ echo foo[0;mfoo
[0Ksection_end:1648024236:section_script_step_0
[0Ksection_end:1648024239:step_script
[0K[32;1mJob succeeded[0;m

Expected behavior

Same result, without the flag

runner-14.9.0

[0Ksection_start:1648024224:step_script
[0K[0K[36;1mExecuting "step_script" stage of the job script[0;m[0;m
[0KUsing docker image sha256:b0757c55a1fdbb59c378fd34dde3e12bd25f68094dd69546cf5ca00ddbaa7a33 for docker:stable with digest docker@sha256:fd4d028713fd05a1fb896412805daed82c4a0cc84331d8dad00cb596d7ce3e3a ...[0;m
[32;1m$ echo foo[0;m
foo
section_end:1648024255:step_script
[0K[32;1mJob succeeded[0;m

For reference, here is another job running on 14.8.2, with the flag enabled

runner-14.8.2-FF_SCRIPT_SECTIONS

[0Ksection_start:1647972641:section_script_step_2
[0K[32;1m$ yarn install[0;m
➤ YN0000: ┌ Resolution step

Relevant logs and/or screenshots

(See below, in Actual behavior and Expected behavior)

Environment description

config.toml contents
concurrent = 4
listen_address = "[::]:8093"
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "gitlab-runner5 medium"
  limit = 4
  output_limit = 4096
  url = "*******"
  token = "*******"
  executor = "docker"
  builds_dir = "/builds"
  environment = ["NODE_OPTIONS=--max_old_space_size=3584", "GOPATH=/usr/local/share/.cache/go", "GOCACHE=/usr/local/share/.cache/go-cache"]
  [runners.cache]
    Type = "s3"
    Shared = true
    [runners.cache.s3]
      ServerAddress = "*******"
      AccessKey = "gitlab-cache"
      SecretKey = "*******"
      BucketName = "gitlab-cache"
      Insecure = true
    [runners.cache.azure]
  [runners.docker]
    "cpus" = "1"
    "memory_swap" = "2g"
    "memory" = "1g"
    "wait_for_services_timeout" = 480
    tls_verify = false
    image = "docker:stable"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache", "/builds:/builds", "/var/run/docker.sock:/var/run/docker.sock", "/etc/docker/daemon.json:/etc/docker/daemon.json:ro", "/caches/local:/usr/local/share/.cache:rw"]

Used GitLab Runner version

$ gitlab-runner --version
Version:      14.9.0
Git revision: d1f69508
Git branch:   14-9-stable
GO version:   go1.17.7
Built:        2022-03-21T19:39:38+0000
OS/Arch:      linux/amd64

Possible fixes

Edited by Thomas Chandelle