openclaw - ✅(Solved) Fix agents delete recursively removes workspace dir — silent data-loss when workspace is shared [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#70890Fetched 2026-04-24 10:38:12
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
referenced ×2cross-referenced ×1

openclaw agents delete <id> --force removes the entire workspace directory referenced by the agent — not only the agent-specific state under ~/.openclaw/agents/<id>/. When a workspace is shared across multiple agents (common pattern for canary/test agents reusing a template workspace path, or when two agents intentionally share identity), deleting one agent silently destroys the shared workspace contents that belong to the others.

Root Cause

This bit us today in two places:

  1. Our canary-deployment testing pattern used --agent-id-override canary-<ts> but left workspace as the spec's default path. Teardown nuked the shared template.
  2. A Wave4u E2E test on 2026-04-23 accidentally wiped ~/.openclaw/workspace-hello-world/ which was the reference template for a production agent deploy. Files were recovered only because the outer ~/.openclaw git repo had the workspace under allowlist tracking and we could git checkout -- workspace-hello-world/. On a non-git workspace or with unstaged local edits, the data would have been unrecoverable.

Fix Action

Fix / Workaround

Workaround we deployed

2026-04-23 by Wave4u during independent verification of agent-deployer. Full post-mortem in today's conversation thread; workaround commit dda96db in ~/.openclaw.

PR fix notes

PR #70897: fix: agents delete JSON output and shared workspace safety

Description (problem / solution / changelog)

Fixes #70889 and #70890.

#70889 — Config overwrite log leaks to stdout in --json mode

  • Added skipOutputLogs flag to ConfigWriteOptions
  • Suppresses Config overwrite: message when --json is requested
  • Passed through replaceConfigFile call chain in agents delete command

#70890 — agents delete recursively removes shared workspace

  • Added isWorkspaceShared guard to detect workspace path collisions
  • Skips workspace removal when another agent references the same directory
  • Reports workspaceSkipped: true in JSON output when guarded
  • Added regression tests for both fixes

Changed files

  • scripts/stage-bundled-plugin-runtime-deps.mjs (modified, +22/-0)
  • src/commands/agents.commands.delete.ts (modified, +28/-1)
  • src/commands/agents.delete.test.ts (modified, +78/-0)
  • src/config/io.ts (modified, +12/-0)
  • test/scripts/stage-bundled-plugin-runtime-deps.test.ts (modified, +68/-0)

Code Example

# Setup: add agent-A, which creates ~/.openclaw/workspace-shared/ with template files
openclaw agents add --workspace ~/.openclaw/workspace-shared \
  --non-interactive --json agent-A

# Add a second agent that reuses the same workspace
openclaw agents add --workspace ~/.openclaw/workspace-shared \
  --non-interactive --json agent-B

# Delete ONE of them
openclaw agents delete agent-A --force --json

# Observe: ~/.openclaw/workspace-shared/ is GONE
ls ~/.openclaw/workspace-shared
# → No such file or directory
RAW_BUFFERClick to expand / collapse

openclaw agents delete recursively removes the workspace directory, including shared/template state

Version affected: OpenClaw 2026.4.14 (323493f) on macOS Severity: data-loss (silent, unbounded blast radius when workspaces are shared across agents)

Summary

openclaw agents delete <id> --force removes the entire workspace directory referenced by the agent — not only the agent-specific state under ~/.openclaw/agents/<id>/. When a workspace is shared across multiple agents (common pattern for canary/test agents reusing a template workspace path, or when two agents intentionally share identity), deleting one agent silently destroys the shared workspace contents that belong to the others.

Reproduction

# Setup: add agent-A, which creates ~/.openclaw/workspace-shared/ with template files
openclaw agents add --workspace ~/.openclaw/workspace-shared \
  --non-interactive --json agent-A

# Add a second agent that reuses the same workspace
openclaw agents add --workspace ~/.openclaw/workspace-shared \
  --non-interactive --json agent-B

# Delete ONE of them
openclaw agents delete agent-A --force --json

# Observe: ~/.openclaw/workspace-shared/ is GONE
ls ~/.openclaw/workspace-shared
# → No such file or directory

agent-B is left in the registry pointing at a workspace path that no longer exists on disk. Any files that were in the workspace (AGENTS.md, SOUL.md, custom skills, memory, DREAMS.md, etc.) are gone.

Expected behavior

delete should only prune state that is unambiguously owned by this agent id:

  1. Remove the entry from ~/.openclaw/openclaw.json agents.list[*] where id == <id>.
  2. Remove routing bindings referring to this agent.
  3. Remove ~/.openclaw/agents/<id>/ recursively (that dir IS agent-specific).
  4. Remove the workspace dir only if no other agent in the registry references that same workspace path. Otherwise, leave the workspace untouched (and note in --json output: "workspaceRetained": true, "workspaceSharedWith": ["agent-B"]).

Alternatively, add an explicit opt-in flag --prune-workspace that defaults to false. This makes the destructive behavior an explicit choice rather than a silent default.

Why this matters

This bit us today in two places:

  1. Our canary-deployment testing pattern used --agent-id-override canary-<ts> but left workspace as the spec's default path. Teardown nuked the shared template.
  2. A Wave4u E2E test on 2026-04-23 accidentally wiped ~/.openclaw/workspace-hello-world/ which was the reference template for a production agent deploy. Files were recovered only because the outer ~/.openclaw git repo had the workspace under allowlist tracking and we could git checkout -- workspace-hello-world/. On a non-git workspace or with unstaged local edits, the data would have been unrecoverable.

Workaround we deployed

Added --workspace-override flag to our own provision_agent.py so canary runs can pass --workspace-override /tmp/canary-ws-<ts> and isolate the blast radius. This protects us but doesn't protect anyone else using openclaw agents delete the naive way.

Discovered

2026-04-23 by Wave4u during independent verification of agent-deployer. Full post-mortem in today's conversation thread; workaround commit dda96db in ~/.openclaw.

extent analysis

TL;DR

To prevent data loss when deleting an OpenClaw agent, consider adding an explicit --prune-workspace flag or checking for shared workspaces before deletion.

Guidance

  • Verify if the workspace is shared among multiple agents before deleting an agent to avoid data loss.
  • Consider adding a --prune-workspace flag that defaults to false to make workspace deletion an explicit choice.
  • Check the openclaw.json file for other agents referencing the same workspace path before deleting the workspace directory.
  • Use the --workspace-override flag to isolate the workspace for canary runs, as implemented in the provision_agent.py workaround.

Example

No code snippet is provided as the issue is more related to the behavior of the openclaw agents delete command rather than a specific code implementation.

Notes

The current implementation of openclaw agents delete silently removes the entire workspace directory, which can lead to data loss if the workspace is shared among multiple agents. The proposed --prune-workspace flag or checking for shared workspaces can help mitigate this issue.

Recommendation

Apply the workaround by adding a --prune-workspace flag or checking for shared workspaces before deletion, as this provides an explicit way to control workspace deletion and prevents silent data loss.

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

delete should only prune state that is unambiguously owned by this agent id:

  1. Remove the entry from ~/.openclaw/openclaw.json agents.list[*] where id == <id>.
  2. Remove routing bindings referring to this agent.
  3. Remove ~/.openclaw/agents/<id>/ recursively (that dir IS agent-specific).
  4. Remove the workspace dir only if no other agent in the registry references that same workspace path. Otherwise, leave the workspace untouched (and note in --json output: "workspaceRetained": true, "workspaceSharedWith": ["agent-B"]).

Alternatively, add an explicit opt-in flag --prune-workspace that defaults to false. This makes the destructive behavior an explicit choice rather than a silent default.

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 - ✅(Solved) Fix agents delete recursively removes workspace dir — silent data-loss when workspace is shared [1 pull requests, 1 participants]