Skip to content

feat(k3s): harden Kyber storage lifecycle - #2134

Merged
shunkakinoki merged 1 commit into
mainfrom
codex/kyber-host-hardening
Jul 19, 2026
Merged

feat(k3s): harden Kyber storage lifecycle#2134
shunkakinoki merged 1 commit into
mainfrom
codex/kyber-host-hardening

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • pin the dedicated containerd filesystem by UUID and keep K3s fail-closed when it is absent or mismatched
  • serialize image pulls, use 70/60 image garbage collection, preserve 20 percent nodefs and imagefs headroom, and cap container logs
  • cap journald and add declarative smartd plus read-only I/O PSI, D-state, imagefs, and CRI health monitoring
  • keep kubelet as the sole CRI garbage collector and keep application PVCs off the containerd SSD

Validation

  • focused ShellSpec: 145 examples, 0 failures
  • ShellCheck and Bash syntax
  • Nix formatting and focused activation-expression evaluation
  • git diff --check

Notes

No live host switch is included. Full ShellSpec has one unrelated sandbox-only failure in the existing security-sync test when it attempts to rewrite config/shared/hooks/security.sh. Full Kyber activation evaluation is also blocked on this aarch64-darwin host by the existing x86_64-linux Obsidian headless IFD; the focused K3s activation expression evaluates successfully.


Summary by cubic

Hardens k3s on Kyber by pinning the containerd SSD to a specific filesystem UUID, tightening image GC/eviction policy, and adding read‑only host reliability checks and log caps. The node now fails closed on storage identity issues and preserves headroom to prevent CRI stalls.

  • New Features

    • Mounts containerd image storage by UUID and refuses to run k3s if the mounted UUID is missing or mismatched.
    • Tunes kubelet: serializes image pulls, sets image GC to 70/60, enforces 20% free on nodefs and imagefs, and rotates container logs (10Mi, 3 files). kubelet remains the sole CRI GC owner.
    • Caps logs via journald (2G persistent, 256M runtime, 7 days) to avoid disk pressure from host logs.
    • Adds native monitoring: smartd for SMART self-tests and a minute-by-minute kyber-host-health check for I/O PSI, sustained D-state, imagefs usage/UUID, and CRI latency/errors. Alerts go to the journal and wall; checks are read-only.
  • Migration

    • Prepare the containerd SSD with the pinned UUID using named-hosts/kyber/prepare-containerd-disk.sh before switching, then verify with findmnt -n -o UUID /var/lib/rancher/k3s/agent/containerd.
    • Activation does not format disks. If the UUID is wrong or missing, k3s will not start until corrected.
    • Persistent volumes remain off the containerd SSD; only containerd runtime data lives on the SSD.

Written for commit 2717a48. Summary will update on new commits.

Review in cubic

@indent-zero

indent-zero Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor
PR Summary

