Watch
0
0
Fork
You've already forked hyperhive
0

agents: hand over the kept drop-in's cap, warn at boot without one

When hive-c0re can't read resource-limits.json and a limits drop-in
already exists, it keeps the drop-in, but it wrote no memory cap file. A
container whose runtime dir had no file yet (hive-c0re upgraded, /run
not cleared) then started with no heap ceiling and no subagent
MemoryHigh=, silently. `stage_limits` now writes the file on every
call: from the new limits, or from the last `MemoryMax=` in the kept
drop-in (`infinity` when it has none or can't be read).

A missing or malformed cap file at boot is no longer silent. The
generators run before the container's journal and an nspawn container
has no /dev/kmsg, so a oneshot `hyperhive-memory-cap-check.service`
logs a warning naming the path. The agent then runs with no JSC heap
ceiling and no subagent MemoryHigh=; the container's MemoryMax= still
applies.

module-eval-agent-memory gains a case pinning how the ceiling reaches
claude: `hive-agent` and `hive-subagent-daemon` neither set nor unset
BUN_JSC_forceRAMSize, both generators and the check unit are installed.

Part of #5081 (slice S0-2).
This commit is contained in:
atlas 2026-10-12 10:10:11 +02:00
commit 57955a6c53
6 changed files with 144 additions and 32 deletions

View file

@ -1,7 +1,7 @@
# Cases for ./agent-memory-cap.nix. Each case writes a cap file (or none), runs
# both generators with a clean environment and compares what they produced,
# then sources the login-shell snippet under each POSIX shell and compares what
# a child process sees.
# both generators and the boot check with a clean environment and compares what
# they produced, then sources the login-shell snippet under each POSIX shell
# and compares what a child process sees.
set -uo pipefail
failures=0
@ -16,12 +16,13 @@ dir=$(mktemp -d)
cap=$dir/memory-max-bytes
sed "s|/run/hive/memory-max-bytes|$cap|g" "$ENV_GENERATOR" >"$dir/env-generator"
sed "s|/run/hive/memory-max-bytes|$cap|g" "$UNIT_GENERATOR" >"$dir/unit-generator"
chmod +x "$dir/env-generator" "$dir/unit-generator"
sed "s|/run/hive/memory-max-bytes|$cap|g" "$CHECK" >"$dir/check"
chmod +x "$dir/env-generator" "$dir/unit-generator" "$dir/check"
sed "s|$ENV_GENERATOR|$dir/env-generator|g" "$PROFILE" >"$dir/profile"
envbin=$(command -v env)
case="setup"
for g in env-generator unit-generator; do
for g in env-generator unit-generator check; do
if grep -q '/run/hive/memory-max-bytes' "$dir/$g"; then fail "$g still names /run/hive after the rewrite"; fi
if ! grep -qF "$cap" "$dir/$g"; then fail "the rewrite did not reach $g's read"; fi
done
@ -31,10 +32,11 @@ if ! printf '%s\n' "$EXTRA_INIT" | grep -qxF '. /etc/hyperhive/memory-cap.sh'; t
fi
# check <description> <expected BUN_JSC_forceRAMSize or ""> <expected MemoryHigh or "">
# <why the boot check warns, or "">
check() {
case=$1
count=$((count + 1))
local want_env=${2:+BUN_JSC_forceRAMSize=$2} want_high=$3 got
local want_env=${2:+BUN_JSC_forceRAMSize=$2} want_high=$3 want_why=${4:-} got
got=$(env -i "$dir/env-generator")
if [ "$got" != "$want_env" ]; then
fail "environment generator printed:"$'\n'"$got"$'\n'"wanted:"$'\n'"$want_env"
@ -55,6 +57,17 @@ check() {
fi
fi
# The warning goes to stderr with the journal's `<4>` priority prefix, and
# nothing goes anywhere for a usable cap.
got=$(env -i "$dir/check" 2>&1)
local want_warn=
if [ -n "$want_why" ]; then
want_warn="<4>$cap $want_why: no BUN_JSC_forceRAMSize heap ceiling and no MemoryHigh= on hive-subagent-daemon; the host's MemoryMax= on the container still applies. hive-c0re writes no file for a cap of infinity or a RAM percentage."
fi
if [ "$got" != "$want_warn" ]; then
fail "boot check printed:"$'\n'"$got"$'\n'"wanted:"$'\n'"$want_warn"
fi
local sh
for sh in $SHELLS; do
# Only what the snippet exported reaches the child's environment. No PATH:
@ -76,19 +89,19 @@ printf '4294967296\nLD_PRELOAD=/x\n' >"$cap"
check "only the first line is read" 3221225472 2863311530
printf '8G\n' >"$cap"
check "a size with a suffix is ignored" "" ""
check "a size with a suffix is ignored" "" "" "does not start with a plain byte count"
printf '0123\n' >"$cap"
check "a leading zero is ignored" "" ""
check "a leading zero is ignored" "" "" "does not start with a plain byte count"
printf '1234567890123456\n' >"$cap"
check "sixteen digits are ignored" "" ""
check "sixteen digits are ignored" "" "" "does not start with a plain byte count"
: >"$cap"
check "an empty file" "" ""
check "an empty file" "" "" "does not start with a plain byte count"
rm -f "$cap"
check "no file" "" ""
check "no file" "" "" "is missing"
echo "$count cases, $failures failed"
[ "$failures" -eq 0 ]