Skip to content

fix(agents): remove external databases during offline delete - #129017

Merged
steipete merged 1 commit into
mainfrom
steipete/elastic-jackson-d3e0e1
Aug 25, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/elastic-jackson-d3e0e1

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #129014

What Problem This Solves

Fixes an issue where operators deleting an agent while the Gateway was unavailable could leave registered agent databases outside the agent directory on disk. The offline fallback removed their registry ownership and completed the deletion journal, so the stale files were no longer discoverable or retryable.

Why This Change Was Made

The deletion journal already owns the complete database file inventory, including SQLite WAL, SHM, and rollback-journal sidecars. The offline command now processes that durable inventory through its existing Trash result collector, skips files already covered by the deleted agent directory, and preserves paths still owned by a surviving agent or overlapping a surviving workspace. Registry cleanup and journal completion remain gated on every selected cleanup target succeeding.

This intentionally does not change Gateway deletion or plugin-owned offline binding cleanup.

User Impact

Offline openclaw agents delete now removes externally located agent database files with the same lifecycle guarantees as normal Gateway deletion. Shared database paths remain intact, and a Trash failure keeps the durable ownership and recovery journal available for a later retry.

Production LOC: +25/-1 (net +24) | Tests: +41/-3

Evidence

  • Pre-fix regression failed because the external database group never reached the Trash boundary; only the workspace and agent directory were processed.
  • node scripts/run-vitest.mjs src/commands/agents.delete.test.ts — 17 passed.
  • node scripts/run-vitest.mjs src/commands/agents.delete.workspace.test.ts — 10 passed.
  • Focused Gateway sibling ownership/Trash cases — 3 passed.
  • Focused agent database registry external/multiple-path cases — 2 passed.
  • node scripts/check-changed.mjs -- src/commands/agents.commands.delete.ts src/commands/agents.delete.test.ts — passed after rebasing onto current main.
  • Mandatory Codex autoreview — no accepted/actionable findings.

A separate live CLI run was not used because the final operation moves real paths into the host Trash. The regression exercises the actual offline command owner boundary with isolated config, state SQLite, database registry, deletion journal, and filesystem paths while mocking only Gateway reachability and the final Trash transport.

  • AI-assisted
  • I understand the change and verified the owner boundary

Move journaled external SQLite files and sidecars to Trash while preserving databases still owned by surviving agents.

Refs #129014
@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: S maintainer Maintainer-authored PR labels Aug 25, 2026
@steipete
steipete marked this pull request as ready for review August 25, 2026 05:12
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 25, 2026
@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 25, 2026, 1:17 AM ET / 05:17 UTC.

ClawSweeper review

What this changes

The PR extends offline agent deletion to Trash journaled external SQLite database files and sidecars while preserving paths shared with another registered database or overlapping a surviving workspace.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

The offline fix addresses the reported orphaned external-database path, but it omits the Gateway deletion path’s surviving-agent-directory ownership check; merging can move a live agent’s directory-contained database to Trash.

Priority: P1
Reviewed head: 298b3ac8565b7eee1d34e1c9501054481031c6b5

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch has focused regression evidence but a concrete cleanup-ownership defect blocks merge.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body supplies focused owner-boundary test evidence, but that evidence does not cover the missing survivor-directory case.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body supplies focused owner-boundary test evidence, but that evidence does not cover the missing survivor-directory case.
Evidence reviewed 5 items Offline ownership gap: The new predicate protects the deleted agent directory, exact surviving database paths, and workspaces, but does not protect a journaled external database located inside another configured agent's directory.
Gateway ownership contract: Current Gateway deletion uses one survivor predicate that checks registered agent-directory ownership, workspace overlap, and both-direction database-path containment before cleanup.
Directory ownership source: Resolving a configured agent directory registers it for containment checks; the offline command resolves only the deleted agent directory and never establishes the survivor-directory guard used by Gateway deletion.
Findings 1 actionable finding [P1] Protect paths owned by surviving agent directories
Security None None.

Live Verification

Command: pnpm openclaw agents delete --help

Result: PASS (completed)

pnpm openclaw agents delete --help
runner@runnervm76f27:/tmp/clawsweeper-live-proof-129017-w4ZEwj/target$ pnpm openclaw agents delete --help
$ node scripts/run-node.mjs agents delete --help
pnpm openclaw agents delete --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 102.29 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.6s
node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

[tsdown-build] invocation 2/2 finished in 11.9s
[plugin-control-plane-loads] verified 35 built modules with native require and checked doctor closures
runtime-postbuild: 11 phases completed in 3932ms (slowest: built plugin control-plane loads 2901ms)
│
◇

