Skip to content

perf(sessions): reuse unchanged transcript accounting during actor hydration - #193274

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-actor-append-reload-in-write-20261105
Nov 5, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-actor-append-reload-in-write-20261105

Conversation

@steipete

@steipete steipete commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Session appends can rescan an unchanged transcript's full byte accounting inside the database write transaction after an entry-only write invalidates the resident actor.

User Impact

Less work while holding the session database writer after metadata invalidation. Transcript bytes, ordering, reload views, and conflict/admission checks are unchanged. No schema or configuration changes.

Why This Change Was Made

Fresh hydration still reads the authoritative actor facts. Its accounting owner now reuses the previous actor's totals only when session ID, generation, raw sequence, and mutation timestamp all match. Cold, dirty, and unclassified projections retain their existing path; a historical metadata rewrite advances the timestamp and forces a fresh scan. This is the same validity contract already used by accounting receipts, within the same physical worker owner.

The initial reload hypothesis did not explain the dominant observed delay: among 669 non-resident slow appends in a 24-hour aggregate, median actor hydration was 1,325 ms versus 4 ms applying the append. Explicit reload callers consume their results and remain unchanged. History-reader rotation is separate from actor execution ownership. Current diagnostics cannot distinguish byte-budget eviction from write-token invalidation; this change targets only the avoidable rescan when the prior actor still exists and its transcript is unchanged.

Runtime production code grows by 16 lines to carry and validate the existing totals; no new cache, retention allowance, or alternate writer is introduced. The separately committed benchmark documents its usage in its header. The existing accounting test now covers both warm and native-invalidated actors, including metadata rewrite refusal, with zero net test-line growth.

Evidence

Acceptance declared in the benchmark before measurements: identical hydrated facts, one fewer full-history aggregate, lower CPU/allocation, and no material GC increase. Synthetic SQLite fixture: 1,024 events, 8,528,630 history bytes, 110 KB skills metadata. Five alternating timing runs per revision, 1,000 hydrations each; two counterbalanced allocation runs per revision, 1,000 each. Allocation includes collected objects and is measured separately from timing.

Owner metric Base Candidate Change
CPU ms / 1,000 hydrations, mean 4,785.1 4,145.9 -13.4%
Wall ms / 1,000, mean 5,021.0 4,165.3 -17.0%
Sampled allocation MB / 1,000, mean 1,519.4 1,457.2 -4.1%
GC ms / 1,000, untraced mean 39.28 36.73 -6.5%
Maximum individual GC pause across timing runs, ms 3.48 3.59 +0.11 ms
Full-history aggregates after entry-only invalidation 1 0 eliminated
Append SQL phase ms, median of 5 per revision 9 8 -1 ms
Append receipt bytes, median 122,424 122,424 unchanged

The real actor append probe used a non-resident actor after native entry invalidation, the same 1,024-event/110 KB fixture, and a current manager view. Both revisions performed zero history reloads despite ~122 KB receipts; the candidate eliminated all five stats scans while preserving receipt size.

Maximum GC pauses by timing pair, baseline → candidate (ms): 2.64 → 3.43; 3.43 → 3.16; 2.95 → 3.35; 3.48 → 3.21; 3.46 → 3.59.

Per-kind GC ms / 1,000, base → candidate: Scavenge 35.71 → 33.00, IncrementalMarking 0.38 → 0.38, MarkSweepCompact 3.19 → 3.35. Across timing runs, minor collection counts were 244 → 240 and major counts 5 → 5; major-collection tails are context only at this sample size.

The fifth baseline timing run had higher outside contention; it is included without trimming. All five CPU pairs improve. These are owner measurements, not a claimed whole-Gateway percentage. No Gateway stress campaign was run under the lane's deletion/duplicate-recompute fast-path exception; no production load was started.

Reproduce with node --expose-gc --import ./scripts/tsx.mjs scripts/perf/session-actor-accounting-reuse-measure.ts --output <new-directory> --iterations 1000, and --mode allocation separately. The script's header describes the original-source overlay for baseline runs.

  • Regression on main: session-actor-entry-residency.test.ts fails with two aggregates instead of one in the invalidated append/rewrite case; the warm control passes. Candidate passes both; a historical metadata rewrite with unchanged generation/sequence refuses the old totals and returns the corrected byte count.
  • Focused actor residency, receipt, and worker tests: 52 cases covered.
  • Changed-file format/lint, root script test types, and the config/core test typecheck pass. Export-name collision guard and both source-closure test files pass (40 tests).
  • Independent subagent review (autoreview route unavailable): no actionable P0–P2 findings. The configured autoreview helper refused the requested provider/config mismatch; configuration was not changed.

