Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions test/e2e/test-issue-2478-crash-loop-recovery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,27 +102,15 @@ sandbox_exec() {
openshell sandbox exec --name "$SANDBOX_NAME" -- "$@" 2>&1
}

# Get the current OpenClaw gateway PID inside the sandbox, or empty string.
# OpenClaw process labels vary by runtime/build: some expose argv as
# `openclaw gateway run`, some re-title as `openclaw-gateway`, and current
# 2026.5.x builds can show only `openclaw` in pgrep/ps even after the gateway
# is ready. Prefer explicit gateway argv/title matches, then fall back to the
# oldest live `openclaw` process when gateway.log proves it reached ready.
# Get the current openclaw gateway PID inside the sandbox, or empty string.
# The gateway re-execs to argv `openclaw-gateway` after startup (it spawns
# from the launcher whose argv is `openclaw gateway run`). Match either form
# via `[o]penclaw[ -]gateway` — bracket trick prevents pgrep self-match,
# `[ -]` accepts both the launcher (space) and the post-rename (dash). `-o`
# returns the OLDEST match (the long-lived launcher 262 in the typical
# parent/child tree); env is inherited so NODE_OPTIONS reads the same.
gateway_pid() {
local script
script=$(
cat <<'SH'
set -eu
pid="$(ps -eo pid=,comm=,args= 2>/dev/null | awk '
$2 == "openclaw-gateway" || $0 ~ /openclaw[[:space:]]+gateway([[:space:]]|$)/ || $0 ~ /openclaw-gateway/ { print $1 }
' | sort -n | head -n 1)"
if [ -z "$pid" ] && grep -Eq "\[gateway\] (ready|http server listening)" /tmp/gateway.log 2>/dev/null; then
pid="$(ps -eo pid=,comm=,args= 2>/dev/null | awk '$2 == "openclaw" { print $1 }' | sort -n | head -n 1)"
fi
printf "%s\n" "$pid"
SH
)
sandbox_exec sh -c "$script" | awk '/^[0-9]+$/ { print; exit }'
sandbox_exec sh -c "pgrep -fo '[o]penclaw[ -]gateway'" | tr -d '[:space:]'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Validate gateway_pid() output is numeric before reporting success.

At Line 113, stderr text from sandbox_exec/pgrep can become a non-empty string after whitespace stripping, and wait_for_gateway_up() will treat that as a valid PID.

Suggested fix
 gateway_pid() {
-  sandbox_exec sh -c "pgrep -fo '[o]penclaw[ -]gateway'" | tr -d '[:space:]'
+  local pid
+  pid="$(sandbox_exec sh -c "pgrep -fo '[o]penclaw[ -]gateway'" | tr -d '[:space:]')"
+  case "$pid" in
+    ''|*[!0-9]*) echo "" ;;
+    *) echo "$pid" ;;
+  esac
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
sandbox_exec sh -c "pgrep -fo '[o]penclaw[ -]gateway'" | tr -d '[:space:]'
gateway_pid() {
local pid
pid="$(sandbox_exec sh -c "pgrep -fo '[o]penclaw[ -]gateway'" | tr -d '[:space:]')"
case "$pid" in
''|*[!0-9]*) echo "" ;;
*) echo "$pid" ;;
esac
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/e2e/test-issue-2478-crash-loop-recovery.sh` at line 113, The
gateway_pid() helper currently returns the trimmed output of sandbox_exec sh -c
"pgrep -fo '[o]penclaw[ -]gateway'" which may be non-numeric stderr/garbage and
causes wait_for_gateway_up() to treat it as a valid PID; update gateway_pid() to
validate the output is a positive integer (e.g., only digits) before returning
it and have it return empty/false on invalid output so wait_for_gateway_up()
only considers numeric PIDs, ensuring sandbox_exec/pgrep stderr does not count
as success.

}

# Read /tmp/nemoclaw-proxy-env.sh — the single source of truth for the
Expand Down Expand Up @@ -244,8 +232,8 @@ gateway_diagnostics() {
sandbox_exec sh -c "tail -n 60 /tmp/gateway.log 2>&1 || echo '(no gateway.log)'" | sed 's/^/ /'
echo " [nemoclaw status]"
nemoclaw "$SANDBOX_NAME" status 2>&1 | head -30 | sed 's/^/ /'
echo " [openshell sandbox get]"
openshell sandbox get "$SANDBOX_NAME" 2>&1 | head -40 | sed 's/^/ /' || true
echo " [openshell sandbox containers / pod]"
openshell sandbox info --name "$SANDBOX_NAME" 2>&1 | head -20 | sed 's/^/ /' || true
if [ -n "$pid" ]; then
echo " [reported pid: $pid]"
echo " [/proc/${pid} listing]"
Expand Down
Loading