OpenClaw 2026.8.1 (298b3ac) — All your chats, one OpenClaw.

Usage: openclaw agents delete [options] ‹id›

Delete an agent and prune workspace/state

Options:
  --force     Skip confirmation (default: false)
  -h, --help  Display help for command
  --json      Output JSON summary (default: false)
runner@runnervm76f27:/tmp/clawsweeper-live-proof-129017-w4ZEwj/target$ pnpm openclaw agents delete --help


Assertions:

  • PASS expect_output: --force

How this fits together

The agent-delete CLI uses a local fallback when Gateway deletion cannot be reached. It removes filesystem state recorded in the durable deletion journal, then releases the database registry and completes recovery bookkeeping.

flowchart LR
  A[Operator deletes agent] --> B[Gateway unavailable]
  B --> C[Offline deletion journal]
  C --> D[Check external database paths]
  D --> E[Ownership and overlap decision]
  E --> F[Move eligible files to Trash]
  F --> G[Release registry and finish journal]
Loading

Before merge

  • Protect paths owned by surviving agent directories (P1) - A deleted agent can have a journaled external database below another configured agent's agentDir. This predicate sees it as outside the deleted directory, not an exact surviving database path, and not a workspace overlap, then moves it to Trash. Gateway deletion already protects this case through its full surviving-owner predicate; apply that same guard here and add the regression.
  • Resolve merge risk (P1) - An external database registered to the deleted agent but placed beneath a surviving agent's directory can be moved to Trash because the offline path lacks Gateway's directory-ownership guard.
  • Resolve merge risk (P1) - The bug fix adds net 24 production lines by duplicating only part of Gateway's cleanup policy, leaving the two deletion paths divergent.
  • Complete next step (P2) - A narrow, source-proven P1 repair can align the offline path with the existing Gateway ownership boundary.

Findings

  • [P1] Protect paths owned by surviving agent directories — src/commands/agents.commands.delete.ts:371-374
Agent review details

Security

None.

PR surface

Source +24, Tests +38. Total +62 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 25 1 +24
Tests 1 41 3 +38
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 66 4 +62

Review metrics

Metric Value Why it matters
Production versus test delta production +24 net; tests +38 net The production growth implements a second cleanup-policy branch, so parity with the existing Gateway ownership boundary is merge-critical.

Stored data model

Persistent data-model change detected: serialized state: src/commands/agents.delete.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #129014
Summary: This PR is the linked candidate repair for the canonical offline-deletion bug, but it needs owner-boundary correction before it can safely fix that issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Align the offline ownership guard (recommended)
    Reuse or extract the Gateway survivor-ownership decision, then prove a database under a surviving agent directory is preserved before merge.
  2. Pause external cleanup
    Do not merge the new external-file deletion behavior until the offline path can preserve every surviving agent-owned location.

Technical review

Best possible solution:

Make offline eligibility use the same complete surviving-owner predicate as Gateway deletion, including registration of all configured survivor directories, and add a regression for a deleted agent database under a surviving agent directory.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: current offline deletion processes only the deleted agent directory and sessions directory, while the branch adds journaled external paths; a focused regression can place that path beneath a surviving agent directory.

Is this the best way to solve the issue?

No. The patch fixes the reported external-path omission but implements a narrower ownership policy than the existing Gateway deletion owner, leaving a reachable destructive case.

Full review comments:

  • [P1] Protect paths owned by surviving agent directories — src/commands/agents.commands.delete.ts:371-374
    A deleted agent can have a journaled external database below another configured agent's agentDir. This predicate sees it as outside the deleted directory, not an exact surviving database path, and not a workspace overlap, then moves it to Trash. Gateway deletion already protects this case through its full surviving-owner predicate; apply that same guard here and add the regression.
    Confidence: 0.95

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against e9017714c2d6.

Labels

Label changes:

  • add P1: The proposed cleanup can remove a database located in a surviving agent's directory during a normal offline deletion.
  • add merge-risk: 🚨 session-state: The changed path moves SQLite databases and sidecars to Trash, and its missing survivor-directory check can remove live agent state.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body supplies focused owner-boundary test evidence, but that evidence does not cover the missing survivor-directory case.

Label justifications:

  • P1: The proposed cleanup can remove a database located in a surviving agent's directory during a normal offline deletion.
  • merge-risk: 🚨 session-state: The changed path moves SQLite databases and sidecars to Trash, and its missing survivor-directory check can remove live agent state.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body supplies focused owner-boundary test evidence, but that evidence does not cover the missing survivor-directory case.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/commands/agents.delete.test.ts.
  • [P1] node scripts/run-vitest.mjs src/commands/agents.delete.workspace.test.ts.
  • [P1] node scripts/check-changed.mjs -- src/commands/agents.commands.delete.ts src/commands/agents.delete.test.ts.

