Skip to content

perf(sessions): lazily wrap catalog entry snapshots - #182986

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-session-catalog-snapshot-20260919
Oct 24, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-session-catalog-snapshot-20260919

Conversation

@steipete

@steipete steipete commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Catalog snapshot rebuilds create a frozen per-agent wrapper for every session and then copy each wrapper into a second catalog row, even when providers only request the catalog.

User Impact

This is a small allocation and retained-memory win for catalog rebuilds, with no user-visible or Plugin SDK behavior change. Unchanged-revision requests remain effectively flat.

Why This Change Was Made

Capture the selected entry pairs in the existing revision-owned snapshot, construct catalog rows directly, and create per-agent wrappers only when a caller requests them. Lookup indexes also consume the captured pairs. Both public row shapes, all freezes, ordering, alias normalization, revision invalidation, and entries captured before provider awaits are preserved.

Production code grows by 13 lines (+26/-13) to preserve the distinct public shapes while removing their eager double wrapping; the regression adds 44 test lines. There is no new cache or configuration.

Evidence

A synthetic isolated Gateway with 10,000 sessions and four clients observed 4.15 catalog requests/minute and 0.92 snapshot rebuilds/minute: 18 requests over 260 seconds, 4 rebuilds and 14 revision-cache hits (77.8%). The mix used two sidebar refreshers at 120 seconds, navigation every 30 seconds, roster reads every 5 seconds, and an active phase with a metadata patch every 10 seconds. Initial request bursts are included. Baseline and candidate produced the same counts and expected responses. This is a synthetic traffic census, not a production request-rate measurement.

Two concurrent, CPU-swapped pairs per allocation mode, 1,000 requests per side, 10,000 persisted synthetic sessions:

Metric Baseline Candidate Change
Catalog allocation per rebuild 5.786 MB 4.252 MB -26.5%
Retained sampled snapshot 2.239 MB 1.494 MB -33.3%
Catalog allocation per unchanged request 0.4267 MB 0.4239 MB -0.65%

MB is decimal. Retained values are sampling estimates after collection, not exact heap dominator sizes. The rebuild allocation pairs improved 26.39% and 26.63%; unchanged pairs were -1.31% and +0.01%. Applying the rebuild saving to the synthetic census gives approximately 1.42 MB/minute, an extrapolation rather than measured production savings. Further reductions in revision churn would reduce the absolute benefit.

Allocation and real-Gateway census evidence came from the original experiment on 3729046a10db. The restored implementation was rebased for the current correctness and untraced checks; both baseline and candidate snapshot-owner files are byte-identical to their original experimental versions. The final patch-identical rebase is covered by exact-head PR CI. Exploratory measurement scripts extended the existing scripts/perf/session-catalog-selection-measure.ts workload locally for 10,000 sessions and catalog-only providers. All six allocation/survivor pairs preserved full ordered-entry and response hashes. Maintenance remained enabled; preparation and measurement used separate CPU placements, exclusive quiet-slot locking, synchronized starts, and the shared production guard.

Untraced CPU/GC qualification passed. Two synchronized, CPU-swapped pairs each for rebuilds and unchanged reads, 1,000 requests per side, on base 0a3d2dc31216. Mean paired CPU deltas were -20.26% / -1.968 ms per rebuild and -5.90% / -0.0491 ms per unchanged request. GC signs were mixed; the positive individual deltas were only +0.001716 and +0.000134 ms/request, below the predeclared +1 ms/op materiality gate. These short runs show no adverse GC result, not a robust GC improvement. Handler and loop tail means improved, with 1,000 handler samples and 1,341–2,626 loop samples per side. The largest candidate GC pause was 30.245 ms, below the maximum-pause safeguard. All four pairs preserved complete response and entry hashes, with no guard interruptions.

Each rebuild side recorded exactly 1,000 rebuilds and zero revision-cache hits; each unchanged side recorded zero rebuilds and 1,000 hits. No allocation inspector or GC tracing was enabled. Per-kind GC tails are context only because collection counts are insufficient; promotion was not measured. Windows lasted 1.73–9.07 seconds, so this requested short safety screen does not qualify rare long-run pauses.

