Skip to content

fix(agents): preserve survivor-owned databases offline - #129085

Merged
steipete merged 1 commit into
mainfrom
steipete/offline-delete-survivor-dir
Aug 25, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/offline-delete-survivor-dir

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #129014

Follow-up to #129017.

What Problem This Solves

Fixes the remaining ownership gap in offline agent deletion: a database journaled for the deleted agent could be physically located beneath another configured agent's agentDir. The first repair protected exact surviving database registrations and workspaces, but could still move this survivor-directory-owned file to Trash.

Why This Change Was Made

Offline deletion now prepares every surviving configured agent directory in the existing process-local agent-directory registry before evaluating journaled database paths. It then applies the same isPathOwnedByAnotherRegisteredAgent boundary used by Gateway deletion, so a path inside or overlapping a surviving agent directory is preserved.

This is the focused correction requested by ClawSweeper's completed review of #129017. It does not change the journal schema, Gateway flow, or plugin-owned binding cleanup.

User Impact

Operators can delete agents offline without risking a database file stored under another surviving agent's state directory. Eligible external database files are still removed, while registry cleanup and journal completion retain the behavior landed in #129017.

Production LOC: +11/-1 (net +10) | Tests: +17/-3 (net +14)

Evidence

  • Pre-fix regression: the offline path attempted to Trash main's directory-contained ops.sqlite.
  • The regression now verifies the survivor-owned file never reaches Trash, remains on disk, and the deleted agent's registry row is still released.
  • 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 survivor ownership scenarios — 3 passed before publication.
  • 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; correctness confidence 0.99.

A separate live CLI deletion was not run because the terminal action moves real host paths into Trash. The regression exercises isolated config, state SQLite, database registry, deletion journal, configured agent directories, and filesystem paths while mocking only Gateway reachability and the final Trash transport.

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

Prepare surviving agent-directory ownership before filtering journaled SQLite paths, addressing the post-merge review of #129017.

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.

@steipete
steipete marked this pull request as ready for review August 25, 2026 07:06
@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: XS maintainer Maintainer-authored PR labels Aug 25, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 25, 2026
@clawsweeper

clawsweeper Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 3:54 AM ET / 07:54 UTC.

ClawSweeper review

What this changes

This PR prevents offline agent deletion from moving a journaled database to Trash when that database lies inside another configured agent’s directory.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

The patch follows the Gateway’s established survivor-ownership boundary and its focused regression covers the reported offline path. Keep it open for a rebase onto current main and exact-head validation; the protected maintainer label requires maintainer handling.

Priority: P2
Reviewed head: e73216c30e0b1073f2e87605ea08ec8e995d703f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The implementation and targeted regression are coherent, with rebase-and-exact-head validation remaining before merge.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless records focused owner-boundary test evidence rather than a live deletion.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless records focused owner-boundary test evidence rather than a live deletion.
Evidence reviewed 6 items Offline owner-boundary repair: The offline cleanup primes the process-local directory registry for every surviving configured agent, then excludes journaled database paths owned by another registered agent before Trash operations.
Canonical ownership predicate: The shared registry canonicalizes paths and treats either nested direction as another agent’s ownership, including symlink-aware normalization.
Gateway sibling behavior: Gateway deletion already combines the same registered-directory predicate with surviving workspace and database ownership checks, so the CLI repair aligns with the established owner boundary.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/commands/agents.delete.test.ts

Result: PASS (completed)

node scripts/run-vitest.mjs src/commands/agents.delete.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-129085-55qoep/target$ node scripts/run-vitest.mjs src/commands/agents.delete.test.ts
node scripts/run-vitest.mjs src/commands/agents.delete.test.ts
[test] starting test/vitest/vitest.commands.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-129085-55qoep/target

 ✓  commands  src/commands/agents.delete.test.ts (17 tests) 2650ms
     ✓ refuses deleting main even when another agent is default  449ms

 Test Files  1 passed (1)
      Tests  17 passed (17)
   Start at  07:55:07
   Duration  15.16s (transform 9.87s, setup 1.15s, import 10.99s, tests 2.65s, environment 0ms)

[test] passed 1 Vitest shard in 21.31s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-129085-55qoep/target$ node scripts/run-vitest.mjs src/commands/agents.delete.test.ts


































Assertions:

  • PASS expect_output: 17 passed

How this fits together

When the Gateway is unavailable, the CLI deletes an agent from local config and uses its deletion journal to remove files. Before issuing Trash operations, it must preserve paths owned by surviving agents while still releasing the deleted agent’s registry state.

flowchart LR
  A[Offline delete command] --> B[Deletion journal paths]
  C[Configured surviving agents] --> D[Directory ownership registry]
  B --> E[Ownership and workspace filter]
  D --> E
  E --> F[Eligible files moved to Trash]
  E --> G[Survivor-owned files preserved]
  F --> H[Registry release and journal completion]
Loading

Before merge

  • Resolve merge risk (P1) - The reviewed head is behind current main; the available checkout is a shallow PR snapshot and cannot source-compare against current main SHA 7ba58ab, so exact-head validation must follow a rebase.
  • Resolve merge risk (P1) - This bug fix adds production code to a destructive lifecycle path; the +10 lines are justified by priming the existing registry and reusing its canonical predicate, but should be retested after rebase.
  • Complete next step (P2) - The protected maintainer PR needs a rebase and exact-head validation, not an automated replacement repair.
