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
46 changes: 46 additions & 0 deletions bin/doctor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,52 @@ else
fi
fi

# ── Runtime Health ────────────────────────────────────────────────────────────

echo ""
echo "Runtime health:"

# Slack bridge
if curl -s -o /dev/null -w '%{http_code}' -X POST http://127.0.0.1:7890/send -H 'Content-Type: application/json' -d '{}' 2>/dev/null | grep -q "400"; then
pass "slack bridge responding (port 7890)"
else
warn "slack bridge not responding on port 7890"
fi

# Disk usage
DISK_PCT=$(df / 2>/dev/null | tail -1 | awk '{print $5}' | tr -d '%')
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The disk usage check uses df / which can fail on systems with long filesystem names (e.g., LVM), causing the doctor.sh script to crash.
Severity: MEDIUM

Suggested Fix

Modify the command to use the POSIX-compliant output format for df by adding the -P flag. This prevents line wrapping and ensures consistent output. The command should be df -P /.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: bin/doctor.sh#L248

Potential issue: The `doctor.sh` script parses disk usage with `df / | tail -1 | awk
'{print $5}'`. On systems with long filesystem names, such as those using LVM or network
mounts, the output of `df` wraps to a new line. This causes the parsing logic to
incorrectly assign the mount point (e.g., `/`) to the `DISK_PCT` variable. Because the
script runs with `set -e`, the subsequent attempt to perform a numeric comparison `[
"$DISK_PCT" -ge 90 ]` on a non-numeric value will cause the script to exit with an
error, preventing the health check from completing.

if [ -n "$DISK_PCT" ]; then
if [ "$DISK_PCT" -ge 90 ]; then
fail "disk usage at ${DISK_PCT}% (critical)"
elif [ "$DISK_PCT" -ge 80 ]; then
warn "disk usage at ${DISK_PCT}%"
else
pass "disk usage at ${DISK_PCT}%"
fi
fi

# Stale session sockets
SOCKET_DIR="$BAUDBOT_HOME/.pi/session-control"
if [ -d "$SOCKET_DIR" ]; then
STALE_SOCKS=0
if command -v fuser &>/dev/null; then
for sock in "$SOCKET_DIR"/*.sock; do
[ -e "$sock" ] || continue
if ! fuser "$sock" &>/dev/null 2>&1; then
STALE_SOCKS=$((STALE_SOCKS + 1))
fi
done
if [ "$STALE_SOCKS" -gt 0 ]; then
warn "$STALE_SOCKS stale session socket(s) in $SOCKET_DIR"
else
pass "no stale session sockets"
fi
else
warn "fuser not installed; skipping stale socket check"
fi
fi


# ── Summary ──────────────────────────────────────────────────────────────────

echo ""
Expand Down