claude-code - 💡(How to fix) Fix Bash: sleep ≥2s blocked unconditionally, breaking legitimate polling/heartbeat patterns [2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#48280Fetched 2026-04-16 07:04:16
View on GitHub
Comments
2
Participants
3
Timeline
4
Reactions
1
Timeline (top)
commented ×2labeled ×2

The harness blocks any sleep N command where N ≥ 2 seconds, even when the sleep is a deliberate, intentional delay (e.g. heartbeat/poll loops). This makes it impossible to implement backoff-based polling within a single agent run.

Error Message

The current hard 2-second cap is too aggressive — it blocks legitimate use cases while the error message itself admits deliberate pacing is valid.

Root Cause

This is a textbook heartbeat pattern. The run_in_background workaround doesn't compose well here because each heartbeat step depends on the result of the previous poll — it's not a fire-and-forget.

Fix Action

Workaround

Currently forced to rely on the scheduled task's own firing frequency as a proxy for the heartbeat, which is much coarser and loses the adaptive backoff behavior.

RAW_BUFFERClick to expand / collapse

Summary

The harness blocks any sleep N command where N ≥ 2 seconds, even when the sleep is a deliberate, intentional delay (e.g. heartbeat/poll loops). This makes it impossible to implement backoff-based polling within a single agent run.

Current behavior

Running: ```bash sleep 30 && echo "heartbeat" ```

Results in:

Blocked: sleep 30 followed by: echo "heartbeat". Run blocking commands in the background with run_in_background: true — you'll get a completion notification when done. For streaming events (watching logs, polling APIs), use the Monitor tool. If you genuinely need a delay (rate limiting, deliberate pacing), keep it under 2 seconds.

Expected behavior

sleep N should be allowed when the agent has a clear reason to wait (rate limiting, deliberate pacing between API calls, heartbeat polling). The block message itself acknowledges this: "If you genuinely need a delay (rate limiting, deliberate pacing), keep it under 2 seconds" — but 2 seconds is far too short for any real polling use case.

Concrete use case

I have a scheduled agent that:

  1. Sends replies to a chat group
  2. Needs to wait 30s, then poll again to catch follow-up messages (exponential backoff: 30s → 1m → 2m → 3m → 4m)
  3. Exits after 5 consecutive empty polls (~10 min total)

This is a textbook heartbeat pattern. The run_in_background workaround doesn't compose well here because each heartbeat step depends on the result of the previous poll — it's not a fire-and-forget.

Workaround

Currently forced to rely on the scheduled task's own firing frequency as a proxy for the heartbeat, which is much coarser and loses the adaptive backoff behavior.

Suggested fix

Either:

  • Raise the sleep threshold (e.g. allow up to 300s), or
  • Allow sleep when the agent explicitly states intent (opt-in via a comment or flag), or
  • Treat sleep inside a pipeline (sleep 30 && poll_command) differently from a bare sleep call

The current hard 2-second cap is too aggressive — it blocks legitimate use cases while the error message itself admits deliberate pacing is valid.

extent analysis

TL;DR

The most likely fix is to adjust the harness to allow longer sleep times for deliberate delays, such as raising the sleep threshold or introducing an opt-in mechanism.

Guidance

  • Review the suggested fixes provided, including raising the sleep threshold, allowing sleep with explicit intent, or treating sleep inside a pipeline differently.
  • Consider the specific use case of heartbeat polling and exponential backoff, where a 2-second sleep limit is too restrictive.
  • Evaluate the current workaround of relying on the scheduled task's firing frequency and its limitations.
  • Investigate the possibility of using a comment or flag to indicate intentional sleep for rate limiting or pacing.

Example

No code snippet is provided as the issue is more related to the harness configuration and behavior rather than a specific code implementation.

Notes

The current implementation of the harness blocks sleep commands with durations of 2 seconds or more, which affects legitimate use cases such as heartbeat polling and exponential backoff. The suggested fixes aim to address this limitation while still preventing unnecessary or accidental long-running commands.

Recommendation

Apply a workaround by adjusting the harness configuration to allow longer sleep times for deliberate delays, such as raising the sleep threshold to 300 seconds, to accommodate legitimate use cases like heartbeat polling.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

sleep N should be allowed when the agent has a clear reason to wait (rate limiting, deliberate pacing between API calls, heartbeat polling). The block message itself acknowledges this: "If you genuinely need a delay (rate limiting, deliberate pacing), keep it under 2 seconds" — but 2 seconds is far too short for any real polling use case.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Bash: sleep ≥2s blocked unconditionally, breaking legitimate polling/heartbeat patterns [2 comments, 3 participants]