openclaw - ✅(Solved) Fix [Bug]: Browser automation processes not cleaned up after cron/subagent tasks complete [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#60104Fetched 2026-04-08 02:36:13
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
0
Author
Participants
Timeline (top)
referenced ×3closed ×1cross-referenced ×1locked ×1

Fix Action

Fixed

PR fix notes

PR #60146: fix(browser): clean up browser tabs/processes when cron tasks and subagents complete

Description (problem / solution / changelog)

Problem

When cron tasks or subagents use browser automation (e.g., headless Chrome for web scraping, email checking, etc.), the browser processes are not cleaned up after the task completes. This leads to orphaned Chrome processes (PPID=1) accumulating over time, consuming memory and CPU resources.

Root Cause

closeTrackedBrowserTabsForSessions was only called during session-reset/session-delete (via ensureSessionRuntimeCleanup in session-reset-service.ts), but:

  1. Cron isolated runs complete without triggering a session reset — the session reaper (session-reaper.ts) only cleans up session store entries and transcript files, not browser processes.
  2. Subagent completions (completeSubagentRun in subagent-registry-lifecycle.ts) handle lifecycle hooks and announce flows but never close tracked browser tabs.

Fix

Add browser tab cleanup in two places:

  1. server-cron.ts: Wrap runCronIsolatedAgentTurn in try/finally to ensure browser tabs are cleaned up after every cron run, regardless of success or failure.
  2. subagent-registry-lifecycle.ts: Call closeTrackedBrowserTabsForSessions when a subagent run completes (in completeSubagentRun), before the announce cleanup flow begins.

Both cleanup calls are best-effort (errors are caught and logged) so they never mask the actual task result or break the completion flow.

Changes

  • src/gateway/server-cron.ts: Added try/finally around runCronIsolatedAgentTurn with browser tab cleanup in finally block
  • src/agents/subagent-registry-lifecycle.ts: Added browser tab cleanup call in completeSubagentRun before startSubagentAnnounceCleanupFlow

Testing

This fix addresses a real-world issue observed with cron tasks that use browser automation for monitoring (e.g., checking web-based messaging platforms). After 2-3 days of cron tasks running, dozens of orphaned Chrome processes accumulate.

Fixes #60104

Changed files

  • src/agents/subagent-registry-lifecycle.ts (modified, +14/-0)
  • src/gateway/server-cron.ts (modified, +26/-10)
RAW_BUFFERClick to expand / collapse

Problem

When cron tasks or subagents use browser automation (e.g., headless Chrome), the browser processes are not cleaned up after the task completes. This leads to orphaned processes accumulating over time.

Steps to Reproduce

  1. Create a cron task that uses browser automation (e.g., checking email via mail.163.com)
  2. Let the task run multiple times
  3. Observe Chrome processes accumulating: ps aux | grep openclaw/browser

Expected Behavior

Browser processes should be terminated when the parent subagent exits.

Actual Behavior

Browser processes become orphaned (PPID=1) and continue running indefinitely.

Evidence

After 2-3 days of cron tasks:

extent analysis

TL;DR

Implement a mechanism to explicitly terminate browser processes after each cron task completes to prevent orphaned processes from accumulating.

Guidance

  • Investigate using a process management tool or library to monitor and clean up child processes spawned by the cron tasks.
  • Modify the cron task script to include a step that kills any remaining browser processes after completion, using a command like pkill or killall.
  • Consider implementing a timeout or idle detection mechanism to automatically terminate browser processes that remain active for an extended period.
  • Review the subagent's exit handling to ensure it properly terminates any spawned processes before exiting.

Example

# Example cleanup step in a cron task script
pkill -f "openclaw/browser"

Notes

The exact implementation details may vary depending on the specific browser automation library and scripting language used. Additionally, care should be taken to avoid terminating unrelated processes.

Recommendation

Apply a workaround by implementing a cleanup mechanism in the cron task script to terminate browser processes after completion, as the root cause of the issue appears to be related to the subagent's exit handling and process management.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING