Repository navigation
refactor(cron): move retention cleanup off the Gateway thread - #160858
Conversation
Move continuation and reaper planning and ordinary deletion through the existing reclamation worker while retaining live parent authority and fresh durable descendant and maintenance checks before commit. Preserve native mutation custody, cold validation proof, and publication ordering. Carry session-absence authority through receipt cleanup. Follow-up to #160508.
|
🦞👀 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 29, 2026, 5:01 AM ET / 09:01 UTC (Revision 14). ClawSweeper reviewWhat this changesMoves Cron retention and continuation cleanup into SQLite workers, adds live-authority guards for deletion and native opening, and expands regression coverage. Merge readiness⛔ Blocked before merge - 4 items remain Current main still has the foreground cleanup path, so this PR remains useful. The earlier receipt-deletion finding is addressed. The remaining merge blocker is the repository-required upgrade check against existing operator state. Priority: P2 Review scores
Verification
How this fits togetherCron timers and completed continuations ask the session lifecycle owner to remove old run sessions. That owner coordinates SQLite deletion, transcript archival, cache invalidation, and publication-receipt cleanup. flowchart LR
A[Cron timer or continuation] --> B[Session lifecycle owner]
B --> C[Worker prepares deletion]
C --> D{Live session and descendant checks}
D -->|Allowed| E[SQLite deletion and archive]
D -->|Refused| F[Preserved session]
E --> G[Cache and receipt publication]
Before merge
Agent review detailsSecurityNone. PR surfacePR surface statistics unavailable: the file list is incomplete. Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one worker-owned cleanup path that preserves existing retention, transcripts, successor receipts, and native admission across fresh and upgraded installations. Do we have a high-confidence way to reproduce the issue? Yes. Current-main source identifies the foreground deletion path, and the branch includes production-worker cases for the cleanup and receipt races; I did not execute them in this read-only review. Is this the best way to solve the issue? Yes. The branch uses the existing reclamation worker and live-admission owners without adding a competing store or public option; upgrade behavior still needs the required check. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against cec7fe73dc4b. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (13 earlier review cycles; latest 8 shown)
|
Resolve the actual fixed-main lifecycle conflicts while preserving shared target validation and native ownership. Keep the deletion predicate with its planning owner to remove a runtime import cycle, and make internal declarations private. Observe native admission in the existing lifecycle tests without injecting test diagnostics into worker RPC or requiring redundant integrity scans. Preserve FIFO, live authority, source identity, historical archives, and all assertions.
|
The integrated head is now The final grouped admission/Cron command passed 55 cases in 69.05 seconds; the build's own phase timer reports 5m32s. Earlier source-bound native-route proof passed 216 cases with one existing opt-in benchmark skipped. These are measured command/group results, not standalone single-worker timings or a before/after speed comparison. Maintainer disposition of the timing-only request is to reuse that scoped evidence without rerunning solely to produce a separate timing inventory; standalone per-file cost remains unmeasured. The data-model checklist is a heuristic mismatch here. This change preserves the stored schema, row representation, archive format, retention policy, and existing transaction kernels. The native schema guard passed at v19. The added planning messages and cache facts are process/worker coordination, while the projection-state extraction moves the existing kernel; no migration or backfill is introduced. The PR body records the remaining repository-workspace foreground checks and the lack of cross-database atomicity. Exact-head CI is running at https://github.com/openclaw/openclaw/actions/runs/36511885968. Its result remains separate from the scoped proof above. |
Repair regressions introduced by 26dffe7 (#160858). Native Incognito deletion must validate the original row before its synchronous mutation, not reject the row's own removal at commit. Keep configured archive locations independent of the physical database pinned for worker admission. Repair worker-consumer fixtures without weakening assertions: pass the board fixture's state environment, inject rollback TEMP triggers on the deleting worker connection without altering the admitted schema, use the canonical entry writer for the cleanup race, and await shared-state retirement before terminating history-budget workers. No test routing registrations were missing. Proof: eight listed consumer files (99 tests), cron worker lifecycle (11), Gateway sessions.delete lifecycle/state (28), and SQLite deletion/admission siblings (32). Core and affected test types, scoped lint/format, diff checks, and independent Codex review through P2 pass. No schema, retention, permissions, or update behavior changes. Bounded repair gaps: prepared-admission had five failures on main and passed 30/30 at the parent. Its corrected cold integrity probe also blocks an independent writer FIFO callback; experimental fixture changes are not retained. First-signin cannot start on either revision because the artifact fence treats an absent macOS LaunchAgent as unverified when missingUnit is absent. No gate bypass, live Gateway change, or push was performed.
* refactor(storage): run repository workspace SQL in workers Move repository reads and synchronous Kysely mutation kernels to the existing SQLite workers, and await their actual callers. Publish row changes from native commit receipts and retain operation custody through cleanup. Prepared repository facts serve synchronous authorization and event frames. Revalidate the original physical and logical session source at receipt and workspace grants, preserving full logical lookup and direct deletion's historical receipt rules. Remove the obsolete native-handle factory option. No storage schema, public configuration, permission or retention change. Current-main proof passes 80 focused SQLite/worker cases and owning types; qualified receiving adds 198 lifecycle/Gateway cases, all 27 test type graphs, and 66 repository/checkpoint/publication/file-RPC cases. Source controls reproduce foreign-write row and receipt loss, and the repaired paths pass. Independent review is clean through P2. Full build and affected receiving bundle checks pass with recorded source applicability. Completes the repository domain cutover after #145048 and #160858. * fix(gateway): bind prepared events to the current projection * fix(storage): finish committed repository artifact cleanup * fix(test): keep Gateway worker paths in canonical order * test(gateway): align prepared publication fixtures
…ce (#161181) * fix(sessions): keep foreground updates responsive during cold maintenance Prepare the original existing database in the reclamation actor instead of opening the foreground executor first. Require canonical native validation, actual identity and lease acceptance before mutation, preserving incoming and outgoing revocable proof and current-authority checks. Keep caller refusal separate from source health, join native cleanup on source retirement, and retain exact cold versus warm lease accounting. Reuse the original concurrency tests and native admission fixture boundaries. Node proof covers the original 39-case pair, cold concurrency, validation reuse, archive/reclamation and Gateway siblings, with affected lease fixtures verified after accounting for the removed foreground actor. Two preparation lifetime cases also pass on Bun. Changed gates, all 27 test type graphs and independent review through P2 pass. The Linux-only managed SIGTERM case was not run locally. Schemas, retention, permissions and update behavior unchanged. Related: #160858 * fix(sessions): preserve cold preparation diagnostics Carry the logical reclamation context through native preparation and observe its real admission releases in the lifetime regression. Keep the foreground proof on the exact-replacement API using the established scoped fixture environment.
…aw#160858) * refactor(cron): use database workers for session retention cleanup Move continuation and reaper planning and ordinary deletion through the existing reclamation worker while retaining live parent authority and fresh durable descendant and maintenance checks before commit. Preserve native mutation custody, cold validation proof, and publication ordering. Carry session-absence authority through receipt cleanup. Follow-up to openclaw#160508. * fix(sessions): keep worker plan contracts independent of implementations * fix(sessions): preserve SDK deletion state environment Forward the existing SDK env option through lifecycle source capture, while excluding it from cloneable deletion plans. Keep the physical database ownership guard and all existing plugin assertions. Run the SDK session-store tests in the existing host-broker worker group. The original six-file Codex group passes all 24 cases, including both CI failures; all 26 SDK session-store cases also pass. Core types, scoped lint, SDK exports, line caps, and fresh Codex review pass. * test(sessions): complete worker cleanup test routing Route the conversation SDK deletion suite through the existing shared-state host broker and import the reclamation runtime from its current owner. Compare the archive destination by physical path on Windows while retaining transcript contents and exact disk-accounting assertions. The exact preceding CI exposed all three gaps. Focused runtime and routing proof passes 504 cases with one Linux-only case skipped locally; affected types and independent review pass. Windows CI remains platform proof. * test(sessions): route remaining deletion consumers through broker Complete the explicit core and plugin worker test registrations for real permanent-deletion consumers. Preserve all archive and lifecycle assertions. Control the clock only in the held-response Mattermost identity race: the real five-second backfill deadline previously settled before cold worker deletion committed. Keep the separate real deadline test unchanged. Proof: 19 package cases, 185 unchanged Codex cases and 20 final Mattermost cases, routing control, extension types, lint and fresh independent review. * test(subagents): join retained cleanup before restart assertions Wait for the existing admitted-work fixture to settle before polling row removal, so asynchronous deletion cannot leave a restart fence contaminating later cases. Preserve the original assertions, poll and timeout. Route Feishu Doctor through the existing host broker for real SDK deletion. Proof: original four-case sequence failed then passed after the one-statement reorder; all 43 recovery/steer and 19 Feishu cases pass, with affected types, lint, formatting and fresh independent review.
Repair regressions introduced by a02ce7b (openclaw#160858). Native Incognito deletion must validate the original row before its synchronous mutation, not reject the row's own removal at commit. Keep configured archive locations independent of the physical database pinned for worker admission. Repair worker-consumer fixtures without weakening assertions: pass the board fixture's state environment, inject rollback TEMP triggers on the deleting worker connection without altering the admitted schema, use the canonical entry writer for the cleanup race, and await shared-state retirement before terminating history-budget workers. No test routing registrations were missing. Proof: eight listed consumer files (99 tests), cron worker lifecycle (11), Gateway sessions.delete lifecycle/state (28), and SQLite deletion/admission siblings (32). Core and affected test types, scoped lint/format, diff checks, and independent Codex review through P2 pass. No schema, retention, permissions, or update behavior changes. Bounded repair gaps: prepared-admission had five failures on main and passed 30/30 at the parent. Its corrected cold integrity probe also blocks an independent writer FIFO callback; experimental fixture changes are not retained. First-signin cannot start on either revision because the artifact fence treats an absent macOS LaunchAgent as unverified when missingUnit is absent. No gate bypass, live Gateway change, or push was performed.
…161124) * refactor(storage): run repository workspace SQL in workers Move repository reads and synchronous Kysely mutation kernels to the existing SQLite workers, and await their actual callers. Publish row changes from native commit receipts and retain operation custody through cleanup. Prepared repository facts serve synchronous authorization and event frames. Revalidate the original physical and logical session source at receipt and workspace grants, preserving full logical lookup and direct deletion's historical receipt rules. Remove the obsolete native-handle factory option. No storage schema, public configuration, permission or retention change. Current-main proof passes 80 focused SQLite/worker cases and owning types; qualified receiving adds 198 lifecycle/Gateway cases, all 27 test type graphs, and 66 repository/checkpoint/publication/file-RPC cases. Source controls reproduce foreign-write row and receipt loss, and the repaired paths pass. Independent review is clean through P2. Full build and affected receiving bundle checks pass with recorded source applicability. Completes the repository domain cutover after openclaw#145048 and openclaw#160858. * fix(gateway): bind prepared events to the current projection * fix(storage): finish committed repository artifact cleanup * fix(test): keep Gateway worker paths in canonical order * test(gateway): align prepared publication fixtures
…ce (openclaw#161181) * fix(sessions): keep foreground updates responsive during cold maintenance Prepare the original existing database in the reclamation actor instead of opening the foreground executor first. Require canonical native validation, actual identity and lease acceptance before mutation, preserving incoming and outgoing revocable proof and current-authority checks. Keep caller refusal separate from source health, join native cleanup on source retirement, and retain exact cold versus warm lease accounting. Reuse the original concurrency tests and native admission fixture boundaries. Node proof covers the original 39-case pair, cold concurrency, validation reuse, archive/reclamation and Gateway siblings, with affected lease fixtures verified after accounting for the removed foreground actor. Two preparation lifetime cases also pass on Bun. Changed gates, all 27 test type graphs and independent review through P2 pass. The Linux-only managed SIGTERM case was not run locally. Schemas, retention, permissions and update behavior unchanged. Related: openclaw#160858 * fix(sessions): preserve cold preparation diagnostics Carry the logical reclamation context through native preparation and observe its real admission releases in the lifetime regression. Keep the foreground proof on the exact-replacement API using the established scoped fixture environment.
…ns (#161608) The prepared-admission maintenance probes pre-released every native integrity check, so they passed even when cold validation ran in the foreground executor under the writer permit (#160858's shape, repaired by #161181). Hold the first integrity check on the fixture database in any worker, assert the reclamation worker owns it, and require a foreground replacement commit while it is held, for the whole-store, lifecycle and replacement entry points and the finalizer lifetime recheck. Keep expired-proof finalization as its own case on the retained branch: the reclamation worker revalidates before committing while foreground writes proceed. Existing integrity-counter callers keep their message shape; the unused before-writer hold mode is removed. With the executor-first preparation temporarily restored, the four cold cases fail in about 2 s each on the owner assertion.
…ns (openclaw#161608) The prepared-admission maintenance probes pre-released every native integrity check, so they passed even when cold validation ran in the foreground executor under the writer permit (openclaw#160858's shape, repaired by openclaw#161181). Hold the first integrity check on the fixture database in any worker, assert the reclamation worker owns it, and require a foreground replacement commit while it is held, for the whole-store, lifecycle and replacement entry points and the finalizer lifetime recheck. Keep expired-proof finalization as its own case on the retained branch: the reclamation worker revalidates before committing while foreground writes proceed. Existing integrity-counter callers keep their message shape; the unused before-writer hold mode is removed. With the executor-first preparation temporarily restored, the four cold cases fail in about 2 s each on the owner assertion.
What Problem This Solves
Cron retention and continuation cleanup still perform database planning and deletion on the Gateway thread, including cold database access. Moving that work exposed two correctness gaps: delayed receipt cleanup could erase a recreated session’s receipts, and native opening could repair an index after the caller revoked authority during integrity validation.
User Impact
File-backed cleanup leaves the event loop available while preserving active descendants, pending media, recent sessions, base transcripts, and native harness ownership. Permanent deletion removes historical and late old-generation publication receipts while preserving a successor’s receipts and replay records. Revoked native opening now unwinds before schema repair.
There is no new configuration, schema, retention contract, SDK option, or protocol version. Ordinary authorized opening retains its existing repair behavior.
Ownership
The existing reclamation worker owns asynchronous planning and synchronous commit. The host retains live admission and original native rollback objects; the worker rereads durable descendant and maintenance facts after the host grants authority. Cold operations retain native database identity without opening a foreground SQLite handle. Confirmed worker results invalidate parent caches and retained facts before observers.
Receipt cleanup captures historical receipt identities before removing the original session. Its final shared-state transaction selects those identities or receipts bound to the exact removed session ID and lifecycle revision. This includes late old-generation inserts without deleting same-ID/new-revision successors. A missing personal lifecycle binding remains distinct from an explicitly absent revision.
Native opening uses the same private integrity generator. Before every synchronous resume, its existing admission owner rechecks the captured lease and original live source; refusal uses the existing unwind path before repair can resume. The synchronous driver now shares the existing admission factory with the other two drivers, preserving the public three-argument function and main-thread maintenance behavior.
Opaque native harness mutations retain their process-held transaction owner. This does not provide cross-database atomicity. Repository-workspace cleanup’s remaining authoritative foreground checks are preserved here and belong to the separately assigned repository-workspaces migration.
Evidence
Current head:
16d75590f497f9099ffd5ada8ba851c21c8c69f7, composed with fixed mainb4ae783fbfd2d50307ef9af357ed944120a1824dfor an actual conflict.The regressions exercise the real owners:
Final receiving proof passes 74 cases with one Linux-only signal case skipped on macOS. Post-organization native proof passes 70 cases, including environment capture, both Gateway cases, physical/source ownership negatives, integrity, and main-thread prepared-lease maintenance. Integrity-driver/worker siblings pass another 54 cases. Three predetermined plain-source Gateway samples each pass both cases with unchanged source, assertions and deadlines; these are bounded stability results, not a claimed cause for an earlier unexplained RPC timeout.
The complete changed-file gate passes: core types, all 27 core-test type graphs, formatting, line/assertion ratchets, dependency and SDK boundary guards, all three unused-export scans, core/scripts lint, schema/storage guards and runtime cycles. The separate Madge check reports zero cycles. Fresh full-context Codex review found no actionable P0–P2 issue.
Source-bound earlier proof includes 80 receipt/deletion/Cron cases, 24 original-order Codex cases plus 26 SDK cases, and the receiving Doctor/cold-snapshot/migration controls. Test routing now uses the existing broker owners for real deletion consumers; the actual analyzer was checked for 157 named callers/helpers, including former-fast watch admission. Held-response and restart fixtures now control their intended ordering or join the existing work owner; production deadlines and forbidden-effect assertions remain intact.
These are composed results, not one whole-suite run. The full build at
9aabc0b3passed in 27m17.3s and is reused only for unaffected scope; maintained worker compilation executed the final native source during current proof. No current whole published-driver upgrade comparison or matched before/after throughput claim is made. The Gateway retirement implementation itself is received from canonical #160201; the new opening-authority check is qualified separately above. Earlier failed and cancelled CI runs remain failed/cancelled. Exact-head CI and native admission remain the final landing gates.