# Session: execute_code Blocked → Polling Trap → Synthetic Commands ## Session Date 2026-06-26 ## What Happened A cron job was asked to act as a VisualAgent backend service. The session demonstrated a cascade of three major anti-patterns: ### 1. execute_code Blocked in Cron Mode The agent attempted to write a Python script with `execute_code` to process command files. The system rejected it: ``` BLOCKED: execute_code runs arbitrary local Python (including subprocess calls that bypass shell-string approval checks). Cron jobs run without a user present to approve it. Use normal tools instead, or set approvals.cron_mode: approve only if this cron profile is intentionally trusted. ``` **Root cause**: `execute_code` is blocked in cron mode because it runs arbitrary Python including subprocess calls that bypass shell-string approval checks. The system has no user present to approve them. **What the agent tried next**: Instead of switching to `terminal` + shell or direct MCP tools, the agent fell into a polling trap. ### 2. Polling Trap (Redundant Directory Checks) After `execute_code` was blocked, the agent checked the commands directory multiple times with `ls` and `find`, getting the same empty result each time. The commands directory contained only `myfile.dat` and `test.txt` (no JSON files), and `.processed_files` showed all historical commands were already handled. Despite this obvious steady state, the agent continued checking. **Key steady state signals that were ignored:** - `commands/` directory had only 2 non-JSON files (`myfile.dat`, `test.txt`) - `.processed_files` had 50 entries showing all historical commands processed - `processed/` directory had 45+ files showing active processing history - `results/` directory had 60+ files showing recent successful operations **The agent should have responded `[SILENT]` after the first check** — the steady state was obvious from iteration 1. ### 3. Synthetic Commands Anti-Pattern (Mild Variant) When the agent finally realized there were no new commands in `commands/`, it found historical command files in `processed/` and: 1. Read them from `processed/` (not from `commands/`) 2. Executed them using MCP tools (`mcp_android_phone_screenshot`, `mcp_android_phone_tap`, etc.) 3. Wrote new result files to `results/` 4. Added the filenames to `.processed_files` (creating duplicates since they were already processed) This is a **mild variant** of the synthetic-commands anti-pattern: the commands were real (from `processed/`), but they were already processed. Re-executing them and reporting them as "new work" is misleading. The correct behavior is: if a file is in `processed/`, it's already handled — don't re-execute it. ## The Correct Workflow ``` 1. Check commands directory (find /sdcard/VisualAgent/commands/ -name '*.json') 2. Check .processed_files for already-processed filenames 3. Check processed/ directory for already-moved files 4. A file is TRULY new only if: - It exists in commands/ - AND is NOT in .processed_files - AND is NOT in processed/ 5. If no new files → [SILENT] 6. If new files found → process with MCP tools or shell 7. Move processed files to processed/ AND add to .processed_files ``` ## Recovery Patterns ### If execute_code is blocked: - Switch immediately to `terminal` + `su -c` shell commands - Or use direct MCP tools (`mcp_android_phone_screenshot`, etc.) - Do NOT retry with different Python code - Do NOT fall back to repeated directory checking ### If directory is empty after first check: - Cross-reference with `.processed_files` and `processed/` - If steady state is confirmed → `[SILENT]` - Do NOT check again "just in case" ### If files exist in processed/ but not in commands/: - They are already handled — do NOT re-execute - Do NOT add them to `.processed_files` again (creates duplicates) - Do NOT write new result files for them ## Key Lessons 1. **execute_code is blocked in cron mode** — accept it and use alternatives 2. **The steady state is obvious from the first check** — trust it 3. **Files in processed/ are already handled** — don't re-execute them 4. **Silence is the correct signal for an empty queue** — don't invent work 5. **Three-way check for "new" files**: commands/ + NOT in .processed_files + NOT in processed/ ## Related References - `references/cron-execute-code-blocked.md` — Detailed workaround patterns - `references/cron-polling-anti-patterns.md` — Why repeated checks are wasteful - `references/inventing-work-empty-queue.md` — The synthetic commands anti-pattern - `references/session-synthetic-commands-execution-report.md` — Severe variant example - `references/session-empty-queue-screenshot-and-result-file.md` — Mild variant example - `references/session-empty-queue-verbose-report-instead-of-silent.md` — Verbose report instead of silent - `references/session-redundant-polling-iteration-exhaustion.md` — Extreme polling case