From 69c11db3a12eb2c3c2126d1d03e5ce3a398974c6 Mon Sep 17 00:00:00 2001 From: jedarden Date: Sun, 7 Jun 2026 09:06:23 -0400 Subject: [PATCH] docs(bf-2q9r): document per-needle-worker MemoryMax ceiling (4 GB) Added systemd-run --scope -p MemoryMax=4G wrapper to all GLM adapter configs (claude-code-glm-4.7, claude-code-glm-5, claude-code-glm-5-1) to prevent any single worker from exhausting cgroup memory. --- notes/bf-2q9r.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 notes/bf-2q9r.md diff --git a/notes/bf-2q9r.md b/notes/bf-2q9r.md new file mode 100644 index 0000000..3c750cc --- /dev/null +++ b/notes/bf-2q9r.md @@ -0,0 +1,41 @@ +# Bead bf-2q9r: Per-needle-worker MemoryMax ceiling (4 GB) + +## Summary + +Added per-needle-worker MemoryMax ceiling (4 GB) via systemd-run scope wrapper so no single worker can exhaust the cgroup's available memory. + +## Implementation + +**Approach:** systemd transient scope with MemoryMax=4G + +Modified needle adapter configs to wrap worker invocation with: +```bash +systemd-run --user --scope -p MemoryMax=4G bash -c '...' +``` + +**Files modified:** +- `/home/coding/.config/needle/adapters/claude-code-glm-4.7.yaml` (already had MemoryMax) +- `/home/coding/.config/needle/adapters/claude-code-glm-5.yaml` (added MemoryMax) +- `/home/coding/.config/needle/adapters/claude-code-glm-5-1.yaml` (added MemoryMax) + +## Verification + +Checked active systemd scopes: +```bash +$ systemctl --user show run-p857080-i9244556.scope -p MemoryMax +MemoryMax=4294967296 # 4 GB + +$ systemctl --user show run-p857080-i9244556.scope -p MemoryCurrent +MemoryCurrent=647168 # ~632 KB +``` + +## Rationale + +With only a cgroup-level soft limit (user-1001.slice MemoryHigh), one runaway worker could still consume all available memory before pressure kills it. The per-process MemoryMax bounds each Claude Code session at 4 GB RSS, ensuring 6 workers + fabric-web + VSCode stay well under 32 GB total. + +## Notes + +- MemoryMax is a hard limit — the process is OOM-killed if it exceeds 4 GB +- This complements (not replaces) the user-1001.slice MemoryHigh soft limit +- systemd-run scope automatically cleanup when process exits +- Backups created: `.pre-memorycap.bak` files