smart-poll-loop
यह क्या करती है
यह स्किल एक पोलिंग लूप का वर्णन करती है जो सेवा लगातार फेल होने पर धीमा हो जाता है और सफलता मिलने पर फिर तेज़ हो जाता है। यह उन डेवलपर्स के लिए है जो बाहरी सेवाओं की नियमित जाँच करते हैं।
कब इस्तेमाल करें
- ✓जब आप किसी बाहरी सेवा को टाइमर पर जाँचते हैं और वह कभी-कभी फेल होती है।
- ✓जब बार-बार विफल अनुरोध किसी परेशान सेवा पर बोझ डाल सकते हैं।
- ✓जब आप चाहते हैं कि सेवा ठीक होते ही जाँच सामान्य गति पर लौट आए।
Skill का लिंक
https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/smart-poll-loop/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“क्या आप मेरे सर्वर स्टेटस की हर मिनट जाँच कर सकते हैं, पर जब तक वह फेल हो रहा हो तब तक जाँच की गति धीमी रखें?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
हर विफलता के बाद प्रतीक्षा समय दोगुना हो जाता है, एक तय सीमा तक। सफलता मिलने पर लूप सामान्य अंतराल पर लौट आता है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Smart Poll Loop Pattern
Overview
The Smart Poll Loop pattern implements resilient, adaptive polling for periodic data refresh operations. It combines exponential backoff on consecutive failures with automatic recovery on success, ensuring system resources are protected during outages while maintaining responsiveness when services are healthy.
This pattern is essential for production applications that need to poll external services or APIs continuously but must gracefully handle intermittent failures, rate limits, or temporary service disruptions without overwhelming the system or degrading user experience.
Key Patterns Identified
Pattern 1: Exponential Backoff on Failure
Purpose: Prevent overwhelming failing services with repeated requests while giving them time to recover.
Implementation: Each consecutive failure doubles the polling interval up to a configurable maximum multiplier. This creates exponentially increasing delays: 1x → 2x → 4x → 8x (default max).
Key Elements:
consecutiveFailures: Counter tracking sequential failurescurrentBackoffMultiplier: Current delay multiplier (starts at 1)maxBackoffMultiplier: Upper bound to prevent infinite delays (typically 4-8x)- Boolean return from callbacks (
true= success,false= failure)
Code Pattern:
// Track failure state per runner
interface RunnerEntry {
consecutiveFailures: number;
currentBackoffMultiplier: number;
intervalMs: number; // base interval
// ... other fields
}
// On failure, increase backoff
if (!success) {
entry.consecutiveFailures++;
const newMultiplier = Math.min(
Math.pow(2, entry.consecutiveFailures),
maxBackoffMultiplier
);
entry.currentBackoffMultiplier = newMultiplier;
// Reschedule with new interval
const effectiveInterval = entry.intervalMs * entry.currentBackoffMultiplier;
scheduleNextRun(effectiveInterval);
}
Pattern 2: Automatic Recovery on Success
Purpose: Immediately restore normal polling frequency when a service recovers, ensuring fresh data flows without unnecessary delay.
Implementation: On any successful callback execution, reset both the failure counter and backoff multiplier to their initial states (0 and 1), then reschedule at the base interval.
Key Elements:
- Reset logic triggered by
success === trueor no error thrown - Immediate rescheduling at base interval (no waiting for current timer)
- Logging state transitions for observability
Code Pattern:
if (success) {
// Auto-recovery: reset backoff and failure count
if (entry.consecutiveFailures > 0 || entry.currentBackoffMultiplier > 1) {
entry.consecutiveFailures = 0;
entry.currentBackoffMultiplier = 1;
// Immediately reschedule at normal interval
if (!paused && entry.timer) {
scheduleNextRun(name, entry); // uses base intervalMs
}
}
}
Pattern 3: Failure Detection via Boolean Return or Exception
Purpose: Provide flexible signaling for success/failure states, supporting both explicit boolean returns and exception-based error handling.
Implementation: Callbacks can return boolean (explicit success/failure), void (success assumed), or throw exceptions (failure). All three mechanisms trigger the same backoff/recovery logic.
Key Elements:
- Type signature:
() => Promise<boolean | void> true= explicit success, triggers recoveryfalse= explicit failure, triggers backoffvoid/undefined= implicit success (no news is good news)- Exception thrown = failure, triggers backoff
Code Pattern:
let success = true;
try {
const result = await entry.fn();
// Boolean return indicates explicit success/failure
if (typeof result === 'boolean') {
success = result;
}
// void/undefined is treated as success
if (success) {
// trigger recovery...
} else {
// trigger backoff...
}
} catch (err) {
// Exception is also treated as failure
success = false;
// trigger backoff...
}
Pattern 4: Visibility-Aware Scheduling
Purpose: Pause or slow down polling when the page is hidden to conserve resources, then resume or refresh immediately when visible.
Implementation: Listen to visibilitychange events. On hide, clear all timers. On show, either flush stale data (if enough time passed) or resume normal polling.
Key Elements:
document.hiddenstate checkpauseWhenHiddenflag (full stop vs slower polling
अक्सर पूछे जाने वाले सवाल
प्रतीक्षा कितनी लंबी हो सकती है?
स्किल एक अधिकतम गुणक तय करती है, आम तौर पर सामान्य अंतराल का चार से आठ गुना।
क्या एक सफलता प्रतीक्षा को रीसेट करती है?
हां। एक सफल जाँच लूप को उसकी सामान्य गति पर लौटा देती है।
क्या कुछ विफलताओं के बाद यह कोशिश बंद कर देता है?
लूप अपने सबसे लंबे इंतज़ार पर चलता रहता है, इसलिए सेवा लौटने पर जाँच फिर शुरू हो जाती है।
जानकारी
लेखक का मूल विवरण
Adaptive polling pattern with exponential backoff on failure, automatic recovery on success, and visibility-aware scheduling
repo: HKUDS/AgentPilot
लोकप्रियता
- GitHub स्टार
- 7.8k
- रैंकिंग में स्थान
- #13082
- लाइसेंस
- MIT
- अपडेट की गई
- 1/11/2026
कमेंट
- …
इस repository की और skills
agentpilot
7.8kआपके एजेंट को AgentPilot से प्रोजेक्ट को चरण-दर-चरण सुधारने में मदद करती है, जिसमें बदलाव सुझाए, परखे और स्कोर किए जाते हैं।
openspace
7.8kआपके एजेंट को OpenSpace सेट करने में मदद करती है, जो एजेंट स्किल्स सहेजता और वापस लाता है, और MCP के ज़रिए आपके AI ऐप से जुड़ता है।
rsi-arena
7.8kआपके एजेंट को AIME और Terminal-Bench जैसे मानक AI बेंचमार्क टेस्ट सेट करने और चलाने में मदद करती है, ताकि सुधार के तरीकों की तुलना हो सके।
experiment-guide
7.8kआपके एजेंट को छोटे प्रयोग बनाने, उनके नतीजे पढ़ने और जाँच के दौरान उपयोगी निष्कर्ष लिखने में मदद करती है।
मिलती-जुलती skills
diffs
394kयह आपके एजेंट को बदलावों का असली diff बनाने देती है, जिसे व्यूअर लिंक या इमेज फ़ाइल के रूप में साझा किया जा सकता है, हाथ से लिखे सारांश के बजाय।
coding-agent
394kयह आपके एजेंट को बड़े कोडिंग काम Codex, Claude Code या OpenCode को बैकग्राउंड वर्कर के रूप में सौंपने, फिर उसकी प्रगति जांचने में मदद करती है।
gh-issues
394kयह आपके एजेंट को GitHub issues खोजने, उनमें से काम करने लायक चुनने, और सुधार के साथ pull requests खोलने में मदद करती है, जिसमें समीक्षा टिप्पणियों का फ़ॉलो-अप भी शामिल है।