Skip to content

perf(agents): compact primitive fingerprint revisions - #183137

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-envelope-fingerprints-20261025
Oct 25, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-envelope-fingerprints-20261025

Conversation

@steipete

@steipete steipete commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Prompt-cache diagnostics retain two revision Maps for mutable message envelopes even when a request projection shares already-frozen content. This changes the primitive-revision Map to a small object, retaining the existing ordered digest Map and weak-key owner. Large primitive text still hashes only when its value changes; nested objects still rehash. Fingerprint bytes, diagnostic ordering, mutation detection, and immutable compaction stay identical. No hydration, provider-request, configuration, or schema changes.

The initial hydration hypothesis was incomplete: cloneTranscriptView shares deeply frozen messages unchanged. Tool-result detail removal and custom-message conversion produce mutable wrappers over frozen content later in request preparation. Those wrappers are collectable after replacement; their current-view revision memos are the retained cost addressed here.

Measurement

Five alternating base/candidate owner samples per mode on Node 26.12.1, each with 16 sessions × 128 messages and 21 observations per session: 1,680 model calls per side per mode, including 80 cold and 1,600 repeated observations. Synthetic fixtures use cloneTranscriptView → real tool-result projection where selected → convertToLlm → request observer → beginPromptCacheObservation. Every comparison matched fixture and fingerprint/diagnostic digests. Force GC before/after retained-heap observations. Current views are replaced, not accumulated.

Runs hold one shared quiet-slot lock, use interleaved CPUs with alternating placement/order, and use the shared production guard. These are sequential owner comparisons, not concurrent whole-Gateway A/B runs. CPU/GC runs are untraced; collected-object allocation sampling (512-byte interval) and main-isolate promotion tracing are separate passes. Benchmark usage is documented in the script header.

Base source archive: 80ee015d2a4c4748b4f4ecb14d7063617390c459, with the later default-preserving hydration option synchronized on both sides. The fingerprint baseline blob and all measured request owners are unchanged in final rebase target 68b73bf9cabdfcf4f3e355df78585c9a141415d0.

Workload (n=5 per side) Retained KiB/current session Cold CPU ms/observation (80/side) Repeated CPU ms/observation (1,600/side)
Projected, fresh view 146.54 → 136.33 (-7.0%) 4.408 → 4.516 (+2.5%) 0.448 → 0.454 (+1.5%)
Projected, retained view 138.82 → 128.56 (-7.4%) 4.434 → 4.430 (-0.1%) 0.176 → 0.178 (+1.1%)
Mutable append envelopes 213.00 → 204.45 (-4.0%) 1.585 → 1.607 (+1.4%) 0.870 → 0.837 (-3.7%)
Sealed control 101.21 → 100.35 (-0.8%) 4.356 → 4.356 (+0.0%) 0.226 → 0.207 (-8.3%)
Fully mutable clone control 315.11 → 276.77 (-12.2%) 1.615 → 1.659 (+2.7%) 1.631 → 1.780 (+9.2%)

For projected fresh views, retained heap normalized by all measured model calls is 7,145.62 → 6,647.60 bytes/call (−6.97%). This is amortized retained occupancy after forced GC, not allocated bytes or memory that accumulates on every call. The per-session figure above avoids dependence on the number of repeated rounds.

Separate allocation/promotion pass (n=5 per side) Before → after, bytes/model call Collected allocation samples, base / candidate
Projected total allocation 587,898.8 → 570,419.7 (-3.0%) 1,652,251 / 1,604,910
Projected fingerprint-family allocation 433,865.2 → 416,148.1 (-4.1%) Same profiles
Append total allocation 1,112,058.1 → 1,080,711.4 (-2.8%) 3,137,836 / 3,054,854
Append fingerprint-family allocation 857,602.8 → 826,394.6 (-3.6%) Same profiles
Projected promotion per repeated observation 34,995.5 → 26,404.9 (-24.5%) 1,600 observations/side; separate traced pass

Acceptance: projected retained heap improves consistently by about 7%, with near-neutral CPU; promotion falls 24.5%. Append CPU and allocation also improve. The fully mutable clone control trades +0.150 ms (+9.2%) repeated CPU for −12.2% retained heap; all five CPU deltas are positive, so this is an explicit tradeoff, not claimed as a speedup. The CPU mean remains below the predeclared adverse threshold, with paired CPU deltas of +10.3%, +7.6%, +8.0%, +12.3%, and +7.8% (three of five below 10%). No GC/promotion/max-pause rejection signal requires an A/A control campaign.

GC and lifetime evidence