What I checked:

  • Offline ownership gap: The new predicate protects the deleted agent directory, exact surviving database paths, and workspaces, but does not protect a journaled external database located inside another configured agent's directory. (src/commands/agents.commands.delete.ts:371, 298b3ac8565b)
  • Gateway ownership contract: Current Gateway deletion uses one survivor predicate that checks registered agent-directory ownership, workspace overlap, and both-direction database-path containment before cleanup. (src/gateway/server-methods/agents.ts:684, 97e732715a42)
  • Directory ownership source: Resolving a configured agent directory registers it for containment checks; the offline command resolves only the deleted agent directory and never establishes the survivor-directory guard used by Gateway deletion. (src/agents/agent-scope-config.ts:440, e9017714c2d6)
  • Regression coverage gap: The added test proves external files and an exactly shared database path, but does not cover an external database registered to the deleted agent beneath a surviving agent's directory. (src/commands/agents.delete.test.ts:676, 298b3ac8565b)
  • Current-main and release check: Current main still has the pre-fix offline cleanup path; the PR head is not contained by any local release tag, so this behavior is neither implemented on main nor shipped. (src/commands/agents.commands.delete.ts:360, e9017714c2d6)

Likely related people:

  • steipete: Current Gateway survivor-ownership predicate dates to this contributor's commit, and the same contributor authored the PR. (role: introduced current Gateway ownership rules and proposed the offline repair; confidence: high; commits: 97e732715a42, 298b3ac8565b; files: src/gateway/server-methods/agents.ts, src/commands/agents.commands.delete.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Use the Gateway survivor-ownership predicate for offline cleanup and add the surviving-agent-directory regression.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready owner-boundary proof: offline agent deletion previously ignored the durable journal's external SQLite file group, removed its registry ownership, and completed recovery anyway. The fix sends every exclusively owned journaled database and SQLite sidecar through the existing Trash result collector while preserving surviving-agent/workspace ownership; registry cleanup and journal completion still require successful cleanup.

The pre-fix regression failed because the external database group never reached Trash. Verification: node scripts/run-vitest.mjs src/commands/agents.delete.test.ts — 17 passed; node scripts/run-vitest.mjs src/commands/agents.delete.workspace.test.ts — 10 passed; focused Gateway sibling ownership/Trash cases — 3 passed; focused database-registry external/multiple-path cases — 2 passed; node scripts/check-changed.mjs -- src/commands/agents.commands.delete.ts src/commands/agents.delete.test.ts — passed. Fresh post-rebase Codex autoreview is clean with no accepted/actionable findings. Exact-head CI: https://github.com/openclaw/openclaw/actions/runs/32811910592. Native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 129017 passed hosted CI/Testbox gates without changing the reviewed head.

Production LOC: +25/-1 (net +24); tests: +41/-3. Proof gap: no separate live CLI run—the owner-boundary integration isolates config, state SQLite, registry, deletion journal, and filesystem, mocking only Gateway reachability and final Trash transport; mutating the real host Trash was intentionally avoided.

@steipete
steipete merged commit 610fefd into main Aug 25, 2026
246 checks passed
@steipete
steipete deleted the steipete/elastic-jackson-d3e0e1 branch August 25, 2026 05:52
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete

Copy link
Copy Markdown
Contributor Author

Follow-up correction: #129085

Post-merge verification found that #129017 did not protect a deleted agent's journaled database when the file was nested beneath a surviving configured agent's agentDir. The follow-up prepares survivor directory ownership and applies the same agent-directory registry predicate used by Gateway deletion, with a focused failing/passing regression.

Issue #129014 remains open until the corrective PR lands.

steipete added a commit that referenced this pull request Aug 25, 2026
Prepare surviving agent-directory ownership before filtering journaled SQLite paths, addressing the post-merge review of #129017.

Refs #129014
@steipete

Copy link
Copy Markdown
Contributor Author

Post-merge correction: #129085 completed this repair on main by preparing all surviving configured agent directories before offline cleanup and reusing Gateway's canonical registered-directory ownership predicate. Its regression proves survivor-owned database paths never reach Trash and remain on disk.

Final merge commit: 203024e

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 26, 2026
)

Move journaled external SQLite files and sidecars to Trash while preserving databases still owned by surviving agents.

Refs openclaw#129014
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 26, 2026
Prepare surviving agent-directory ownership before filtering journaled SQLite paths, addressing the post-merge review of openclaw#129017.

Refs openclaw#129014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Offline agents delete leaves external databases behind

1 participant