Skip to content

Comments

fix: add automatic temp folder cleanup at Maestro startup#158

Merged
leonvanzyl merged 1 commit intoAutoForgeAI:masterfrom
Mediainvita:fix/temp-cleanup
Feb 5, 2026
Merged

fix: add automatic temp folder cleanup at Maestro startup#158
leonvanzyl merged 1 commit intoAutoForgeAI:masterfrom
Mediainvita:fix/temp-cleanup

Conversation

@Mediainvita
Copy link
Contributor

Summary

Adds automatic cleanup of stale temporary files at Maestro (orchestrator) startup to prevent temp folder bloat.

Problem: When AutoForge runs agents that use Playwright for browser testing or mongodb-memory-server for database tests, temporary files accumulate in the system temp folder. These files are never cleaned up automatically and can consume hundreds of GB over time.

Solution: New temp_cleanup.py module that runs at every Maestro startup (Play button click or auto-restart after rate limits).

What gets cleaned up

Pattern Description
playwright_firefoxdev_profile-* Playwright Firefox browser profiles
playwright-artifacts-* Playwright test artifacts
playwright-transform-cache Playwright transform cache
mongodb-memory-server* MongoDB Memory Server binaries
ng-* Angular CLI temp directories
scoped_dir* Chrome/Chromium temp directories
.78912*.node Node.js native module cache (~7MB each!)
claude-*-cwd Claude CLI working directory temp files
mat-debug-*.log Material/Angular debug logs

Safety

  • Only deletes files older than 1 hour - safe for running processes
  • Uses ignore_errors=True for graceful handling of locked files
  • Non-blocking: errors are logged but don't stop the agent

Changes

  • New file: temp_cleanup.py - Cleanup module with cleanup_stale_temp() function
  • Modified: autonomous_agent_demo.py - Calls cleanup at orchestrator startup (not in subprocess agents)

Testing

Manual test:

python temp_cleanup.py

Output: Cleanup complete: X dirs, Y files, Z MB freed

Integration test:

  1. Create test files with old timestamps:
    mkdir -p "$TEMP/playwright-artifacts-TESTDIR"
    touch -d "2 hours ago" "$TEMP/playwright-artifacts-TESTDIR"
    touch -d "2 hours ago" "$TEMP/.78912TEST-00000000.node"
  2. Start Maestro (click Play button in UI)
  3. Press D to open Debug panel
  4. Look for: [CLEANUP] Removed X dirs, Y files (Z MB freed)

Verified working:

Cleanup in Debug Log

Screenshot shows cleanup running at Maestro startup:

00:21:15 [ENTRY] autonomous_agent_demo.py starting...
00:21:15 [CLEANUP] Removed 1 dirs, 9 files (33.2 MB freed)
00:21:15 [ORCHESTRATOR] run_parallel_orchestrator called with max_concurrency=1

Why cleanup at Maestro startup?

  • Reliable hook point - runs every time Play is clicked or agent auto-restarts
  • No background timers needed - no extra complexity
  • Frequent enough - rate limit restarts happen every ~5 hours minimum
  • Safe timing - cleanup runs before new temp files are created

Closes #155

Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com

Problem:
When AutoForge runs agents that use Playwright for browser testing or
mongodb-memory-server for database tests, temporary files accumulate in
the system temp folder (%TEMP% on Windows, /tmp on Linux/macOS). These
files are never cleaned up automatically and can consume hundreds of GB
over time.

Affected temp items:
- playwright_firefoxdev_profile-* (browser profiles)
- playwright-artifacts-* (test artifacts)
- playwright-transform-cache
- mongodb-memory-server* (MongoDB binaries)
- ng-* (Angular CLI temp)
- scoped_dir* (Chrome/Chromium temp)
- .78912*.node (Node.js native module cache, ~7MB each)
- claude-*-cwd (Claude CLI working directory files)
- mat-debug-*.log (Material/Angular debug logs)

Solution:
- New temp_cleanup.py module with cleanup_stale_temp() function
- Called at Maestro (orchestrator) startup in autonomous_agent_demo.py
- Only deletes files/folders older than 1 hour (safe for running processes)
- Runs every time the Play button is clicked or agent auto-restarts
- Reports cleanup stats: dirs deleted, files deleted, MB freed

Why cleanup at Maestro startup:
- Reliable hook point (runs on every agent start, including auto-restart
  after rate limits which happens every ~5 hours)
- No need for background timers or scheduled tasks
- Cleanup happens before new temp files are created

Testing:
- Tested on Windows with 958 items in temp folder
- Successfully cleaned 45 dirs, 758 files, freed 415 MB
- Files younger than 1 hour correctly preserved

Closes AutoForgeAI#155

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@leonvanzyl leonvanzyl merged commit ee993ed into AutoForgeAI:master Feb 5, 2026
2 checks passed
@leonvanzyl
Copy link
Collaborator

Thanks

leonvanzyl added a commit that referenced this pull request Feb 5, 2026
PR #158 added temp_cleanup.py and its import in autonomous_agent_demo.py
but did not include the file in the package.json "files" array. This
caused ModuleNotFoundError for npm installations since the module was
missing from the published tarball.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@Mediainvita Mediainvita deleted the fix/temp-cleanup branch February 6, 2026 00:57
CoreAspectStu pushed a commit to CoreAspectStu/autocoder-custom that referenced this pull request Feb 9, 2026
fix: add automatic temp folder cleanup at Maestro startup
CoreAspectStu pushed a commit to CoreAspectStu/autocoder-custom that referenced this pull request Feb 9, 2026
PR AutoForgeAI#158 added temp_cleanup.py and its import in autonomous_agent_demo.py
but did not include the file in the package.json "files" array. This
caused ModuleNotFoundError for npm installations since the module was
missing from the published tarball.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Temp folder fills up with mongodb-memory-server data (hundreds of GB)

2 participants