smart-poll-loop
Skill này làm gì
Skill này mô tả một vòng lặp kiểm tra (polling) sẽ chậm lại khi dịch vụ liên tục lỗi và tăng tốc trở lại sau khi thành công. Skill dành cho lập trình viên kiểm tra các dịch vụ bên ngoài thường xuyên.
Khi nào nên dùng
- ✓Khi bạn kiểm tra một dịch vụ bên ngoài theo bộ hẹn giờ và đôi khi nó bị lỗi.
- ✓Khi các yêu cầu lỗi lặp lại có thể làm quá tải một dịch vụ đang gặp khó khăn.
- ✓Khi bạn muốn việc kiểm tra trở lại tốc độ bình thường ngay khi dịch vụ phục hồi.
Liên kết skill
https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/smart-poll-loop/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Bạn có thể kiểm tra trạng thái máy chủ của tôi mỗi phút nhưng giảm tốc độ kiểm tra khi nó liên tục lỗi không?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Sau mỗi lần lỗi, thời gian chờ tăng gấp đôi, đến một giới hạn đặt sẵn. Sau một lần thành công, vòng lặp quay lại khoảng thời gian bình thường.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
Câu hỏi thường gặp
Thời gian chờ có thể dài đến đâu?
Skill đặt một hệ số tối đa, thường gấp bốn đến tám lần khoảng thời gian bình thường.
Một lần thành công có đặt lại thời gian chờ không?
Có. Một lần kiểm tra thành công đưa vòng lặp về tốc độ bình thường.
Nó có dừng thử sau nhiều lần lỗi không?
Vòng lặp tiếp tục chạy ở thời gian chờ dài nhất, nên sẽ kiểm tra lại khi dịch vụ quay lại.
Chi tiết
Mô tả gốc của tác giả
Adaptive polling pattern with exponential backoff on failure, automatic recovery on success, and visibility-aware scheduling
repo: HKUDS/AgentPilot
Độ phổ biến
- Sao GitHub
- 7.8k
- Vị trí xếp hạng
- #13082
- Giấy phép
- MIT
- Cập nhật
- 1/11/2026
Bình luận
- …
Thêm skill từ kho mã này
agentpilot
7.8kGiúp agent của bạn cải thiện dự án từng bước bằng cách chuẩn bị tác vụ và chạy vòng lặp AgentPilot, gồm đề xuất, kiểm thử và chấm điểm thay đổi.
openspace
7.8kGiúp agent của bạn thiết lập OpenSpace, công cụ lưu và lấy lại skill của agent, rồi kết nối nó với ứng dụng AI của bạn qua MCP.
rsi-arena
7.8kGiúp agent của bạn thiết lập và chạy các bài kiểm thử benchmark AI chuẩn, như AIME và Terminal-Bench, để so sánh các phương pháp cải tiến khác nhau.
experiment-guide
7.8kGiúp agent của bạn lên kế hoạch các thí nghiệm nhỏ, đọc kết quả và ghi lại phát hiện khi tìm cách cải thiện một chương trình.
Skill tương tự
diffs
394kGiúp agent của bạn tạo một diff có thể chia sẻ về các chỉnh sửa, dưới dạng liên kết xem hoặc file ảnh, thay vì một bản tóm tắt viết tay.
coding-agent
394kGiúp agent của bạn giao một việc lập trình lớn cho Codex, Claude Code hoặc OpenCode chạy nền, rồi theo dõi tiến độ của nó.
gh-issues
394kGiúp agent của bạn tìm issue trên GitHub, chọn những issue cần xử lý và mở pull request với bản sửa, kể cả theo dõi nhận xét đánh giá.