All observed timed untraced collections were minor; zero major collections were observed, so major-GC tails are unmeasured. Collection counts below 200 per side per run do not support p95/p99 gates. The table reports every pair's count and both maximum single pauses instead. Maxima are well below the 50 ms safeguard; the only GC increase is +0.000123 ms/observation in retained-view mode, below the 1 ms/op materiality threshold.

Workload Total GC ms/repeated observation Minor counts per run, base → candidate Max pause ms, base → candidate, samples 1–5
Projected, fresh view 0.024472 → 0.023585 (-3.6%) 5→5, 5→5, 5→5, 5→5, 5→5 1.741→2.149, 1.943→1.870, 2.044→1.813, 2.011→2.023, 1.966→1.982
Projected, retained view 0.000862 → 0.000984 (+14.2%) 1→1, 1→1, 1→1, 1→1, 1→1 0.216→0.334, 0.287→0.343, 0.211→0.237, 0.388→0.398, 0.277→0.263
Mutable append envelopes 0.057426 → 0.046359 (-19.3%) 11→10, 11→10, 11→10, 11→10, 11→10 2.223→1.974, 2.240→1.994, 2.179→1.973, 2.200→1.973, 2.289→2.100
Sealed control 0.013172 → 0.011630 (-11.7%) 3→3, 3→3, 3→3, 3→3, 3→3 1.705→1.184, 1.657→1.285, 1.587→1.376, 1.628→1.390, 1.794→1.379
Fully mutable clone control 0.139860 → 0.135982 (-2.8%) 21→20, 21→20, 21→20, 21→20, 21→20 2.502→2.583, 2.666→2.606, 2.666→2.642, 2.517→2.697, 2.631→2.614

Each projected request contains 64 deeply frozen messages and 64 mutable envelopes with frozen content; append contains 128 mutable envelopes with frozen content; the clone control contains 32 mutable envelopes with frozen content and 96 fully mutable messages. No owned envelope roots occur in these fixtures. All modes use 2,048 resident messages. In fresh projected mode, 1,025 initial envelopes remain after replacement (1,024 intentionally retained frozen originals plus one fixture reference), and 1,024 current envelopes remain after releasing model contexts (the frozen originals). Append and fully mutable modes retain one initial fixture reference and zero current envelopes after release. The weak memo owner does not extend envelope lifetime; these are source/lifetime observations, not a production leak claim.

Proof and tradeoffs

  • 130 focused tests passed: prompt-cache-observability.history.test.ts (48), prompt-cache-observability.test.ts (30), prompt-cache-request-observer.test.ts and provider-prompt-state.test.ts (41 combined), and agent-tools.prefix-stability.test.ts (11). Existing tests remain unchanged; three added special-key cases cover __proto__, constructor, and toString, including one-hash reuse, undefined/null, nested transitions, and deletion.
  • Changed-file formatting, scoped core/scripts lint, and git diff --check passed. No full local suite/build/typecheck or Testbox lease. Final head d0ed20097db483374074b5e989f42c8b65b0d774 passed the aggregate CI gate: 59 successful checks, 54 skipped, one neutral CodeQL result, no failures or reruns.
  • Independent subagent review (autoreview route unavailable): final production and tests clean at P2. Automated Codex review of the final head also completed with no findings. The standard helper refused its provider/operator-configuration mismatch; no configuration changed.
  • Production LOC +12 (20 added, 8 removed). The old primitive Map is removed completely. The growth preserves the existing arbitrary-key contract: own-key checks distinguish absence from undefined, __proto__ remains a writable/deletable data key, and immutable records still allocate no revision object. No new cache, alternate fast path, or compatibility shim.

After deployment, compare matched-phase fingerprint-family allocation and retained diagnostic heap per model call/context; primitive Map backing stores should decrease while primitive hash counts and rewrite diagnostics stay stable. Watch observation CPU for unusually mutable histories. Owner-level synthetic measurements do not establish a whole-Gateway CPU or latency improvement, and diverse extension-key shapes can reduce object-shape sharing. Production profiling remains with the coordinating maintainer.

Ready for the lead to verify and merge; this lane does not merge.

@clawsweeper

clawsweeper Bot commented Oct 25, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 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-25T03:16:08.407463Z d0ed200 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.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts agents Agent runtime and tooling size: S labels Oct 25, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. labels Oct 25, 2026
@clawsweeper

clawsweeper Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR replaces mutable history fingerprint Maps with ordered field tuples and extends the existing measurement script.

Example: A projected tool result for call-1 shares frozen text content while its message envelope remains mutable.

  • Before: The envelope retains separate Maps for field digests and primitive revisions.
  • After: One tuple array retains those values while timestamp edits and field deletions remain detectable.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch is focused and has no identified correctness defect, but its central performance claim remains unproven.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Conversation diagnostics retain avoidable bookkeeping alongside mutable message projections.
