feat(server): S3 box is for coding — OOM kills the command not the session, no tests from Claude, 4 AI sessions per member
- tool-run (CLAUDE_CODE_SHELL_PREFIX in member panes) runs each command Claude runs at oom_score_adj 1000 (session 300, Terminal tab 800, dashboard/tmux -100), so an OOM inside the capped unit kills the test run and tells Claude why, instead of killing the conversation. - member-guard.js, a synchronous managed hook for ah-* accounts: denies test runners and container commands from Claude's Bash, and refuses the prompts of a session started by hand past MAX_AI_SESSIONS. - ai-procs.js counts a member's top-level AI processes from /proc; spawnRun refuses a new pane past the limit (429 ESESSIONLIMIT). Needs `agenthub server install-system` once, then a restart.
This commit is contained in:
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
# @file tool-run.sh
|
||||
# @description Server mode, one Linux user per account (S3): installed as
|
||||
# /opt/agenthub/libexec/tool-run and named by CLAUDE_CODE_SHELL_PREFIX in
|
||||
# every member pane (pane-launch). Claude Code runs each Bash command (and
|
||||
# hook) as `tool-run '<command string>'`. The command runs at the kernel's
|
||||
# highest OOM preference, so when memory runs out it is the command — a test
|
||||
# run, a build — that is killed, never the Claude session above it that holds
|
||||
# the conversation (pane-launch puts that one at 300). When the cgroup's OOM
|
||||
# count moved while the command ran, Claude is told why it died.
|
||||
# @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
||||
[ $# -gt 0 ] || exec /bin/bash
|
||||
echo 1000 >/proc/self/oom_score_adj 2>/dev/null
|
||||
cg=$(sed -n 's/^0:://p' /proc/self/cgroup 2>/dev/null)
|
||||
events=/sys/fs/cgroup${cg}/memory.events
|
||||
kills() { sed -n 's/^oom_kill //p' "$events" 2>/dev/null; }
|
||||
before=$(kills)
|
||||
/bin/bash -c "$1"
|
||||
rc=$?
|
||||
if [ "$rc" -ne 0 ] && [ -n "$before" ] && [ "$(kills)" != "$before" ]; then
|
||||
printf '\n%s\n' "AgentHub: the server ran out of memory, so a process of this command was stopped (exit $rc). This shared server is for writing code only: do not run tests, containers or other heavy jobs here — tell the user to run them on their own machine." >&2
|
||||
fi
|
||||
exit "$rc"
|
||||
Reference in New Issue
Block a user