Repository navigation
perf(sessions): reuse sealed history proof during manager loads - #199480
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 Summary: ✅ CompletedThis 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 lets session-manager loads reuse the transcript owner’s existing immutability guarantee instead of inspecting sealed history again. Example: Repeatedly load 32 retained histories containing 512 tool results each.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR removes source-confirmed redundant history scans through a minimal ownership handoff, and I found no actionable correctness or security defect. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherTranscript hydration seals decoded history before SessionManager constructs navigation and private envelopes; public getters detach nested payloads when callers request writable views. flowchart TD
A[Decoded transcript history] --> B[Transcript snapshot owner]
B --> C[Sealed events array]
C --> D[Session manager codec]
D --> E[Private envelopes and navigation]
E --> F[Writable SDK views]
Technical reviewBest possible solution: Record the sealed events array at the existing transcript owner and reuse that fact during manager loading while retaining private envelopes and writable detachment. Do we have a high-confidence way to reproduce the issue? Current-main source shows sealed entries being inspected again after bounded memo eviction, and the supplied benchmark and regression report exercise that path; no target code was run during this read-only review. Is this the best way to solve the issue? This is the smallest complete repair: it extends the existing ownership record instead of adding a cache or weakening inspection for unowned inputs. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 43396ecfd6e5. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +4, Tests +37, Other +174. Total +215 across 5 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
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 November 15, 2026, 12:43 AM ET / 05:43 UTC. |
What Problem This Solves
Loading retained session histories repeatedly allocates deep-inspection arrays, property descriptors, and sets after the generic frozen-data memo rotates, even though the transcript owner already sealed those histories.
User Impact
Session loading does less allocation and CPU work with large retained histories. Transcript bytes, navigation, writable SDK views, and caller isolation stay unchanged. There are no configuration or storage changes.
Why This Change Was Made
freezeTranscriptSnapshotalready records an immutable snapshot and its message payload roots independently of the generic freezer's bounded memo. Record the sealed events array in that same owner and consume that fact inprepareSessionManagerEntries. Unowned/shallow-frozen caller data still takes the existing inspection path. No generic immutable-data or provider-conversion behavior changes.Writable envelopes remain manager-owned: their identity is shared by the manager's file array and navigation index, and SDK getters detach nested payloads into those envelopes. Removing that copy would require replacing the writable-view ownership contract. Runtime production delta is +4 lines, carrying the existing owner fact rather than adding a cache or another validation policy.
The catalog was also measured. Its same-revision flattened entries are already reused; actual row changes must publish new immutable entries. No catalog change is included.
Evidence
Acceptance declared before measurement: remove reinspection of owner-sealed graphs, preserve mutation isolation and transcript bytes, improve allocation/CPU for a rotating retained working set, and check the warm memo-hit case. The committed
scripts/perf/session-load-inspect-measure.tsexercises the realSessionManagerCoreconstructor /setLoadedSessionTarget, with 32 histories × 512 tool results × 16 approximately 4-KiB text blocks (311,360 retained objects). Fixture creation and freezing are outside measurement. Timing is uninstrumented; allocation is a separate sampling pass. This isolates the load boundary and does not measure database reads or Gateway transport.Five alternating, counterbalanced runs per arm and workload, 3,000 loads per run (15,000 per arm per metric). Main-thread CPU comes from
threadCpuUsage; allocation uses separate 16-KiB sampling with collected objects included. Base source:37d977fd28b060e8fd964a632858e5c0a709ca1b; rebasing did not change the measured load owners.Rotating workload CPU ranges: base 3,961–4,179 µs/load, candidate 97–137 µs/load. Allocation ranges: base 8.796–8.816 MB/load, candidate 0.232–0.235 MB/load. Host 1-minute load ranged 31.3–69.7 across arms; raw per-arm host loads were recorded. The warm control is effectively neutral. These are owner-workload improvements, not whole-Gateway percentages.
Counted inspections per 512-entry load: 9,729 objects / 30,724 properties → 0 / 0. The 513 shallow manager envelopes remain; payload bytes are shared until writable exposure. A separate 1-KiB sampling profile (512 base loads) attributes the waste to
inspectPlainData,getOwnPropertyDescriptor, and set insertion rather than payload text copies.Catalog residual, unchanged code (40 agents × 270 rows): same-revision capture ~1.03 µs CPU / 1,467 B per request; actual revision rebuild ~271 µs / 892,914 B. Timing used 3,000 captures; allocation used 3,000 warm / 512 cold captures. Existing catalog revision reuse predates the production evidence; this measures its residual rather than treating the earlier fix as an exit condition.
Reproduction commands:
The regression fails on the unchanged base: loading after memo rotation reinspects the retained transcript; the candidate performs no own-key inspection of transcript entries. The same test checks that shallow-frozen caller data is still inspected and that modifying one manager's returned message/envelope cannot change another manager or the source snapshot.
Local validation passed:
session-manager-codec.test.ts: 27 tests, including owned/unowned inputs, immutable source bytes, and cross-manager mutation isolation; final runner wall time 77.34 s, mostly compilation (test work ~11 s).session-manager.test.ts: 23 persistence/navigation/stale-parent tests; runner wall time 136.25 s, mostly compilation (test work ~42 s).transcript-snapshot.test.ts: 2 tests;immutable-data.test.ts: 9 tests.pnpm tsgo:test:root; matchingtsconfig.core.test.agents-sessions.jsontypecheck.The initial candidate test attempt was invalidated by formatting during subprocess compilation and was rerun on stable sources. The first counter also included lazy schema setup; the final assertion counts only fixture-entry inspections. Production behavior did not need a follow-up repair. Test delta is +37 lines with an exact allocation record; benchmark +172 lines. Exact-head CI run 43681261163 completed on
d2c669e04488a3974173ea7186602393665c5c26. CI is not green because of infrastructure capacity:checks-node-changed-compact-small-7failed in runner setup after the provider refused a sandbox start at its daily quota. Checkout and every test step were skipped. All test jobs that reached execution passed; the aggregate gate failed because that selected job never ran. This is an unexecuted CI coverage gap, not a test failure or a passing check. No rerun, empty push, provider change, or merge was performed.Per maintainer direction, independent Codex review and merging are handled by the coordinating maintainer after this ready PR. No local autoreview verdict is claimed. No production load was started. Whole-Gateway stress is omitted under the scoped redundant-work deletion protocol: this change carries an existing immutable-root guarantee and preserves the existing copies, writes, and call order.