Agent review details

Security

None.

PR surface

Source +10, Tests +14. Total +24 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 11 1 +10
Tests 1 17 3 +14
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 28 4 +24

Review metrics

Metric Value Why it matters
Production versus regression coverage production +10, tests +14 The production growth is the minimal registry-preparation and ownership-filter integration; the added test exercises the survivor-owned database boundary.

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 a focused candidate fix for the remaining survivor-ownership case in the canonical offline-deletion report.

Members:

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

Merge-risk options

Maintainer options:

  1. Rebase and validate the exact head (recommended)
    Rebase onto current main and rerun the focused offline-deletion suites so the destructive cleanup boundary is proven against the mergeable head.

Technical review

Best possible solution:

Rebase onto current main, retain the shared ownership predicate as the single policy boundary, and rerun the focused offline deletion tests on the rebased head.

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

Yes, from source: with Gateway reachability failing, register a deleted agent database below a surviving agent directory and invoke offline deletion; the changed test encodes that path, though this read-only review did not execute it.

Is this the best way to solve the issue?

Yes, subject to an exact-head rebase check: the CLI now prepares surviving directories and reuses the Gateway’s existing ownership predicate rather than inventing a parallel rule.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a focused agent-state cleanup repair with limited but meaningful operator impact.
  • merge-risk: 🚨 session-state: The changed path decides whether persistent agent database files are preserved or moved to Trash.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless records focused owner-boundary test evidence rather than a live deletion.

Evidence

What I checked:

  • Offline owner-boundary repair: The offline cleanup primes the process-local directory registry for every surviving configured agent, then excludes journaled database paths owned by another registered agent before Trash operations. (src/commands/agents.commands.delete.ts:364, e73216c30e0b)
  • Canonical ownership predicate: The shared registry canonicalizes paths and treats either nested direction as another agent’s ownership, including symlink-aware normalization. (src/agents/agent-dir-registry.ts:71, e73216c30e0b)
  • Gateway sibling behavior: Gateway deletion already combines the same registered-directory predicate with surviving workspace and database ownership checks, so the CLI repair aligns with the established owner boundary. (src/gateway/server-methods/agents.ts:684, e73216c30e0b)
  • Focused regression coverage: The changed command test creates a survivor-owned database under the surviving agent directory and asserts that it is not sent to Trash, remains on disk, while the deleted agent registry entries are released and its journal completes. (src/commands/agents.delete.test.ts:676, e73216c30e0b)
  • Head provenance: The reviewed head is the single commit implementing this follow-up, authored by Peter Steinberger on 2026-08-25T06:53:48Z. (src/commands/agents.commands.delete.ts:364, e73216c30e0b)
  • Release check: No local tag contains the PR head, as expected for an unmerged branch. (e73216c30e0b)

Likely related people:

  • steipete: Authored both this head and the earlier merged offline-database repair referenced by the PR. (role: prior merged repair author and recent area contributor; confidence: high; commits: 610fefdabbce, e73216c30e0b; files: src/commands/agents.commands.delete.ts, src/commands/agents.delete.test.ts)

Rank-up moves

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

  • Rebase onto current main and rerun the focused offline deletion tests on the resulting head.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-25T07:12:31.268Z sha e73216c :: needs maintainer review before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

Landing proof for exact head e73216c30e0b1073f2e87605ea08ec8e995d703f:

Offline agent deletion previously filtered journaled database paths before preparing every surviving configured agent directory, so a deleted-agent database nested beneath a survivor's directory could incorrectly reach Trash. The fix prepares all surviving agent directories and reuses the canonical isPathOwnedByAnotherRegisteredAgent ownership boundary already used by Gateway deletion; no duplicated path policy or cleanup planner.

The pre-fix regression attempted to Trash that survivor-owned database. The corrected regression proves the path never reaches Trash and remains on disk while eligible external database cleanup still proceeds. 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 survivor-ownership scenarios (3 passed); node scripts/check-changed.mjs -- src/commands/agents.commands.delete.ts src/commands/agents.delete.test.ts (passed). Fresh branch autoreview found no actionable issues (correctness 0.97).

ClawSweeper completed its exact-head review with no actionable findings and no security findings: #129085 (comment). Exact-head CI is green: https://github.com/openclaw/openclaw/actions/runs/32819982867. Its earlier failure was an unrelated UI EnvironmentTeardownError; rerunning the failed jobs passed without changing the reviewed head.

The optional rebase rank-up move was consciously skipped: current-main drift is advisory, the PR is mergeable without conflicts, and exact-head CI is green. Production delta +11/-1 (net +10); tests +17/-3 (net +14). Remaining proof gap: no real host Trash run; isolated boundary tests mock only Gateway reachability and the final Trash transport.

@steipete
steipete merged commit 203024e into main Aug 25, 2026
354 of 356 checks passed
@steipete
steipete deleted the steipete/offline-delete-survivor-dir branch August 25, 2026 08:03
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Offline agents delete leaves external databases behind

1 participant