Reason: The maintainer-authored direction addresses an established memory-cost area without changing provider behavior; the new flags affect only the measurement script.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this maintainer-authored PR open: it makes a focused change within the existing fingerprint owner, and source review found no definite correctness or security defect.

Priority: P2
Reviewed head: 4b43b176e8da397181359f1b6b3b6d4251ca2a09

Before merge

  • Await maintainer action - The coordinating maintainer must verify the completed comparative tables against the PR's declared performance acceptance rule before merging.

Findings

None.

Tests

  • Missing end-to-end proof: The declared alternating base/head owner measurements have not supplied after-change memory, allocation, CPU, GC, and fingerprint-equivalence results.
Agent review details

How this fits together

The request observer fingerprints converted conversation messages before model dispatch and retains compact baselines for subsequent history-rewrite diagnostics.

flowchart LR
  A[Transcript view] --> B[Message projection]
  B --> C[Request observer]
  C --> D[History fingerprints]
  D --> E[Diagnostic baseline]
  E --> F[Rewrite diagnostics]
Loading

Technical review

Best possible solution:

Retain the focused representation change only if comparative owner measurements satisfy the declared acceptance rule while preserving fingerprint bytes and rewrite diagnostics.

Do we have a high-confidence way to reproduce the issue?

Source confirms that mutable projected envelopes retain two Maps on main; the proposed performance benefit has not been demonstrated by a completed comparative run.

Is this the best way to solve the issue?

The tuple representation is a small, coherent change within the existing owner, but its linear field lookup must earn its cost through the declared measurements.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against a3f44fb8a9f6.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +6, Other +79. Total +85 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 29 23 +6
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 88 9 +79
Total 2 117 32 +85

Review metrics

Metric Value Why it matters
Production and measurement code Production net +6 lines; measurement script net +79 lines; tests unchanged The small production growth combines existing revision state without adding an owner or cache; script growth exercises projections, retained views, allocation, and release behavior.

Labels

Label changes:

  • add P2: This is a bounded diagnostic-memory optimization without an established urgent user-facing failure.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.

Label justifications:

  • P2: This is a bounded diagnostic-memory optimization without an established urgent user-facing failure.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Supply the declared alternating base/head measurement tables and sanitized owner output demonstrating the acceptance rule.

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 October 24, 2026, 10:19 PM ET / October 25, 2026, 02:19 UTC.

@steipete
steipete force-pushed the steipete/perf-envelope-fingerprints-20261025 branch from 4b43b17 to a37e890 Compare October 25, 2026 02:25
Keep ordered field digests in their existing Map and store primitive revisions in a small object. Preserve own-key semantics and hash reuse for arbitrary extension fields. Five alternating owner samples reduce projected-context retained heap by 7.0% and promotion by 24.5%, with near-neutral CPU on that path. Fully mutable histories trade 9.2% CPU for 12.2% less retained heap.
@steipete
steipete force-pushed the steipete/perf-envelope-fingerprints-20261025 branch from a37e890 to d0ed200 Compare October 25, 2026 03:14
@steipete steipete changed the title perf(agents): compact mutable history fingerprint records perf(agents): compact primitive fingerprint revisions Oct 25, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The final head is d0ed20097db483374074b5e989f42c8b65b0d774. It replaces only the primitive-revision Map; the ordered digest Map remains. The earlier tuple candidate is superseded. The PR body now contains the complete five-sample retained-heap, CPU, allocation, promotion, GC, fingerprint-equivalence, and envelope-lifetime results, including the fully mutable control's CPU tradeoff. All 130 focused tests and the final aggregate CI gate passed without reruns. Independent review and the automated Codex review are clean. This PR remains open for the coordinating maintainer to verify and merge.

@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit ee9b334 into main Oct 25, 2026
131 of 133 checks passed
@steipete
steipete deleted the steipete/perf-envelope-fingerprints-20261025 branch October 25, 2026 03:29
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
* perf(agents): compact mutable history fingerprint records

* perf(agents): reuse fingerprint revision lookup indices

* perf(agents): compact primitive fingerprint revisions

Keep ordered field digests in their existing Map and store primitive revisions in a small object. Preserve own-key semantics and hash reuse for arbitrary extension fields. Five alternating owner samples reduce projected-context retained heap by 7.0% and promotion by 24.5%, with near-neutral CPU on that path. Fully mutable histories trade 9.2% CPU for 12.2% less retained heap.
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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: S status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant