[CI] Keep OTel bytecode out of mounted checkouts (#56766)
Signed-off-by: Kevin Luu <51931015+khluu@users.noreply.github.com> Co-authored-by: OpenAI Codex <codex@openai.com>
Kevin H. Luu committed
Sep 14, 2026 at 02:52 UTC
5236bef721223a45d52b3649530e88b5e824e0d9
2 files changed
+40
-6
.buildkite/scripts/ci-otel/ci_otel.sh
+10
-6
@@ -26,7 +26,8 @@ if [ -z "${CI_INFRA_OTEL_RUNTIME_DIR}" ] ||
26
[ -z "${_CI_INFRA_OTEL_PYTHON}" ] ||
27
[ ! -f "${CI_INFRA_OTEL_DIR}/ci_otel.py" ] ||
28
! mkdir -p "${CI_INFRA_OTEL_SPOOL_DIR}" ||
29
- ! PYTHONPATH="${CI_INFRA_OTEL_DIR}${PYTHONPATH:+:${PYTHONPATH}}" \
29
+ ! PYTHONDONTWRITEBYTECODE=1 \
30
+ PYTHONPATH="${CI_INFRA_OTEL_DIR}${PYTHONPATH:+:${PYTHONPATH}}" \
31
"${_CI_INFRA_OTEL_PYTHON}" -c "import ci_otel" >/dev/null 2>&1; then
32
echo "vLLM CI OTel: tracing unavailable; test command will run normally" >&2 || :
33
if [ "${_CI_INFRA_OTEL_OWNS_RUNTIME}" = "1" ]; then
@@ -58,9 +59,9 @@ fi
59
60
_ci_otel_python() {
61
if command -v timeout >/dev/null 2>&1; then
61
- timeout 2s "${_CI_INFRA_OTEL_PYTHON}" "$@"
62
+ PYTHONDONTWRITEBYTECODE=1 timeout 2s "${_CI_INFRA_OTEL_PYTHON}" "$@"
63
else
63
- "${_CI_INFRA_OTEL_PYTHON}" "$@"
64
+ PYTHONDONTWRITEBYTECODE=1 "${_CI_INFRA_OTEL_PYTHON}" "$@"
65
fi
66
}
67
@@ -86,7 +87,8 @@ ci_otel_start() {
87
if [ "${CI_INFRA_GPU_SAMPLING:-1}" != "0" ] &&
88
[ -f "${CI_INFRA_OTEL_DIR}/ci_gpu.py" ] &&
89
command -v nvidia-smi >/dev/null 2>&1; then
89
- "${_CI_INFRA_OTEL_PYTHON}" "${CI_INFRA_OTEL_DIR}/ci_gpu.py" "$$" </dev/null &
90
+ PYTHONDONTWRITEBYTECODE=1 \
91
+ "${_CI_INFRA_OTEL_PYTHON}" "${CI_INFRA_OTEL_DIR}/ci_gpu.py" "$$" </dev/null &
92
_CI_INFRA_GPU_PID=$!
93
fi
94
}
@@ -137,9 +139,11 @@ _ci_otel_on_exit() {
139
trap - 0
140
ci_otel_finish "${_CI_INFRA_OTEL_EXIT_STATUS}" || :
141
if command -v timeout >/dev/null 2>&1; then
140
- timeout 4s "${_CI_INFRA_OTEL_PYTHON}" "${CI_INFRA_OTEL_DIR}/ci_otel.py" flush || :
142
+ PYTHONDONTWRITEBYTECODE=1 timeout 4s \
143
+ "${_CI_INFRA_OTEL_PYTHON}" "${CI_INFRA_OTEL_DIR}/ci_otel.py" flush || :
144
else
142
- "${_CI_INFRA_OTEL_PYTHON}" "${CI_INFRA_OTEL_DIR}/ci_otel.py" flush || :
145
+ PYTHONDONTWRITEBYTECODE=1 \
146
+ "${_CI_INFRA_OTEL_PYTHON}" "${CI_INFRA_OTEL_DIR}/ci_otel.py" flush || :
147
fi
148
if [ "${_CI_INFRA_OTEL_OWNS_RUNTIME}" = "1" ]; then
149
rm -rf -- "${CI_INFRA_OTEL_RUNTIME_DIR}" || :
.buildkite/scripts/ci-otel/tests/test_ci_otel.py
+30
@@ -6,6 +6,7 @@ from __future__ import annotations
6
import json
7
import os
8
import shlex
9
+import shutil
10
import subprocess
11
import sys
12
import threading
@@ -396,6 +397,35 @@ def test_shell_wrapper_preserves_failure_status(tmp_path):
397
assert result.returncode == 1
398
399
400
+def test_shell_wrapper_does_not_write_bytecode_to_helper_tree(tmp_path):
401
+ helper_dir = tmp_path / "ci-otel"
402
+ shutil.copytree(
403
+ SCRIPTS_DIR,
404
+ helper_dir,
405
+ ignore=shutil.ignore_patterns("__pycache__"),
406
+ )
407
+ shell = (
408
+ f'. "{helper_dir / "ci_otel.sh"}"; '
409
+ f"ci_otel_start 1 {_quoted('true')}; ci_otel_finish 0"
410
+ )
411
+
412
+ result = subprocess.run(
413
+ ["/bin/sh", "-c", shell],
414
+ check=False,
415
+ capture_output=True,
416
+ text=True,
417
+ env={
418
+ **os.environ,
419
+ "CI_INFRA_OTEL_DIR": str(helper_dir),
420
+ "CI_INFRA_GPU_SAMPLING": "0",
421
+ "CI_INFRA_OTEL_SPOOL_DIR": str(tmp_path / "spans"),
422
+ },
423
+ )
424
+
425
+ assert result.returncode == 0, result.stderr
426
+ assert list(helper_dir.rglob("*.pyc")) == []
427
+
428
+
429
def test_ci_otel_run_records_command_and_preserves_status(tmp_path):
430
shell = (
431
f'. "{SCRIPTS_DIR / "ci_otel.sh"}"; '