Validation: 15 focused tests passed across session-catalog-entry-snapshot.test.ts, session-catalog-selection.test.ts, and session-catalog-resident-entries.test.ts. The new work-count regression failed on the original baseline (two wrappers instead of one), and checks lazy wrapping, exact public fields, freezes, same-revision reuse, and old-entry isolation after a projection update. Changed-file oxfmt and core-config oxlint passed; exact-head PR CI run 40140075706 passed on 1aab639b21b7067b35cf5e6d39aab2e5346aab7b, including lint, production/test types, changed-node tests, architecture/boundary guards, UI e2e, and the aggregate CI gate. Dependency and security-sensitive statuses also passed.

Independent subagent review (autoreview route unavailable): clean through P2. The configured autoreview helper refused a provider mismatch; operator configuration was left unchanged. The reviewer independently checked retained-pair lifetime, both public shapes, alias/order preservation, revision reuse, lookup behavior, and isolation across awaits. The simplification pass retained only the two-shape lazy wrapping change.

Untraced paired results, sample counts, per-kind GC and both maxima

Process CPU includes metadata writes, projection settling, the real catalog handler, response hashing and pacing. GC is observed in the main isolate. Preparation is excluded. Relative deltas are the mean of the two paired percentages; absolute deltas are the signed mean. Maintenance defaults remained enabled.

rebuild

Metric Pair 1 baseline → candidate Pair 2 baseline → candidate Mean signed delta Mean paired relative delta
CPU ms/op 7.787299 → 6.504833 11.031514 → 8.377960 -1.968010 -20.261%
GC ms/op 0.553742 → 0.555458 0.914898 → 0.263340 -0.324921 -35.453%
handler p95 ms 4.872680 → 4.797056 7.379415 → 6.929880 -0.262579 -3.822%
handler p99 ms 7.052294 → 5.876188 9.542325 → 8.155722 -1.281354 -15.604%
loop p95 ms 5.492735 → 5.173247 7.839743 → 7.143423 -0.507904 -7.349%
loop p99 ms 7.520255 → 6.582271 9.854975 → 8.945663 -0.923648 -10.850%
GC max ms 26.034109 → 25.667037 25.495861 → 30.245275 +2.191171 +8.609%

Both pairs match every full response-sequence, initial/final response and ordered entry hash (no omitted fields).

Pair 1

Start UTC: baseline 2026-10-24T23:15:27.287Z; candidate 2026-10-24T23:15:27.287Z. Elapsed: 6883.2 → 6227.4 ms.
Snapshot counters baseline {'planningBuilds': 1000, 'planningHits': 0, 'deliverySnapshots': 1000, 'catalogBuilds': 1000, 'agentCaptures': 4000}; candidate {'planningBuilds': 1000, 'planningHits': 0, 'deliverySnapshots': 1000, 'catalogBuilds': 1000, 'agentCaptures': 4000}.
Loop samples: 2601 → 2559; handler samples: 1000 → 1000. Loop max: 26.542079 → 25.804799 ms.

GC kind count baseline → candidate total ms baseline → candidate p95 ms baseline → candidate p99 ms baseline → candidate max ms baseline → candidate
total 204 → 169 553.741944 → 555.457917 3.619818 → 5.590067 10.556829 → 10.860896 26.034109 → 25.667037
minor 198 → 165 488.504915 → 517.009888 3.611145 → 5.502616 4.364917 → 6.180164 4.938098 → 8.017574
major 3 → 2 61.525575 → 36.527933 26.034109 → 25.667037 26.034109 → 25.667037 26.034109 → 25.667037
incremental 3 → 2 3.711454 → 1.920096 1.413453 → 1.159773 1.413453 → 1.159773 1.413453 → 1.159773
weakCallbacks 0 → 0 0.000000 → 0.000000 n/a → n/a n/a → n/a 0.000000 → 0.000000

Pair 2

Start UTC: baseline 2026-10-24T23:16:25.571Z; candidate 2026-10-24T23:16:25.571Z. Elapsed: 9073.5 → 8089.5 ms.
Snapshot counters baseline {'planningBuilds': 1000, 'planningHits': 0, 'deliverySnapshots': 1000, 'catalogBuilds': 1000, 'agentCaptures': 4000}; candidate {'planningBuilds': 1000, 'planningHits': 0, 'deliverySnapshots': 1000, 'catalogBuilds': 1000, 'agentCaptures': 4000}.
Loop samples: 2626 → 2624; handler samples: 1000 → 1000. Loop max: 25.608191 → 32.473087 ms.

