Repository navigation
perf(gateway): reuse sharing keys across session deltas - #184201
Merged
Merged
Conversation
Retain serialized viewer keys under the projection sharing revision while preparing live policy and membership on every call. Preserve canonical audience grouping and invalidate reuse for identity, scope, profile, policy, and config publication changes. Owner benchmark: paired mean main-thread CPU -23.0%, sampled allocation -22.6%; identical key and role digests. Broadcast and profile regressions plus focused guards pass. Independent review clean through P2.
Contributor
|
🦞👀 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. |
steipete
marked this pull request as ready for review
October 26, 2026 04:32
Contributor
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. |
This was referenced Oct 26, 2026
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Oct 27, 2026
) Retain serialized viewer keys under the projection sharing revision while preparing live policy and membership on every call. Preserve canonical audience grouping and invalidate reuse for identity, scope, profile, policy, and config publication changes. Owner benchmark: paired mean main-thread CPU -23.0%, sampled allocation -22.6%; identical key and role digests. Broadcast and profile regressions plus focused guards pass. Independent review clean through P2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
Streaming session broadcasts repeatedly sort and serialize the same viewer-sharing identity for each connected recipient, even when the session-sharing revision and viewer facts have not changed.
User Impact
Less allocation and CPU in session-event fanout. Wire payloads, audience grouping, membership reads, and live authorization remain unchanged.
Why This Change Was Made
Retain the serialized key under the existing projection sharing revision, with weak recipient keys. Every call still prepares current sharing policy and authorization. Reuse also checks config publication, access revision, resolved profile/policy, authenticated identity, and scope contents. Revision retirement drops the old cache; disconnected clients are weakly held. Generic synchronous readers do not opt into retained keys.
This deliberately retains only serialization, not sharing closures: a membership reader belongs to the current projection/read. Related: #184097 removes a different allocation source in the event envelope.
Production LOC is net +46 (+50/−4). Runtime growth is bounded to the key cache and its invalidation checks; these preserve config publication, profile merges, in-place scope changes, and canonical cross-client audience grouping. No new configuration or storage is introduced.
Evidence
Acceptance declared in
scripts/perf/session-sharing-key-measure.ts: identical key/role digest with lower owner allocation and CPU. The workload uses 65 interleaved clients, eight identities, 10,000 synthetic target entries, and 3,000 events; sharing revisions and membership change every 100 events. Forty configured plugin entries are synthetic config shape only; no plugin or provider execution is measured.Base:
29397d2a185c29d4b4d79d2ad41af0f7cf1f6a9b. Timing and sampled allocation are separate passes, five counterbalanced pairs each. Main-thread CPU usesprocess.threadCpuUsage; V8 sampling includes objects collected by minor and major GC. Host load and memory are recorded per run.Every pair improved. Node 26.12.1 on macOS. One-minute host load ranges: timing base 45.9–93.6, candidate 40.9–85.6; allocation base 34.6–50.9, candidate 37.8–65.3. The paired order is AB/BA/AB/BA/AB for each mode. These are process-thread CPU measurements, not elapsed-time or Gateway-latency claims. All twenty runs produced digest
3db36efcb344be52f92c8c98cea318b4cbf4ee7f61bfc27cf5ca6df3a444bf22.Command:
node --expose-gc --import ./scripts/tsx.mjs scripts/perf/session-sharing-key-measure.ts --events 3000; add--owner src/gateway/.session-sharing-read-base.tsfor a saved base sibling and--allocationsfor the separate allocation pass.The broadcast regression fails on base with 24 key encodings; the expected 16 represent cold recipients, while eight already-primed recipients need no re-encoding. Existing payload, interleaved delivery-history, and mid-broadcast revocation assertions remain. The prepared-profile regression covers profile merges, scope edits, same-object policy changes with revision retirement, and identity detachment.
Seven focused tests pass across
session-row-delta-audiences,session-row-publication-authority, andsession-sharing.prepared. Changed audience file: 10.2 s test execution; changed prepared-profile file: 1.8 s. The unchanged publication-authority fixture took 25.3 s. Wrapper wall time was 874.6 s on the loaded host; compilation/import preparation dominated. This extends existing fixtures rather than adding another Gateway boot.Changed-file formatting and core lint passed. The script typecheck passed. Script lint initially found three missing loop braces in the benchmark; these were corrected without changing its workload. Final script lint passed. Both closure guard files passed (22 tests, 434.6 s wrapper wall time), and the export-collision guard passed after the temporary measurement baseline source was removed.
Independent subagent review: clean through P2 (autoreview route unavailable because its provider selector did not match the operator configuration). No actionable findings. The review covered the diff, relevant source contracts, regressions, and benchmark in a fresh context. No Testbox lease was used.
The lane's explicit fast-path exception applies to this duplicate-serialization removal. No whole-Gateway latency, GC, or retained-memory improvement is claimed, and no long Gateway stress campaign was run.