Repository navigation
fix(agents): release model and auth readers when deleting agents - #159013
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. |
✅ Maintainer security changes approvedA maintainer approved this revision with an explicit security approval comment.
A later push requires a fresh approval comment for an external contributor's PR. |
|
Codex review: blocked before merge. Reviewed October 2, 2026, 1:31 AM ET / 05:31 UTC (Revision 16). ClawSweeper reviewWhat this changesAgent deletion retires model and memory resources, drains database readers across workers, preserves surviving agents’ stores, and restores readers after legitimate recreation. Merge readiness⛔ Blocked before merge - 1 item remains The PR remains necessary and has no identified blocking patch defect. Prior lifecycle findings are resolved, and the previous migration checkbox is inapplicable because the change introduces no stored-data contract. Likely related people: @steipete (high-confidence routing through current-main area history and recorded owner involvement). Priority: P2 Review scores
Verification
How this fits togetherThe Gateway’s agent lifecycle coordinates configuration, model and memory owners, and SQLite readers. Deletion must release these resources before file cleanup while preventing later workers from reopening retained deleted stores. flowchart TD
A[Agent delete request] --> B[Journal and live lease checks]
B --> C[Select deleted agent resources]
C --> D[Retire model and memory owners]
D --> E[Drain and fence database readers]
E --> F[Complete cleanup]
G[Committed agent recreation] --> H[Restore reader admission]
H --> E
Before merge
Agent review detailsSecurityNone. PR surfaceSource +539, Tests +943, Other +2. Total +1484 across 58 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: 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: Keep deletion cleanup with the existing lifecycle and worker owners, preserving survivor access and committed recreation outcomes. Do we have a high-confidence way to reproduce the issue? Yes, source supports the reported deletion-time leak: current main omits retirement and cross-worker reader fencing. The recorded real Gateway sequence creates a session, refreshes secrets, deletes its agent, and checks retained readers; this review did not execute it locally. Is this the best way to solve the issue? Yes, the patch extends existing lifecycle, model, memory, and worker owners and removes superseded reader-close paths. It preserves physical ownership checks and avoids a competing recovery manager. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b21e522e2ad1. 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 (15 earlier review cycles; latest 8 shown)
|
|
The memory-manager follow-up is now included in The latest hosted run has one failing test: deferred-restart SecretRef revalidation timeout. The other 1,525 cases in that shard passed. The preceding SDK-generation timeout and repair-log assertion did not recur in this run. I investigated without changing or weakening the failing test. Both variants pass on the candidate and pristine pinned base. This case mocks out the secrets preparation and model ownership changed here, and does not perform agent deletion. However, hosted CI tested merge Could a maintainer rerun the failed CI jobs? This account is not permitted to rerun them. The cleanup source remains unchanged; if the timeout repeats, the next useful reproduction is that exact merge on Linux/Node 24 rather than increasing timeouts or adding retries to this patch. |
1ad87ed to
00ede2a
Compare
|
Addressed both lifecycle findings in
Final focused proof: 321 tests across agent mutations, native reload handlers, and read-only scopes pass; production/Gateway-methods types, typed lint, formatting, native line caps, and fresh scoped review pass. No new Gateway boot was added. The preceding CI reader failure was also reproduced: a one-shot injected close error lets a second registered closer close the handle. Its fault now persists until the explicit retry, while preserving error identity, custody, and survivor assertions. The Windows sparse-checkout fixture remains unrelated and unchanged. The four hosted verifier-child exits remain unexplained despite a passing exact-file local run, so I am not calling full CI green. Details and original failed-run attribution are in the updated PR body; the exact-head maintainer security gate is still required. |
|
/allow-security-sensitive-change |
|
Merged via squash.
|
The complete SubsystemLogger mock from 06d2de9 (#163249) already provided trace. Merging 40d284f (#159013) added it again and broke check-test-types-core-4 with TS1117. Keep one trace and every other logger method; no test case or assertion changes. Validation: gateway-root tsgo, check-changed, scoped and boundary lint, and P2 review. Static proof ran locally as authorized for this main repair.
The catalog-worker deletion test introduced by #159013 expected an idle WAL reader to keep the surviving agent database locked. That lock is already absent before deletion on current main. Verify the actual survivor contract instead: commit a new auth profile through an independent connection, then read the exact update through the existing prepared worker. Keep the deleted-database lock-release and single live-worker assertions. Validation: five complete local file runs, local and Linux Testbox check-changed, changed-file and boundary lint, and P2 review passed. The full infra run was cancelled before completion. Landing uses the coordinator-approved single-file Testbox exception for this test-only change; the completed focused and static proof remains valid. Three additional post-rebase file runs passed.
…nclaw#159013) * fix: release deleted agents' model and auth resources * fix: await only existing deleted-agent builds * fix: close deleted agents' native memory managers * fix(agents): close deleted database readers across worker isolates * fix(agents): revive deleted stores by their captured owner * refactor(state): remove superseded reader-close entry points * fix(agents): preserve commit outcomes and close readers before trash * fix(tooling): include agent readers in native wrapper inventory * fix(agents): adapt deleted-reader cleanup to native worker owners * fix(agents): preserve deletion fences across worker generations * fix(agents): release deletion guards and repair CI proof Release worker heartbeat references when a deletion lease closes. Keep the journal authority SELECT in its worker-only module and route the catalog reader fixture through the existing database-worker lane. Close the survivor fixture's seed writer before recovery, establish archive LRU order, and restore the shared logger mock's trace contract. Add effect boundary coverage for revoked deletion authority and move bounded transport, channel logging, and fixture code to their existing modules. Preserves the agent deletion and recreation repair for openclaw#159007. Co-authored-by: Chris Eckert <[email protected]> * test(ci): retain native command and auth retirement diagnostics Wait for a native command receipt before checking its result so a terminal failure exposes its reason immediately. Include isolated Gateway logs in the removed-profile assertion, with a debug-only publication retirement summary that identifies cache, owner, pending-build, and Gateway-loan state. This diagnoses UI and auth failures from CI run 36965599681 without relaxing assertions, extending timeouts, or changing retirement/recovery authority. Co-authored-by: Chris Eckert <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: Chris Eckert <[email protected]>
The complete SubsystemLogger mock from ddd9021 (openclaw#163249) already provided trace. Merging 69f660d (openclaw#159013) added it again and broke check-test-types-core-4 with TS1117. Keep one trace and every other logger method; no test case or assertion changes. Validation: gateway-root tsgo, check-changed, scoped and boundary lint, and P2 review. Static proof ran locally as authorized for this main repair.
The catalog-worker deletion test introduced by openclaw#159013 expected an idle WAL reader to keep the surviving agent database locked. That lock is already absent before deletion on current main. Verify the actual survivor contract instead: commit a new auth profile through an independent connection, then read the exact update through the existing prepared worker. Keep the deleted-database lock-release and single live-worker assertions. Validation: five complete local file runs, local and Linux Testbox check-changed, changed-file and boundary lint, and P2 review passed. The full infra run was cancelled before completion. Landing uses the coordinator-approved single-file Testbox exception for this test-only change; the completed focused and static proof remains valid. Three additional post-rebase file runs passed.
Closes #159007
What Problem This Solves
Deleting an agent can leave model/auth readers and native memory owners alive, or allow later workers to reopen its retained database. A stale deleted-agent registration can also point to a surviving agent's database; path-only cleanup must not close or fence that survivor.
User Impact
Deletion retires model and memory owners and drains physical readers before completion and file cleanup. Current and replacement workers keep retained deleted stores fenced until legitimate recreation. Independently surviving agents remain readable, including when a historical registration names their database. A failed worker revival message does not turn a committed recreation into failure.
There is no schema, stored-format, configuration, credential-policy, or retained-history migration. The configured-candidate flag and reader fences are transient lifecycle facts.
Why This Change Was Made
The deletion plan now separates all registration paths, needed for removal under the deleted agent ID, from survivor-filtered reader paths, used for path-only auth-reader closure and cross-worker fencing. Historical directories remain available to model retirement, which checks both agent ID and directory.
New runtime journal checks read exact operation identity and completion state through the existing state-read worker, then verify live lease ownership through the existing heartbeat worker. They recheck closure, cancellation, and captured state admission after awaiting. Existing transaction and native cleanup commit checks retain their current contracts. Authority is also verified after lazy imports and before the first model-retirement effect.
Main integration preserves current catalog-publication and session-history scope owners. Contributor ancestry remains intact.
Owner direction
On October 1, 2026, repository owner Peter Steinberger, an active organization admin, explicitly directed: “contributor PRs that fit into our plan: improve and land.” This PR is included in that approved scope. That direction supplies owner involvement for its restricted/security paths under AGENTS.md; final-head CI and review gates remain enforced.
Evidence
Candidate:
c724689570f625a9606ee5f7266fbc4bca632bd3. Integrated main:9fc095cae88889df55309cf4bfd73fe7920f09c9.Main integration before landing
GitHub reported a real conflict after native preparation of the passing ad6e209 candidate. Main had independently landed the same deterministic archive-LRU fixture assertions; the sole conflict was their comment wording. The merge keeps main's wording, current transcript read owners, the PR's generic reader-close handling and catalog-worker test routing. The integrated candidate passed full independent review through P2. ClawSweeper revision 14 accepted its unchanged production-boundary proof with no blocking patch defect; its CI failed as described below; the passing execution results below remain explicitly bound to ad6e209.
Current CI investigation
Run 36965599681 tested e902786 and failed two jobs, with 109 successful jobs and 22 skipped. The aggregate gate reflects those two failures. No failed job was blindly rerun.
The UI native-session action returned a terminal
{ok:false}receipt, but its assertion omitted the error reason. That feature and case came from main's #163193 and have no owning fix through inspected main 970faff. The auth product case successfully completed profile logout and refresh, then chat reported a retired plugin generation instead of missing-profile recovery. Its affected source is unchanged from passing ad6e209, and the precise cache/registry retirement source remains unestablished.The current diagnostic commit preserves all authority rules, assertions and timeouts. It waits for a native command receipt before validating it with its full reason, attaches isolated Gateway logs to the auth assertion, and records four non-sensitive retirement facts through the existing debug logger. Independent review is clean through P2. The diagnostic run completed successfully as recorded below. This passing replay does not identify or repair the earlier intermittent causes; no timeout, assertion or recovery authority was relaxed.
Final-head hosted result
CI run 36967591602 passed for
c724689570f625a9606ee5f7266fbc4bca632bd3: 115 successful jobs, 21 skipped, no failures. Its checked-out merge wasad11c77e9e9546ad2620cc451286c698784f12e3, with base18966380071ee171527a11a914fc6cafb0db05fb. Original hosted logs verify all 282 focused cases, with no selection gaps:Times are reporter case sums, not file wall time. The previously failing selected-session native action passed in 2.320 s (UI job); removed-profile recovery passed in 11.374 s (Node job). Captured Gateway logs are emitted only on assertion failure, so the successful run does not establish which retirement events occurred internally.
ClawSweeper revision 15 reviewed this exact head at 2026-10-02T05:16:28.229Z: no blocking patch defect, behavior proof sufficient, and no stored-data contract change requiring migration proof. The remaining generated migration checkbox contradicts that explicit assessment and does not apply to this transient lifecycle repair.
Corrective CI attribution
Run 36959800135 tested
7ecc748e25d61c1cb35b43f1d9f105ac721931a8: 102 successful jobs, 22 skipped, and six failed jobs plus the aggregate gate. Each failure was investigated before this corrective push:The same run reported three advisory file-length warnings. Small extractions move transport serialization to its existing worker module, channel-suppression logging to channel restart, and fixture constructors to existing test support. No cap was raised. These warnings did not cause the GitHub ratchet failure.
The existing real model-owner test now calls deletion runtime retirement with replaced journal authority and a closed operation, verifies both published snapshots remain current, then retires the intended owner as a positive control. The Gateway handler test additionally rejects authority lost during session purge before reader fencing, Trash, unregistering, or completion. Existing real-worker tests separately establish stolen-lease rejection and closure during an outstanding journal reply.
The corrective delta passed independent review through P2. Secretless GitHub CI run 36962111463 completed successfully on
ad6e209362c8d1b7b03b5e85c271c6aa7f79d893, using its bound synthetic merge091bfb78. The enforced CI gate, SQL ratchet, type and lint checks passed. Maintainer security approval is recorded for this exact head.Passing behavior proof on the prior candidate ad6e209
The following results were read from the completed run's original log archive. Times are sums of reporter case durations, not file wall time; imports, setup and teardown are excluded. No contributor code ran locally.
Selected ad6e209 terminal results, reduced to synthetic test names and durations:
The model-owner case invokes the actual deletion runtime with replaced and closed authority, observes that the real published snapshots remain current, then proves the intended snapshot can be retired. Stolen-lease and held-reply closure semantics are exercised through real journal/heartbeat workers. The handler's post-purge refusal test uses mocked effect boundaries; actual physical reader closure, survivor recovery, fencing and replacement-worker behavior are exercised by the real Gateway/catalog-worker cases. This is complementary boundary coverage, not a claim that the mocked refusal case performs physical reader I/O.
ClawSweeper revision 13 completed on ad6e209 at 2026-10-02T04:16:58.312Z: prior findings resolved, no blocking patch defect, and the recorded production-boundary evidence satisfies the proof request. Its residual data-model checkbox is inapplicable, as the review itself confirms. No schema, journal encoding, durable receipt, retention rule, or configuration migration is introduced; the worker fences and configured-candidate fields are transient lifecycle state, so no stored-data migration proof applies.
Incoming CI attribution
Run 36774346839 belongs to original head
de1caeb419fa4ad7d5f54cc0c26cccd9c8e9eaf4and failed. Three failures have owning fixes included through main: first-signin's incidental confirm-versus-note expectation (5c4041708d66, #161451); shutdown's short polling instead of a model-start signal (22d7946296bf, #162133); and private-completion cancellation losing canonical generation/FIFO ownership (fef7992b3697).The Bun provider-readiness case failed after 5,124 ms against a 5,000 ms deadline and remains unattributed. Its unchanged loop, a later directory-mismatch diagnostic, and subsequent Bun upgrades do not establish a specific fix. No failed job was blindly rerun; the changed candidate needs its own CI result.
Contributor credit
Thanks to Chris Eckert (@ceckert) for the original repair and real Gateway proof. All ten contributor commits remain in the branch, with human co-author credit preserved for landing.
Historical contributor proof on de1caeb
The following results are contributor evidence for their named earlier heads, not proof of the new candidate.
Original-head contributor evidence
agents.delete(deleteFiles:false)succeeds and the database inode is retained, the first real worker wrongly reads that deleted database. The unchanged expectation fails. The repair also closes the rotated-worker boundary and captures fences after an already-queued asynchronous input finishes.agents.createcommit succeeds but a precisely targeted failedrevivepacket leaves the next real worker read fenced. The unchanged expectation fails. With parent-first revival, the pool's next real worker task recovers.