Skip to content

[Bug]: CLI commands hang after completion (process never exits) #12904

@DrCrinkle

Description

@DrCrinkle

Description

After running any CLI command that completes successfully (e.g. openclaw gateway restart, openclaw daemon status, etc.), the CLI process hangs indefinitely instead of exiting. The user must Ctrl+C to regain the terminal.

$ openclaw gateway restart
21:25:20 [plugins] [token-refresh] Scheduler started (checking every 1min)
21:25:20 [plugins] [unbrowse] Auto-discovery hook active
21:25:20 [plugins] [unbrowse] Plugin registered (16 tools, auto-discover)

🦞 OpenClaw 2026.2.9 (1fad190) — Because texting yourself reminders is so 2024.

Restarted systemd service: openclaw-gateway.service
^C^C^C

Root Cause

Two issues combine to cause this:

  1. No explicit process exit in runCli(): After program.parseAsync() resolves in src/cli/run-main.ts, the function just returns. Commander.js does not force-exit the process.

  2. Eager side-effect imports keep the event loop alive: src/cli/daemon-cli/register.ts calls void createDefaultDeps() at registration time, which eagerly imports all messaging-provider modules (WhatsApp, Telegram, Discord, Slack, Signal, iMessage). These modules create persistent connections or timers that prevent Node.js from exiting naturally.

The failure path (defaultRuntime.exit(1)) works fine — it's only the success paths that hang, since they just return without exiting.

Affected Commands

This is not limited to gateway restart. Any CLI command whose success path doesn't explicitly call process.exit() / defaultRuntime.exit() will hang when side-effect imports keep the event loop alive.

Related: #7662

Expected Behavior

The CLI should exit cleanly (exit code 0) once a command completes successfully.

Environment

  • OS: AlmaLinux 10.1 (aarch64)
  • Kernel: Linux 6.12.0-124.31.1.el10_1.aarch64
  • Node.js: v22.22.0
  • OpenClaw: 2026.2.9 (1fad190)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions