Repository navigation
fix: skip retained deleted agent stores during plugin cleanup - #158473
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 29, 2026, 2:42 AM ET / 06:42 UTC (Revision 9). ClawSweeper reviewWhat this changesPlugin cleanup skips session stores belonging to recorded, retained deleted agents, continues cleaning active stores after individual failures, and adds shutdown and store-level regression tests. Merge readiness✅ Ready for maintainer review Keep this PR open. Current main still has the reported shutdown cleanup path, while the branch has a focused fix and real Gateway and upgrade evidence tied to its final head. The linked shutdown issue remains open; the related Doctor fix addresses a different lifecycle path. Priority: P1 Review scores
Verification
How this fits togetherThe Gateway asks loaded plugins to release session-store resources during shutdown or retirement. Store discovery supplies agent targets, and cleanup updates eligible session state before the Gateway records its close outcome. flowchart LR
A[Gateway shutdown] --> B[Plugin cleanup]
C[Discovered session stores] --> B
D[Deletion journal] --> E{Retained deleted agent?}
B --> E
E -->|Yes| F[Preserve historical store]
E -->|No| G[Clean eligible store]
G --> H[Close outcome]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +44, Tests +317. Total +361 across 4 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Land the focused shutdown fix through the normal PR gates while preserving retained history and completing cleanup for healthy stores. Do we have a high-confidence way to reproduce the issue? Yes. The PR records a published Gateway reproduction using sessions.create, agents.delete with deleteFiles:false, and shutdown; current main still has the affected cleanup loop. Is this the best way to solve the issue? Yes. The branch uses the existing deletion journal and per-store admission boundary, while its Gateway test covers the registered shutdown path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 46147f5e5d13. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (8 earlier review cycles)
|
f8d4bc5 to
4ece373
Compare
|
Both remaining revision-7 items now have observed evidence on Canonical @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Resolved the confirmed merge conflict in normal merge commit Revalidated this exact combined head, including a fresh package build and the unmodified published 2026.9.6 updater against the retained-history fixture. Update returned |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged as 66799b3. Thanks @anyech for fixing the deleted-agent shutdown cleanup, and for the report in #157645 (now closed). Exact-head Gateway proof showed shutdown completing in 450 ms from source and 662 ms after the published-driver upgrade, with exit code 0, a clean-stop receipt, and the retained deleted-agent database unchanged. CI passed and ClawSweeper marked the exact head ready for maintainer review. |
…aw#158473) Gateway shutdown no longer fails or hangs when an agent's directory was deleted while the Gateway was running. Cleanup now skips the missing agent's state instead of trying to reopen it, so shutdown finishes and records a clean stop. Fixes openclaw#157645. Proof: a real Gateway, run from source and from an installed build, with an agent directory deleted before shutdown. The installed build shut down in 662 ms with exit 0 and a clean_stop receipt, leaving the deleted agent's retained database unchanged. An upgrade from the published build reports ok with serviceRestartSafe true. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Fixes #157645: Gateway shutdown fails when a deleted agent's historical directory remains on disk.
User Impact
Operators can retain deleted-agent history and still shut down cleanly. Healthy agents remain eligible for plugin cleanup. This fix introduces no schema, configuration, permission, or public API changes.
Why This Change Was Made
Plugin cleanup skips unconfigured agents positively identified by the existing completed-deletion journal. Database admission remains authoritative when that advisory read fails, and individual store failures are recorded without preventing cleanup of healthy siblings. Shared stores retain deleted agents' logical rows.
Thanks to @anyech for both reporting the failure and contributing the fix.
No overlap with Pash/Sarah changes: their authorship history has no hits on the four changed files.
Evidence
Final head:
32b1ba2f329e3dff1d29719c0b30f841b115794c. The merge ofbb869836e98bresolved a confirmed GitHub merge conflict by preserving both sides' Gateway test imports. The PR remains +377/-16 across the same four files.0e6c5a8d891, created a session usinggateway call sessions.create, then deleted its agent usinggateway call agents.deletewithdeleteFiles:false. SIGINT caused both loaded plugins' session-store cleanup to fail with “agent retired is deleted”; the boot receipt recordedforced_stop. The final built candidate served an active-agent session and loggedcompleted cleanly in 450ms, includingagent database clean-close receipt: written. The retained database's SHA-256 was unchanged. The active database first went through the newer main branch's required Doctor migration; retained history remained untouched.[email protected](eb377ac) into an isolated npm prefix and created retained history through its actual Gateway RPCs, not a seeded deletion journal. Published shutdown reproduced the failure. Its unmodifiedupdate --tag <candidate.tgz> --no-restart --yes --jsonreturnedstatus: ok, activated the package built from the exact final head, and reportedserviceRestartSafe: true(309.373s wall). The installed candidate then servedsessions.create, closed cleanly in 662ms, exited 0, and recordedclean_stop. The retained database remained byte-identical across update and shutdown. The earlier contributor head also passed this complete upgrade cell before the conflict-resolution merge.pnpm test src/plugins/host-hook-cleanup.session-store.test.ts --maxWorkers=1: 20/20, 156.84s wall.pnpm test src/gateway/server-close.agent-databases.test.ts --maxWorkers=1: 4 passed, 1 existing Linux-only test skipped, 236.61s wall. Measured on macOS arm64 / Node 24.21.0, including cold worker preparation. The retained-agent Gateway case protects registered shutdown/disposal, which the plugin-only cases cannot establish.The installed updater retained existing Doctor advisories for preserved history and the deliberately minimal fixture configuration. It correctly skipped managed-service changes for relocated state. No updater or UI behavior was changed by this patch.