Skip to content

perf(sessions): share history reader adapters across retained reads - #182200

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-transcript-reader-setup-20260919
Oct 24, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-transcript-reader-setup-20260919

Conversation

@steipete

@steipete steipete commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Repeated transcript reads rebuild the complete history-reader method table and its projection/preparation closures, then copy that table into a second owner object. Single-database reads also allocate the batch helper's target, retained-reader, mapped-owner, and reversed cleanup arrays.

User Impact

No intended user-visible behavior change. History, transcript, board, and inventory readers keep their existing results, admission, cancellation, revocation, and cleanup boundaries.

Why This Change Was Made

Create the stateless reader adapters once and carry the request runner as an own property on each retained reader. The runner still captures that read's database options, lane, and known-source state. Own methods remain enumerable for existing reader decorators. Preserve the receiver in the transcript execution adapter, add assertCurrent without copying the table again, and let single-database callers retain/release directly.

No new cache, retained database scope, schema, configuration, or invalidation mechanism. Production source grows by 7 lines to make the shared methods' receiver explicit; the allocated closure graph and redundant single-reader batching disappear. Most changed lines are the method table moving out of the factory.

Evidence

  • Independent subagent review (autoreview route unavailable): scoped clean at P0–P2. The helper refused the requested provider route before inference; no operator configuration was changed. Separate caller audit identified and migrated the production detached-method adapter and two fixture interceptors.
  • Focused reader/lane tests: 46 passed. Consumer/reader rerun: 59 passed, including public-share revocation during awaited reads, history eviction, and interleaved decorated reader isolation. The latter preserves behavior and is not claimed as a failing performance regression test.
  • Core targeted typecheck passed. Changed-file formatting and git diff --check passed. Changed-file lint passed. The benchmark also passed syntax/lint, 22 closure tests, and the export-name guard; its independent review is clean. CI initially caught the missing explicit allowlist entry for the benchmark’s documented no-implied-eval exception; that exact one-entry repair was independently reviewed, and all 14 tests in test/scripts/lint-suppressions.test.ts now pass. The trusted source file is already executable input; no production execution boundary was weakened.
  • Setup-only measurement passed the predeclared acceptance rule: remove per-read method construction and lower retained or sampled allocation, with no ≥20% adverse mean unprofiled setup CPU/time. Five concurrent synchronized pairs, swapped interleaved CPU placement, 200,000 setups/side after 20,000 warmups; a ring retains 64 owners. Node 26.12.1, isolated synthetic source capsules, shared host guard enabled. Start skew was 0, 0, 0, −1, +2 ms. Every timing pair improved.
Setup metric Baseline mean Candidate mean Absolute delta Paired relative mean
New reader method identities / setup 65 0 −65 −100%
Elapsed / setup 2.0897 µs 1.3324 µs −0.7573 µs −36.25%
Process CPU / setup 2.2492 µs 1.3579 µs −0.8913 µs −39.61%
Retained bytes / owner, 10,000 retained per side 11,209.98 B 3,161.99 B −8,047.99 B −71.79%
Sampled allocation / setup, separate 100,000-setup pass 17,614.07 B 6,065.98 B −11,548.10 B −65.56%

Unprofiled elapsed pairs (baseline → candidate, µs/setup): 2.0081 → 1.2800; 2.1170 → 1.2629; 2.1709 → 1.4302; 2.1098 → 1.3852; 2.0426 → 1.3036. Sampling includes objects collected by minor and major GC; its timing is not a gate. Elapsed medians were 2.1098 → 1.3036 µs, ranges 2.0081–2.1709 → 1.2629–1.4302 µs.

Scope: exact reader factory plus the extracted owner-construction expression, with synthetic runner sanity checks. The capsule's unused collaborator imports throw if invoked. Admission, SQLite, worker execution, the removed singleton batch wrapper, Gateway latency, and live deployment gains are not measured. Per-kind GC, promotion, event-loop tails, and both max pauses were not collected; there is no GC verdict or GC-based rejection, so no A/A GC gate is claimed. This is the requested structural simplification, with a measured setup allocation reduction and unchanged behavioral contracts.

Reproduce each side using its pinned files (baseline captured from 3bcc91708d8ee794e52f9cb0ae98ebb1f848ad25; these two modules also match the current base):

node --expose-gc scripts/perf/session-history-reader-setup-measure.mjs \
  --owner /path/to/pinned/session-transcript-worker-readers.ts \
  --runtime-owner /path/to/pinned/session-transcript-worker-runtime.ts \
  --capsule --operations 200000

