Skip to content

Commit 2d0d82e

Browse files
ruiling-smartbearGaoRuilin1haizhongzhengclaude
authored
Stop the wire meters a launcher starts once its runs end (#87)
* Stop the wire meters a launcher starts once its runs end (#82) Each launcher records the meters it starts and, through a detached waiter, stops them once its trainings (ServeLearnBench: the tests that follow) have ended; the harness2 restart loop is stopped with its meter as one process group. A meter found already running is left to the launch that started it. * Wire meters: stop within a second; reuse only a meter still up on a second look A launch started right after another could reuse that launch's meter while its waiter was about to stop it. ServeLearnBench's waiter also waits for the training itself. * Wire meters: a shared meter stops after every launch using it; a restarted one keeps its ledger Review fixes for #82: - A meter started on a ledger an earlier one left carries its totals on (LEDGER_RESUME=1 in hermit/runtime/wire_meter.py, set by the eight launchers whose ledger outlives a meter). Once the launchers stop their meters, the next meter on the port (`run && run eval`, a ServeLearnBench test run again, a CL-Bench tag refused because it exists) wrote an empty ledger over the earlier bill. Off by default: lean_swarm's rerun of an attempt starts empty as before. - Every launch on a port lists its processes in /tmp/hermit-wire-meter-<uid>-<port>.users, and the launch that started the meter stops it only once none of them is alive, so a launch that reuses a running meter no longer loses it when the starter's run ends. - OfficeQA ReHarness prints the meter's pid, not the watcher's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: SmartBea_Linlin_r <80329948+GaoRuilin1@users.noreply.github.com> Co-authored-by: Haizhong Zheng <hzzheng@umich.edu> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent a5c0485 commit 2d0d82e

12 files changed

Lines changed: 374 additions & 21 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ Changes are grouped by software version. Entries under Unreleased describe work
202202
- The AHE Adapter Evolver took a `change_manifest.json` an earlier step left for the current step's: a manifest
203203
naming the next iteration was refused at its own step, then archived as the next step's when that step's session
204204
wrote none. The file (or a directory a session made in its place) is now removed before each Evolve session.
205+
- Nine example launchers left their wire meters running after the run (#82), so a later run on the same port
206+
reused one and wrote its records into the earlier run's ledger. The meters a launch starts now stop within a second
207+
or two of the runs that use them ending: its own trainings (and, for ServeLearnBench, the tests after them) and
208+
those of any launch that reuses one, which each list their processes in the port's users file
209+
(`/tmp/hermit-wire-meter-<uid>-<port>.users`); the harness2 restart loop is stopped with its meter. A
210+
launch reuses a running meter only if it is still up three seconds on, so it never takes one that is being
211+
stopped. A meter started on a ledger an earlier one left now carries its totals on (`LEDGER_RESUME=1` in
212+
`hermit/runtime/wire_meter.py`, which these launchers set): the next run's meter on the port (`launch.sh run &&
213+
launch.sh run eval`, a ServeLearnBench `test` run again, a CL-Bench tag refused because it exists) wrote an empty
214+
ledger over the earlier run's bill.
205215
- On macOS a CLI session stopped at its timeout or on cancel could leave processes behind or fail: the processes
206216
below it were found through `/proc`, which macOS lacks, so one in a session of its own (as a sandbox starts its
207217
program) was never stopped; and signalling a process group left with only exited, unreaped processes raises

‎examples/clbench_database/mwm/launch.sh‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,45 @@ fi
7878
command -v codex >/dev/null || { echo "REFUSING: codex CLI not on PATH"; exit 1; }
7979
[ -f "$TASKDIR/tasks.jsonl" ] || { echo "REFUSING: run $TASKDIR/prepare.py first"; exit 1; }
8080

81+
# The meters this launch starts stop within a second or two of the processes that use them ending (#82): its own and
82+
# those of any launch that reuses one. Each launch on a port lists its processes in the port's users file, emptied
83+
# when the meter stops; a launch reuses a running meter only if it is still up on a second look (one being stopped is
84+
# gone by then).
85+
METERS=() OWNED=() PORTS=()
86+
meter_users() { echo "/tmp/hermit-wire-meter-$(id -u)-$1.users"; } # port: /tmp, which every launch on it shares
87+
meter_started() { # port pid: a meter this launch started, this launch one of its users
88+
{ echo $$ >> "$(meter_users "$1")" || true; } 2>/dev/null
89+
METERS+=("$2"); OWNED+=("$1")
90+
}
91+
stop_meters_after() { # pid...: what this launch leaves running; the meters it started stop after every user
92+
local port files=()
93+
[ $# -eq 0 ] || for port in ${PORTS[@]+"${PORTS[@]}"}; do
94+
printf '%s\n' "$@" >> "$(meter_users "$port")" 2>/dev/null || true; done
95+
[ ${#METERS[@]} -gt 0 ] || return 0
96+
for port in "${OWNED[@]}"; do files+=("$(meter_users "$port")"); done
97+
setsid nohup bash -c 'while :; do up=
98+
for p in $(cat $1 2>/dev/null); do kill -0 "$p" 2>/dev/null && { up=1; break; }; done
99+
[ -n "$up" ] || break; sleep 1; done
100+
for f in $1; do : > "$f"; done 2>/dev/null # a launch listed after this look finds the meter gone and starts one
101+
for m in $2; do kill -- "-$m" 2>/dev/null || kill "$m" 2>/dev/null || true; done' _ "${files[*]}" "${METERS[*]}" \
102+
> /dev/null 2>&1 < /dev/null &
103+
}
104+
meter_health() { # port: the /health of a meter still up three seconds on, this launch listed as one of its users first
105+
curl -s -m 2 "http://127.0.0.1:$1/health" > /dev/null 2>&1 \
106+
&& { echo $$ >> "$(meter_users "$1")" || true; } 2>/dev/null \
107+
&& sleep 3 && curl -s -m 2 "http://127.0.0.1:$1/health" 2>/dev/null
108+
}
109+
trap 'stop_meters_after ${PIDS[@]+"${PIDS[@]}"}' EXIT # after the trainings started below, if any
81110
start_meter() { # port upstream ledger log [extra env...]: a meter already on the port must face the same upstream
82111
local port=$1 upstream=$2 ledger=$3 log=$4 health; shift 4
83-
if health=$(curl -s -m 2 "http://127.0.0.1:$port/health" 2>/dev/null); then
112+
PORTS+=("$port") # started here or reused: this launch's processes use it
113+
if health=$(meter_health $port); then
84114
case "$health" in *"\"upstream\": \"$upstream\""*) echo "wire meter already on port $port -> $upstream";;
85115
*) echo "REFUSING: port $port has a wire meter facing another or an unknown upstream ($health); choose another WM_PORT"; exit 1;; esac
86116
else
87-
env "$@" PORT=$port LEDGER="$ledger" UPSTREAM="$upstream" \
117+
env "$@" PORT=$port LEDGER="$ledger" LEDGER_RESUME=1 UPSTREAM="$upstream" \
88118
setsid nohup "$PY" "$METER" > "$log" 2>&1 < /dev/null &
119+
meter_started $port $!
89120
echo "wire meter pid $! port $port -> $upstream"; sleep 2
90121
fi
91122
}

‎examples/clbench_database/prompt_only/launch.sh‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,45 @@ fi
8282
command -v codex >/dev/null || { echo "REFUSING: codex CLI not on PATH"; exit 1; }
8383
[ -f "$TASKDIR/tasks.jsonl" ] || { echo "REFUSING: run $TASKDIR/prepare.py first"; exit 1; }
8484

85+
# The meters this launch starts stop within a second or two of the processes that use them ending (#82): its own and
86+
# those of any launch that reuses one. Each launch on a port lists its processes in the port's users file, emptied
87+
# when the meter stops; a launch reuses a running meter only if it is still up on a second look (one being stopped is
88+
# gone by then).
89+
METERS=() OWNED=() PORTS=()
90+
meter_users() { echo "/tmp/hermit-wire-meter-$(id -u)-$1.users"; } # port: /tmp, which every launch on it shares
91+
meter_started() { # port pid: a meter this launch started, this launch one of its users
92+
{ echo $$ >> "$(meter_users "$1")" || true; } 2>/dev/null
93+
METERS+=("$2"); OWNED+=("$1")
94+
}
95+
stop_meters_after() { # pid...: what this launch leaves running; the meters it started stop after every user
96+
local port files=()
97+
[ $# -eq 0 ] || for port in ${PORTS[@]+"${PORTS[@]}"}; do
98+
printf '%s\n' "$@" >> "$(meter_users "$port")" 2>/dev/null || true; done
99+
[ ${#METERS[@]} -gt 0 ] || return 0
100+
for port in "${OWNED[@]}"; do files+=("$(meter_users "$port")"); done
101+
setsid nohup bash -c 'while :; do up=
102+
for p in $(cat $1 2>/dev/null); do kill -0 "$p" 2>/dev/null && { up=1; break; }; done
103+
[ -n "$up" ] || break; sleep 1; done
104+
for f in $1; do : > "$f"; done 2>/dev/null # a launch listed after this look finds the meter gone and starts one
105+
for m in $2; do kill -- "-$m" 2>/dev/null || kill "$m" 2>/dev/null || true; done' _ "${files[*]}" "${METERS[*]}" \
106+
> /dev/null 2>&1 < /dev/null &
107+
}
108+
meter_health() { # port: the /health of a meter still up three seconds on, this launch listed as one of its users first
109+
curl -s -m 2 "http://127.0.0.1:$1/health" > /dev/null 2>&1 \
110+
&& { echo $$ >> "$(meter_users "$1")" || true; } 2>/dev/null \
111+
&& sleep 3 && curl -s -m 2 "http://127.0.0.1:$1/health" 2>/dev/null
112+
}
113+
trap 'stop_meters_after ${PIDS[@]+"${PIDS[@]}"}' EXIT # after the trainings started below, if any
85114
start_meter() { # port upstream ledger log [extra env...]: a meter already on the port must face the same upstream
86115
local port=$1 upstream=$2 ledger=$3 log=$4 health; shift 4
87-
if health=$(curl -s -m 2 "http://127.0.0.1:$port/health" 2>/dev/null); then
116+
PORTS+=("$port") # started here or reused: this launch's processes use it
117+
if health=$(meter_health $port); then
88118
case "$health" in *"\"upstream\": \"$upstream\""*) echo "wire meter already on port $port -> $upstream";;
89119
*) echo "REFUSING: port $port has a wire meter facing another or an unknown upstream ($health); choose another WM_PORT"; exit 1;; esac
90120
else
91-
env "$@" PORT=$port LEDGER="$ledger" UPSTREAM="$upstream" \
121+
env "$@" PORT=$port LEDGER="$ledger" LEDGER_RESUME=1 UPSTREAM="$upstream" \
92122
setsid nohup "$PY" "$METER" > "$log" 2>&1 < /dev/null &
123+
meter_started $port $!
93124
echo "wire meter pid $! port $port -> $upstream"; sleep 2
94125
fi
95126
}

‎examples/clbench_database/reharness/launch.sh‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,45 @@ fi
9090

9191
[ -f "$TASKDIR/tasks.jsonl" ] || { echo "REFUSING: run $TASKDIR/prepare.py first"; exit 1; }
9292

93+
# The meters this launch starts stop within a second or two of the processes that use them ending (#82): its own and
94+
# those of any launch that reuses one. Each launch on a port lists its processes in the port's users file, emptied
95+
# when the meter stops; a launch reuses a running meter only if it is still up on a second look (one being stopped is
96+
# gone by then).
97+
METERS=() OWNED=() PORTS=()
98+
meter_users() { echo "/tmp/hermit-wire-meter-$(id -u)-$1.users"; } # port: /tmp, which every launch on it shares
99+
meter_started() { # port pid: a meter this launch started, this launch one of its users
100+
{ echo $$ >> "$(meter_users "$1")" || true; } 2>/dev/null
101+
METERS+=("$2"); OWNED+=("$1")
102+
}
103+
stop_meters_after() { # pid...: what this launch leaves running; the meters it started stop after every user
104+
local port files=()
105+
[ $# -eq 0 ] || for port in ${PORTS[@]+"${PORTS[@]}"}; do
106+
printf '%s\n' "$@" >> "$(meter_users "$port")" 2>/dev/null || true; done
107+
[ ${#METERS[@]} -gt 0 ] || return 0
108+
for port in "${OWNED[@]}"; do files+=("$(meter_users "$port")"); done
109+
setsid nohup bash -c 'while :; do up=
110+
for p in $(cat $1 2>/dev/null); do kill -0 "$p" 2>/dev/null && { up=1; break; }; done
111+
[ -n "$up" ] || break; sleep 1; done
112+
for f in $1; do : > "$f"; done 2>/dev/null # a launch listed after this look finds the meter gone and starts one
113+
for m in $2; do kill -- "-$m" 2>/dev/null || kill "$m" 2>/dev/null || true; done' _ "${files[*]}" "${METERS[*]}" \
114+
> /dev/null 2>&1 < /dev/null &
115+
}
116+
meter_health() { # port: the /health of a meter still up three seconds on, this launch listed as one of its users first
117+
curl -s -m 2 "http://127.0.0.1:$1/health" > /dev/null 2>&1 \
118+
&& { echo $$ >> "$(meter_users "$1")" || true; } 2>/dev/null \
119+
&& sleep 3 && curl -s -m 2 "http://127.0.0.1:$1/health" 2>/dev/null
120+
}
121+
trap 'stop_meters_after ${PIDS[@]+"${PIDS[@]}"}' EXIT # after the trainings started below, if any
93122
start_meter() { # port upstream ledger log [extra env...]: a meter already on the port must face the same upstream
94123
local port=$1 upstream=$2 ledger=$3 log=$4 health; shift 4
95-
if health=$(curl -s -m 2 "http://127.0.0.1:$port/health" 2>/dev/null); then
124+
PORTS+=("$port") # started here or reused: this launch's processes use it
125+
if health=$(meter_health $port); then
96126
case "$health" in *"\"upstream\": \"$upstream\""*) echo "wire meter already on port $port -> $upstream";;
97127
*) echo "REFUSING: port $port has a wire meter facing another or an unknown upstream ($health); choose another WM_PORT"; exit 1;; esac
98128
else
99-
env "$@" PORT=$port LEDGER="$ledger" UPSTREAM="$upstream" \
129+
env "$@" PORT=$port LEDGER="$ledger" LEDGER_RESUME=1 UPSTREAM="$upstream" \
100130
setsid nohup "$PY" "$METER" > "$log" 2>&1 < /dev/null &
131+
meter_started $port $!
101132
echo "wire meter pid $! port $port -> $upstream"; sleep 2
102133
curl -s -m 2 "http://127.0.0.1:$port/health" > /dev/null \
103134
|| { echo "REFUSING: the wire meter on port $port did not come up (see $log)"; exit 1; }
@@ -108,7 +139,7 @@ start_meter $WM_PORT "$HOST_ORIGIN" "$RUNS/$TAG/wire_ledger.json" "$RUNS/$TAG/wi
108139
start_meter $META_PORT "$EVOLVER_ORIGIN" "$RUNS/$TAG/meta_wire_ledger.json" "$RUNS/$TAG/meta_wire_meter.log"
109140
# The embedding relay signs the reader's keyless requests with the embedding backend's key (none for a keyless server);
110141
# a relay already on the port is refused unless its /health says it signs (`"signs": true`).
111-
if [ -n "$EMBED_API_KEY_ENV" ] && health=$(curl -s -m 2 "http://127.0.0.1:$EMBED_PORT/health" 2>/dev/null); then
142+
if [ -n "$EMBED_API_KEY_ENV" ] && health=$(meter_health $EMBED_PORT); then
112143
case "$health" in *'"signs": true'*) ;; *) echo "REFUSING: port $EMBED_PORT has a relay that does not sign requests (started without UPSTREAM_KEY_ENV); choose another WM_PORT"; exit 1;; esac
113144
fi
114145
start_meter $EMBED_PORT "$EMBED_ORIGIN" "$RUNS/$TAG/embed_wire_ledger.json" "$RUNS/$TAG/embed_wire_meter.log" \

‎examples/clbench_poker/mwm/launch.sh‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,45 @@ export MWM_CLBENCH=$CLBENCH MWM_METAWORLD=$METAWORLD
7373
command -v codex >/dev/null || { echo "REFUSING: codex CLI not on PATH"; exit 1; }
7474
[ -f "$TASKDIR/tasks.jsonl" ] || { echo "REFUSING: run $TASKDIR/prepare.py first"; exit 1; }
7575

76+
# The meters this launch starts stop within a second or two of the processes that use them ending (#82): its own and
77+
# those of any launch that reuses one. Each launch on a port lists its processes in the port's users file, emptied
78+
# when the meter stops; a launch reuses a running meter only if it is still up on a second look (one being stopped is
79+
# gone by then).
80+
METERS=() OWNED=() PORTS=()
81+
meter_users() { echo "/tmp/hermit-wire-meter-$(id -u)-$1.users"; } # port: /tmp, which every launch on it shares
82+
meter_started() { # port pid: a meter this launch started, this launch one of its users
83+
{ echo $$ >> "$(meter_users "$1")" || true; } 2>/dev/null
84+
METERS+=("$2"); OWNED+=("$1")
85+
}
86+
stop_meters_after() { # pid...: what this launch leaves running; the meters it started stop after every user
87+
local port files=()
88+
[ $# -eq 0 ] || for port in ${PORTS[@]+"${PORTS[@]}"}; do
89+
printf '%s\n' "$@" >> "$(meter_users "$port")" 2>/dev/null || true; done
90+
[ ${#METERS[@]} -gt 0 ] || return 0
91+
for port in "${OWNED[@]}"; do files+=("$(meter_users "$port")"); done
92+
setsid nohup bash -c 'while :; do up=
93+
for p in $(cat $1 2>/dev/null); do kill -0 "$p" 2>/dev/null && { up=1; break; }; done
94+
[ -n "$up" ] || break; sleep 1; done
95+
for f in $1; do : > "$f"; done 2>/dev/null # a launch listed after this look finds the meter gone and starts one
96+
for m in $2; do kill -- "-$m" 2>/dev/null || kill "$m" 2>/dev/null || true; done' _ "${files[*]}" "${METERS[*]}" \
97+
> /dev/null 2>&1 < /dev/null &
98+
}
99+
meter_health() { # port: the /health of a meter still up three seconds on, this launch listed as one of its users first
100+
curl -s -m 2 "http://127.0.0.1:$1/health" > /dev/null 2>&1 \
101+
&& { echo $$ >> "$(meter_users "$1")" || true; } 2>/dev/null \
102+
&& sleep 3 && curl -s -m 2 "http://127.0.0.1:$1/health" 2>/dev/null
103+
}
104+
trap 'stop_meters_after ${PIDS[@]+"${PIDS[@]}"}' EXIT # after the trainings started below, if any
76105
start_meter() { # port upstream ledger log [extra env...]: a meter already on the port must face the same upstream
77106
local port=$1 upstream=$2 ledger=$3 log=$4 health; shift 4
78-
if health=$(curl -s -m 2 "http://127.0.0.1:$port/health" 2>/dev/null); then
107+
PORTS+=("$port") # started here or reused: this launch's processes use it
108+
if health=$(meter_health $port); then
79109
case "$health" in *"\"upstream\": \"$upstream\""*) echo "wire meter already on port $port -> $upstream";;
80110
*) echo "REFUSING: port $port has a wire meter facing another or an unknown upstream ($health); choose another WM_PORT"; exit 1;; esac
81111
else
82-
env "$@" PORT=$port LEDGER="$ledger" UPSTREAM="$upstream" \
112+
env "$@" PORT=$port LEDGER="$ledger" LEDGER_RESUME=1 UPSTREAM="$upstream" \
83113
setsid nohup "$PY" "$METER" > "$log" 2>&1 < /dev/null &
114+
meter_started $port $!
84115
echo "wire meter pid $! port $port -> $upstream"; sleep 2
85116
fi
86117
}

‎examples/clbench_poker/prompt_only/launch.sh‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,45 @@ export MWM_CLBENCH=$CLBENCH MWM_METAWORLD=$METAWORLD
7777
command -v codex >/dev/null || { echo "REFUSING: codex CLI not on PATH"; exit 1; }
7878
[ -f "$TASKDIR/tasks.jsonl" ] || { echo "REFUSING: run $TASKDIR/prepare.py first"; exit 1; }
7979

80+
# The meters this launch starts stop within a second or two of the processes that use them ending (#82): its own and
81+
# those of any launch that reuses one. Each launch on a port lists its processes in the port's users file, emptied
82+
# when the meter stops; a launch reuses a running meter only if it is still up on a second look (one being stopped is
83+
# gone by then).
84+
METERS=() OWNED=() PORTS=()
85+
meter_users() { echo "/tmp/hermit-wire-meter-$(id -u)-$1.users"; } # port: /tmp, which every launch on it shares
86+
meter_started() { # port pid: a meter this launch started, this launch one of its users
87+
{ echo $$ >> "$(meter_users "$1")" || true; } 2>/dev/null
88+
METERS+=("$2"); OWNED+=("$1")
89+
}
90+
stop_meters_after() { # pid...: what this launch leaves running; the meters it started stop after every user
91+
local port files=()
92+
[ $# -eq 0 ] || for port in ${PORTS[@]+"${PORTS[@]}"}; do
93+
printf '%s\n' "$@" >> "$(meter_users "$port")" 2>/dev/null || true; done
94+
[ ${#METERS[@]} -gt 0 ] || return 0
95+
for port in "${OWNED[@]}"; do files+=("$(meter_users "$port")"); done
96+
setsid nohup bash -c 'while :; do up=
97+
for p in $(cat $1 2>/dev/null); do kill -0 "$p" 2>/dev/null && { up=1; break; }; done
98+
[ -n "$up" ] || break; sleep 1; done
99+
for f in $1; do : > "$f"; done 2>/dev/null # a launch listed after this look finds the meter gone and starts one
100+
for m in $2; do kill -- "-$m" 2>/dev/null || kill "$m" 2>/dev/null || true; done' _ "${files[*]}" "${METERS[*]}" \
101+
> /dev/null 2>&1 < /dev/null &
102+
}
103+
meter_health() { # port: the /health of a meter still up three seconds on, this launch listed as one of its users first
104+
curl -s -m 2 "http://127.0.0.1:$1/health" > /dev/null 2>&1 \
105+
&& { echo $$ >> "$(meter_users "$1")" || true; } 2>/dev/null \
106+
&& sleep 3 && curl -s -m 2 "http://127.0.0.1:$1/health" 2>/dev/null
107+
}
108+
trap 'stop_meters_after ${PIDS[@]+"${PIDS[@]}"}' EXIT # after the trainings started below, if any
80109
start_meter() { # port upstream ledger log [extra env...]: a meter already on the port must face the same upstream
81110
local port=$1 upstream=$2 ledger=$3 log=$4 health; shift 4
82-
if health=$(curl -s -m 2 "http://127.0.0.1:$port/health" 2>/dev/null); then
111+
PORTS+=("$port") # started here or reused: this launch's processes use it
112+
if health=$(meter_health $port); then
83113
case "$health" in *"\"upstream\": \"$upstream\""*) echo "wire meter already on port $port -> $upstream";;
84114
*) echo "REFUSING: port $port has a wire meter facing another or an unknown upstream ($health); choose another WM_PORT"; exit 1;; esac
85115
else
86-
env "$@" PORT=$port LEDGER="$ledger" UPSTREAM="$upstream" \
116+
env "$@" PORT=$port LEDGER="$ledger" LEDGER_RESUME=1 UPSTREAM="$upstream" \
87117
setsid nohup "$PY" "$METER" > "$log" 2>&1 < /dev/null &
118+
meter_started $port $!
88119
echo "wire meter pid $! port $port -> $upstream"; sleep 2
89120
fi
90121
}

0 commit comments

Comments
 (0)