Repository navigation
fix: agents delete leaves no stale database registry row - #124347
Merged
Merged
Conversation
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Contributor
Author
|
Merged via squash.
|
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Aug 16, 2026
…4347) * fix(agents): deregister agent databases on delete * refactor(claws): finalize agent registry cleanup with removal state
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #109956 (deleted-agent registry leak only; this does not address the separate phantom-writer or retained-present-database policy questions)
What Problem This Solves
Fixes an issue where
openclaw agents delete --forcecould leave the deleted agent's durableagent_databasesrow behind when no usable Gateway was reachable and the CLI used its local fallback. The database files were gone, but registry discovery still reported them until an operator happened to runopenclaw doctor.The live report showed the long-term effect clearly: 3 configured agents versus 15 registry rows after ordinary churn, with doctor later emitting
Removed missing agent database registry entryandSkipped missing registered agent databasefor state the delete owner should have finalized itself.Why This Change Was Made
The Gateway RPC deletion path already had the correct architecture: begin a durable deletion journal, remove roster authority, finish filesystem cleanup, deregister exact database ownership through the registry owner, and only then complete the journal. The leak was the CLI transport/credential fallback, which was a separate non-journaled implementation.
The fallback now joins the same lifecycle model. It records or resumes the deletion journal before roster mutation, retains database registration while any file cleanup is incomplete, atomically deregisters every row for the deleted agent through the registry owner's
unregisterOpenClawAgentDatabasesAPI, and completes the journal last. A crash before deregistration leaves the row plus unfinished journal; a crash after deregistration but before completion retries the idempotent deregistration and completes. No schema or schema-version change is involved.The independent
claws removeagent-deletion path now releases database registration through the same registry owner only after its existing removal state reaches complete. Doctor reconciliation remains unchanged as the safety net for old versions, crashes, and manual file removal.User Impact
Completed agent deletion now leaves no stale database registry entry, including when the Gateway is unavailable or requires credentials and the CLI falls back locally. Interrupted local deletions can be retried by agent id even after the roster entry was already removed.
This deliberately does not remove the harmless empty
agents/<id>/container: the journal owns the agent and sessions subdirectories, while safely claiming the parent would require a separate empty/default-layout ownership check. Completed deletion-journal rows also remain durable one-row-per-agent tombstones until recreation claims them; changing that authority-retention contract is outside this repair.Production LOC: +103/-28 (net +75) | Tests: +90/-0. The production growth is the durable offline deletion/recovery boundary that was previously absent, plus one registry-owner bulk removal operation; it replaces the non-resumable fallback rather than adding a second policy path.
AI-assisted implementation; the resulting lifecycle and failure semantics were reviewed directly and with the repository autoreview workflow.
Evidence
Before
Live reproduction on 2026-08-15 at
eb13f5719f0:Accumulated profile state: 3 configured agents, 15
agent_databasesrows. Doctor then repaired the 12 deleted-agent rows downstream.After
Exact built-tree macOS proof with isolated
OPENCLAW_STATE_DIR,OPENCLAW_SKIP_CHANNELS=1, no Gateway port, and read-only local Ollamaqwen3:4b-instruct:The Ollama turn returned
OK(30,260 input tokens, 2 output tokens). The subsequent doctor run completed without either registry reconciliation message.Automated validation
node scripts/run-vitest.mjs src/commands/agents.delete.test.ts src/claws/lifecycle-state.test.ts src/infra/state-migrations.media-persistence-targets.test.ts src/gateway/server-methods/agents-mutate.test.ts— 155 tests passed across 4 shards.node scripts/check-changed.mjs— green on Blacksmith Testbox (tbx_01m043kxmskdhv8cp9pmw298sy, Actions run 31920094059).pnpm buildequivalent through the hydrated Testbox — green in 3m25s (tbx_01m044wgf3trv1yd6ebbrdpqsb, Actions run 31920942565; wrapper exit 0)..agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main --stream-engine-output— clean, no accepted/actionable findings.