Skip to content

perf(sessions): avoid cloning registry maintenance snapshots - #160510

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-session-registry-owned-snapshot-20260928
Sep 28, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-session-registry-owned-snapshot-20260928

Conversation

@steipete

@steipete steipete commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

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 structuredClone calls 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, profile openclaw-check, lease tbx_01m3m60nkd3vfy9n81hyyx0q9k (run). Baseline eed9d9bf225e and the candidate ran on the same lease through runSessionRegistryMaintenanceForStore, with 256 entries averaging about 35 KB and 20 sweeps per phase. Allocation sampling includes objects collected by minor and major GC.

Per sweep Before After
Preview allocation 38,263,438 B 19,447,991 B
Apply without removals allocation 36,212,281 B 18,092,201 B
Preview allocation under structuredClone 18,932,588 B 0 B
Apply allocation under structuredClone 17,998,430 B 0 B
Preview wall time 64.24 ms 45.83 ms
Apply wall time 61.96 ms 40.76 ms
Preview main-thread CPU 44.34 ms 23.43 ms
Apply main-thread CPU 42.26 ms 20.21 ms

Allocation 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.ts passed 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 no origin/main ref; 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 and git diff --check passed. The lease was stopped before committing.

CI on 14342eb64d41 exposed 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 6e58f0986088 brings the canonical repairs d9569745764f (heartbeat), 9b730f0cfb47 (channel fixture package repair), 6b9da9dc0287 (roster ordering), and f03d64f6a56e (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.

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.
@steipete
steipete marked this pull request as ready for review September 28, 2026 15:13
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete enabled auto-merge (squash) September 28, 2026 15:17
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 28, 2026
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 28, 2026, 1:12 PM ET / 17:12 UTC (Revision 2).

ClawSweeper review

What this changes

Cron 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
Reviewed head: 779f4ff74f175263b7d34351ab81c04a34ae8afe

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused, shrinking production patch has relevant safety coverage and detailed before/after measurements, with no actionable defect found.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body reports before/after measurements from the production maintenance entrypoint on a 256-entry Testbox fixture, with lower allocation and time after the change; focused tests cover preview persistence and a concurrent snapshot change. The linked workflow was cancelled, so the detailed PR-body measurements carry the performance observation. No stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body reports before/after measurements from the production maintenance entrypoint on a 256-entry Testbox fixture, with lower allocation and time after the change; focused tests cover preview persistence and a concurrent snapshot change. The linked workflow was cancelled, so the detailed PR-body measurements carry the performance observation. No stored-data contract changes.
Evidence reviewed 9 items Introduced change: The pinned PR delta builds one fresh key map over worker-returned entries and uses it for preview or apply; it removes both store-wide structured clones.
Current-main necessity: Fetched current main still clones the entire map separately for preview and apply.
Pruning behavior: The prune helper deletes eligible synthetic keys from its map; its in-place entry-archive branch is for non-synthetic entries, which this caller preserves.
Findings None None.
Security None None.

How this fits together

Cron 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -15, Tests +64. Total +49 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 11 26 -15
Tests 1 67 3 +64
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 78 29 +49

Review metrics

Metric Value Why it matters
Measured allocation preview 38.3→19.4 MB; apply 36.2→18.1 MB per sweep The PR reports these before/after values for the same 256-entry Testbox fixture, giving maintainers a bounded performance result.

Technical review

Best 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.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • remove rating: 🦞 diamond lobster: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: This is a focused session-maintenance performance improvement with limited user-facing blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body reports before/after measurements from the production maintenance entrypoint on a 256-entry Testbox fixture, with lower allocation and time after the change; focused tests cover preview persistence and a concurrent snapshot change. The linked workflow was cancelled, so the detailed PR-body measurements carry the performance observation. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body reports before/after measurements from the production maintenance entrypoint on a 256-entry Testbox fixture, with lower allocation and time after the change; focused tests cover preview persistence and a concurrent snapshot change. The linked workflow was cancelled, so the detailed PR-body measurements carry the performance observation. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • SunnyShu: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Josh Lehman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-28T15:26:22.357Z sha 14342eb :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Sep 28, 2026
@steipete
steipete merged commit c23c659 into main Sep 28, 2026
217 checks passed
@steipete
steipete deleted the steipete/perf-micro-session-registry-owned-snapshot-20260928 branch September 28, 2026 17:33
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 29, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant