[PR #2274] linux-boot: harden boot-digest/run-boot dedup, empty-stats, and argument checks #2276

Open
opened 2026-11-26 21:20:39 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2274
Author: @kirigayakazima
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fix/linux-boot-scripts-safety


📝 Commits (1)

  • bfde05d linux-boot: harden boot-digest/run-boot dedup, empty-stats, and argument checks

📊 Changes

3 files changed (+175 additions, -18 deletions)

View changed files

📝 scripts/linux-boot/boot-digest.sh (+20 -11)
📝 scripts/linux-boot/run-boot.sh (+23 -7)
➕ tests/test_linux_boot_scripts.py (+132 -0)

📄 Description

Claimed in the coordination issue as: LINUX-BOOT-SCRIPTS-EXACT-DEDUP-EMPTY-STATS-AND-ARG-GUARDS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191439979)

What and why

scripts/linux-boot/boot-digest.sh and scripts/linux-boot/run-boot.sh previously:

  • Hardcoded /opt/leonida instead of defaulting via LEONIDA_BOOT_ROOT, lacked directory creation before digest/ledger writes in boot-digest.sh, and ran flock without checking availability.
  • Used grep -q -P "^[^\t]*\t$AGENT\t$N\t" for ledger deduplication, allowing regex metacharacters in agent names (e.g. a.b matching axb).
  • Checked [ -f "$CAP/index.txt" ] (emitting broken counts for 0-byte index.txt) and ignored sample row counts in awk over resources.tsv (printing empty MB stats and 0 peak MB on header-only files), while leaving sed stderr unguarded when boot-<n>.meta was missing.
  • Accepted invalid AGENT, N, SECS (<= 0 or non-numeric), and malformed KEY=VALUE environment overrides without upfront validation.

This adds LEONIDA_BOOT_ROOT support, upfront argument validation, literal awk ledger deduplication, [ -s "$CAP/index.txt" ] and awk sample-count checks, flock / .meta guards, LF preservation, and stdlib bash regression tests in tests/test_linux_boot_scripts.py.

Tested

  • python -I tests/test_linux_boot_scripts.py -v (3 passed)
  • Detached upstream/main baseline negative control: failed with tests/test_linux_boot_scripts.py before the fix
  • python -I tests/test_ci_registration.py, python -I tests/test_text_write_line_endings.py, python -I scripts/check_no_game_data.py, python -I -m compileall -q, and git diff --cached --check

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2274 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/linux-boot-scripts-safety` --- ### 📝 Commits (1) - [`bfde05d`](https://github.com/ubiquitarianism/leonida/commit/bfde05dcb741441379ebc6e0a43ae46eec660467) linux-boot: harden boot-digest/run-boot dedup, empty-stats, and argument checks ### 📊 Changes **3 files changed** (+175 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `scripts/linux-boot/boot-digest.sh` (+20 -11) 📝 `scripts/linux-boot/run-boot.sh` (+23 -7) ➕ `tests/test_linux_boot_scripts.py` (+132 -0) </details> ### 📄 Description Claimed in the coordination issue as: LINUX-BOOT-SCRIPTS-EXACT-DEDUP-EMPTY-STATS-AND-ARG-GUARDS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191439979) ### What and why `scripts/linux-boot/boot-digest.sh` and `scripts/linux-boot/run-boot.sh` previously: - Hardcoded `/opt/leonida` instead of defaulting via `LEONIDA_BOOT_ROOT`, lacked directory creation before digest/ledger writes in `boot-digest.sh`, and ran `flock` without checking availability. - Used `grep -q -P "^[^\t]*\t$AGENT\t$N\t"` for ledger deduplication, allowing regex metacharacters in agent names (e.g. `a.b` matching `axb`). - Checked `[ -f "$CAP/index.txt" ]` (emitting broken counts for 0-byte `index.txt`) and ignored sample row counts in `awk` over `resources.tsv` (printing empty MB stats and `0` peak MB on header-only files), while leaving `sed` stderr unguarded when `boot-<n>.meta` was missing. - Accepted invalid `AGENT`, `N`, `SECS` (`<= 0` or non-numeric), and malformed `KEY=VALUE` environment overrides without upfront validation. This adds `LEONIDA_BOOT_ROOT` support, upfront argument validation, literal `awk` ledger deduplication, `[ -s "$CAP/index.txt" ]` and `awk` sample-count checks, `flock` / `.meta` guards, LF preservation, and stdlib bash regression tests in `tests/test_linux_boot_scripts.py`. ### Tested - `python -I tests/test_linux_boot_scripts.py -v` (3 passed) - Detached `upstream/main` baseline negative control: failed with `tests/test_linux_boot_scripts.py` before the fix - `python -I tests/test_ci_registration.py`, `python -I tests/test_text_write_line_endings.py`, `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q`, and `git diff --cached --check` 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#2276
No description provided.