Skip to content

perf(sessions): reuse sealed history proof during manager loads - #199480

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-session-load-inspect-20261115
Nov 15, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-session-load-inspect-20261115

Conversation

@steipete

@steipete steipete commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

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

freezeTranscriptSnapshot already 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 in prepareSessionManagerEntries. 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.ts exercises the real SessionManagerCore constructor / 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.

Workload / metric Base median Candidate median Mean paired delta
32 retained histories: timing 4,044.18 µs/load 102.47 µs/load -97.32%
32 retained histories: allocation 8,801,093.43 B/load 233,266.99 B/load -97.35%
1-history warm control: timing 95.48 µs/load 94.38 µs/load -1.65%
1-history warm control: allocation 236,108.36 B/load 235,335.92 B/load -0.19%

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:

# Save the base codec before applying the candidate.
git show 37d977fd28b060e8fd964a632858e5c0a709ca1b:src/agents/sessions/session-manager-codec.ts > .local/base-session-manager-codec.ts
node --import ./scripts/tsx.mjs scripts/perf/session-load-inspect-measure.ts --mode timing --iterations 3000 --codec-file .local/base-session-manager-codec.ts
node --import ./scripts/tsx.mjs scripts/perf/session-load-inspect-measure.ts --mode timing --iterations 3000
# Repeat both with --mode allocation, and with --sessions 1 for warm controls.
node --import ./scripts/tsx.mjs scripts/perf/session-load-inspect-measure.ts --mode counts --iterations 64

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.
  • Changed-file oxfmt and type-aware oxlint; pnpm tsgo:test:root; matching tsconfig.core.test.agents-sessions.json typecheck.
  • Export-name collision guard and eager-import / PR-wrapper source-closure guards (24 tests).

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-7 failed 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.

@clawsweeper

clawsweeper Bot commented Nov 15, 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 scripts Repository scripts agents Agent runtime and tooling labels Nov 15, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T05:31:36.748457Z d2c669e PR opened
ℹ️ 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:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. 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:bug Preliminary submission classification; full source review pending. labels Nov 15, 2026
@clawsweeper

clawsweeper Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: The supplied benchmark reports median CPU of 4,044.18 microseconds per load after the generic memo rotates.
  • After: The supplied benchmark reports 102.47 microseconds per load while preserving writable manager envelopes.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is focused and correct by inspection, with useful production-owner measurements and regression coverage; validation remains scoped to in-process loading and pending CI.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored internal performance change is outside the contributor shipped-entry-point gate; its supplied measurements exercise SessionManagerCore loading directly and make no whole-Gateway performance claim.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Loading large retained session histories repeatedly spends CPU and allocation inspecting data that hydration already sealed.
Reason: The maintainer-authored direction has concrete owner-level measurements and preserves existing transcript, navigation, and writable-view contracts.

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
Reviewed head: d2c669e04488a3974173ea7186602393665c5c26

Before merge

None.

Findings

None.

Agent review details

How this fits together

Transcript 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]
Loading

Technical review

Best 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

  • Session-manager envelope preparation keeps the original intent (245cbaf: Share immutable transcript payloads internally while preserving writable public SDK views through manager-owned envelopes and deferred detachment.)
  • Transcript snapshot ownership keeps the original intent (ee52ed4: Keep sealed message-root guarantees available independently of generic freezer memo rotation.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 245cbaf adds src/config/sessions/transcript-snapshot.ts:17 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 245cbaf915c2; files: src/config/sessions/transcript-snapshot.ts)

PR surface

Source +4, Tests +37, Other +174. Total +215 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 5 1 +4
Tests 1 39 2 +37
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 174 0 +174
Total 5 218 3 +215

Preflight source

Source 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

Metric Value Why it matters
Production versus regression-test growth Production +4 net lines; tests +37 net lines The small production addition carries an existing owner guarantee; the tests protect memo-rotation behavior, caller-input handling, and writable isolation.

Labels

Label changes:

  • add P2: Repeated deep inspection adds measurable CPU and allocation for large retained working sets, with limited impact on ordinary warm single-history loads.
  • 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:

  • P2: Repeated deep inspection adds measurable CPU and allocation for large retained working sets, with limited impact on ordinary warm single-history loads.
  • 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.

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 November 15, 2026, 12:43 AM ET / 05:43 UTC.

@steipete
steipete merged commit 51bed3b into main Nov 15, 2026
153 of 158 checks passed
@steipete
steipete deleted the steipete/perf-session-load-inspect-20261115 branch November 15, 2026 06:12
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: M 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