Repository navigation
perf(gateway): reuse session row publication encoding - #166591
Conversation
Build immutable cached session rows from their canonical JSON and retain those bytes for list and event delivery. This removes the structured-clone pass while keeping mutable producer state isolated and redacted views separately encoded. Synthetic materialized-row measurements reduce sampled allocation per publication by 19-53%. Preserve uncached own-undefined semantics and check absent derived titles by value in the existing preview regression.
|
🦞👀 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 changes before merge. Reviewed October 7, 2026, 9:49 AM ET / 13:49 UTC (Revision 3). ClawSweeper reviewWhat this changesThe Gateway creates immutable cached session rows from their JSON encoding, reuses those bytes for delivery, and adjusts a preview assertion for omitted undefined fields. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Needs changes before merge - 2 items remain The optimization remains useful and is absent from current main. The pinned head still breaks two existing test files; the author acknowledges those failures and is preparing corrections. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway presents session metadata for session lists and events. It applies current recipient visibility and model restrictions before delivering immutable rows to connected clients. flowchart TD
A[Session metadata] --> B[Resident session projection]
B --> C[Recipient presentation]
D[Current visibility and model policy] --> C
C --> E[Immutable JSON publication]
E --> F[Session list responses]
E --> G[Session events]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +3, Tests -1. Total +2 across 2 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Retain the shared JSON publication and make cached-row tests verify absent values without requiring properties that the wire format omits. Do we have a high-confidence way to reproduce the issue? Yes, from source: cached publication drops undefined properties while the foreground and recovery tests require them to exist. The captured CI report confirms those failures; this read-only review did not execute tests. Is this the best way to solve the issue? Yes. Reusing the publication's canonical bytes is a narrow optimization; correcting cached-row assertions preserves the meaningful recovery and authorization coverage. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 96ccec4a1385. LabelsLabel 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
History |
* perf(gateway): reuse session row publication encoding Build immutable cached session rows from their canonical JSON and retain those bytes for list and event delivery. This removes the structured-clone pass while keeping mutable producer state isolated and redacted views separately encoded. Synthetic materialized-row measurements reduce sampled allocation per publication by 19-53%. Preserve uncached own-undefined semantics and check absent derived titles by value in the existing preview regression. * test(gateway): check optional cached row values
What Problem This Solves
Session list and event publications deep-clone every new recipient row and then independently encode it for delivery, allocating a second large row graph including fields JSON omits.
User Impact
Lower allocation and CPU cost when session rows change. Wire output, recipient authorization, snapshot isolation, and revision invalidation remain unchanged. No config or schema changes.
Why This Change Was Made
Create the immutable publication from its canonical JSON bytes and retain those same bytes for delivery. This removes the structured-clone pass from cached row publication. Uncached internal snapshots retain their own-undefined field semantics; model-redacted copies retain separate encodings.
Production LOC: +4/-1 (net +3). The extra lines preserve the existing immutable-publication contract: nested inputs belong to mutable producers, so freezing the source row would be unsafe. This replaces one copy/encode sequence without adding a cache, helper, or parallel path.
Evidence
A 60.18-second live-only Gateway heap sample (32 KiB interval, both collected-object flags false) contained 7.6 MiB of surviving sampled allocations. Top named core sites included worker reply deserialization (1.8 MiB), session-row structured cloning (0.8 MiB), and row JSON encoding (0.8 MiB). This ranks survivors at capture end, not gross allocation rate.
An isolated Ubuntu rig on Node 26.8.1 measured the before/after publication copy plus encoding using actual materialized synthetic rows (135 own fields). Each variant ran three 10,000-operation samples after warmup. Allocation sampling included minor- and major-collected objects at a 4 KiB interval; timing was measured separately without profiling. Median results:
Every sample checked identical encoded bytes and snapshot JSON. This is boundary microbenchmark evidence, not a claim of whole-RPC or production RSS improvement.
Validation completed with the reviewed production bytes unchanged throughout:
blacksmith-testbox, leasetbx_01m4b42yb2hg931csdwykz1myb: owner/sibling proof covered 63 cases across 11 files. The initial 52/53 run exposed one own-undefined assertion; its corrected file passed 26/26, and three additional event/model-policy files passed 10/10.pnpm test src/gateway/server-methods/sessions-read-cache.test.ts --maxWorkers=1took 83.81s runner wall time (80.76s Vitest).signalargument. Main already fixed that exact line in1d10375ee563bfaa203e9aad7fe88275adedd3a6; this branch rebased onto main without copying that fix into its own commits.blacksmith-testboxleasetbx_01m4b6qqwp6w0n3dw8bdg4fq7t: current core types plus UI-components/Gateway-methods/Gateway-root test type graphs passed. Every remaining command from the changed-check plan passed, including export checks, targeted lint (0 warnings/errors), schema/storage/import/webhook/pairing guards. Final list/event smoke: 27/27 passed, 89.72s runner wall time. The combined completion command exited 0 in 8m37.4s.aws, leasecbx_36dd7d25f599, runrun_ec1b88c9092d150e6a94cf517acf9707: the two final assertion corrections plus six publication/list siblings passed 60/60 cases across eight files in 166.79s. The test-onlycheck-changedgate passed, including the owning Gateway type graph and lint. The combined command exited 0 in 7m18.2s. A transient coordinator error while saving the receipt was reconciled throughcrabbox receipt; the recovered signed receipt confirms exit 0. All leases are released or expired.The first CI run had 34 successful jobs and two failing test shards (plus the aggregate gate). Both failures were caused by this change: cached-row own-undefined expectations in the foreground and recovery tests. The follow-up commit checks the same values and preserves array membership, current sharing/metadata, preview recovery, and all uncached snapshot assertions. These are not inherited failures. The correction adds no cases, fixture boots, or waits. The first CI measured 12.02s for the foreground file's two-file Node group and 14.17s for the recovery file. Corrected-head CI passed on
80d64546ed2576d0cc88e8ee5569da5da3f362c0: 37 successful jobs and 637 seconds from first job start to final job completion. The PR merged asebc4e6de603c5c1ce55086f13565e21feb1c297d.Remote command scope
The native full gate used
node scripts/check-changed.mjs -- src/gateway/session-row-presentation.ts src/gateway/server-methods/sessions-read-cache.test.ts. After rebasing, retained passing checks were reused; current core types,core-test-ui-components,core-test-gateway-methods,core-test-gateway-root, and all remaining native-plan commands completed separately.Final correction proof:
No new module, export, or test file was added. No post-deployment throughput, GC, or RSS improvement is claimed.