Repository navigation
perf(sessions): avoid cloning registry maintenance snapshots - #160510
Conversation
Prune the fresh key map over owned worker entries and share preview/apply planning. Keep ordinary entries immutable, preserve active work, and retain full-entry deletion CAS and live commit authority. The real worker-entrypoint benchmark with 256 sessions reduced allocation from 38.3 to 19.4 MB per preview and 36.2 to 18.1 MB per apply sweep. Seven owner tests, changed-file checks and independent review through P2 passed on Testbox tbx_01m3m60nkd3vfy9n81hyyx0q9k.
|
🦞👀 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 28, 2026, 1:12 PM ET / 17:12 UTC (Revision 2). ClawSweeper reviewWhat this changesCron session maintenance plans previews and removals from worker-returned entries without cloning the full registry, with tests for snapshot preservation and concurrent changes. Merge readiness✅ Ready for maintainer review Current main still makes the reported full-registry copies. The related open PR addresses metadata reads, a distinct allocation source, and this review found no actionable defect in the proposed optimization. Priority: P2 Review scores
Verification
How this fits togetherCron maintenance receives running-job information and session entries from a read worker, then selects expired cron runs. The lifecycle writer archives their transcripts and removes eligible rows after checking current authority and stored entry identity. flowchart LR
A[Maintenance request] --> B[Running job IDs]
A --> C[Session entries from read worker]
B --> D[Retention selection]
C --> D
D --> E[Preview counts]
D --> F[Lifecycle writer]
F --> G[Transcript archive and row removal]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -15, Tests +64. Total +49 across 2 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep the lifecycle writer as the sole deletion owner, retaining full-entry and current-authority checks while maintenance uses its owned read snapshot for selection. Do we have a high-confidence way to reproduce the issue? Yes, at source level: current main makes a full-registry clone in both preview and apply. The PR supplies a repeatable benchmark scenario, which this read-only review did not execute. Is this the best way to solve the issue? Yes. Reusing the worker-returned entries inside a fresh key map removes the extra copies while the existing lifecycle writer retains the deletion checks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 46a227c51867. LabelsLabel changes:
Label 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)
|
…w#160510) Prune the fresh key map over owned worker entries and share preview/apply planning. Keep ordinary entries immutable, preserve active work, and retain full-entry deletion CAS and live commit authority. The real worker-entrypoint benchmark with 256 sessions reduced allocation from 38.3 to 19.4 MB per preview and 36.2 to 18.1 MB per apply sweep. Seven owner tests, changed-file checks and independent review through P2 passed on Testbox tbx_01m3m60nkd3vfy9n81hyyx0q9k.
What Problem This Solves
Cron registry maintenance copies every saved session snapshot a second time while deciding which expired cron runs to remove.
User Impact
Maintenance allocates about half as much memory in the measured fixture and spends less time on the main thread. Retention, preview behavior, transcript archiving, and active-work protection stay the same.
Why This Change Was Made
The worker reply already owns its entries, and the caller builds a fresh key map. Ordinary sessions are preserved before pruning; eligible cron sessions are removed from that map without mutating their entries. Both
structuredClonecalls and the duplicate preview-planning branch are deleted. The lifecycle writer still receives full expected entries and checks caller authority and current stored values before deleting anything.Production code shrinks by 15 lines. An existing preview test now checks ordinary cold snapshots, and a deletion-race test verifies that changing only saved skills after planning preserves the session and transcript.
Evidence
Provider
blacksmith-testbox, profileopenclaw-check, leasetbx_01m3m60nkd3vfy9n81hyyx0q9k(run). Baselineeed9d9bf225eand the candidate ran on the same lease throughrunSessionRegistryMaintenanceForStore, with 256 entries averaging about 35 KB and 20 sweeps per phase. Allocation sampling includes objects collected by minor and major GC.structuredClonestructuredCloneAllocation falls 49.2% for preview and 50.0% for apply; measured wall time falls 28.7% and 34.2%. End-of-phase process RSS varied from 667–689 MB before and 655–676 MB after; this is not a sustained-RSS or loaded-Gateway measurement. Worker serialization still allocates the owned reply.
The task-only probe ran with
OPENCLAW_SESSION_REGISTRY_CLONE_BENCH=1 node scripts/run-vitest.mjs src/config/sessions/session-registry-clone.benchmark.test.ts --maxWorkers=1; its temporary source was removed after measurement. It proves preview is non-persistent, eight eligible rows are removed by apply, and running/admitted/recent/ordinary sessions retain their snapshots.node scripts/run-vitest.mjs src/config/sessions/session-registry-maintenance.test.ts --maxWorkers=1: baseline 6 passed, candidate 7 passed. Runner wall was 12.19 → 12.14 s; candidate test time was about 5 s. The added case needs the actual read-worker-to-lifecycle-writer race to protect deletion CAS; it adds no process boot beyond the existing fixture owner.node scripts/check-changed.mjs --base eed9d9bf225e517e4be07048bb66bec604eb2bb7 -- src/config/sessions/session-registry-maintenance.ts src/config/sessions/session-registry-maintenance.test.tspassed in 27m58s, including production types, all 26 selected core test-type graphs, unused-export scans, scoped lint, and the selected architecture/boundary guards. The first invocation stopped because the shallow Testbox had noorigin/mainref; the successful run used the exact baseline commit. Independent Codex review, including the unchanged pruning and worker-reader owners, was scoped-clean through P2. Formatting andgit diff --checkpassed. The lease was stopped before committing.CI on
14342eb64d41exposed inherited fixture failures: heartbeat delivery-confirmation timing; package repair during Slack channel presentation; initial-roster ordering in the sidebar digest; and startup readiness in model-control/avatar UI fixtures. The actual failing jobs were in run 36441931897. The lint stripe was canceled, not a reported lint violation.Integration of main
6e58f0986088brings the canonical repairsd9569745764f(heartbeat),9b730f0cfb47(channel fixture package repair),6b9da9dc0287(roster ordering), andf03d64f6a56e(shared UI startup fixtures). No product change or weakened assertion was added for these failures; the avatar timeout's exact trigger remains unproven. The final PR diff is still only the two registry-maintenance files. Fresh review of that diff is scoped-clean through P2. CI for the new head is being monitored; no rerun or auto-merge command was issued.