From d8dab4a18a2aaa7f2a842f61f91162e8b27871f8 Mon Sep 17 00:00:00 2001 From: openhands Date: Thu, 26 Mar 2026 15:00:12 +0000 Subject: [PATCH] fix: Extract memory_guard() to lib/env.sh to deduplicate poll scripts The memory guard block in action-poll.sh and dev-poll.sh became identical after removing matrix_send calls, triggering the duplicate-detection CI check. Extract to a shared function in lib/env.sh (already sourced by both scripts). Co-Authored-By: Claude Opus 4.6 (1M context) --- action/action-poll.sh | 6 +----- dev/dev-poll.sh | 6 +----- lib/env.sh | 12 ++++++++++++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/action/action-poll.sh b/action/action-poll.sh index 1ec6814..100d854 100755 --- a/action/action-poll.sh +++ b/action/action-poll.sh @@ -25,11 +25,7 @@ log() { } # --- Memory guard --- -AVAIL_MB=$(awk '/MemAvailable/{printf "%d", $2/1024}' /proc/meminfo) -if [ "$AVAIL_MB" -lt 2000 ]; then - log "SKIP: only ${AVAIL_MB}MB available (need 2000MB)" - exit 0 -fi +memory_guard 2000 # --- Find open 'action' issues --- log "scanning for open action issues" diff --git a/dev/dev-poll.sh b/dev/dev-poll.sh index effeea2..1f81287 100755 --- a/dev/dev-poll.sh +++ b/dev/dev-poll.sh @@ -309,11 +309,7 @@ if [ -f "$LOCKFILE" ]; then fi # --- Memory guard --- -AVAIL_MB=$(awk '/MemAvailable/{printf "%d", $2/1024}' /proc/meminfo) -if [ "$AVAIL_MB" -lt 2000 ]; then - log "SKIP: only ${AVAIL_MB}MB available (need 2000MB)" - exit 0 -fi +memory_guard 2000 # ============================================================================= # HELPER: check if a dependency issue is fully resolved (closed + PR merged) diff --git a/lib/env.sh b/lib/env.sh index a453b40..0d0aeb6 100755 --- a/lib/env.sh +++ b/lib/env.sh @@ -146,6 +146,18 @@ wpdb() { -t "$@" 2>/dev/null } +# Memory guard — exit 0 (skip) if available RAM is below MIN_MB. +# Usage: memory_guard [MIN_MB] (default 2000) +memory_guard() { + local min_mb="${1:-2000}" + local avail_mb + avail_mb=$(awk '/MemAvailable/{printf "%d", $2/1024}' /proc/meminfo) + if [ "${avail_mb:-0}" -lt "$min_mb" ]; then + log "SKIP: only ${avail_mb}MB available (need ${min_mb}MB)" + exit 0 + fi +} + # Source tea helpers (available when tea binary is installed) if command -v tea &>/dev/null; then # shellcheck source=tea-helpers.sh