openclaw - 💡(How to fix) Fix [Bug] chat.send implicit session creation leaks workspace directories [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#68571Fetched 2026-04-19 15:10:03
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
closed ×1renamed ×1reopened ×1

Root Cause

OpenClaw owns the full session lifecycle silently:

Caller
  → chat.send { sessionKey, message }
  → OpenClaw checks sessionKey
  → Session not found
  → OpenClaw implicitly creates session + workspace directory
  → chat.send returns
  → Session ends
  → Workspace directory: NEVER CLEANED UP

Key facts:

  • No caller calls sessions.create — all callers only invoke chat.send
  • Callers cannot control workspace lifecycle because OpenClaw handles it implicitly
  • When a caller writes session metadata to its own local DB, that DB record is separate from OpenClaw's own workspace directory, which OpenClaw manages entirely

Code Example

Caller
  → chat.send { sessionKey, message }
OpenClaw checks sessionKey
Session not found
OpenClaw implicitly creates session + workspace directory
  → chat.send returns
Session ends
Workspace directory: NEVER CLEANED UP

---

~/.openclaw/workspace-2hlghlah5v5d3t79clxmn/
~/.openclaw/workspace-xj45ribstldgcdvybnosn/
... (106 orphaned workspaces on a system with only 12 legitimate agent workspaces)
RAW_BUFFERClick to expand / collapse

Bug: chat.send implicit session creation leaks workspace directories

Problem

When chat.send is called with a sessionKey that does not exist in OpenClaw, OpenClaw implicitly creates a new session and a corresponding workspace directory at ~/.openclaw/workspace-<id>/. This workspace is populated with bootstrap files (AGENTS.md, BOOTSTRAP.md, HEARTBEAT.md, IDENTITY.md, SOUL.md, TOOLS.md, USER.md).

When the session ends, the workspace directory is never cleaned up.

Over time this causes:

  1. Disk bloat: Each orphaned workspace is ~8-64KB; with hundreds of sessions this accumulates
  2. Operational confusion: Users see dozens/hundreds of unnamed workspace-* directories with no way to know which are active vs orphaned
  3. No caller control: Callers that only invoke chat.send have no API to prevent or clean up workspace creation

Root Cause

OpenClaw owns the full session lifecycle silently:

Caller
  → chat.send { sessionKey, message }
  → OpenClaw checks sessionKey
  → Session not found
  → OpenClaw implicitly creates session + workspace directory
  → chat.send returns
  → Session ends
  → Workspace directory: NEVER CLEANED UP

Key facts:

  • No caller calls sessions.create — all callers only invoke chat.send
  • Callers cannot control workspace lifecycle because OpenClaw handles it implicitly
  • When a caller writes session metadata to its own local DB, that DB record is separate from OpenClaw's own workspace directory, which OpenClaw manages entirely

Evidence

~/.openclaw/workspace-2hlghlah5v5d3t79clxmn/
~/.openclaw/workspace-xj45ribstldgcdvybnosn/
... (106 orphaned workspaces on a system with only 12 legitimate agent workspaces)

All orphaned workspaces contain identical bootstrap files and are created implicitly by OpenClaw during chat.send with unknown sessionKeys.

Expected Behavior

OpenClaw should clean up the workspace directory when an implicitly-created session ends. Options:

  1. Session-scoped cleanup: When an implicitly-created session ends (completes, times out, errors), delete its workspace directory
  2. Ephemeral workspace path: For implicit sessions, use a temp path (e.g. /tmp/openclaw-<sessionKey>) so cleanup is automatic on reboot
  3. Explicit workspace opt-out: Add a workspace: false flag to chat.send for callers that do not need a persistent workspace directory
  4. Startup GC: On Gateway startup, remove any workspace-* directories that do not correspond to active sessions

Environment

  • OpenClaw 2026.4.15 (041266a)
  • macOS / Linux
  • Gateway running as user-level service

Priority

Medium — Low functional impact but creates operational overhead, disk waste, and no caller control.

extent analysis

TL;DR

Implement a cleanup mechanism for implicitly created workspace directories when sessions end, such as session-scoped cleanup or using ephemeral workspace paths.

Guidance

  • Identify the session lifecycle events (e.g., completion, timeout, error) to trigger workspace directory cleanup.
  • Consider adding a workspace: false flag to chat.send for callers that do not need a persistent workspace directory.
  • Explore using a temporary path (e.g., /tmp/openclaw-<sessionKey>) for implicit sessions to enable automatic cleanup on reboot.
  • Develop a startup garbage collection mechanism to remove orphaned workspace-* directories that do not correspond to active sessions.

Example

No code snippet is provided as the issue does not contain sufficient implementation details.

Notes

The solution may require modifications to the OpenClaw API and internal session management logic. The chosen approach should balance the need for cleanup with potential performance and complexity implications.

Recommendation

Apply a workaround by implementing a session-scoped cleanup mechanism, as it directly addresses the issue of orphaned workspace directories and provides a clear trigger for cleanup events.

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

openclaw - 💡(How to fix) Fix [Bug] chat.send implicit session creation leaks workspace directories [1 participants]