Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions everyrow-mcp/scripts/everyrow-stop-guard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,29 @@ if [ "$STOP_HOOK_ACTIVE" = "true" ]; then
fi

TASK_FILE="$HOME/.everyrow/task.json"
STALE_SECONDS=240 # 4 minutes
Copy link

Choose a reason for hiding this comment

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

Bug: The STALE_SECONDS variable is set to 240 (4 minutes), but the documented intent is 60 minutes, which could cause premature termination of active sessions.
Severity: CRITICAL

Suggested Fix

In everyrow-stop-guard.sh, change the value of STALE_SECONDS from 240 to 3600 to align with the documented 60-minute timeout.

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: everyrow-mcp/scripts/everyrow-stop-guard.sh#L16

Potential issue: The script `everyrow-stop-guard.sh` sets a timeout of 4 minutes
(`STALE_SECONDS=240`) to determine if a session is stale. However, the PR description
and commit message state the intended timeout is 60 minutes. With polling happening
approximately every 12 seconds, any task experiencing a delay longer than 4 minutes due
to network issues or system load will be incorrectly terminated. This aggressive timeout
contradicts the intended safety margin and will lead to the premature termination of
potentially active user sessions.

Did we get this right? 👍 / 👎 to inform future reviews.


if [ -f "$TASK_FILE" ]; then
STATUS=$(jq -r '.status' "$TASK_FILE")
TASK_ID=$(jq -r '.task_id' "$TASK_FILE")

if [ "$STATUS" = "running" ]; then
# Check staleness using file mtime (updated on every everyrow_progress poll).
# If no poll has happened in STALE_SECONDS, the session that started this
# task is likely dead — clean up rather than blocking all future sessions.
if [[ "$(uname)" == "Darwin" ]]; then
FILE_MTIME=$(stat -f %m "$TASK_FILE")
else
FILE_MTIME=$(stat -c %Y "$TASK_FILE")
fi
NOW=$(date +%s)
ELAPSED=$(( NOW - FILE_MTIME ))

if [ "$ELAPSED" -gt "$STALE_SECONDS" ]; then
rm -f "$TASK_FILE"
exit 0
fi

jq -n \
--arg reason "[everyrow] Task $TASK_ID still running. Call everyrow_progress(task_id=\"$TASK_ID\") to check status." \
'{decision: "block", reason: $reason}'
Expand Down
20 changes: 18 additions & 2 deletions everyrow-mcp/tests/test_hook_stop_guard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ TASK_FILE="$HOME/.everyrow/task.json"
mkdir -p "$HOME/.everyrow"
rm -f "$TASK_FILE"

# Test 1: Blocks when task is running
echo '{"task_id":"abc-123","status":"running","total":50,"completed":10}' > "$TASK_FILE"
# Test 1: Blocks when task is running (recently started)
NOW=$(date +%s)
echo "{\"task_id\":\"abc-123\",\"status\":\"running\",\"total\":50,\"completed\":10,\"started_at\":$NOW}" > "$TASK_FILE"
RESULT=$(echo '{"stop_hook_active": false}' | bash "$SCRIPT_DIR/everyrow-stop-guard.sh")
echo "$RESULT" | jq -e '.decision == "block"' || { echo "FAIL: should block"; exit 1; }
echo "$RESULT" | jq -e '.reason | contains("abc-123")' || { echo "FAIL: reason should contain task_id"; exit 1; }
Expand All @@ -31,6 +32,21 @@ RESULT=$(echo '{"stop_hook_active": false}' | bash "$SCRIPT_DIR/everyrow-stop-gu
[ -z "$RESULT" ] || { echo "FAIL: should allow when completed"; exit 1; }
echo "PASS: allows when completed"

# Test 5: Allows when task file is stale (mtime > 30 min ago)
echo "{\"task_id\":\"abc-123\",\"status\":\"running\",\"total\":50,\"completed\":10,\"started_at\":$NOW}" > "$TASK_FILE"
# Set file mtime to 2 hours ago
touch -t "$(date -v-2H '+%Y%m%d%H%M.%S' 2>/dev/null || date -d '2 hours ago' '+%Y%m%d%H%M.%S')" "$TASK_FILE"
RESULT=$(echo '{"stop_hook_active": false}' | bash "$SCRIPT_DIR/everyrow-stop-guard.sh")
[ -z "$RESULT" ] || { echo "FAIL: should allow when stale"; exit 1; }
[ ! -f "$TASK_FILE" ] || { echo "FAIL: should remove stale task file"; exit 1; }
echo "PASS: allows and cleans up stale task (mtime-based)"

# Test 6: Blocks when task file is recent (mtime < 30 min ago, i.e. just written)
echo "{\"task_id\":\"abc-123\",\"status\":\"running\",\"total\":50,\"completed\":10,\"started_at\":$NOW}" > "$TASK_FILE"
RESULT=$(echo '{"stop_hook_active": false}' | bash "$SCRIPT_DIR/everyrow-stop-guard.sh")
echo "$RESULT" | jq -e '.decision == "block"' || { echo "FAIL: should block recent task"; exit 1; }
echo "PASS: blocks recent running task"

# Cleanup
rm -f "$TASK_FILE"
echo "ALL PASS: stop guard"