.claude/skills/polling-loop-finalization-escape/SKILL.md
Fix polling loops that repeat finalization actions instead of exiting after a trigger. Use when: (1) a return/completion signal is detected but the loop keeps running and re-triggering the same action, (2) "resilient" try/except blocks inside a polling loop cause the loop to continue after a finalization error, (3) repeated dock/stop/ cleanup commands are sent when only one was expected. The pattern: inner finalization steps are individually try/excepted for resilience, but an outer except catches unexpected errors and doesn't exit, causing the loop to re-detect the trigger.
npx skillsauth add Dbochman/dotfiles polling-loop-finalization-escapeInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
A polling loop detects a trigger condition (e.g., "return home detected"), executes finalization steps (dock Roombas, send notification, update state), then should exit. But if any exception occurs during finalization that isn't caught by the inner try/except blocks, the outer loop's generic except Exception handler catches it, logs the error, and continues the loop — causing the trigger to be re-detected and finalization to re-execute on every poll cycle.
if trigger_condition: ... return finalization blockexcept Exception around the entire poll iteration that logs but doesn't returnEnsure the outer exception handler checks whether the trigger was already detected, and if so, exits instead of looping:
# BEFORE (broken): exception during finalization causes loop to continue
while polling:
try:
if detect_trigger():
try:
finalize_step_1()
except Exception:
log("step 1 failed (non-fatal)")
try:
finalize_step_2() # <-- unexpected error here
except Exception:
log("step 2 failed (non-fatal)")
return # never reached if step_2 throws something uncaught
except Exception as e:
log(f"Error: {e}") # catches it, but doesn't exit!
await sleep(interval) # loops back and re-triggers
# AFTER (fixed): outer handler respects the trigger state
while polling:
trigger = None
try:
trigger = detect_trigger()
if trigger:
# ... finalization steps ...
return
except Exception as e:
log(f"Error: {e}")
if trigger:
log("Exiting despite error (trigger was already detected)")
return # don't loop back and re-trigger
await sleep(interval)
After fix, logs should show exactly one "trigger detected" + "docking" sequence, then the monitor ends. No repeated dock commands at 30s intervals.
UnboundLocalError on a variable that appears unreachable) — fixing the exception alone isn't sufficient because other future exceptions could cause the same loop behaviordevelopment
Search the web for current information, news, facts, and answers. Use when asked questions about current events, needing to look something up, finding websites, researching topics, or when you need up-to-date information beyond your training data.
development
Summarize any URL, YouTube video, podcast, PDF, or file into concise text. Use when asked to read an article, summarize a link, get the gist of a video or podcast, extract content from a URL, or when you need to understand what a web page or document contains.
development
Play music via Spotify and control Google Home speakers. Use when asked to play music, songs, artists, playlists, podcasts, or control speakers/volume/audio.
testing
Create new OpenClaw skills, modify and improve existing skills, and measure skill performance with evals. Use when users want to create a skill from scratch, update or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. Also use when asked to "make a skill", "turn this into a skill", "improve this skill", or "test this skill".