fix: adaptive throttle for timer-based status updates#52
Open
sunchan-park wants to merge 1 commit intosix-ddc:mainfrom
Open
fix: adaptive throttle for timer-based status updates#52sunchan-park wants to merge 1 commit intosix-ddc:mainfrom
sunchan-park wants to merge 1 commit intosix-ddc:mainfrom
Conversation
…am rate limits
When Claude Code waits on a long-running task (e.g. agent sub-tasks),
the status line timer increments every second ("Thinking… 1s", "2s", …).
The status poller detects each tick as a text change and enqueues a
Telegram edit_message_text call — roughly 60/min. This quickly exceeds
Telegram's rate limit, triggering 429 responses and a flood-control ban
that silences the bot for extended periods.
Add _should_send_status() in status_polling.py that detects timer
suffixes via regex and applies an adaptive send interval based on how
long the same status has been active:
0–10 s → every 1 s (real-time, useful for short tasks)
10–60 s → every 5 s
60 s+ → every 30 s
Key design decisions:
- Poll interval stays at 1 s — interactive UI detection is unaffected
- Non-timer status changes always send immediately (no delay)
- Timer detection uses a trailing regex matching "5s", "1m 30s", etc.
- Intervals are configurable via STATUS_THROTTLE_INTERVALS env var
(comma-separated, e.g. "1,5,30"; set "1,1,1" to disable)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When Claude Code runs a long task (e.g. waiting for an agent sub-task), the terminal status line shows a timer that increments every second:
The status poller (
STATUS_POLL_INTERVAL = 1s) captures each tick as a new text change and enqueues anedit_message_textcall to Telegram — roughly 60 calls/min. This quickly exceeds Telegram's rate limits, triggering429 Too Many Requestsresponses.The existing
AIORateLimiter(max_retries=5)and flood-control logic handle the response but don't reduce the request rate, so the cycle repeats:In practice, this caused the bot to go completely unresponsive overnight while Claude Code was running long agent tasks. All queued messages arrived at once the next morning when the ban finally lifted.
Solution
Add
_should_send_status()instatus_polling.pythat detects timer suffixes via regex and applies an adaptive send interval based on how long the same status has been active:Timer detection
Claude Code uses two status line formats with timers:
The regex matches both patterns and extracts the "base text" (everything before the timer) for comparison — so if the task description changes (different base text), the throttle resets instantly and the new status sends immediately.
Key design decisions
Configuration
Intervals are configurable via
STATUS_THROTTLE_INTERVALSenv var (comma-separated seconds for the three elapsed-time tiers):Changes
src/ccbot/config.pystatus_throttle_intervalsconfig withSTATUS_THROTTLE_INTERVALSenv varsrc/ccbot/handlers/status_polling.py_should_send_status()adaptive throttle, call beforeenqueue_status_update()tests/ccbot/handlers/test_timer_throttle.pytests/ccbot/test_config.pyTest plan
5s,1m 30s,2m,5s (Esc to interrupt)(54s · ↓ 776 tokens),(25m 8s · ↓ 5.8k · …)Reading file.py,file2s,Bash echo helloSTATUS_THROTTLE_INTERVALSworkCoalescing…,Drizzling…)🤖 Generated with Claude Code