GC kind count baseline → candidate total ms baseline → candidate p95 ms baseline → candidate p99 ms baseline → candidate max ms baseline → candidate
total 252 → 141 914.897648 → 263.339899 5.161334 → 2.664863 11.601338 → 12.363452 25.495861 → 30.245275
minor 246 → 137 853.331701 → 218.359369 4.969045 → 2.476180 5.869437 → 3.527650 6.309658 → 3.906909
major 3 → 2 57.877715 → 42.608727 25.495861 → 30.245275 25.495861 → 30.245275 25.495861 → 30.245275
incremental 3 → 2 3.688232 → 2.371804 1.517290 → 1.427545 1.517290 → 1.427545 1.517290 → 1.427545
weakCallbacks 0 → 0 0.000000 → 0.000000 n/a → n/a n/a → n/a 0.000000 → 0.000000

unchanged

Metric Pair 1 baseline → candidate Pair 2 baseline → candidate Mean signed delta Mean paired relative delta
CPU ms/op 0.845508 → 0.772860 0.797384 → 0.771803 -0.049115 -5.900%
GC ms/op 0.015399 → 0.015135 0.015611 → 0.015745 -0.000065 -0.428%
handler p95 ms 1.088245 → 0.835415 1.039291 → 0.884198 -0.203961 -19.078%
handler p99 ms 1.201014 → 1.073253 1.247784 → 1.057228 -0.159159 -12.955%
loop p95 ms 1.983487 → 1.809407 1.839103 → 1.832959 -0.090112 -4.555%
loop p99 ms 2.279423 → 1.973247 2.191359 → 2.103295 -0.197120 -8.725%
GC max ms 1.489868 → 1.344390 1.355586 → 1.315366 -0.092849 -6.366%

Both pairs match every full response-sequence, initial/final response and ordered entry hash (no omitted fields).

Pair 1

Start UTC: baseline 2026-10-24T23:17:33.703Z; candidate 2026-10-24T23:17:33.704Z. Elapsed: 1801.0 → 1729.9 ms.
Snapshot counters baseline {'planningBuilds': 0, 'planningHits': 1000, 'deliverySnapshots': 1000, 'catalogBuilds': 0, 'agentCaptures': 0}; candidate {'planningBuilds': 0, 'planningHits': 1000, 'deliverySnapshots': 1000, 'catalogBuilds': 0, 'agentCaptures': 0}.
Loop samples: 1385 → 1369; handler samples: 1000 → 1000. Loop max: 2.662399 → 2.590719 ms.

GC kind count baseline → candidate total ms baseline → candidate p95 ms baseline → candidate p99 ms baseline → candidate max ms baseline → candidate
total 16 → 16 15.398873 → 15.135346 1.489868 → 1.344390 1.489868 → 1.344390 1.489868 → 1.344390
minor 16 → 16 15.398873 → 15.135346 1.489868 → 1.344390 1.489868 → 1.344390 1.489868 → 1.344390
major 0 → 0 0.000000 → 0.000000 n/a → n/a n/a → n/a 0.000000 → 0.000000
incremental 0 → 0 0.000000 → 0.000000 n/a → n/a n/a → n/a 0.000000 → 0.000000
weakCallbacks 0 → 0 0.000000 → 0.000000 n/a → n/a n/a → n/a 0.000000 → 0.000000

Pair 2

Start UTC: baseline 2026-10-24T23:18:35.900Z; candidate 2026-10-24T23:18:35.900Z. Elapsed: 1754.1 → 1731.3 ms.
Snapshot counters baseline {'planningBuilds': 0, 'planningHits': 1000, 'deliverySnapshots': 1000, 'catalogBuilds': 0, 'agentCaptures': 0}; candidate {'planningBuilds': 0, 'planningHits': 1000, 'deliverySnapshots': 1000, 'catalogBuilds': 0, 'agentCaptures': 0}.
Loop samples: 1364 → 1341; handler samples: 1000 → 1000. Loop max: 2.543615 → 2.750463 ms.

GC kind count baseline → candidate total ms baseline → candidate p95 ms baseline → candidate p99 ms baseline → candidate max ms baseline → candidate
total 16 → 16 15.611289 → 15.744891 1.355586 → 1.315366 1.355586 → 1.315366 1.355586 → 1.315366
minor 16 → 16 15.611289 → 15.744891 1.355586 → 1.315366 1.355586 → 1.315366 1.355586 → 1.315366
major 0 → 0 0.000000 → 0.000000 n/a → n/a n/a → n/a 0.000000 → 0.000000
incremental 0 → 0 0.000000 → 0.000000 n/a → n/a n/a → n/a 0.000000 → 0.000000
weakCallbacks 0 → 0 0.000000 → 0.000000 n/a → n/a n/a → n/a 0.000000 → 0.000000