Copy the matching session-transcript-worker.types.ts beside the reader. Use the documented start-file barrier for concurrent pairs; run --allocations --operations 100000 separately. Workload SHA-256: a8045717ce7ed60ebe25bc9584d3819b4c9870acc266318580ee049c38d85963. Benchmark/tooling adds 194 lines and its README adds 29; production is +7 lines, with no new owner/cache or compatibility path.

  • No Testbox/Crabbox lease used; broad proof belongs to PR CI.

@clawsweeper

clawsweeper Bot commented Oct 24, 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 gateway Gateway runtime size: L labels Oct 24, 2026
@steipete
steipete marked this pull request as ready for review October 24, 2026 04:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 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-24T04:35:28.497961Z 7ec838c 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.

@steipete
steipete force-pushed the steipete/perf-micro-transcript-reader-setup-20260919 branch from eca70be to f1d4fb6 Compare October 24, 2026 04:24
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 24, 2026
@steipete
steipete force-pushed the steipete/perf-micro-transcript-reader-setup-20260919 branch from f1d4fb6 to 7ec838c Compare October 24, 2026 04:33
@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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR shares stateless history-reader methods while retaining a separate request runner and cleanup lifetime for each reader.

Example: Open the same session history repeatedly.

  • Before: Each retained read constructs 65 new method identities and copies the reader table into another object.
  • After: Reads reuse the method identities while keeping their own database runner and returning the same history.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is focused and source-consistent, with useful setup measurements and preservation coverage; evidence remains limited to synthetic and in-process paths.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored internal refactor is outside the ordinary contributor proof gate; supplied evidence consists of synthetic construction measurements and reported reader/consumer tests, without a deployed 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: Repeated session reads allocate avoidable reader adapters, increasing internal allocation pressure.
Reason: The maintainer-authored direction has verified feature-history ownership, removes measurable setup allocation, and preserves the existing product contract.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it is an owner-backed allocation reduction with no actionable introduced correctness or security defect found.

Priority: P3
Reviewed head: 7ec838c6661c23c104f05a47d0bdf8d61f889509

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence does not exercise history reads through a shipped Gateway entry point.
Agent review details

How this fits together

History, transcript, board, and inventory callers enter the retained history-reader owner, which admits work to the selected database worker and returns projected results before releasing custody.

flowchart TD
  A[History and board callers] --> B[Retained reader owner]
  B --> C[Shared reader methods]
  C --> D[Per reader request runner]
  D --> E[Admission and database worker]
  E --> F[Projected read result]
  F --> A
Loading

Technical review

Best possible solution:

Keep the shared method table on the existing retained owner, with receiver-preserving adapters and direct single-reader cleanup.

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

The base factory visibly reconstructs the reader closures and the runtime copies their table on every retained read; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The change removes repeated construction using the existing reader and resource owners, preserves enumerable decorators, and updates the detached adapter without adding a cache or another lifecycle.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • History reader adapters keeps the original intent (dbd3bf7: Move transcript hydration off-thread while retaining database custody and typed result decoding; later consolidation centralized ordinary request construction.)
  • Retained database ownership and single-target reads keeps the original intent (88004e9: Retain selected physical databases across asynchronous reads; subsequent maintenance-lane work preserves foreground responsiveness and lane-aware cleanup.)
  • Prepared transcript forwarding keeps the original intent (e589d87: Consolidate typed prepared-read forwarding while keeping physical worker ownership and current effect authority, as recorded in refactor(sessions): consolidate storage readers and worker ownership #172357.)
  • Connection-local transcript search keeps the original intent (6fdc930: Keep search and freshness checks on the same live connection without serializing foreground searches through the projection worker.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +7, Tests +23, Docs +29, Other +194. Total +253 across 9 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 307 300 +7
Tests 4 25 2 +23
Docs 1 29 0 +29
Config 0 0 0 0
Generated 0 0 0 0
Other 1 194 0 +194
Total 9 555 302 +253

Review metrics

Metric Value Why it matters
Production versus test growth Production +7 net lines; tests +23 net lines The production growth makes shared-method receivers explicit; the added test protects decorated-reader isolation and the static guard registers the benchmark's narrow exception.

Labels

Label changes:

  • add P3: This is a bounded internal allocation improvement with no intended user-visible behavior change or established urgent regression.
  • 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:

  • P3: This is a bounded internal allocation improvement with no intended user-visible behavior change or established urgent regression.
  • 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 October 24, 2026, 12:48 AM ET / 04:48 UTC.

@steipete
steipete merged commit 83fd5dd into main Oct 24, 2026
138 checks passed
@steipete
steipete deleted the steipete/perf-micro-transcript-reader-setup-20260919 branch October 24, 2026 05:01
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
…penclaw#182200)

* perf(sessions): share history reader adapters across retained reads

* test(perf): measure history reader construction allocations

* test(perf): register trusted source benchmark lint exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L 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