Repository navigation
fix(claws): preserve active and shared agent data during removal - #138693
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
|
Codex review: blocked before merge. Reviewed September 4, 2026, 11:06 PM ET / September 5, 2026, 03:06 UTC. ClawSweeper reviewWhat this changesMakes Claw, Gateway, and offline agent removal preserve active or shared databases and retain retryable cleanup state when session cleanup fails. Merge readiness⛔ Blocked before merge - 2 items remain This remains a useful repair absent from current main. The previous retained-session purge finding is addressed, and no new blocking correctness defect was found. Priority: P2 Review scores
Verification
How this fits togetherAgent removal coordinates configuration, execution approvals, session databases, and filesystem cleanup. Its deletion journal prevents recreation while cleanup is unfinished and distinguishes the removed agent’s data from surviving agents’ data. flowchart TD
A[Claw or agent removal] --> B[Claim deletion journal]
B --> C[Check database owners and leases]
C -->|Active holder| D[Refuse before removal]
C -->|Safe| E[Remove configuration and purge sessions]
E -->|Cleanup fails| F[Retain journal for retry]
E -->|Cleanup succeeds| G[Preserve shared paths and complete deletion]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +388, Tests +811, Docs +11, Other +4. Total +1214 across 28 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the shared planner and journal-owned cleanup with documented retry recovery; the private handle lifetime justifies the remaining production growth without changing the stored schema. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main lacks Claw’s pre-effect lease check and ignores purge failure before continuing cleanup. The branch contains focused two-process and populated-store regressions; this review did not execute them. Is this the best way to solve the issue? Yes: extending the existing deletion journal and database lifecycle repairs the owning boundary across all three callers. Moving purge ahead of the fence or introducing a global maintenance bypass would weaken isolation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 790fbf0304a6. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
|
Merged via squash.
|
…nclaw#138693) * fix(claws): preserve active and shared agent data during removal * fix(agents): keep session cleanup within deletion ownership * refactor(state): remove deletion cleanup type cycle
* commit 'cf127a39cb97ff5c3c2dfe8d4b37bc9dee9470e8': fix(claws): preserve active and shared agent data during removal (openclaw#138693)
What Problem This Solves
Claw removal could commit config and remove directories while another process still held an agent database. It also used incomplete ownership information for retained directories. Share the existing Gateway deletion preparation with Claw and offline CLI removal: fence new claims, close only the deleted agent's actual registered handles, and reject active leases before config, approvals, MCP, cron, or filesystem effects. Retain directories containing surviving database owners, including closed databases with older or newer schemas.
Why This Change Was Made
Session cleanup needs the same deletion owner across its awaited purge and transcript archive work. An ordinary reopen after claiming the deletion journal correctly refuses access, which previously left retained databases unpurged while removal reported completion. The deletion owner now provides a scoped cleanup operation bound to its live closure, exact unfinished journal, state database, and physical store owner/path. Connections opened by that scope stay private to it, remain borrowed across awaits, and close before the operation settles. Ordinary callers, stale callbacks, foreign journal rows, and overlapping foreign leases retain their existing fences. Preexisting surviving shared-store connections retain their ordinary ownership, and cleanup removes only the deleted agent's rows.
User Impact
Failed session cleanup or archive export now keeps the deletion journal unfinished. Claw reports a partial result and supports preview/retry; Gateway and offline CLI retain
purgeFailedand defer filesystem cleanup and completion. Creation provenance is removed only when the exact deletion operation successfully completes. The canonical shared directory check replaces the CLI's duplicate retention rules, and Claw's repeated partial-result construction is consolidated.Evidence
Validation: original config-file and two-process reproductions are preserved; the final owner suite passes 325 tests with six existing platform skips across nine files. Coverage includes real postcommit archive publication failure and retry, active foreign child leases, relocated paths, closed foreign databases, stale registry/schema information, warm/cold shared stores, replacement/rollback/completion retirement, retained callbacks and aliases, and exact failed-close retry with the original operation error preserved. A fresh built standalone CLI run removed the target agent/session while preserving a foreign database and its surviving session. Final source hashes are checked before and after remote execution. The final extracted source passed the fresh standalone CLI build and all nine suites with identical hashes before, after CLI execution, and after the suites. The full changed-code gate passed on Linux (Node 24.19.0, pnpm 12.1.0) in 863.851 seconds on Testbox run https://github.com/openclaw/openclaw/actions/runs/33939598362. Fresh independent P2 review found no actionable findings. An earlier gate failed with corepack ENOENT while its runner was being cancelled; the cause of the missing binary was not established. The unchanged gate passed on a newly acquired matching lease. The final command succeeded before a runner-portal synchronization warning.
The review's retained-session purge finding and associated coverage requests are addressed by the scoped owner and real archive retry proof. The contract type move does not change a database schema or stored representation. No schema version, migration, configuration, dependency, or public RPC change; no changelog edit.
Production changes are +873/-498 (net +375); tests and test support are +855/-40 (net +815); docs are +11. Planner/type moves add no capability. The remaining production growth supplies the missing exact cleanup lifetime and handle isolation across awaited archive work. It reuses the journal, existing native borrower/close owner, existing path matcher, and lease fence; the duplicated Gateway/CLI retention rules and repeated Claw partial-result branches were removed. No global maintenance bypass or second deletion registry was introduced.
Hosted CI on the preceding head exposed two additional structural issues: the merged database owner exceeded the 700-line lint limit, and Madge counted a type-only registry cycle that the runtime-value check excludes. The repair removes the type dependency by taking the existing matcher signature and absorbs the one-use slow-open logger at its original call site. The actual merged-source lint now passes (the same pre-fix merge reproduces the failure), both cycle guards pass, scoped typed lint passes, and a fresh independent P2 review found no actionable findings. Cleanup and native-close behavior are unchanged by this follow-up.
Final head
24f56c0341ba039c58ef9a773b58c73a38586690passed CI attempt 2, includingopenclaw/ci-gate. Attempt 1 failed only while downloading the Matrix crypto native dependency (ECONNRESET before the boundary check); the normal targeted retry passed.The latest ClawSweeper review confirms the retained-session finding and both rank-up requests are addressed. Its remaining compatibility reminder is accepted: active database owners must release their handles, and callers must retry an unfinished deletion rather than recreate over it. This is documented and covered by refusal/retry tests. The flagged lifecycle and cleanup additions are process-local closures, AsyncLocalStorage, and handle maps; no serialized field, schema version, migration, or stored representation changes, so a data migration is not applicable.