linux-boot: harden boot-inner.sh and configure-worktree.sh #2305

Merged
leonida/mandy
kirigayakazima merged 1 commit from fix/linux-boot-inner-configure-safety into main 2026-11-28 19:41:23 +00:00

Pull request successfully merged and closed

kirigayakazima commented 2026-11-26 13:20:06 +00:00

Claimed in the coordination issue as: LINUX-BOOT-INNER-AND-CONFIGURE-WORKTREE-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7193109369)

What and why

  • Harden scripts/linux-boot/boot-inner.sh:
    • Validate required environment variables (BOOT_AGENT, BOOT_N, BOOT_SECS, GTA6RT) upfront (single path segment checks for BOOT_AGENT/BOOT_N, non-negative integer checks for BOOT_SECS/WAIT_ITERS/LEONIDA_BOOT_MIN_FREE_MB) with exit code 2 before creating or truncating files, and mkdir -p work/root directories before opening logs or locks.
    • Guard flock with command -v flock, select the cgroup v2 0:: entry cleanly from /proc/self/cgroup, coerce non-digit cgroup values such as "max" to 0 via read_uint() before shell arithmetic, and register a signal-safe cleanup() trap (EXIT, INT, TERM) to reap the background sampler subshell immediately.
    • Preserve production defaults while supporting LEONIDA_BOOT_ROOT, LEONIDA_BOOT_WORK, BOOT_SH, NVIDIA_SMI, LEONIDA_MEMINFO_PATH, LEONIDA_SELF_CGROUP_PATH, LEONIDA_CGROUP_ROOT, LEONIDA_WAIT_SLEEP_SECS, LEONIDA_SAMPLE_SLEEP_SECS, and LEONIDA_WAIT_ITERS overrides for testing.
  • Harden scripts/linux-boot/configure-worktree.sh:
    • Support -h/--help (exit 0), validate argument count, worktree directory existence, runtime/CMakeLists.txt, runtime/cmake/clang-cl-xwin.cmake, CMAKE executable availability, and optional SDL3_SRC directory upfront with exit code 2.
    • Pass CMake options via a quoted cmake_args array so paths and SDL3_SRC containing spaces remain intact single argv tokens instead of undergoing unquoted word splitting.
  • Add standard-library unit tests in tests/test_linux_boot_inner_and_configure.py (verifying LF line endings, bash -n syntax, validation exits, cgroup "max" sampling, exit 124 mapping, and spaced worktree/SDL3_SRC paths).

Tested

  • python -I tests/test_linux_boot_inner_and_configure.py -v (via Git Bash): 4 passed, 0 failed (detached upstream/main baseline with only the new test file fails with 8 subtest/test failures).
  • python -I tests/test_ci_registration.py: 16 passed.
  • python -I tests/test_text_write_line_endings.py: 3 passed.
  • python -I scripts/check_no_game_data.py, python -I -m compileall -q tests/test_linux_boot_inner_and_configure.py, and git diff --cached --check: passed.

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
Claimed in the coordination issue as: LINUX-BOOT-INNER-AND-CONFIGURE-WORKTREE-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7193109369) ### What and why - Harden `scripts/linux-boot/boot-inner.sh`: - Validate required environment variables (`BOOT_AGENT`, `BOOT_N`, `BOOT_SECS`, `GTA6RT`) upfront (single path segment checks for `BOOT_AGENT`/`BOOT_N`, non-negative integer checks for `BOOT_SECS`/`WAIT_ITERS`/`LEONIDA_BOOT_MIN_FREE_MB`) with exit code `2` before creating or truncating files, and `mkdir -p` work/root directories before opening logs or locks. - Guard `flock` with `command -v flock`, select the cgroup v2 `0::` entry cleanly from `/proc/self/cgroup`, coerce non-digit cgroup values such as `"max"` to `0` via `read_uint()` before shell arithmetic, and register a signal-safe `cleanup()` trap (`EXIT`, `INT`, `TERM`) to reap the background sampler subshell immediately. - Preserve production defaults while supporting `LEONIDA_BOOT_ROOT`, `LEONIDA_BOOT_WORK`, `BOOT_SH`, `NVIDIA_SMI`, `LEONIDA_MEMINFO_PATH`, `LEONIDA_SELF_CGROUP_PATH`, `LEONIDA_CGROUP_ROOT`, `LEONIDA_WAIT_SLEEP_SECS`, `LEONIDA_SAMPLE_SLEEP_SECS`, and `LEONIDA_WAIT_ITERS` overrides for testing. - Harden `scripts/linux-boot/configure-worktree.sh`: - Support `-h`/`--help` (exit `0`), validate argument count, worktree directory existence, `runtime/CMakeLists.txt`, `runtime/cmake/clang-cl-xwin.cmake`, `CMAKE` executable availability, and optional `SDL3_SRC` directory upfront with exit code `2`. - Pass CMake options via a quoted `cmake_args` array so paths and `SDL3_SRC` containing spaces remain intact single argv tokens instead of undergoing unquoted word splitting. - Add standard-library unit tests in `tests/test_linux_boot_inner_and_configure.py` (verifying LF line endings, `bash -n` syntax, validation exits, cgroup `"max"` sampling, exit `124` mapping, and spaced worktree/`SDL3_SRC` paths). ### Tested - `python -I tests/test_linux_boot_inner_and_configure.py -v` (via Git Bash): 4 passed, 0 failed (detached `upstream/main` baseline with only the new test file fails with 8 subtest/test failures). - `python -I tests/test_ci_registration.py`: 16 passed. - `python -I tests/test_text_write_line_endings.py`: 3 passed. - `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q tests/test_linux_boot_inner_and_configure.py`, and `git diff --cached --check`: passed. GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
zmasi commented 2026-11-28 09:46:42 +00:00

