Skip to content

fix: cleanup old suspended claude processes to prevent memory leaks - #814

Closed
Nachx639 wants to merge 1 commit into
openclaw:mainfrom
Nachx639:fix/cleanup-old-claude-processes
Closed

Nachx639 wants to merge 1 commit into
openclaw:mainfrom
Nachx639:fix/cleanup-old-claude-processes

Conversation

@Nachx639

Copy link
Copy Markdown
Contributor

When resuming Claude sessions, old processes with --resume flags were never killed, causing them to accumulate in memory (60+ processes, ~3GB of RAM).

This fix kills old processes with the same sessionId before launching a new one.

Changes

  • Added cleanup of old suspended processes before launching new sessions
  • Uses pkill to match and kill processes with matching sessionId
  • Only runs when using --resume flag

Fixes memory leak from zombie claude processes.

When resuming Claude sessions, old processes with --resume flags
were never killed, causing them to accumulate in memory (60+ processes,
~3GB of RAM). This fix kills old processes with the same sessionId
before launching a new one.

Fixes: Memory leak from zombie claude processes
@steipete steipete self-assigned this Jan 13, 2026
@steipete

Copy link
Copy Markdown
Contributor
  • High: Hardened runtime removed for main app bundle + Sparkle + relay
    binaries; likely notarization/security regression. scripts/codesign-mac-
    app.sh:204, scripts/codesign-mac-app.sh:223, scripts/codesign-mac-
    app.sh:265. Suggest: keep runtime for app/Sparkle; exempt only bun/native
    bits with clear rationale.
  • Medium: Location entitlement removed from base/app entitlements;
    potential feature break, unrelated to PR goal. scripts/codesign-mac-
    app.sh:146, scripts/codesign-mac-app.sh:178.
  • Medium: Stray CR (\r) after return in select_identity line; can trigger
    bash: $'\r': command not found. scripts/codesign-mac-app.sh:24.
  • Low: Placeholder issue link issues/XXX in comment. src/agents/cli-
    runner.ts:602.
  • Low/Behavior: pkill -f kills any matching --resume process, possibly
    active one for same session; “old suspended only” not enforced. src/
    agents/cli-runner.ts:602.

# Prefer a Developer ID Application cert.
# Prefer ClawdisDev (custom identity).
preferred="$(security find-identity -p codesigning -v 2>/dev/null \
| awk -F'\"' '/ClawdisDev/ { print $2; exit }')"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad I commited a personal fix for running the app. The only important part is the cli runner

sign_item_no_runtime() {
local target="$1"
local entitlements="$2"
# Sign without hardened runtime (needed for bun-compiled binaries with native modules)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not ship bun anymore

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.

2 participants