The first CI head passed the focused runtime checks but failed the test-line ratchet because its base already had 29 lines of budget debt despite this PR allocating its exact growth. The regression was consolidated into the existing test table with zero net growth and the allocation removed; the focused test-line ratchet now passes without changing the shared baseline. CI is green on exact head 7bd86dbebb6251543177cefb7b88c389de830f62: CI run succeeded, including all PostgreSQL conformance shards; the aggregate CI, dependency-review, and security-sensitive-review gates also passed. This PR is intentionally left ready for maintainer review and merge.

@clawsweeper

clawsweeper Bot commented Nov 5, 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 Nov 5, 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-11-05T07:39:41.633136Z 7bd86db 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 size: M labels Nov 5, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro 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. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 5, 2026
@clawsweeper

clawsweeper Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR reuses a previous session actor’s accounting totals when freshly hydrated transcript identity and version fields match.

Example: An entry-only metadata write invalidates an actor holding a 1,024-event transcript.

  • Before: Hydration rescans the unchanged transcript to calculate its byte totals.
  • After: Hydration reuses the totals; a transcript mutation still forces fresh accounting.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused and coherent implementation with useful owner-level measurements and regression controls; evidence stops at the in-process boundary.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its supplied SQLite-owner benchmark and append probe cover unchanged accounting reuse, while no full Gateway campaign is claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Session appends can hold the database writer while recalculating unchanged transcript totals after metadata invalidation.
Reason: The maintainer-authored direction has measured owner-level value and preserves transcript, admission, configuration, and storage contracts.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR removes a concrete accounting rescan still present on main, with no actionable correctness or security defect found.

Priority: P2
Reviewed head: 4b4e3c7034acbee9b7820ef7a211d7348a07ae5b

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence exercises real SQLite accounting and actor append owners rather than a shipped Gateway session flow.
Agent review details

How this fits together

The physical database worker hydrates session actors from authoritative SQL facts and publishes transcript accounting through existing actor receipts.

flowchart TD
  A[Session append] --> B[Physical database worker]
  B --> C[Fresh actor hydration]
  D[Previous resident actor] --> E[Accounting version comparison]
  C --> E
  E --> F[Reuse totals or read canonical accounting]
  F --> G[Actor receipt]
Loading

Technical review

Best possible solution:

Retain this focused reuse within the existing accounting owner, preserving fresh hydration and canonical accounting whenever transcript versions differ.

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

Source shows entry-only invalidation reaching fresh hydration and full-history accounting beyond the resident window; the supplied regression reports base failure and candidate success, without execution during this read-only review.

Is this the best way to solve the issue?

The patch is the smallest complete fix: carry existing totals to their current owner, reuse only on matching authoritative transcript facts, and retain the existing fallback.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Actor accounting initialization keeps the original intent (87ca2c8: Keep exact accounting independent of bounded transcript residency, with canonical reads for uncovered rewrites and boundary changes.)
  • Actor hydration and execution ownership keeps the original intent (d5173cc: Hydrate authoritative actor facts inside the existing serialized physical database owner.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 87ca2c8 adds src/config/sessions/session-actor-context-stats.worker.ts:9 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 87ca2c83893c; files: src/config/sessions/session-actor-context-stats.worker.ts)

PR surface

Source +16, Tests +30, Other +166. Total +212 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 17 1 +16
Tests 1 30 0 +30
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 166 0 +166
Total 6 213 1 +212

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.

Labels

Label changes:

  • add P2: Avoidable full-history accounting extends database writer occupancy for affected large-session appends.
  • 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: Avoidable full-history accounting extends database writer occupancy for affected large-session appends.
  • 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 5, 2026, 2:34 AM ET / 07:34 UTC.

@steipete
steipete force-pushed the steipete/perf-actor-append-reload-in-write-20261105 branch from 4b4e3c7 to 7bd86db Compare November 5, 2026 07:37
@steipete
steipete merged commit 952c33e into main Nov 5, 2026
132 of 134 checks passed
@steipete
steipete deleted the steipete/perf-actor-append-reload-in-write-20261105 branch November 5, 2026 08:05
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 6, 2026
…dration (openclaw#193274)

* perf(sessions): reuse unchanged transcript accounting during actor hydration

* perf(sessions): consolidate actor accounting regression coverage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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