Skip to content

fix: stop guard treats stale task.json as expired after 60 minutes#256

Merged
nikosbosse merged 2 commits intomainfrom
fix/stop-guard-stale-task
Mar 2, 2026
Merged

fix: stop guard treats stale task.json as expired after 60 minutes#256
nikosbosse merged 2 commits intomainfrom
fix/stop-guard-stale-task

Conversation

@nikosbosse
Copy link
Contributor

@nikosbosse nikosbosse commented Feb 28, 2026

Summary

  • Fixes a bug where a stale ~/.everyrow/task.json with "status": "running" blocks all Claude Code sessions from stopping indefinitely
  • The stop guard now checks file mtime (updated on every everyrow_progress poll) — if no poll has happened in 60 minutes, the session is likely dead, so it removes the file and allows the stop
  • Using mtime rather than started_at means long-running tasks that are still being actively polled won't be affected
  • Root cause: if a session crashes or is force-quit before everyrow_progress polling completes, SessionEnd doesn't always fire, leaving a permanent stale state file

Test plan

  • Existing tests updated: test 1 now includes started_at (matches real MCP server output)
  • New test 5: stale file mtime (2 hours old) → allows stop and removes file
  • New test 6: recent file mtime (just written) → still blocks as expected
  • All 6 tests pass: bash everyrow-mcp/tests/test_hook_stop_guard.sh
  • Results hook tests still pass: bash everyrow-mcp/tests/test_hook_results.sh

🤖 Generated with Claude Code

@nikosbosse nikosbosse force-pushed the fix/stop-guard-stale-task branch 2 times, most recently from 3284094 to 1ef58f8 Compare February 28, 2026 11:46
If a Claude Code session crashes or is force-quit before everyrow_progress
polling completes, ~/.everyrow/task.json stays with status "running"
forever. The SessionEnd hook doesn't always fire on force-quit, so the
stale file blocks ALL future sessions from stopping.

Add a staleness check using file mtime (which is updated on every
everyrow_progress poll). If no poll has happened in 60 minutes, the
session is likely dead — remove the file and allow the stop.

Using mtime rather than started_at means long-running tasks that are
still being actively polled won't be affected.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nikosbosse nikosbosse force-pushed the fix/stop-guard-stale-task branch from 1ef58f8 to 408d745 Compare February 28, 2026 11:46
@nikosbosse nikosbosse changed the title fix: stop guard treats stale task.json as expired after 30 minutes fix: stop guard treats stale task.json as expired after 60 minutes Feb 28, 2026
@nikosbosse nikosbosse requested a review from rgambee March 1, 2026 09:55
Copy link
Contributor

@rgambee rgambee left a comment

Choose a reason for hiding this comment

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

Thanks. I would like to get rid of this stop guard soon, but this is a helpful incremental improvement.

fi

TASK_FILE="$HOME/.everyrow/task.json"
STALE_SECONDS=3600 # 60 minutes
Copy link
Contributor

Choose a reason for hiding this comment

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

This could probably be lowered significantly. The file is supposed to update every 15 seconds or so. 5 minutes or even 1 minute of inactivity is likely a sign that it can be ignored.

@nikosbosse
Copy link
Contributor Author

Changed to 4 minutes. Will merge soon

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.

@nikosbosse nikosbosse merged commit e58d051 into main Mar 2, 2026
9 checks passed
@nikosbosse nikosbosse deleted the fix/stop-guard-stale-task branch March 2, 2026 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants