Skip to content

perf(agents): share resident transcript strings across reloads - #185156

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-transcript-text-string-sharing-20261026
Oct 26, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-transcript-text-string-sharing-20261026

Conversation

@steipete

@steipete steipete commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Active runs retain duplicate copies of unchanged transcript text after SessionManager reloads, including reloads during orphan reconciliation and committed-append recovery.

User Impact

Lower retained transcript memory during active runs. Transcript content, persistence, history windows, mutable-container isolation, and reload/authorization checks are unchanged.

Why This Change Was Made

Initial model-context preparation already shares equal resident strings. Reload adoption now uses that same helper before publishing its fresh containers. Numeric and other non-string scalar leaves no longer allocate unused property descriptors. No cache or additional retained state is introduced.

Matching incoming values has a measured cost: approximately 0.064 ms more main-thread CPU and 138 KiB more sampled allocation per reload in this fixture. This is a retained-memory improvement, not an allocation-rate improvement. Runtime production code grows by 13 lines to share the existing implementation across both boundaries while preserving private mutable containers. The non-test diff is +226 lines including the 212-line reproducible benchmark and its one-line entrypoint registration.

Evidence

Acceptance: unchanged transcript/context digests, private mutable containers, changed persisted text remains authoritative, and fewer physical copies of unchanged large text across active history and SessionManager.

The regression exercises real SQLite hydration and reloads, verifies isolation and persisted rewrites, and checks physical string identity in a Node subprocess with independent positive/negative controls. The existing compiled-subprocess owner keeps preparation outside its 30-second deadline. The full hydration file passes 21 tests; the new regression takes 5.93 seconds. The exact same final regression fails on baseline with “reload copied resident transcript text”; it passes on the candidate. The V8 identity oracle was also checked on Node 24.22.1 and 26.12.1.

Owner workload: 69 entries, 57 active-history messages, 526,362 bytes of tool-result text, one initial context kept live across repeated bounded reloads. Timing and allocation run separately in AB/BA order: 2,000 measured reloads per arm per pair, two pairs (4,000 per revision per mode), after 20 warmups each. Measured base: a1b840f. Two-module source substitution pins the compared owner code; workers and remaining code are common.

Per reload, paired mean Base Candidate Change
Main-thread CPU 1.255 ms 1.319 ms +5.1% (+0.064 ms)
Total process CPU, including workers 8.513 ms 8.091 ms -5.0%
Sampled main-isolate allocation 1,843,785 B 1,985,371 B +7.7%
Main-isolate GC 0.0454 ms 0.0416 ms -8.5%
Elapsed time 6.990 ms 6.267 ms -10.3%

Shared-host timing is context rather than a throughput claim. Timing host load (one-minute average, start→end): base 58.5→52.4 and 43.3→42.3; candidate 45.3→44.2 and 43.2→44.6. Maximum GC pauses per timing pair: 6.12→4.75 ms and 4.23→3.66 ms; major counts are below the percentile gate threshold. Allocation sampling includes collected objects and runs separately from timing.

node --import ./scripts/tsx.mjs scripts/perf/session-reload-measure.ts \
  --state-dir <prepared-synthetic-state> --iterations 2000 --output <result.json>
# Add --source-dir <prepared-base-source> for the baseline, --allocations for allocation passes.

The built-Gateway active-run capture starts each arm from the same preserved synthetic state. Four runs remain active with 12 large text references in their snapshot histories:

Active history + SessionManager text Base Candidate
Physical copies for 12 unchanged large strings 24 12
Retained shallow string bytes in that group 1,573,824 786,912
Cross-owner duplicate bytes 786,912 0

The snapshot Map shares runtime history in both arms; it is not another copy. Heap census groups use V8’s recorded 1,024-character prefix plus exact shallow size, so duplicate grouping is approximate; the regression independently verifies physical identity for exact values. This is a targeted retained-string reduction, not a whole-process heap claim: post-snapshot heapUsed was 534,780,808→563,623,944 bytes and RSS was 2,931,500,336→2,999,709,544 bytes. Other active-run allocations and capture timing vary. No overall memory-regression or throughput verdict is inferred from this single capture pair. A full Gateway throughput comparison is omitted: the Team-shaped stress harness rejected its startup shape census after maintenance changed archive counts. The isolated retention replay uses a 10,000-session synthetic fixture, 65 clients, four concurrent mock-provider runs with tool calls, and 40 plugins.

Focused validation: hydration (21 tests), initial-context/reload rejection consumers, prompt-prefix stability, both import-closure guards, and the export-name collision guard pass. Changed-file lint, formatting, and the core typecheck pass. The first CI run found unique-symbol type widening in the benchmark’s dynamic import; its declaration is corrected, and the exact failed script-types command passes locally. Runtime code and measurements are unchanged. Both sourcePerformance builds and the isolated active-run replays complete successfully. No Testbox lease or production Gateway was used.

Review: independent subagent review (autoreview route unavailable), no actionable P0–P2 findings. No provider configuration was changed.

Exact-head CI: run 40420528022 passed on 132946919da0c92fc67c84c4fb37effba1859ee4; the combined CI, dependency-review, and security-sensitive-review statuses are successful. Automated Codex review also completed on this head with no findings. This PR is ready and intentionally left unmerged for maintainer handoff.

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts agents Agent runtime and tooling size: M labels Oct 26, 2026
@steipete
steipete marked this pull request as ready for review October 26, 2026 23:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T23:35:08.859020Z 1329469 New commits
ℹ️ 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 26, 2026
Reuse immutable resident strings while adopting fresh transcript containers. Keeps active history shared across orphan-repair and append reloads without changing transcript bytes, mutable-container isolation, ownership checks, or history windows.
@steipete
steipete force-pushed the steipete/perf-transcript-text-string-sharing-20261026 branch from 97e1a7b to 1329469 Compare October 26, 2026 23:33
@clawsweeper clawsweeper Bot removed the clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. label Oct 26, 2026
@steipete
steipete merged commit 775e4d5 into main Oct 26, 2026
145 of 147 checks passed
@steipete
steipete deleted the steipete/perf-transcript-text-string-sharing-20261026 branch October 26, 2026 23:50
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
…law#185156)

* perf(agents): share resident transcript strings across reloads

Reuse immutable resident strings while adopting fresh transcript containers. Keeps active history shared across orphan-repair and append reloads without changing transcript bytes, mutable-container isolation, ownership checks, or history windows.

* fix(perf): preserve initial-context symbol type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawsweeper:intake:bug Preliminary submission classification; full source review pending. scripts Repository scripts size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant