diff --git a/scripts/apricot-run.sh b/scripts/apricot-run.sh index 5ad23b33..4aa8e9e0 100755 --- a/scripts/apricot-run.sh +++ b/scripts/apricot-run.sh @@ -263,18 +263,27 @@ if [[ "${MODE}" == "status" ]]; then QUERY_STAMP="${1:?usage: apricot-run.sh status }" UNIT="mc-batch-${QUERY_STAMP}" - # Single ssh probe with short ConnectTimeout. Three lightweight queries: + # Single ssh probe with short ConnectTimeout. Four lightweight queries: # 1. systemctl --user is-active (active|inactive|failed|unknown) # 2. count of completion.marker files under /*/ # 3. count of turn_stats.jsonl files under /*/game_*/ + # 4. count of live godot processes for THIS batch stamp # We also read seeds_total from the first submode dir if present. + # + # The godot-proc count is load-bearing: `flatpak run` detaches into a + # systemd user scope, so autoplay-batch.sh's `wait` returns and + # completion.marker is touched while the actual godot processes are still + # running headless games. Without checking live procs, fetch would pull + # mid-run turn_stats with outcome=in_progress and the consumer would + # think the gate failed when in fact games hadn't finished yet. PROBE='set +e IS_ACTIVE=$(systemctl --user is-active '"${UNIT}"' 2>/dev/null || echo unknown) MARKER_COUNT=$(ls "$HOME/.cache/mc-batches/'"${QUERY_STAMP}"'"/*/completion.marker 2>/dev/null | wc -l | tr -d " ") STATS_COUNT=$(ls "$HOME/.cache/mc-batches/'"${QUERY_STAMP}"'"/*/game_*/turn_stats.jsonl 2>/dev/null | wc -l | tr -d " ") + GODOT_PROCS=$(pgrep -af "godot.*'"${QUERY_STAMP}"'" 2>/dev/null | grep -c "godot --path" || echo 0) SEEDS_TOTAL=$(cat "$HOME/.cache/mc-batches/'"${QUERY_STAMP}"'"/*/seeds_total 2>/dev/null | head -1) SEEDS_TOTAL=${SEEDS_TOTAL:-0} - printf "%s|%s|%s|%s\n" "$IS_ACTIVE" "$MARKER_COUNT" "$STATS_COUNT" "$SEEDS_TOTAL"' + printf "%s|%s|%s|%s|%s\n" "$IS_ACTIVE" "$MARKER_COUNT" "$STATS_COUNT" "$SEEDS_TOTAL" "$GODOT_PROCS"' PROBE_OUT="$(ssh -o ConnectTimeout=5 -o BatchMode=yes "${APRICOT}" "${PROBE}" 2>/dev/null)" || PROBE_OUT=""