Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ”§ chore(acceptance): wire the project resource guard (#20251)

Arvin Xuf651c6b32d4a
diff --git a/.agents/acceptance/PROCESS.md b/.agents/acceptance/PROCESS.md
index 03c609f5cc9..2943b194311 100644
--- a/.agents/acceptance/PROCESS.md
+++ b/.agents/acceptance/PROCESS.md
@@ -201,14 +201,39 @@ will not take the intended path, call the server endpoint directly.
Project scripts live in `.agents/acceptance/scripts/` and are described in
`PROJECT.md` Β§5:
-| Script | Use |
-| ----------------------- | ------------------------------------------------------------------- |
-| `report-init.sh` | Scaffold a report directory grouped by acceptance subject |
-| `fixture.mjs` | Per-check fixtures: `init-check`, `list`, `compose` |
-| `record-gif.sh` | Frame sequence β†’ GIF for time-based behavior |
-| `capture-app-window.sh` | Screenshot one app window (macOS OS capture) |
-| `record-app-screen.sh` | Record an app screen (CDP frames β†’ video + gallery) |
-| `agent-browser-klm.mjs` | Wrap an `agent-browser` action and append its interaction-cost atom |
+| Script | Use |
+| ----------------------- | ---------------------------------------------------------------------- |
+| `acceptance-guard.sh` | Bound the run's memory: tier the host, stop this run's heavy processes |
+| `report-init.sh` | Scaffold a report directory grouped by acceptance subject |
+| `fixture.mjs` | Per-check fixtures: `init-check`, `list`, `compose` |
+| `record-gif.sh` | Frame sequence β†’ GIF for time-based behavior |
+| `capture-app-window.sh` | Screenshot one app window (macOS OS capture) |
+| `record-app-screen.sh` | Record an app screen (CDP frames β†’ video + gallery) |
+| `agent-browser-klm.mjs` | Wrap an `agent-browser` action and append its interaction-cost atom |
+
+**Bound the run's memory before the first heavy command.** A browser, a dev server
+and type-check workers grow while the round runs. Unbounded they swap the host out
+and freeze the client driving the run β€” measured here at 30.9 GB / 31.7 GB of swap
+with 867 MB free, while the round was still mid-capture. Start the project guard
+with the run's own tag, and hand it every long-lived process the run starts:
+
+```bash
+GUARD=.agents/acceptance/scripts/acceptance-guard.sh
+export ACCEPTANCE_RUN_TAG="acceptance-<subject>-$(date +%Y%m%d-%H%M%S)-$$"
+
+bash "$GUARD" start # before the first heavy command
+
+SESSION="app-$ACCEPTANCE_RUN_TAG"
+agent-browser --session "$SESSION" open "http://localhost:3000/"
+bash "$GUARD" claim-browser "$SESSION" # the browser this run opened
+
+bun run dev >"$DIR/devserver.log" 2>&1 &
+bash "$GUARD" claim "$!" # the dev server this run started
+```
+
+`stop-owned` stops only what this run tagged or claimed, so a sibling run's browser
+and a dev server the user started are never in its kill set. `bash "$GUARD" check --json` gives one verdict on the same thresholds the watcher uses (0 green, 10
+yellow, 20 red). Thresholds and groups are in `PROJECT.md` Β§5.
Generic capture helpers come from the installed skill, not the project layer:
@@ -281,6 +306,7 @@ What is specific to this repository:
test profile.** Follow [Publish auth preflight](#publish-auth-preflight) below
for both looking up existing rounds and publishing. Do not unconditionally
remove API keys or assume a stored login exists.
+
- **The publish target is not the verification surface.** `app.lobehub.com` is
where the acceptance is stored, not where the product was verified. Reaching
production to publish must never decide which environment ran the delivery; name
@@ -413,6 +439,11 @@ in a source file corrupts the next run and the next agent's mental model.
- **Keep the report and its evidence** until the round is published. It lives in
the temp report root, never in the working tree; the published round is the
durable copy.
+- **Stop the resource guard last**, after the browsers and dev servers above:
+ `bash .agents/acceptance/scripts/acceptance-guard.sh stop`. Read its verdict with
+ `... status --json` and put the peak tier in the round report. A run that reached
+ red says so and marks the checks it could not finish `blocked` β€” never `passed`.
+ A guard left running keeps sampling a machine nobody is verifying any more.
- **Check `git status` before calling the tree clean.** Some dev servers write
managed files on start.
diff --git a/.agents/acceptance/PROJECT.md b/.agents/acceptance/PROJECT.md
index 8d5b9938629..3645355f633 100644
--- a/.agents/acceptance/PROJECT.md
+++ b/.agents/acceptance/PROJECT.md
@@ -341,6 +341,39 @@ closed-loop probe/dump/analyze tooling lives at
`.agents/acceptance/scripts/agent-gateway/`; the closed-loop + JWKS setup workflow is
in `.agents/acceptance/references/agent-gateway.md`.
+`.agents/acceptance/scripts/acceptance-guard.sh` bounds a run's memory. It wraps the
+skill's [resource guard](../skills/acceptance/references/resource-guard.md) with this
+repository's groups and thresholds and pins a per-run state directory, so a round
+that boots a browser, a dev server and type-check workers cannot swap the host out
+and freeze the client driving the run. Run and teardown discipline:
+[`PROCESS.md`](./PROCESS.md) Step 4 and Step 6.
+
+```bash
+GUARD=.agents/acceptance/scripts/acceptance-guard.sh
+export ACCEPTANCE_RUN_TAG="acceptance-<subject>-<timestamp>-$$" # required
+
+bash "$GUARD" start # before the first heavy command
+bash "$GUARD" claim <pid>... # a process this run started
+bash "$GUARD" claim-browser <session> # the browser behind an agent-browser session
+bash "$GUARD" check --json # one verdict; 0 green, 10 yellow, 20 red
+bash "$GUARD" status --json # samples, tiers, recorded stops
+bash "$GUARD" stop # teardown, always
+```
+
+| Setting | Default | Why |
+| ------------------------- | --------------------------------------------- | ---------------------------------------------------------- |
+| `ACCEPTANCE_RUN_TAG` | β€” (required) | Proves ownership; must be β‰₯ 8 chars and `[A-Za-z0-9._-]+` |
+| `ACCEPTANCE_GUARD_DIR` | `${TMPDIR:-/tmp}/lobe-acceptance/guard/<tag>` | Keeps the run's samples and claims out of the working tree |
+| `ACCEPTANCE_GUARD_YELLOW` | `swap=60,free=20` | Recycle before red |
+| `ACCEPTANCE_GUARD_RED` | `swap=80,free=8` | Stop this run's claimed processes |
+
+Thresholds are host-level on purpose. The groups (`Google Chrome for Testing`,
+`next-server|vite`, `tsgo`) also match other worktrees' servers and other runs'
+browsers β€” five such processes held \~20 GB here β€” so a group or total RSS cap turns a
+merely busy machine red and stops a healthy run. Swap exhaustion is what actually
+freezes the host, so that is what the tier is made of; the groups exist so
+`stop-owned` has something it is allowed to stop.
+
## 6. Known constraints
- **QStash is a hard prerequisite for ANY agent-runtime test.** Any test that
diff --git a/.agents/acceptance/scripts/acceptance-guard.sh b/.agents/acceptance/scripts/acceptance-guard.sh
new file mode 100755
index 00000000000..41fb6e0802b
--- /dev/null
+++ b/.agents/acceptance/scripts/acceptance-guard.sh
@@ -0,0 +1,129 @@
+#!/usr/bin/env bash
+# LobeHub adapter over the acceptance skill's resource guard.
+#
+# A run boots a browser, a dev server and type-check workers. Left alone they grow
+# until the host swaps itself to a crawl and the client driving the run freezes β€”
+# measured in this repository at 30.9 GB / 31.7 GB of swap with 867 MB free. The
+# skill's guard owns the generic half of the fix: sample the host, tier it, and stop
+# only what this run can prove it started. This wrapper owns the project half β€” the
+# groups worth watching here, this repository's thresholds, and the run's state dir.
+#
+# Usage:
+# acceptance-guard.sh start start this run's sampler
+# acceptance-guard.sh claim <pid>... register a process this run started
+# acceptance-guard.sh claim-browser [session] claim the browser behind an agent-browser session
+# acceptance-guard.sh check [--json] one sample now; exit 0 green, 10 yellow, 20 red
+# acceptance-guard.sh status [--json] this run's recorded guard state
+# acceptance-guard.sh stop stop the sampler (teardown; always)
+#
+# Environment:
+# ACCEPTANCE_RUN_TAG required. Names this run. Ownership of a process is proven
+# by this tag or by an explicit claim, so it has to be
+# specific enough not to appear in unrelated command lines.
+# ACCEPTANCE_GUARD_DIR state directory (default: ${TMPDIR:-/tmp}/lobe-acceptance/guard/<tag>)
+# ACCEPTANCE_GUARD_YELLOW, ACCEPTANCE_GUARD_RED override the thresholds
+# ACCEPTANCE_GUARD_SCRIPT the skill's guard to wrap (test seam)
+#
+# The thresholds are host-level on purpose. The group patterns below also match other
+# worktrees' servers and other runs' browsers β€” five such processes held ~20 GB here
+# β€” so a group or total RSS cap would turn a merely busy machine red and stop a
+# healthy run. Swap exhaustion is what actually freezes the host, so that is what
+# this adapter tiers on; the groups exist so `stop-owned` has something it may stop.
+#
+# Contract: .agents/skills/acceptance/references/resource-guard.md
+set -uo pipefail
+
+PROG='[acceptance-guard]'
+fail() { echo "$PROG $*" >&2; exit 2; }
+
+ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
+GUARD="${ACCEPTANCE_GUARD_SCRIPT:-$ROOT/.agents/skills/acceptance/scripts/resource-guard.sh}"
+
+YELLOW="${ACCEPTANCE_GUARD_YELLOW:-swap=60,free=20}"
+RED="${ACCEPTANCE_GUARD_RED:-swap=80,free=8}"
+
+# The processes a LobeHub run is worth bounding. A pattern alone never grants
+# ownership: only the run tag or an explicit claim does.
+GUARD_GROUPS=(
+ 'browser=Google Chrome for Testing'
+ 'devserver=next-server|vite'
+ 'typecheck=tsgo'
+)
+
+RUN_TAG="${ACCEPTANCE_RUN_TAG:-}"
+[ -n "$RUN_TAG" ] || fail "set ACCEPTANCE_RUN_TAG before running the guard"
+case "$RUN_TAG" in
+ *[!A-Za-z0-9._-]*) fail "ACCEPTANCE_RUN_TAG must be [A-Za-z0-9._-]+ (got: $RUN_TAG)" ;;
+esac
+# A short tag is a substring of unrelated command lines, which would hand this run
+# ownership of processes it never started.
+[ "${#RUN_TAG}" -ge 8 ] || fail "ACCEPTANCE_RUN_TAG must be at least 8 characters (got: $RUN_TAG)"
+
+STATE_DIR="${ACCEPTANCE_GUARD_DIR:-${TMPDIR:-/tmp}/lobe-acceptance/guard/$RUN_TAG}"
+[ -f "$GUARD" ] || fail "the acceptance skill is not installed at $GUARD (run: lh acceptance install)"
+# `claim` is what lets this adapter prove a browser or dev server is ours. An older
+# installed skill has no such mode, and wiring it would leave a guard that can never
+# stop anything on this repository.
+case "$(bash "$GUARD" --help 2>&1 || true)" in
+ *claim*) ;;
+ *) fail "$GUARD has no 'claim' mode β€” update the installed skill (lh acceptance update) first" ;;
+esac
+
+guard() {
+ local sub="$1"
+ shift
+ local args=("$sub" '--state-dir' "$STATE_DIR" '--run-tag' "$RUN_TAG")
+ local group
+ for group in "${GUARD_GROUPS[@]}"; do args+=('--group' "$group"); done
+ bash "$GUARD" "${args[@]}" "$@"
+}
+
+case "${1:-}" in
+ start)
+ shift
+ guard start --yellow "$YELLOW" --red "$RED" --on-red stop-owned "$@"
+ ;;
+ check)
+ shift
+ # The one-shot verdict must tier on the same thresholds as the watcher, or a run
+ # reads one tier from `check` and is acted on by another.
+ guard check --yellow "$YELLOW" --red "$RED" "$@"
+ ;;
+ status)
+ shift
+ guard status "$@"
+ ;;
+ stop)
+ shift
+ guard stop "$@"
+ ;;
+ claim)
+ shift
+ [ $# -gt 0 ] || fail "claim needs at least one pid: acceptance-guard.sh claim <pid>..."
+ pids=()
+ for pid in "$@"; do pids+=('--pid' "$pid"); done
+ guard claim "${pids[@]}"
+ ;;
+ claim-browser)
+ shift
+ session="${1:-}"
+ if [ -n "$session" ]; then
+ url="$(agent-browser --session "$session" get cdp-url 2>/dev/null | tail -n 1)"
+ else
+ url="$(agent-browser get cdp-url 2>/dev/null | tail -n 1)"
+ fi
+ [ -n "$url" ] || fail "no CDP url β€” no agent-browser session is open yet"
+ port="$(printf '%s' "$url" | sed -E 's|^ws://[^:]+:([0-9]+)/.*$|\1|')"
+ case "$port" in '' | *[!0-9]*) fail "could not read a CDP port from '$url'" ;; esac
+ # The session's CDP port is the one identifier agent-browser gives us that ties a
+ # browser to this run: its profile is a random temp dir and named sessions keep no
+ # pid file, so the listening process is the positive answer, not a guess.
+ pid="$(lsof -nP -tiTCP:"$port" -sTCP:LISTEN 2>/dev/null | head -n 1)"
+ [ -n "$pid" ] || fail "nothing is listening on CDP port $port"
+ guard claim --pid "$pid"
+ printf '%s browser pid %s (cdp %s) belongs to %s\n' "$PROG" "$pid" "$port" "$RUN_TAG"
+ ;;
+ *)
+ fail "Usage: acceptance-guard.sh start|claim|claim-browser|check|status|stop"
+ ;;
+esac
diff --git a/.agents/acceptance/scripts/acceptance-guard.test.sh b/.agents/acceptance/scripts/acceptance-guard.test.sh
new file mode 100755
index 00000000000..dc2913559ee
--- /dev/null
+++ b/.agents/acceptance/scripts/acceptance-guard.test.sh
@@ -0,0 +1,149 @@
+#!/usr/bin/env bash
+# Acceptance guard adapter: asserts the arguments LobeHub supplies to the skill's
+# resource guard, and the run-tag validation that keeps ownership narrow.
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+SCRIPT="$SCRIPT_DIR/acceptance-guard.sh"
+TEST_TMP="$(mktemp -d)"
+trap 'rm -rf "$TEST_TMP"' EXIT
+
+fail() {
+ echo "FAIL: $*" >&2
+ exit 1
+}
+
+assert_contains() {
+ local value="$1"
+ local expected="$2"
+ [[ "$value" == *"$expected"* ]] || fail "expected '$expected' in '$value'"
+}
+
+# The skill's guard is stubbed: what this test owns is the adapter's arguments. The
+# real guard's behaviour is covered upstream in lobehub/acceptance.
+cat > "$TEST_TMP/guard-stub.sh" <<'SH'
+#!/usr/bin/env bash
+if [ "${1:-}" = "--help" ]; then
+ echo "Usage: bash resource-guard.sh check|start|claim|stop|status [options]" >&2
+ exit 2
+fi
+printf '%s\n' "$*" >> "${GUARD_STUB_LOG:?}"
+SH
+chmod +x "$TEST_TMP/guard-stub.sh"
+
+mkdir -p "$TEST_TMP/bin"
+cat > "$TEST_TMP/bin/agent-browser" <<'SH'
+#!/usr/bin/env bash
+echo "ws://127.0.0.1:57604/devtools/browser/49e9d98b-cda8-4136-8b65-3d5342403a02"
+SH
+cat > "$TEST_TMP/bin/lsof" <<'SH'
+#!/usr/bin/env bash
+echo 75919
+SH
+chmod +x "$TEST_TMP/bin/agent-browser" "$TEST_TMP/bin/lsof"
+
+export PATH="$TEST_TMP/bin:$PATH"
+export ACCEPTANCE_GUARD_SCRIPT="$TEST_TMP/guard-stub.sh"
+export GUARD_STUB_LOG="$TEST_TMP/calls.log"
+export ACCEPTANCE_RUN_TAG="lobehub-acceptance-test"
+export ACCEPTANCE_GUARD_DIR="$TEST_TMP/state"
+
+# Runs the adapter, records the stub's arguments, and returns the adapter's exit code.
+adapter() {
+ : > "$GUARD_STUB_LOG"
+ set +e
+ "$SCRIPT" "$@" > "$TEST_TMP/stdout" 2> "$TEST_TMP/stderr"
+ STATUS=$?
+ set -e
+ return 0
+}
+
+stub_args() { cat "$GUARD_STUB_LOG"; }
+
+expect_refused() {
+ local message="$1"
+ shift
+ if adapter "$@" && [ "$STATUS" -eq 0 ]; then
+ fail "$message"
+ fi
+}
+
+# A tag short enough to appear inside unrelated command lines must be refused: the
+# guard grants ownership by substring, so a short tag stops other runs' work.
+ACCEPTANCE_RUN_TAG=abc
+expect_refused "a short run tag must be refused" check
+assert_contains "$(cat "$TEST_TMP/stderr")" "at least 8 characters"
+
+ACCEPTANCE_RUN_TAG="has space"
+expect_refused "a run tag with spaces must be refused" check
+
+ACCEPTANCE_RUN_TAG=""
+expect_refused "an empty run tag must be refused" check
+
+ACCEPTANCE_RUN_TAG="lobehub-acceptance-test"
+
+# start supplies this repository's groups, thresholds, red action and state dir.
+adapter start
+assert_contains "$(stub_args)" "start --state-dir $TEST_TMP/state"
+assert_contains "$(stub_args)" "--run-tag lobehub-acceptance-test"
+assert_contains "$(stub_args)" "--group browser=Google Chrome for Testing"
+assert_contains "$(stub_args)" "--group devserver=next-server|vite"
+assert_contains "$(stub_args)" "--group typecheck=tsgo"
+assert_contains "$(stub_args)" "--yellow swap=60,free=20"
+assert_contains "$(stub_args)" "--red swap=80,free=8"
+assert_contains "$(stub_args)" "--on-red stop-owned"
+
+# A run may retune the thresholds without editing the adapter.
+export ACCEPTANCE_GUARD_RED='swap=95,free=4'
+adapter start
+assert_contains "$(stub_args)" "--red swap=95,free=4"
+export ACCEPTANCE_GUARD_RED='swap=80,free=8'
+
+# check tiers on the same thresholds as the watcher, so a run cannot read one tier
+# from the one-shot and be acted on by another.
+adapter check --json
+assert_contains "$(stub_args)" "check --state-dir $TEST_TMP/state"
+assert_contains "$(stub_args)" "--yellow swap=60,free=20"
+assert_contains "$(stub_args)" "--red swap=80,free=8"
+assert_contains "$(stub_args)" "--json"
+
+# Every claimed pid is forwarded, and an empty claim is a usage error.
+adapter claim 11 22
+assert_contains "$(stub_args)" "claim --state-dir $TEST_TMP/state"
+assert_contains "$(stub_args)" "--pid 11 --pid 22"
+expect_refused "claim without a pid must be refused" claim
+assert_contains "$(cat "$TEST_TMP/stderr")" "claim needs at least one pid"
+
+# claim-browser resolves the session's CDP port to the listening process, which is
+# the only positive identifier agent-browser exposes for a run's own browser.
+adapter claim-browser app-1234
+assert_contains "$(stub_args)" "--pid 75919"
+assert_contains "$(cat "$TEST_TMP/stdout")" "browser pid 75919"
+
+# status and stop carry the state dir the run started with, so a run can read its
+# recorded tier and teardown can find the watcher it started.
+adapter status --json
+assert_contains "$(stub_args)" "status --state-dir $TEST_TMP/state"
+assert_contains "$(stub_args)" "--json"
+
+adapter stop
+assert_contains "$(stub_args)" "stop --state-dir $TEST_TMP/state"
+
+# An unknown subcommand is a usage error, not a silent no-op.
+expect_refused "an unknown subcommand must fail" sweep
+assert_contains "$(cat "$TEST_TMP/stderr")" "Usage: acceptance-guard.sh"
+
+# A skill too old to have `claim` cannot back this adapter's ownership proof: say so
+# instead of failing later with an opaque guard error.
+cat > "$TEST_TMP/old-guard-stub.sh" <<'SH'
+#!/usr/bin/env bash
+echo "Usage: bash resource-guard.sh check|start|stop|status [options]" >&2
+exit 2
+SH
+chmod +x "$TEST_TMP/old-guard-stub.sh"
+ACCEPTANCE_GUARD_SCRIPT="$TEST_TMP/old-guard-stub.sh"
+expect_refused "an installed skill without claim must be refused" start
+assert_contains "$(cat "$TEST_TMP/stderr")" "has no 'claim' mode"
+ACCEPTANCE_GUARD_SCRIPT="$TEST_TMP/guard-stub.sh"
+
+echo "acceptance-guard.test.sh: ok"