Repository navigation
fix: retain agent database lease owners during cleanup - #138454
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: blocked before merge. Reviewed September 4, 2026, 2:43 PM ET / 18:43 UTC. ClawSweeper reviewWhat this changesThe PR captures an agent database lease’s resolved state-store directory and external-supervision status when acquired, then uses that immutable snapshot for later cleanup. Merge readiness⛔ Blocked before merge - 1 item remains Keep open. The introduced snapshot repairs the actual mutable-environment ownership defect across normal close, eviction, failed-open cleanup, and Worker settlement; no blocking patch defect was found. Current main still has the pre-fix source, and this maintainer-authored, maintainer-labeled PR is not eligible for automated cleanup closure. Priority: P2 Review scores
Verification
How this fits togetherAgent database handles acquire durable leases in OpenClaw’s shared SQLite state store before opening. Cache close, eviction, failed opens, and worker shutdown must remove the lease from that same state-store owner without creating state in a later environment. flowchart LR
A[Agent database open] --> B[Resolve state-store owner]
B --> C[Acquire durable lease]
C --> D[Cache database handle]
D --> E[Close, eviction, or worker shutdown]
E --> F[Release original lease]
F --> G[Shared state database]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +9, Tests +163. Total +172 across 3 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the local two-field acquisition snapshot: it is the minimum state that identifies both the original store and its write permission, so a net-neutral cleanup refactor cannot preserve the invariant. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: opening durable A, changing the state environment to B, then closing or evicting the cached handle follows the old mutable environment into the wrong state store. The new focused tests encode that order for normal, external-supervisor, Worker, failed-open, and eviction cleanup. Is this the best way to solve the issue? Yes. The state-store choice is made by the lease callee from its environment, and the opener is the only boundary that knows the resolved acquisition directory plus supervision state; a close-only workaround would miss eviction and failed-open paths. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 26f87a37009b. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
The nine-line production increase is accepted for this repair. The opener is the only boundary that knows both the resolved state directory and supervision mode at acquisition. Keeping those two facts in one private snapshot replaces the borrowed environment in the existing lease cache; every release path uses it, and no public configuration or persistence contract changes. This is the mitigation recommended by the review. A cleanup-only guard would miss eviction and failed-open paths; retaining the entire caller environment would carry unnecessary state. The source review and the real SQLite RED→GREEN proof support the current owner-level fix. No additional code change is needed for this item. Exact-head CI remains a separate landing gate. The current run has a UI performance failure being handled separately; the lease-related compact test shard passed. The original run and its diagnostic will remain recorded. |
Capture the canonical state directory and supervision facts when a durable agent database lease is acquired. Reuse that owned snapshot for every release path after ambient or caller-provided environments change. Cover normal close, eviction, Worker settlement, and immediate or retained failed-open cleanup without changing schemas or persisted data.
53cc9f9 to
5fa2b51
Compare
|
Merged via squash.
|
Capture the canonical state directory and supervision facts when a durable agent database lease is acquired. Reuse that owned snapshot for every release path after ambient or caller-provided environments change. Cover normal close, eviction, Worker settlement, and immediate or retained failed-open cleanup without changing schemas or persisted data.
What Problem This Solves
Resolves a problem where closing a cached agent database after its environment changes could create an unrelated shared-state database and leave its original durable lease behind. The stale lease can block database maintenance. The same producer defect reproduces an empty-state violation during incognito transcript cleanup; it does not persist the incognito transcript itself.
Why This Change Was Made
The cache retained either an absent environment or the caller’s mutable environment object. Release then resolved the current directory and supervision mode instead of the lease’s acquisition owner. Capture the canonical state directory and supervision flag at acquisition, and reuse that private snapshot for claim, failed-open cleanup, cached close, eviction, and Worker settlement. Existing release consumers stay unchanged. No schema, stored representation, migration, configuration, or RPC changes.
User Impact
Cleanup releases the lease in the store that granted it without creating state in a later environment. Incognito sessions retain their no-disk behavior. Production changes are 14 added / 5 removed lines; the nine-line increase establishes owned acquisition facts in place of a borrowed environment. Cache hits and incognito opens return before this capture.
Evidence
7167fb6f1959e9ecb9381e33c4c0a36b6865459a, Node 24.19.0, four effective CPUs, canonical frozen dependencies, and complete source/mode guards.typescript/unbound-methodlint failure; the corrected test passes lint, its consuming test type graph, formatting/ratchets, and all eight previously unrun guards. The original aggregate exit 1 remains recorded; this is not a claim that the original aggregate passed. The source-performance build and final source guard pass. Independent P0–P2 review is clean.control-ui-performanceand the aggregate gate failed. On Node 24.20.0, startup gzip was 350,388 B against a 350,141 B limit. The exact CI merge changes only the three state files; its UI and dependency inputs match its main base. Already-merged fix(channels): keep quiet progress and the tool log under toolProgress #137342 passed its UI gate at 348,987 B under the unchanged limit. One patch-identical refresh onto main0062f2b127bbbdc9fd7db65c679066a11101b6c3preserves all three reviewed postimages; refreshed CI run 33906807123 completed successfully on exact head5fa2b514aeff1b1cd5d5d8b5af368dd7ebbe6c3e, including both Windows jobs andopenclaw/ci-gate.The original hosted log does not identify the previously retained durable handle, so this proves the producer defect and matching failure order/shape, not the exact hosted predecessor. No overall Gateway latency improvement is claimed.