session-20260626-search-files-sdcard-failure.md 3.43 KB

Session 2026-06-26: search_files Fails on /sdcard/ Paths in Cron Mode

Context

Cron job on Pixel Fold (Android 16) checking /sdcard/VisualAgent/commands/ for pending JSON command files.

Tool Failure: search_files on /sdcard/

search_files fails on /sdcard/ paths with "Path not found" even when the directory exists and is accessible via terminal + su -c:

search_files(path="/sdcard/VisualAgent/commands", pattern="*.json", target="files")
→ "Path not found: /sdcard/VisualAgent/commands"

terminal: su -c 'ls /sdcard/VisualAgent/commands/'
→ myfile.dat  test.txt  (directory exists, no .json files)

This happened twice in the same session — retrying with identical arguments hit the tool-loop warning ("repeated_exact_failure_warning; count=2"). The failure affects both target='files' and target='content' modes on /sdcard/ paths.

Root Cause

The search_files tool appears unable to traverse the FUSE-mounted /sdcard/ filesystem from the cron execution context. The /sdcard/ path resolves through the FUSE symlink chain (/sdcard → /storage/self/primary → /storage/emulated/0), and the tool may not have the necessary mount namespace or filesystem access from cron.

Correct Workaround

Always use terminal + su -c for /sdcard/ file operations in cron:

# File discovery
su -c 'find /sdcard/VisualAgent/commands/ -maxdepth 1 -name "*.json" -type f'

# Directory listing
su -c 'ls -la /sdcard/VisualAgent/commands/'

# File reading
su -c 'cat /sdcard/VisualAgent/VisualAgent/.processed_files'

# File writing
su -c 'echo "content" > /sdcard/VisualAgent/commands/test.json'

Do NOT use read_file, write_file, search_files, or patch tools for /sdcard/ paths in cron mode.

Session-Specific Findings

Daemon Status

  • Daemon not running — daemon.pid was empty (write failed with "Permission denied" when started earlier)
  • visualagent_daemon.sh start reported "Permission denied" writing PID file but process started
  • Background process didn't survive shell exit — nohup blocked by Hermes

Preferred Cron Mode

  • Use visualagent_daemon.sh once for single-scan execution
  • Avoids daemon lifecycle issues entirely
  • Each cron invocation is independent

End-to-End Test

  • Created test command: {"command": "screenshot", "filename": "cron_e2e_test_screenshot.png"}
  • Ran visualagent_daemon.sh once → screenshot captured (1080x2364 PNG)
  • Result saved to both /sdcard/VisualAgent/results/screenshot_1782487195.png and /sdcard/VisualAgent/screenshots/cron_e2e_test_screenshot.png
  • Two different result JSON formats observed: {"status":"success",...} (daemon.sh) vs {"success":true,...} (service.py)

Corrupted File Detected

  • test_screenshot.json in processed/ was actually a PNG file (PNG magic bytes)
  • Caused "无法识别命令类型" error when daemon tried to parse it as JSON
  • Filed under the "Corrupted Command Files" pitfall

Found Infrastructure

  • 4 VisualAgent scripts in /data/data/com.termux/files/home/:
    • visualagent_service.py (Python, uses /data/local/tmp/VisualAgent/)
    • visualagent_daemon.sh (Shell, uses /sdcard/VisualAgent/, supports start/stop/once/file modes)
    • visualagent_processor.sh (Shell, uses /sdcard/VisualAgent/, basic grep-based JSON parsing)
    • visualagent_cron.sh (Wrapper that runs the Python version)
  • 45 previously processed command files in processed/
  • Recent activity: 2026-06-26 16:06 in daemon.log