# Session Example: Redundant Polling Anti-Pattern (Extreme Case) ## Context Cron job running as VisualAgent backend service. Task: monitor `/sdcard/VisualAgent/commands/` for new `.json` command files, execute them, save results to `/sdcard/VisualAgent/results/`. ## What Happened 1. **First check** (iteration 1): `su -c "ls -la /sdcard/VisualAgent/commands/"` returned: - `myfile.dat` (13 bytes, not JSON) - `test.txt` (5 bytes, not JSON) - No `.json` files present 2. **`.processed_files` check** (iteration 1): Listed 7 already-processed files: - `test_screenshot.json`, `test_tap.json`, `va_cmd.json`, `va_tap.json`, `va_swipe.json`, `va_input.json`, `va_app.json` 3. **Subsequent behavior**: The agent ran the **exact same `ls` command 130+ times** across iterations 2-133, each time getting the same result (no JSON files, same two non-JSON files). 4. **Outcome**: Hit the max tool-calling iteration limit. Final response was forced to summarize findings without completing any actual work. ## Root Cause The agent was waiting for new command files to appear, but: - No new files were being dropped into the directory - The two existing files were not JSON and not valid commands - The agent kept polling instead of recognizing the "steady state" and responding `[SILENT]` ## Correct Behavior After the first check confirms: 1. Directory exists ✓ 2. No `.json` files present ✓ 3. `.processed_files` shows all historical commands were handled ✓ → **Respond `[SILENT]` immediately.** No further checks needed. ## The Steady State Signal When ALL of these are true, the service is in "steady state": - Commands directory exists and is readable - No unprocessed `.json` files (after checking both `ls` and cross-referencing `.processed_files`) - Results directory exists - Historical processed files are recorded (in `.processed_files` or `processed/` directory) The existence of processed-file tracking (`.processed_files` with entries, or files in `processed/`) is evidence that the service infrastructure is operational. No health check is needed. ## Anti-Pattern Checklist - [ ] Ran the same command more than 3 times with identical arguments - [ ] Got the same result each time - [ ] Did not change strategy after repeated identical results - [ ] Did not respond `[SILENT]` when directory was clearly empty - [ ] Hit iteration limit without producing meaningful output If any box is checked, you fell into the redundant polling trap. ## Recovery If you realize you're in a polling loop: 1. Stop immediately — do not run the command again 2. Assess: has anything changed since the last check? 3. If no → respond `[SILENT]` 4. If yes but you can't process it → explain the blocker 5. Never retry the exact same command more than twice ## Cross-References - `references/cron-polling-anti-patterns.md` — General polling guidance - `references/cron-empty-directory-silent-pattern.md` — When to respond `[SILENT]` - `references/tool-loop-guardrail.md` — What happens when you retry too many times