openclaw - ✅(Solved) Fix TUI processes peg 100% CPU each and survive terminal close, eating all RAM [1 pull requests, 2 comments, 3 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#75289Fetched 2026-05-01 05:35:44
View on GitHub
Comments
2
Participants
3
Timeline
8
Reactions
2
Timeline (top)
cross-referenced ×4commented ×2referenced ×2

openclaw-tui processes spin at 100% CPU per process and do not exit when the controlling terminal closes or when the gateway restarts. On a 16 GB Mac mini running the gateway as a LaunchAgent, this repeatedly causes the machine to run out of RAM and swap-thrash until macOS kills processes or the machine becomes unresponsive.

The TUI processes also resist kill (SIGTERM) and require kill -9 (SIGKILL) to terminate.

Error Message

PID    PROCESS          RAM      CPU
5302   openclaw-tui     1.1 GB   98%
4728   openclaw-tui     1.0 GB   99%
5696   openclaw-tui     810 MB   74%
4909   openclaw-gateway 1.1 GB   2%

Root Cause

Root cause analysis (partial)

Fix Action

Workaround

pkill -9 openclaw-tui

PR fix notes

PR #75294: fix(tui): bound shutdown after terminal hangup

Description (problem / solution / changelog)

Summary

  • handle POSIX SIGHUP as a TUI shutdown signal so terminal-tab close follows the same exit path as SIGTERM
  • stop status loader/timers before exit cleanup and bound terminal drain to avoid orphaned spinner/render loops
  • keep normal Ctrl+C behavior unchanged while making signal shutdown best-effort and idempotent

Fixes #75289.

Pre-implement audit

  • Existing helper: reused drainAndStopTuiSafely / stopTuiSafely shape and added a bounded exit-only wrapper instead of changing normal suspend behavior.
  • Shared callers: drainAndStopTuiSafely remains unchanged for existing callers; runTui uses the new exit-only helper only on shutdown.
  • Broader rival: no open PR references #75289; existing TUI PRs target different surfaces.

Tests

  • pnpm exec oxfmt --check --threads=1 CHANGELOG.md src/tui/tui.ts src/tui/tui.test.ts
  • pnpm test src/tui/tui.test.ts -- --run
  • pnpm check:changed (passes conflict/changelog/extension guards, duplicate coverage, core typecheck, core test typecheck; fails at existing oxlint config parse: Rule 'no-underscore-dangle' not found in plugin 'eslint')

Changed files

  • CHANGELOG.md (modified, +1/-0)
  • src/tui/tui.test.ts (modified, +61/-0)
  • src/tui/tui.ts (modified, +62/-6)

Code Example

PID    PROCESS          RAM      CPU
5302   openclaw-tui     1.1 GB   98%
4728   openclaw-tui     1.0 GB   99%
5696   openclaw-tui     810 MB   74%
4909   openclaw-gateway 1.1 GB   2%

---

pkill -9 openclaw-tui
RAW_BUFFERClick to expand / collapse

Summary

openclaw-tui processes spin at 100% CPU per process and do not exit when the controlling terminal closes or when the gateway restarts. On a 16 GB Mac mini running the gateway as a LaunchAgent, this repeatedly causes the machine to run out of RAM and swap-thrash until macOS kills processes or the machine becomes unresponsive.

The TUI processes also resist kill (SIGTERM) and require kill -9 (SIGKILL) to terminate.

Environment

  • OpenClaw: 2026.4.29 (a448042)
  • Node: v25.6.1
  • OS: macOS Darwin 25.3.0 (Mac mini, Apple Silicon, 16 GB RAM)
  • Gateway mode: local loopback LaunchAgent, port 18789
  • TUI invocation: openclaw tui --session <name>

Reproduction

  1. Start the gateway via LaunchAgent
  2. Open openclaw tui --session provisioning in a terminal tab
  3. Either: (a) close the terminal tab, or (b) gateway restarts (e.g., after brew upgrade or openclaw doctor --fix rewrites the plist)
  4. The openclaw-tui process does not exit. It continues running at 100% CPU with ~900 MB RSS
  5. Opening new terminal tabs and running openclaw tui creates additional TUI processes that also spin
  6. Within minutes, 3-5 orphaned TUI processes consume 3-5 GB RAM and 300-500% CPU

Observed behavior

PID    PROCESS          RAM      CPU
5302   openclaw-tui     1.1 GB   98%
4728   openclaw-tui     1.0 GB   99%
5696   openclaw-tui     810 MB   74%
4909   openclaw-gateway 1.1 GB   2%
  • kill <pid> (SIGTERM) does not terminate TUI processes
  • kill -9 <pid> is required
  • Machine reaches 15/16 GB RAM used, 77 MB free, then swap-thrashes
  • Gateway itself is fine (2% CPU, connectivity probe passes)
  • This has happened multiple times across sessions

Root cause analysis (partial)

Code inspection of tui-DN9rW-QU.js and pi-tui shows:

  1. No SIGHUP handler. The TUI registers handlers for SIGINT and SIGTERM (lines 4626-4627) but not SIGHUP. When a terminal tab closes, macOS sends SIGHUP. Node.js default SIGHUP behavior (exit) can be suppressed if any other code path registers a SIGHUP listener. attachChildProcessBridge in child-process-bridge-BMx3So6b.js temporarily registers one, which may leave a window where SIGHUP is swallowed.

  2. SIGTERM handler calls requestExit() but the exit path may hang. requestExit() calls client.stop() then drainAndStopTuiSafely(tui), which calls tui.stop(). If tui.stop() tries to write to a dead stdout (terminal already closed), this could block or fail silently, preventing the process from actually exiting.

  3. Loader animation keeps firing. The Loader component (pi-tui/dist/components/loader.js) runs a setInterval at 80ms that calls requestRender() on every tick. Each render writes to process.stdout. When stdout is a dead pipe (orphaned process), these writes may fail in a way that triggers immediate re-rendering rather than backing off.

  4. The gateway client reconnect loop is properly throttled (exponential backoff 1s to 30s in client-CLNzli6Y.js:706-721), so the spin is not from reconnection attempts.

The exact mechanism causing 100% CPU in orphaned processes could not be fully pinned down via static analysis. Profiling a live orphaned process with --prof or --cpu-prof would identify the hot function.

Expected behavior

  • TUI should exit when its controlling terminal closes (handle SIGHUP)
  • TUI should exit cleanly on SIGTERM without requiring SIGKILL
  • TUI should not spin at 100% CPU when disconnected from the gateway
  • TUI should not accumulate multiple zombie processes across gateway restarts

Workaround

pkill -9 openclaw-tui

extent analysis

TL;DR

The most likely fix involves implementing a SIGHUP handler in the TUI process to ensure it exits cleanly when the controlling terminal closes.

Guidance

  • Register a SIGHUP handler in the TUI process to catch the signal sent when the terminal tab closes, allowing the process to exit cleanly.
  • Review the SIGTERM handler to ensure that requestExit() and subsequent calls do not hang due to attempts to write to a dead stdout.
  • Consider modifying the Loader component to stop firing when the process is orphaned or the stdout is a dead pipe.
  • Profile a live orphaned process to identify the hot function causing 100% CPU usage.

Example

No code example is provided as the issue requires modifications to the existing codebase, which is not fully available.

Notes

The exact mechanism causing 100% CPU usage in orphaned processes is not fully understood and may require additional profiling or debugging to identify.

Recommendation

Apply a workaround by registering a SIGHUP handler and reviewing the SIGTERM handler, as this addresses the likely cause of the issue and can help prevent the accumulation of zombie processes.

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…

FAQ

Expected behavior

  • TUI should exit when its controlling terminal closes (handle SIGHUP)
  • TUI should exit cleanly on SIGTERM without requiring SIGKILL
  • TUI should not spin at 100% CPU when disconnected from the gateway
  • TUI should not accumulate multiple zombie processes across gateway restarts

Still need to ship something?

×6

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

Back to top recommendations

TRENDING