Hardens the Kyber k3s host storage lifecycle by pinning the containerd SSD by ext4 UUID (rather than the user-editable label), tightening kubelet's disk headroom and log rotation, capping journald, and installing native smartd + a periodic read-only host-health monitor. Activation now refuses to start k3s if the mounted containerd filesystem's UUID does not match, giving a fail-closed storage-identity contract. Alerts are logged to journald and broadcast via wall, and never mutate CRI state — kubelet remains the sole image/container GC owner.

  • Pin containerd filesystem to UUID 90f29a7b-38ff-460b-b534-92a02f1412ec in containerd.mount, prepare-containerd-disk.sh, and the activation guard; mkfs.ext4 now takes -U, and both prep and activation re-validate UUID+type before use.
  • Tighten kubelet.conf: serializeImagePulls: true, imageGCHigh/Low 70/60, evictionHard with 20% nodefs/imagefs and 10% inodes, containerLogMaxSize=10Mi / containerLogMaxFiles=3.
  • Add journald.conf drop-in (2G persistent, 256M runtime, 10G keep-free, 7-day retention) and try-restart systemd-journald on change.
  • Add kyber-smartd.{service,conf} running smartd with DEVICESCAN, short/long self-tests, temperature warnings, and -M exec to a shared kyber-host-alert script (logger + wall).
  • Add kyber-host-health.{service,timer,sh} — a Type=oneshot monitor that runs every minute and checks I/O PSI avg300, sustained D-state processes (5 consecutive samples), containerd image-filesystem identity/usage, and CRI probe latency + recent k3s lifecycle-error grep. Alerts are deduplicated with /run/kyber-host-health/*.alerted markers and emit recovery notices.
  • Extend home-manager/services/k3s/{default.nix,activate.sh} to plumb blkid and the four new unit files, refactor sync into a sync_root_file helper, and enable the new units.
  • Update README with the new UUID contract, kubelet policy, and monitoring/verification commands; update spec/coverage_spec.sh to include untracked additions and spec/k3s_service_activate_spec.sh with matching assertions.

Issues

3 potential issues found:

  • Persistent=true in config/k3s/kyber-host-health.timer has no effect: per systemd.timer(5), the setting only applies to OnCalendar= timers, but this unit is purely monotonic (OnBootSec= / OnUnitActiveSec=). Either drop the line or switch to a calendar expression like OnCalendar=*:0/1 if you actually want missed intervals replayed after downtime. → Autofix
  • Pre-mount UUID guard in home-manager/services/k3s/activate.sh calls @blkid@ without sudo, but on Ubuntu the containerd block device is only readable by root/disk group; a normal-user make switch will get an empty UUID back and abort activation with unexpected containerd filesystem UUID: even when the disk is correctly mounted. The cleanest fix is to swap blkid for findmnt --output UUID --target "$MOUNT_POINT", which works unprivileged and lets you drop the new blkid dependency from home-manager/services/k3s/default.nix entirely. → Autofix
  • check_d_state in config/k3s/kyber-host-health.sh reads previous_samples from /run/kyber-host-health/d-state.samples and immediately performs $((previous_samples + 1)); a non-numeric or partially written value in that file will fail arithmetic evaluation under set -euo pipefail, aborting the entire health run and silently disabling the reliability monitor until reboot. Validate the value with a regex (or printf %d) and reset to 0 on garbage. → Autofix

CI Checks

Waiting for CI checks...


⚡ Autofix All Issues

@mesa-dot-dev

mesa-dot-dev Bot commented Jul 19, 2026

Copy link
Copy Markdown

You do not have enough credits to review this pull request. Please purchase more credits to continue.

@cursor

cursor Bot commented Jul 19, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added periodic host health monitoring for storage, I/O pressure, container runtime responsiveness, and filesystem capacity.
    • Added SMART disk monitoring with alerts sent to system logs and active sessions.
    • Added persistent journaling, log retention limits, and kubelet container log rotation.
  • Bug Fixes
    • Improved containerd disk identification and safety by mounting only the verified filesystem UUID.
    • Added safeguards against formatting or mounting an unexpected device.
  • Documentation
    • Expanded setup, verification, safety, monitoring, and troubleshooting guidance.

Walkthrough

Kyber containerd storage now uses a pinned filesystem UUID. Kubelet and journald limits are added, while SMART and periodic host-health monitoring are packaged, installed, enabled, and tested through Home Manager.

Changes

Kyber storage and reliability

Layer / File(s) Summary
Pinned containerd filesystem identity
config/k3s/containerd.mount, named-hosts/kyber/prepare-containerd-disk.sh, home-manager/services/k3s/activate.sh, spec/k3s_service_activate_spec.sh, named-hosts/kyber/README.md
Containerd preparation, mounting, activation checks, documentation, and tests now validate and use the fixed filesystem UUID.
Kubelet and journald resource controls
config/k3s/kubelet.conf, config/k3s/journald.conf
Kubelet image pulls, garbage collection, eviction thresholds, and log rotation are bounded, and journald receives persistent retention limits.
Kyber host monitoring units
config/k3s/kyber-host-*.sh, config/k3s/kyber-*.service, config/k3s/kyber-host-health.timer, config/k3s/kyber-smartd.conf, config/k3s/default.nix
SMART monitoring, periodic I/O, D-state, filesystem, and CRI checks, alert deduplication, and Kyber-only generated units are added.
Home Manager systemd integration
home-manager/services/k3s/activate.sh, home-manager/services/k3s/default.nix, spec/coverage_spec.sh, spec/k3s_service_activate_spec.sh
Activation substitutes new paths, synchronizes root-owned files, reloads systemd when required, and enables the SMART and host-health units.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Poem

A rabbit checks the disks at night,
With UUIDs pinned snug and tight.
SMART bells ring, logs softly stay,
Health checks hop through every day.
Kubelet guards the storage bright—
Reliability takes flight! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main Kyber K3s storage-hardening changes and is concise.
Description check ✅ Passed The description is directly related to the changeset and accurately describes the main storage, monitoring, and log-cap changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/kyber-host-hardening

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces host reliability monitoring, log limits, and storage validation for the Kyber k3s environment. It transitions the containerd SSD mount from label-based to UUID-based identification, adds scripts and systemd services for health checks and SMART disk monitoring, and configures native log rotation and journald limits. The review feedback highlights critical improvements to ensure script robustness under set -e, specifically recommending the use of findmnt instead of blkid to avoid permission issues during unprivileged Home Manager activation, and adding a guard for /proc/pressure/io to prevent premature script termination.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +111 to +112
mounted_source="$(@findmnt@ --noheadings --output SOURCE --target "$MOUNT_POINT")"
mounted_uuid="$(@blkid@ --match-tag UUID --output value "$mounted_source")"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Running blkid on a block device as a non-root user during Home Manager activation will fail or return an empty string due to permission restrictions on raw block devices. Since Home Manager activation runs as the unprivileged user, this will cause the activation script to abort or fail with an unexpected UUID error.

Using findmnt to retrieve the UUID directly is safe, does not require root privileges, and avoids the dependency on blkid entirely.

Suggested change
mounted_source="$(@findmnt@ --noheadings --output SOURCE --target "$MOUNT_POINT")"
mounted_uuid="$(@blkid@ --match-tag UUID --output value "$mounted_source")"
mounted_uuid="$(@findmnt@ --noheadings --output UUID --target "$MOUNT_POINT")"

Comment on lines 12 to +13
awk = "${pkgs.gawk}/bin/awk";
blkid = "${pkgs.util-linux}/bin/blkid";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since we can retrieve the UUID directly using findmnt in activate.sh without requiring root privileges, the blkid dependency is no longer needed here.

    awk = "${pkgs.gawk}/bin/awk";

Comment on lines +38 to +39
check_io_pressure() {
local some_avg300 full_avg300

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If /proc/pressure/io does not exist (e.g., on kernels where PSI is disabled or unsupported), the awk command will fail. Because set -e is enabled, this failure will prematurely abort the entire health check script, preventing subsequent checks from running.

Adding a guard to check for the existence of /proc/pressure/io ensures the script handles this state gracefully.

Suggested change
check_io_pressure() {
local some_avg300 full_avg300
check_io_pressure() {
if [ ! -f /proc/pressure/io ]; then
return 0
fi
local some_avg300 full_avg300
References
  1. When 'set -e' is enabled in Bash scripts, ensure that individual command failures do not prematurely abort the entire script. Handle potential failures gracefully.

Comment on lines +82 to +87
mounted_source="$(findmnt --noheadings --output SOURCE --target "$CONTAINERD_MOUNT")"
mounted_uuid="$(blkid --match-tag UUID --output value "$mounted_source")"
if [ "$mounted_uuid" != "$EXPECTED_CONTAINERD_UUID" ]; then
set_alert "image-filesystem" "$CONTAINERD_MOUNT has UUID $mounted_uuid, expected $EXPECTED_CONTAINERD_UUID"
return
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using blkid to query the UUID of the mounted source device can be fragile if the device is temporarily inaccessible or if the blkid cache is stale.

We can retrieve the UUID directly and robustly using findmnt --output UUID, which also handles potential command failures gracefully with || true to prevent set -e from aborting the script.

Suggested change
mounted_source="$(findmnt --noheadings --output SOURCE --target "$CONTAINERD_MOUNT")"
mounted_uuid="$(blkid --match-tag UUID --output value "$mounted_source")"
if [ "$mounted_uuid" != "$EXPECTED_CONTAINERD_UUID" ]; then
set_alert "image-filesystem" "$CONTAINERD_MOUNT has UUID $mounted_uuid, expected $EXPECTED_CONTAINERD_UUID"
return
fi
mounted_uuid="$(findmnt --noheadings --output UUID --target "$CONTAINERD_MOUNT" 2>/dev/null || true)"
if [ -z "$mounted_uuid" ] || [ "$mounted_uuid" != "$EXPECTED_CONTAINERD_UUID" ]; then
set_alert "image-filesystem" "$CONTAINERD_MOUNT has UUID ${mounted_uuid:-unknown}, expected $EXPECTED_CONTAINERD_UUID"
return
fi
References
  1. When 'set -e' is enabled in Bash scripts, ensure that individual command failures do not prematurely abort the entire script. Handle potential failures gracefully.


if @findmnt@ --mountpoint "$MOUNT_POINT" >/dev/null 2>&1; then
mounted_source="$(@findmnt@ --noheadings --output SOURCE --target "$MOUNT_POINT")"
mounted_uuid="$(@blkid@ --match-tag UUID --output value "$mounted_source")"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bare blkid will read empty for non-root users on Ubuntu, tripping the guard.

On Ubuntu the containerd block device (/dev/sda*) is brw-rw---- root disk, and blkid only returns cached info for devices readable by the invoking user. Since home-manager activation runs as the user, this call typically returns an empty string, and the check on line 113 then compares "" != "90f29a7b-..." — which is true — so activation aborts with unexpected containerd filesystem UUID: (empty), even when the disk is correctly mounted.

The same script already reaches for run_sudo @tune2fs@ -l "$root_source" in configure_root_ext4_reserve for exactly this reason, and prepare-containerd-disk.sh uses sudo blkid for the equivalent probe. Suggest:

if @findmnt@ --mountpoint "$MOUNT_POINT" >/dev/null 2>&1; then
  mounted_source="$(@findmnt@ --noheadings --output SOURCE --target "$MOUNT_POINT")"
  require_sudo || exit 0
  mounted_uuid="$(run_sudo @blkid@ --match-tag UUID --output value "$mounted_source")"
  ...
fi

The existing spec assertion grep -q 'mounted_uuid=.*@blkid@' in spec/k3s_service_activate_spec.sh still matches after the change.

fi

if [ "$d_state_count" -ge "$D_STATE_THRESHOLD" ]; then
samples=$((previous_samples + 1))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latent: corrupted state file crashes the health check.

previous_samples is read from /run/kyber-host-health/d-state.samples and fed directly into $((previous_samples + 1)). If that file ever contains non-numeric content (a partial write, a manual edit, or a truncated line), arithmetic evaluation fails and, under set -euo pipefail at the top of the file, the whole script exits non-zero — no subsequent check runs, and since the monitor is Type=oneshot the timer simply logs a failed unit and moves on. On tmpfs the file is normally rewritten on every run, so this is dormant today, but any interrupted write leaves the reliability monitor silently disabled until reboot.

A one-line guard makes this resilient:

if [ -r "$count_file" ]; then
  read -r previous_samples <"$count_file" || previous_samples=0
  [[ "$previous_samples" =~ ^[0-9]+$ ]] || previous_samples=0
fi

@mesa-dot-dev

mesa-dot-dev Bot commented Jul 19, 2026

Copy link
Copy Markdown

Mesa Description

TL;DR

Hardens Kyber host storage lifecycle and reliability by pinning the dedicated containerd storage device to its UUID and implementing proactive host health monitoring, SMART disk daemon configs, journald log limits, and tuned Kubelet garbage collection/eviction thresholds.

What changed?

  • config/k3s/containerd.mount: Mounts the containerd storage device by its disk UUID instead of label.
  • config/k3s/default.nix: Integrates Nix/Home Manager definitions for host health and SMART monitoring services, timers, and alert scripts.
  • config/k3s/journald.conf: Configures persistent storage behavior and sets maximum storage limits/retention times for log data.
  • config/k3s/kubelet.conf: Limits container log rotation, serializes image pulls, and lowers garbage collection thresholds to 70% high and 60% low.
  • config/k3s/kyber-host-alert.sh: Dispatches system reliability alerts by logging to syslog and broadcasting to active terminals.
  • config/k3s/kyber-host-health.sh: Monitors health metrics including I/O pressure, D-state processes, filesystem mounts, and CRI latency.
  • config/k3s/kyber-host-health.service & .timer: Adds a systemd oneshot service and 1-minute interval timer to verify Kyber storage and CRI reliability.
  • config/k3s/kyber-smartd.conf & .service: Enables SMART disk scanning, test schedules, temperature monitoring, and error alerts.
  • home-manager/services/k3s/activate.sh: Refactors the activation flow to enforce UUID validation and dynamically register the new host-health and smartd services.
  • home-manager/services/k3s/default.nix: Declares path variables for the new systemd configurations to pass to the setup script.
  • named-hosts/kyber/README.md: Updates the host setup documentation to focus on UUID-based disk preparation and reliability monitoring.
  • named-hosts/kyber/prepare-containerd-disk.sh: Refactors disk preparation to identify, format, and mount the SSD using a pinned UUID instead of labels.
  • spec/coverage_spec.sh: Registers the new health and alerting helper scripts in ShellSpec coverage.
  • spec/k3s_service_activate_spec.sh: Updates the test suite to validate UUID checks, Kubelet limits, and health timer configs.

Description generated by Mesa. Update settings

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@config/k3s/kyber-host-health.sh`:
- Around line 38-44: Update check_io_pressure to test whether /proc/pressure/io
is readable before invoking either awk command; if it is unavailable, return
successfully from the function so set -e does not terminate the script and
subsequent health checks still run.
- Around line 82-84: Update the mounted_uuid assignment in the health-check
script to tolerate blkid failure by appending the requested non-failing
fallback. Preserve an empty mounted_uuid so the existing comparison against
EXPECTED_CONTAINERD_UUID triggers the mismatch alert instead of terminating
under set -e.

In `@home-manager/services/k3s/activate.sh`:
- Around line 53-66: Update sync_root_file so both run_sudo mkdir and run_sudo
cp explicitly append “|| return 1”, ensuring command failures propagate even
when the function is used as an if condition; retain the existing successful
return 0 behavior.
- Around line 141-156: Initialize systemd_changed to 0 before the
systemd_file_pair loop. Keep sync_root_file setting it to 1 when any systemd
file changes, so the daemon-reload condition remains unchanged and idempotent
runs do not fail under set -u.
- Around line 110-119: Update the mounted filesystem UUID lookup in the
mount-check block to invoke blkid through the existing run_sudo helper, ensuring
it runs with root privileges while preserving the current UUID comparison and
refusal behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d998676f-d9b4-415f-8294-f21e8ab22814

📥 Commits

Reviewing files that changed from the base of the PR and between cf24506 and 2717a48.

📒 Files selected for processing (16)
  • config/k3s/containerd.mount
  • config/k3s/default.nix
  • config/k3s/journald.conf
  • config/k3s/kubelet.conf
  • config/k3s/kyber-host-alert.sh
  • config/k3s/kyber-host-health.service
  • config/k3s/kyber-host-health.sh
  • config/k3s/kyber-host-health.timer
  • config/k3s/kyber-smartd.conf
  • config/k3s/kyber-smartd.service
  • home-manager/services/k3s/activate.sh
  • home-manager/services/k3s/default.nix
  • named-hosts/kyber/README.md
  • named-hosts/kyber/prepare-containerd-disk.sh
  • spec/coverage_spec.sh
  • spec/k3s_service_activate_spec.sh

Comment on lines +38 to +44
check_io_pressure() {
local some_avg300 full_avg300

# shellcheck disable=SC2016
some_avg300="$(awk '$1 == "some" { for (i = 1; i <= NF; i++) if ($i ~ /^avg300=/) { sub(/^avg300=/, "", $i); print $i } }' /proc/pressure/io)"
# shellcheck disable=SC2016
full_avg300="$(awk '$1 == "full" { for (i = 1; i <= NF; i++) if ($i ~ /^avg300=/) { sub(/^avg300=/, "", $i); print $i } }' /proc/pressure/io)"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Gracefully handle missing PSI file to prevent premature script failure.

If the system lacks PSI capabilities or /proc/pressure/io is not readable, awk will throw a fatal error. Due to set -e, this will cause the entire health check script to crash, preventing subsequent checks (like check_d_state and check_image_filesystem) from running.

Add a readability check to return early if the file does not exist.

🛠️ Proposed fix
 check_io_pressure() {
+  if [ ! -r /proc/pressure/io ]; then
+    return 0
+  fi
   local some_avg300 full_avg300
 
   # shellcheck disable=SC2016
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
check_io_pressure() {
local some_avg300 full_avg300
# shellcheck disable=SC2016
some_avg300="$(awk '$1 == "some" { for (i = 1; i <= NF; i++) if ($i ~ /^avg300=/) { sub(/^avg300=/, "", $i); print $i } }' /proc/pressure/io)"
# shellcheck disable=SC2016
full_avg300="$(awk '$1 == "full" { for (i = 1; i <= NF; i++) if ($i ~ /^avg300=/) { sub(/^avg300=/, "", $i); print $i } }' /proc/pressure/io)"
check_io_pressure() {
if [ ! -r /proc/pressure/io ]; then
return 0
fi
local some_avg300 full_avg300
# shellcheck disable=SC2016
some_avg300="$(awk '$1 == "some" { for (i = 1; i <= NF; i++) if ($i ~ /^avg300=/) { sub(/^avg300=/, "", $i); print $i } }' /proc/pressure/io)"
# shellcheck disable=SC2016
full_avg300="$(awk '$1 == "full" { for (i = 1; i <= NF; i++) if ($i ~ /^avg300=/) { sub(/^avg300=/, "", $i); print $i } }' /proc/pressure/io)"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@config/k3s/kyber-host-health.sh` around lines 38 - 44, Update
check_io_pressure to test whether /proc/pressure/io is readable before invoking
either awk command; if it is unavailable, return successfully from the function
so set -e does not terminate the script and subsequent health checks still run.

Comment on lines +82 to +84
mounted_source="$(findmnt --noheadings --output SOURCE --target "$CONTAINERD_MOUNT")"
mounted_uuid="$(blkid --match-tag UUID --output value "$mounted_source")"
if [ "$mounted_uuid" != "$EXPECTED_CONTAINERD_UUID" ]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Prevent script termination if the filesystem lacks a UUID.

If the mounted device lacks a UUID (e.g., due to corruption or unexpected filesystem type), blkid will exit with status 2. Under set -e, this will crash the script before it can trigger the alert or proceed to other health checks.

Append || true so that an empty mounted_uuid correctly triggers the mismatch alert.

🛠️ Proposed fix
   mounted_source="$(findmnt --noheadings --output SOURCE --target "$CONTAINERD_MOUNT")"
-  mounted_uuid="$(blkid --match-tag UUID --output value "$mounted_source")"
+  mounted_uuid="$(blkid --match-tag UUID --output value "$mounted_source" || true)"
   if [ "$mounted_uuid" != "$EXPECTED_CONTAINERD_UUID" ]; then
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
mounted_source="$(findmnt --noheadings --output SOURCE --target "$CONTAINERD_MOUNT")"
mounted_uuid="$(blkid --match-tag UUID --output value "$mounted_source")"
if [ "$mounted_uuid" != "$EXPECTED_CONTAINERD_UUID" ]; then
mounted_source="$(findmnt --noheadings --output SOURCE --target "$CONTAINERD_MOUNT")"
mounted_uuid="$(blkid --match-tag UUID --output value "$mounted_source" || true)"
if [ "$mounted_uuid" != "$EXPECTED_CONTAINERD_UUID" ]; then
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@config/k3s/kyber-host-health.sh` around lines 82 - 84, Update the
mounted_uuid assignment in the health-check script to tolerate blkid failure by
appending the requested non-failing fallback. Preserve an empty mounted_uuid so
the existing comparison against EXPECTED_CONTAINERD_UUID triggers the mismatch
alert instead of terminating under set -e.

Comment on lines +53 to +66
sync_root_file() {
local source="$1"
local target="$2"

if [ ! -f "$source" ] || @diff@ -q "$source" "$target" >/dev/null 2>&1; then
return 1
fi

require_sudo || return 1
run_sudo mkdir -p "$(dirname "$target")"
run_sudo cp -f "$source" "$target"
return 0
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Propagate command failures in sync_root_file.

Because sync_root_file is evaluated as the condition of an if statement later in the script (e.g. if sync_root_file ...; then), Bash temporarily suspends set -e execution inside the function body. If run_sudo mkdir or run_sudo cp fails, the script will not abort and will silently proceed to return 0, falsely reporting a successful synchronization.

Append || return 1 to ensure failures are correctly propagated.

🐛 Proposed fix
   require_sudo || return 1
-  run_sudo mkdir -p "$(dirname "$target")"
-  run_sudo cp -f "$source" "$target"
-  return 0
+  run_sudo mkdir -p "$(dirname "$target")" || return 1
+  run_sudo cp -f "$source" "$target" || return 1
+  return 0
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
sync_root_file() {
local source="$1"
local target="$2"
if [ ! -f "$source" ] || @diff@ -q "$source" "$target" >/dev/null 2>&1; then
return 1
fi
require_sudo || return 1
run_sudo mkdir -p "$(dirname "$target")"
run_sudo cp -f "$source" "$target"
return 0
}
sync_root_file() {
local source="$1"
local target="$2"
if [ ! -f "$source" ] || `@diff`@ -q "$source" "$target" >/dev/null 2>&1; then
return 1
fi
require_sudo || return 1
run_sudo mkdir -p "$(dirname "$target")" || return 1
run_sudo cp -f "$source" "$target" || return 1
return 0
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@home-manager/services/k3s/activate.sh` around lines 53 - 66, Update
sync_root_file so both run_sudo mkdir and run_sudo cp explicitly append “||
return 1”, ensuring command failures propagate even when the function is used as
an if condition; retain the existing successful return 0 behavior.

Comment on lines +110 to +119
if @findmnt@ --mountpoint "$MOUNT_POINT" >/dev/null 2>&1; then
mounted_source="$(@findmnt@ --noheadings --output SOURCE --target "$MOUNT_POINT")"
mounted_uuid="$(@blkid@ --match-tag UUID --output value "$mounted_source")"
if [ "$mounted_uuid" != "$EXPECTED_CONTAINERD_UUID" ]; then
echo "Refusing to run k3s with unexpected containerd filesystem UUID: $mounted_uuid" >&2
echo "Expected $EXPECTED_CONTAINERD_UUID at $MOUNT_POINT" >&2
exit 1
fi
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Run blkid with root privileges.

By default, reading block device attributes with blkid requires root privileges. Because this script executes as a normal user during Home Manager activation, blkid will fail with an exit code of 2 and produce empty output. The set -e policy will immediately catch the failure inside the command substitution and abort the activation.

🐛 Proposed fix to use `run_sudo`
 if `@findmnt`@ --mountpoint "$MOUNT_POINT" >/dev/null 2>&1; then
   mounted_source="$(`@findmnt`@ --noheadings --output SOURCE --target "$MOUNT_POINT")"
-  mounted_uuid="$(`@blkid`@ --match-tag UUID --output value "$mounted_source")"
+  mounted_uuid="$(run_sudo `@blkid`@ --match-tag UUID --output value "$mounted_source")"
   if [ "$mounted_uuid" != "$EXPECTED_CONTAINERD_UUID" ]; then
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if @findmnt@ --mountpoint "$MOUNT_POINT" >/dev/null 2>&1; then
mounted_source="$(@findmnt@ --noheadings --output SOURCE --target "$MOUNT_POINT")"
mounted_uuid="$(@blkid@ --match-tag UUID --output value "$mounted_source")"
if [ "$mounted_uuid" != "$EXPECTED_CONTAINERD_UUID" ]; then
echo "Refusing to run k3s with unexpected containerd filesystem UUID: $mounted_uuid" >&2
echo "Expected $EXPECTED_CONTAINERD_UUID at $MOUNT_POINT" >&2
exit 1
fi
fi
if `@findmnt`@ --mountpoint "$MOUNT_POINT" >/dev/null 2>&1; then
mounted_source="$(`@findmnt`@ --noheadings --output SOURCE --target "$MOUNT_POINT")"
mounted_uuid="$(run_sudo `@blkid`@ --match-tag UUID --output value "$mounted_source")"
if [ "$mounted_uuid" != "$EXPECTED_CONTAINERD_UUID" ]; then
echo "Refusing to run k3s with unexpected containerd filesystem UUID: $mounted_uuid" >&2
echo "Expected $EXPECTED_CONTAINERD_UUID at $MOUNT_POINT" >&2
exit 1
fi
fi
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@home-manager/services/k3s/activate.sh` around lines 110 - 119, Update the
mounted filesystem UUID lookup in the mount-check block to invoke blkid through
the existing run_sudo helper, ensuring it runs with root privileges while
preserving the current UUID comparison and refusal behavior.

Comment on lines +141 to 156
for systemd_file_pair in \
"$MOUNT_FILE:$SYSTEM_MOUNT" \
"$SERVICE_FILE:$SYSTEM_SERVICE" \
"$HEALTH_SERVICE_FILE:$SYSTEM_HEALTH_SERVICE" \
"$HEALTH_TIMER_FILE:$SYSTEM_HEALTH_TIMER" \
"$SMARTD_SERVICE_FILE:$SYSTEM_SMARTD_SERVICE"; do
source_file="${systemd_file_pair%%:*}"
target_file="${systemd_file_pair#*:}"
if sync_root_file "$source_file" "$target_file"; then
systemd_changed=1
fi
done

if [ "$systemd_changed" -eq 1 ]; then
run_sudo @systemctl@ daemon-reload
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Initialize systemd_changed to avoid an unbound variable crash.

If none of the systemd files require synchronization, the for loop completes without assigning a value to systemd_changed. Evaluating [ "$systemd_changed" -eq 1 ] will then trigger an "unbound variable" error because of the set -u policy, crashing the script during steady-state (idempotent) runs.

🐛 Proposed fix
+systemd_changed=0
 for systemd_file_pair in \
   "$MOUNT_FILE:$SYSTEM_MOUNT" \
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for systemd_file_pair in \
"$MOUNT_FILE:$SYSTEM_MOUNT" \
"$SERVICE_FILE:$SYSTEM_SERVICE" \
"$HEALTH_SERVICE_FILE:$SYSTEM_HEALTH_SERVICE" \
"$HEALTH_TIMER_FILE:$SYSTEM_HEALTH_TIMER" \
"$SMARTD_SERVICE_FILE:$SYSTEM_SMARTD_SERVICE"; do
source_file="${systemd_file_pair%%:*}"
target_file="${systemd_file_pair#*:}"
if sync_root_file "$source_file" "$target_file"; then
systemd_changed=1
fi
done
if [ "$systemd_changed" -eq 1 ]; then
run_sudo @systemctl@ daemon-reload
fi
systemd_changed=0
for systemd_file_pair in \
"$MOUNT_FILE:$SYSTEM_MOUNT" \
"$SERVICE_FILE:$SYSTEM_SERVICE" \
"$HEALTH_SERVICE_FILE:$SYSTEM_HEALTH_SERVICE" \
"$HEALTH_TIMER_FILE:$SYSTEM_HEALTH_TIMER" \
"$SMARTD_SERVICE_FILE:$SYSTEM_SMARTD_SERVICE"; do
source_file="${systemd_file_pair%%:*}"
target_file="${systemd_file_pair#*:}"
if sync_root_file "$source_file" "$target_file"; then
systemd_changed=1
fi
done
if [ "$systemd_changed" -eq 1 ]; then
run_sudo `@systemctl`@ daemon-reload
fi
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@home-manager/services/k3s/activate.sh` around lines 141 - 156, Initialize
systemd_changed to 0 before the systemd_file_pair loop. Keep sync_root_file
setting it to 1 when any systemd file changes, so the daemon-reload condition
remains unchanged and idempotent runs do not fail under set -u.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7 issues found across 16 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="home-manager/services/k3s/activate.sh">

<violation number="1" location="home-manager/services/k3s/activate.sh:62">
P1: A failed privileged copy is reported as success, so activation can reload and enable stale or missing K3s/health/SMART units after a disk-full or permission failure. Make each install command terminate the activation on failure rather than falling through to `return 0`.</violation>

<violation number="2" location="home-manager/services/k3s/activate.sh:112">
P1: This UUID probe uses `@blkid@` before privilege escalation. During user-scoped activation, `blkid` can return no data or non-zero, which can trigger `set -e` or an empty-value mismatch and fail activation even when the mount is correct. Running this probe via `run_sudo` after `require_sudo` avoids that failure mode.</violation>

<violation number="3" location="home-manager/services/k3s/activate.sh:171">
P2: Updated SMART monitoring configuration never takes effect while `kyber-smartd.service` is already active: `enable --now` starts inactive units but does not restart the running smartd process. Track a changed smartd unit and restart it after `daemon-reload` (while preserving first-install start behavior).</violation>
</file>

<file name="config/k3s/kyber-host-health.sh">

<violation number="1" location="config/k3s/kyber-host-health.sh:42">
P2: Guard `/proc/pressure/io` before running `awk`. On hosts without PSI support, this command exits non-zero and `set -e` stops the health script before the remaining checks run.</violation>

<violation number="2" location="config/k3s/kyber-host-health.sh:63">
P3: Validate `previous_samples` before arithmetic. A malformed state file can break this calculation and terminate the health run early under `set -e`.</violation>

<violation number="3" location="config/k3s/kyber-host-health.sh:83">
P2: An unreadable or unsupported mounted source makes `blkid` terminate this script instead of producing the image-filesystem alert. Treat an empty UUID as a mismatch so the failed identity check remains visible and later health checks still run.</violation>

<violation number="4" location="config/k3s/kyber-host-health.sh:101">
P2: A hung `k3s crictl` that ignores or blocks TERM can keep this health service active past its intended 15-second bound, suppressing subsequent timer probes. Add a short kill-after grace period to enforce a real upper limit.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

fi

require_sudo || return 1
run_sudo mkdir -p "$(dirname "$target")"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: A failed privileged copy is reported as success, so activation can reload and enable stale or missing K3s/health/SMART units after a disk-full or permission failure. Make each install command terminate the activation on failure rather than falling through to return 0.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At home-manager/services/k3s/activate.sh, line 62:

<comment>A failed privileged copy is reported as success, so activation can reload and enable stale or missing K3s/health/SMART units after a disk-full or permission failure. Make each install command terminate the activation on failure rather than falling through to `return 0`.</comment>

<file context>
@@ -41,6 +50,20 @@ require_sudo() {
+  fi
+
+  require_sudo || return 1
+  run_sudo mkdir -p "$(dirname "$target")"
+  run_sudo cp -f "$source" "$target"
+  return 0
</file context>


if @findmnt@ --mountpoint "$MOUNT_POINT" >/dev/null 2>&1; then
mounted_source="$(@findmnt@ --noheadings --output SOURCE --target "$MOUNT_POINT")"
mounted_uuid="$(@blkid@ --match-tag UUID --output value "$mounted_source")"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: This UUID probe uses @blkid@ before privilege escalation. During user-scoped activation, blkid can return no data or non-zero, which can trigger set -e or an empty-value mismatch and fail activation even when the mount is correct. Running this probe via run_sudo after require_sudo avoids that failure mode.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At home-manager/services/k3s/activate.sh, line 112:

<comment>This UUID probe uses `@blkid@` before privilege escalation. During user-scoped activation, `blkid` can return no data or non-zero, which can trigger `set -e` or an empty-value mismatch and fail activation even when the mount is correct. Running this probe via `run_sudo` after `require_sudo` avoids that failure mode.</comment>

<file context>
@@ -84,6 +107,16 @@ configure_root_ext4_reserve() {
 
+if @findmnt@ --mountpoint "$MOUNT_POINT" >/dev/null 2>&1; then
+  mounted_source="$(@findmnt@ --noheadings --output SOURCE --target "$MOUNT_POINT")"
+  mounted_uuid="$(@blkid@ --match-tag UUID --output value "$mounted_source")"
+  if [ "$mounted_uuid" != "$EXPECTED_CONTAINERD_UUID" ]; then
+    echo "Refusing to run k3s with unexpected containerd filesystem UUID: $mounted_uuid" >&2
</file context>
Suggested change
mounted_uuid="$(@blkid@ --match-tag UUID --output value "$mounted_source")"
require_sudo || exit 0
mounted_uuid="$(run_sudo @blkid@ --match-tag UUID --output value "$mounted_source")"

run_sudo @systemctl@ enable --now k3s

if [ -f "$SMARTD_SERVICE_FILE" ]; then
run_sudo @systemctl@ enable --now kyber-smartd.service

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Updated SMART monitoring configuration never takes effect while kyber-smartd.service is already active: enable --now starts inactive units but does not restart the running smartd process. Track a changed smartd unit and restart it after daemon-reload (while preserving first-install start behavior).

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At home-manager/services/k3s/activate.sh, line 171:

<comment>Updated SMART monitoring configuration never takes effect while `kyber-smartd.service` is already active: `enable --now` starts inactive units but does not restart the running smartd process. Track a changed smartd unit and restart it after `daemon-reload` (while preserving first-install start behavior).</comment>

<file context>
@@ -129,6 +167,14 @@ fi
 run_sudo @systemctl@ enable --now k3s
 
+if [ -f "$SMARTD_SERVICE_FILE" ]; then
+  run_sudo @systemctl@ enable --now kyber-smartd.service
+fi
+
</file context>

fi

mounted_source="$(findmnt --noheadings --output SOURCE --target "$CONTAINERD_MOUNT")"
mounted_uuid="$(blkid --match-tag UUID --output value "$mounted_source")"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: An unreadable or unsupported mounted source makes blkid terminate this script instead of producing the image-filesystem alert. Treat an empty UUID as a mismatch so the failed identity check remains visible and later health checks still run.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At config/k3s/kyber-host-health.sh, line 83:

<comment>An unreadable or unsupported mounted source makes `blkid` terminate this script instead of producing the image-filesystem alert. Treat an empty UUID as a mismatch so the failed identity check remains visible and later health checks still run.</comment>

<file context>
@@ -0,0 +1,121 @@
+  fi
+
+  mounted_source="$(findmnt --noheadings --output SOURCE --target "$CONTAINERD_MOUNT")"
+  mounted_uuid="$(blkid --match-tag UUID --output value "$mounted_source")"
+  if [ "$mounted_uuid" != "$EXPECTED_CONTAINERD_UUID" ]; then
+    set_alert "image-filesystem" "$CONTAINERD_MOUNT has UUID $mounted_uuid, expected $EXPECTED_CONTAINERD_UUID"
</file context>
Suggested change
mounted_uuid="$(blkid --match-tag UUID --output value "$mounted_source")"
mounted_uuid="$(blkid --match-tag UUID --output value "$mounted_source" 2>/dev/null || true)"

local started_at finished_at latency_seconds error_count

started_at="$(date +%s)"
if ! timeout 15 k3s crictl info >/dev/null 2>&1; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: A hung k3s crictl that ignores or blocks TERM can keep this health service active past its intended 15-second bound, suppressing subsequent timer probes. Add a short kill-after grace period to enforce a real upper limit.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At config/k3s/kyber-host-health.sh, line 101:

<comment>A hung `k3s crictl` that ignores or blocks TERM can keep this health service active past its intended 15-second bound, suppressing subsequent timer probes. Add a short kill-after grace period to enforce a real upper limit.</comment>

<file context>
@@ -0,0 +1,121 @@
+  local started_at finished_at latency_seconds error_count
+
+  started_at="$(date +%s)"
+  if ! timeout 15 k3s crictl info >/dev/null 2>&1; then
+    set_alert "cri-health" "k3s crictl info failed or exceeded 15 seconds"
+    return
</file context>
Suggested change
if ! timeout 15 k3s crictl info >/dev/null 2>&1; then
if ! timeout -k 1s 15s k3s crictl info >/dev/null 2>&1; then

local some_avg300 full_avg300

# shellcheck disable=SC2016
some_avg300="$(awk '$1 == "some" { for (i = 1; i <= NF; i++) if ($i ~ /^avg300=/) { sub(/^avg300=/, "", $i); print $i } }' /proc/pressure/io)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Guard /proc/pressure/io before running awk. On hosts without PSI support, this command exits non-zero and set -e stops the health script before the remaining checks run.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At config/k3s/kyber-host-health.sh, line 42:

<comment>Guard `/proc/pressure/io` before running `awk`. On hosts without PSI support, this command exits non-zero and `set -e` stops the health script before the remaining checks run.</comment>

<file context>
@@ -0,0 +1,121 @@
+  local some_avg300 full_avg300
+
+  # shellcheck disable=SC2016
+  some_avg300="$(awk '$1 == "some" { for (i = 1; i <= NF; i++) if ($i ~ /^avg300=/) { sub(/^avg300=/, "", $i); print $i } }' /proc/pressure/io)"
+  # shellcheck disable=SC2016
+  full_avg300="$(awk '$1 == "full" { for (i = 1; i <= NF; i++) if ($i ~ /^avg300=/) { sub(/^avg300=/, "", $i); print $i } }' /proc/pressure/io)"
</file context>

fi

if [ "$d_state_count" -ge "$D_STATE_THRESHOLD" ]; then
samples=$((previous_samples + 1))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: Validate previous_samples before arithmetic. A malformed state file can break this calculation and terminate the health run early under set -e.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At config/k3s/kyber-host-health.sh, line 63:

<comment>Validate `previous_samples` before arithmetic. A malformed state file can break this calculation and terminate the health run early under `set -e`.</comment>

<file context>
@@ -0,0 +1,121 @@
+  fi
+
+  if [ "$d_state_count" -ge "$D_STATE_THRESHOLD" ]; then
+    samples=$((previous_samples + 1))
+  fi
+  printf '%s\n' "$samples" >"$count_file"
</file context>

@shunkakinoki
shunkakinoki merged commit 6b6549b into main Jul 19, 2026
35 of 36 checks passed
@shunkakinoki
shunkakinoki deleted the codex/kyber-host-hardening branch July 19, 2026 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant