Repository navigation
perf(sessions): lazily wrap catalog entry snapshots - #182986
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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis 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.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +13, Tests +44. Total +57 across 2 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 24, 2026, 7:04 PM ET / 23:04 UTC. |
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:
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 existingscripts/perf/session-catalog-selection-measure.tsworkload 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, andsession-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 on1aab639b21b7067b35cf5e6d39aab2e5346aab7b, 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
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.
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.
unchanged
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.
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.