#2305 | head 9a2ac71066ee1cfc23b39c6b4b4b121ed2ab72d0 (merged cleanly with main 3ca0707dd) | python -I tests/test_linux_boot_inner_and_configure.py | red on main: FAILED (failures=1) on -k test_configure_worktree_help_validation_and_spaced_paths (1 != 0, and boot-inner.sh on main enters its hardcoded 40 x 15s wait loop instead of rejecting invalid env vars with exit 2) | green on PR+main: 4 tests OK (-k test_boot_inner_handles_cgroup_max_and_timeout_exit_124: 1 test OK) | Windows 11, Python 3.12.10 (Git Bash) | AI-assisted: yes

Audited scripts/linux-boot/boot-inner.sh and configure-worktree.sh (upfront BOOT_AGENT/BOOT_N path-segment and integer env validation, max cgroup handling via read_uint, sampler cleanup trap, and --help / spaced-path CMake argument array handling), and verified both PR + main (3ca0707dd) and a combined main + #2305 + #2298 merge (0 conflicts; 4 OK + 4 OK). Also passed tests/test_ci_registration.py (18 OK), tests/test_text_write_line_endings.py (3 OK), tests/test_runner_calls_all_tests.py (3 OK), and scripts/check_no_game_data.py.

#2305 | head 9a2ac71066ee1cfc23b39c6b4b4b121ed2ab72d0 (merged cleanly with main 3ca0707dd) | `python -I tests/test_linux_boot_inner_and_configure.py` | red on main: `FAILED (failures=1)` on `-k test_configure_worktree_help_validation_and_spaced_paths` (`1 != 0`, and `boot-inner.sh` on `main` enters its hardcoded `40 x 15s` wait loop instead of rejecting invalid env vars with exit `2`) | green on PR+main: `4 tests OK` (`-k test_boot_inner_handles_cgroup_max_and_timeout_exit_124`: `1 test OK`) | Windows 11, Python 3.12.10 (Git Bash) | AI-assisted: yes Audited `scripts/linux-boot/boot-inner.sh` and `configure-worktree.sh` (upfront `BOOT_AGENT`/`BOOT_N` path-segment and integer env validation, `max` cgroup handling via `read_uint`, sampler cleanup trap, and `--help` / spaced-path CMake argument array handling), and verified both `PR + main` (`3ca0707dd`) and a combined `main + #2305 + #2298` merge (`0` conflicts; `4 OK` + `4 OK`). Also passed `tests/test_ci_registration.py` (`18 OK`), `tests/test_text_write_line_endings.py` (`3 OK`), `tests/test_runner_calls_all_tests.py` (`3 OK`), and `scripts/check_no_game_data.py`.
MoonEyes commented 2026-11-28 19:41:21 +00:00

Red/green: tests/test_linux_boot_inner_and_configure.py fails 8 assertions on main (boot-inner.sh/configure-worktree.sh do not validate env vars, cgroup max or timeout 124) and passes with the PR (cloud run on main 7daa4a4).
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main 7daa4a4a5 in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

Red/green: tests/test_linux_boot_inner_and_configure.py fails 8 assertions on main (boot-inner.sh/configure-worktree.sh do not validate env vars, cgroup max or timeout 124) and passes with the PR (cloud run on main 7daa4a4). Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main 7daa4a4a5 in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No description provided.