@clawsweeper

clawsweeper Bot commented Oct 24, 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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Oct 24, 2026
@steipete
steipete marked this pull request as ready for review October 24, 2026 22:47
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T22:49:30.571499Z 1aab639 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR builds catalog rows directly from captured session entries and creates frozen per-agent wrappers only when requested.

Example: A catalog-only refresh reads 10,000 sessions.

  • Before: The snapshot eagerly creates 10,000 per-agent wrappers plus 10,000 catalog rows.
  • After: It creates 10,000 catalog rows and defers per-agent wrappers until a caller requests them.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The implementation is focused and source-supported; reported measurements support its value, but the declared performance qualification is unfinished.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its body reports an isolated real-Gateway census and paired allocation measurements, while explicitly leaving untraced qualification pending and identifying the earlier measured revision.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Large catalog rebuilds allocate and retain unnecessary intermediate session wrappers.
Reason: The maintainer-directed change removes measured waste within the existing owner without adding configuration, a new cache, or a public contract.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-directed optimization removes unnecessary catalog allocations and is absent from current main; no actionable correctness or security findings were identified.

Priority: P3
Reviewed head: 1aab639b21b7067b35cf5e6d39aab2e5346aab7b

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The declared untraced rebuild and unchanged-request qualification remains pending; the supplied real-Gateway census and allocation results identify an earlier experiment revision.
Agent review details

How this fits together

The Gateway catalog snapshot consumes resident session-selection pairs and supplies immutable planning rows and lookup indexes to catalog providers before asynchronous enumeration.

flowchart LR
  A[Resident session projection] --> B[Capture selected entry pairs]
  B --> C[Revision owned snapshot]
  C --> D[Catalog rows]
  C --> E[Lazy per agent summaries]
  C --> F[Session lookup indexes]
  D --> G[Catalog providers]
Loading

Technical review

Best possible solution:

Retain the existing revision-owned snapshot and immutable public shapes while eliminating eager per-agent wrapping for catalog-only consumers.

Do we have a high-confidence way to reproduce the issue?

The base source visibly allocates per-agent wrappers before copying them into catalog rows; the PR reports a baseline-failing work-count regression, but no target code was executed during this read-only review.

Is this the best way to solve the issue?

This is a focused solution using the existing owner: capture stable pairs once, construct each public representation when needed, and preserve revision scope, ordering, freezing, and pre-await capture.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 219e9181aab0.

Provenance checked

  • Request snapshot and pre-await entry capture keeps the original intent (perf(gateway): reuse session catalog entry snapshots per request #114358: Share captured session entries across providers and lookups instead of repeatedly enumerating stores within one request.)
  • Revision-owned planning reuse keeps the original intent (15e3269: Reuse immutable planning entries under metadata revision, configuration, and fallback-agent scope while keeping delivery current.)
  • Frozen public row representations keeps the original intent (823f6f5: Publish immutable catalog snapshots and reuse neutral displays without changing caller visibility or adoption attribution.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 15e3269 adds src/gateway/server-methods/session-catalog-entry-snapshot.ts:50 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 15e32694c7dd; files: src/gateway/server-methods/session-catalog-entry-snapshot.ts)

PR surface

Source +13, Tests +44. Total +57 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 26 13 +13
Tests 1 44 0 +44
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 70 13 +57

Review metrics

Metric Value Why it matters
Production versus test LOC Production +26/-13; tests +44/-0 The modest production growth preserves two distinct public row shapes while making their construction lazy; the regression checks allocation work and captured-entry lifetime.

Labels

Label changes:

  • add P3: This is a bounded allocation improvement with preserved behavior and no demonstrated urgent user-facing failure.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P3: This is a bounded allocation improvement with preserved behavior and no demonstrated urgent user-facing failure.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Complete the already-declared untraced qualification and establish that its measured implementation matches this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 24, 2026, 7:04 PM ET / 23:04 UTC.

@steipete
steipete merged commit 6188758 into main Oct 24, 2026
208 checks passed
@steipete
steipete deleted the steipete/perf-micro-session-catalog-snapshot-20260919 branch October 24, 2026 23:21
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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