Repository navigation
perf(memory): share published tool checkpoint descriptors - #199609
Merged
Merged
Conversation
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Contributor
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. |
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Nov 16, 2026
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
Each new session tool checkpoint recreated a descriptor for every published tool. Transcript admission then detached identical
name/descriptionstrings again, even though the parameter schema was already shared. In a synthetic 1,000-session/100-tool composition, this retained 100,002 three-field descriptor objects and 14.23 MiB of duplicate description excess.User Impact
Lower memory use when many retained sessions share tool definitions, with unchanged checkpoint JSON and provider payloads. The owner benchmark saves about 18.2 MiB of collected heap at 1,000 sessions, 10.7% of allocation and 21.5% of CPU in tool preparation/checkpointing. This is a bounded improvement to one producer, not a claim to fix all duplicate strings or an uptime leak.
Why This Change Was Made
Descriptor creation now has one weak slot per existing immutable schema publication. Matching name/description reuse the admitted descriptor; changed metadata replaces the slot, and a new schema has a separate slot. Unpublished mutable schemas retain ordinary transcript admission. String detachment still occurs once, preserving lone surrogates and preventing a small description from retaining a large source buffer. No execution, policy, or authorization result is cached.
Both callers use the same descriptor owner. The old function is removed. Runtime production delta is +21 lines: the weak lifetime and single admission require growth, and the existing prompt-state module's enforced line-cap ratchet requires the small sibling module. Benchmark usage stays in its header. Tests add 27 lines with an exact allocation. No schema, persisted-shape, configuration, dependency, or public SDK change.
Evidence
Five alternating fresh-process repetitions per side on Node 26.12.1. Each process retains 1,000 sessions, 100 published tools, 10,000 compact subagent records, and performs 3,000 prepare/checkpoint operations: 15,000 iterations per side. Exact V8 allocated-byte counters and main-thread CPU; heap capture/collection outside timed windows. Baseline uses the unchanged owner through the existing sparse benchmark overlay. Provider payload hashes and canonical-schema identities match throughout.
Heap evidence comes from
scripts/heap-snapshot-diff.mjs --summaryplus a retainer walk and an exact three-field descriptor-node group. The union excludes shared descendants; duplicate excess excludes sliced/concatenated and truncated strings. At 24 sessions, description excess is 867,464 → 550,664 B; at 1,000 sessions, 14,921,864 → 550,664 B. The removed base slope is 14,400 bytes per added retained session for 100 tools. Unchanged extra turns in one already-pinned session do not add another surface. Remaining descriptor objects include source fixture and canonical publication objects.Reproduce owner proof:
node --expose-gc --import ./scripts/tsx.mjs scripts/perf/duplicate-tool-strings-measure.ts .local/tool-descriptors 1000 0 # Append --no-snapshot for CPU/allocation repetitions.Regression:
shares published descriptors across sessions without sharing changed or mutable definitionsfails on base at the cross-session identity assertion (34 existing tests pass), and passes with the change. It covers changed name/description/schema and mutable input isolation; existing checkpoint tests cover serialization and ownership. Focused prompt-state, prompt-prefix stability, transcript normalization, prompt-state consumers, export-name and eager/source-closure guards, and strict root-script/agents-other typechecks are exercised. The initial sibling extraction's incorrect package subpath was caught by compilation and corrected to the existing internal tool-schema contract.Local lint's only remaining source violation is inherited file size: the original prompt-state module was already 743 counted lines against a 700 limit. This change reduces it; no suppression or threshold change. The commit ratchet enforces that reduction, while CI's existing policy makes size warnings advisory.
Additional local built-Gateway retention diagnostics used 10,000 seeded sessions, 512 shared skills, four agents, 41 configured plugin entries, 65 WebSocket clients, mock-provider/tool/subagent turns, cron, and list/history/search churn. Each measured window lasted about 362 seconds, under the lane's focused fast-path exception. These are diagnostic context, not matched timing gates: the baseline reused state after an earlier RPC-coverage setup failure; candidate ran alongside local compilation/checks at higher load. Retention sampling includes forced collections. No controlled Gateway speedup or regression is claimed, and no A/A rejection decision is made.
The retention-mode survivor sampler is deliberately not reported as an allocation rate; exact allocation evidence is the owner benchmark above. Warm/end snapshots were captured in both diagnostics. On base, retained graph grew 482,865,662 → 580,225,884 B and duplicate excess 25,181,104 → 32,056,432 B; this includes compiler/schema/skill state beyond this descriptor owner. Candidate retained graph grew 482,442,808 → 583,079,501 B and duplicate excess 25,337,824 → 32,333,288 B. The unexplained production
encodedgroup remains unassigned, and Node ResolveCache strings are untouched. Independent residual skill-source objects and TypeBox literal descriptors are follow-ups, not included fixes.Final-head built-Gateway MCP proof also passed: 65 clients, 40 plugin entries, two mock MCP servers × 40 tools, both catalogs consumed by four concurrent sessions, and 20 measured turns with 20 tool calls/results across five rounds.
Exact-head CI is green for
929431cebc85855299d57e0ab25e485ab73a3f0b: 61 passed checks, 57 skipped, none failed or pending. CI run. Review/merge remains with the coordinating maintainer as requested; no self-autoreview or merge.