Skip to content

perf(sessions): retain unchanged transcript windows and compact entry receipts - #193326

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-actor-residency-receipt-20261105
Nov 5, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-actor-residency-receipt-20261105

Conversation

@steipete

@steipete steipete commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Entry-only session writes can invalidate an actor and make its next append reload an unchanged 512-event transcript window inside the database writer. The same publication can leave the main-thread replica with a complete entry but no full actor snapshot, causing the next receipt to resend large entry metadata that the main thread already owns.

User Impact

Less database work while appending after metadata changes, and smaller worker-to-main receipts. Transcript bytes, ordering, entry and participant facts, conflict handling, rollback, and live admission checks remain unchanged. No schema, configuration, retention-budget, or permission changes.

Why This Change Was Made

This follows #193274. The hydration owner now checks the retained transcript's session ID, generation, final sequence, mutation timestamp, and projection facts in its existing SQL snapshot. When they match, SQL skips the three history-window projections and hydration keeps the retained window. Fresh, changed, cold, dirty, or unclassified transcripts still load their canonical rows. Entry, sharing, pending-input, completion, and authority facts are refreshed normally; actor version conflicts keep their existing behavior.

The replica now offers its retained full entry facts to the existing receipt compressor when its full actor snapshot is absent. The worker still requires the exact write token, and partial entry facts are ineligible. This reuses the existing delta wire format and restoration owner; it does not turn the reference into authority or make an entry-only reference eligible for actor rollback restoration.

The synthetic residency census used 20 actors with 1,024 events of about 8 KiB and a 110 KB skills snapshot each. All 20 remained resident on a second pass: zero rehydrations. Each tested native entry replacement and sharing change caused one rehydration on the following append; owner-managed title/status/unread patches and participant updates caused zero. History-reader rotation belongs to a different worker. This identifies avoidable invalidation paths, but does not establish their relative production frequency or rule out eviction with larger real working sets.

Runtime production growth is 108 lines, principally the same-snapshot SQL validity predicate needed to skip canonical window reads safely. No new cache or residency allowance is introduced. Regression growth is 21 lines with an exact allocation record: one existing large-history test gains a SQL reply-byte bound, and the existing receipt matrix gains entry-only publication cases.

Evidence

Acceptance was declared before the comparative hydration runs: unchanged entry/transcript facts and digests, no repeated unchanged history-window load, reduced CPU/allocation and receipt size, and no material total-GC regression. The committed benchmark uses 1,024 events, 8,528,630 history bytes and 110 KB entry metadata; it checks full hydrated-state equality and emits a transcript digest. Five alternating timing pairs at 1,000 operations per arm; two separate counterbalanced allocation pairs at 1,000 operations per arm.

Metric Base Candidate
CPU ms / 1,000 hydrations 3,936.42 838.36 (-78.7%)
Wall ms / 1,000 hydrations 3,940.70 846.34 (-78.5%)
Sampled allocation MB / 1,000 hydrations 1,459.10 613.43 (-58.0%)
Untraced GC ms / 1,000 hydrations 31.15 23.09 (-25.9%)
Native-title append receipt bytes 122,601 12,679 (-89.7%)
Full entry on receipt wire, isolated serialized bytes 110,289 5 (omitted)
Restored full entry, serialized bytes 110,289 110,289
Transcript rows after append 1,025 1,025
History reloads in receipt probe 0 0

The receipt probe exercises native entry publication, the actual main replica's command reference, worker append, and receipt restoration. Its baseline arm omits the reference exactly as the old replica did; separately, the regression fails against unchanged main. Entry and transcript SHA-256 digests match across arms, and each restored complete postimage matches its canonical worker read, including participants. The large receipt was dominated by the entry's skills snapshot, not a 512-event history projection. The append transcript section was about 11 KB; conversation and entry-metadata sections were absent in this probe. Isolated field sizes are not additive because serialization preserves aliases.

Timing-pair maximum GC pauses, base → candidate (ms): 2.42 → 2.48; 2.86 → 2.53; 2.77 → 2.88; 2.91 → 1.48; 2.50 → 2.56. Per-kind mean GC ms / 1,000: scavenge 28.10 → 20.73; incremental marking 0.36 → 0.27; mark-sweep 2.69 → 2.09. Minor collection counts were 239 → 104, major counts 5 → 4; major tails are context only. One candidate setup failed during a mechanical local refactor before producing measurements; that incomplete pair was replaced with a fresh full pair, without trimming measured pauses.

These are owner measurements, not a whole-Gateway percentage. No long Gateway stress campaign ran under the explicitly authorized duplicate-recompute fast path; no production load or mutation was performed.

Reproduce hydration timing with node --expose-gc --import ./scripts/tsx.mjs scripts/perf/session-actor-accounting-reuse-measure.ts --output <new-directory> --iterations 1000; use --mode allocation separately and the header's original-source overlay for baseline. The existing receipt regression matrix reproduces real publication and restoration behavior.

  • Main regression: unchanged-window hydration returned 234,333 SQL text bytes, failing the new <10,000 bound; the warm control passed. Candidate passes both, including metadata rewrite/accounting and bounded-history checks.
  • Receipt regression: four entry-only publication cases fail the receipt-size bound on main; candidate preserves exact restoration, stale-token refusal, caller isolation, and participants.
  • Focused residency/kernel tests: 24 passed. Receipt/worker/replica/actor tests: 80 passed; participant-enriched receipt rerun: 13 passed. Changed test files remain under five seconds of test execution; wrapper totals include compilation (residency/kernel 36.2 seconds).
  • Changed-file format/lint, root script test-type shards, config/core test types, export-name guard, and both source-closure files (38 tests) pass.
  • Independent subagent review (autoreview route unavailable): no actionable P0–P2 findings in the complete eight-file diff against 952c33eaee9754e0a08cf45d16dc42dfbc699acc. The configured helper refused the provider/operator configuration mismatch; configuration was not changed. Exact-head CI passed on 18c57bf25b8a887c85b6e043573e479d3b412f12: CI run, including all three PostgreSQL conformance shards. The aggregate CI, dependency-review, and security-sensitive-review gates are green. No CI failures or reruns were needed on this head.

This PR is intentionally ready for maintainer review and merge; the author will not merge it.

@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-05T08:30:40.449034Z 18c57bf PR opened
ℹ️ 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-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-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 unchanged resident transcript windows and complete entry facts to reduce hydration work and receipt traffic.

Example: Append after a native title change in the supplied 1,024-event session with 110 KB of entry metadata.

  • Before: Hydration reloads unchanged transcript windows, and the append receipt transfers 122,601 bytes.
  • After: Hydration retains the verified windows, and the receipt transfers 12,679 bytes while restoring the complete entry.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused owner-level optimization with concrete comparative evidence and no identified defect; supplied behavioral coverage remains below the shipped Gateway entry point.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; public owner measurements exercise hydration, native entry publication, replica references, append receipts, and exact restoration without claiming whole-Gateway coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Appending after metadata changes repeats transcript hydration and transfers large entry metadata already retained by the host.
Reason: The maintainer-authored direction has measured owner-level benefits and preserves stored values, existing budgets, and public contracts.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-directed optimization removes verified redundant work, and no actionable correctness defect was found; exact-head CI remains pending.

Priority: P2
Reviewed head: 18c57bf25b8a887c85b6e043573e479d3b412f12

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Supplied evidence exercises hydration and receipt owners in synthetic SQLite setups; no shipped Gateway run is supplied.
Agent review details

How this fits together

The session actor hydrates authoritative SQLite facts inside the database worker, executes ordered commands, and publishes commit receipts to the main-thread replica.

flowchart LR
  A[Session command] --> B[Main replica]
  B --> C[Database worker]
  C --> D[Hydration owner]
  D --> E[SQLite snapshot]
  D --> F[Retained transcript window]
  C --> G[Commit receipt]
  G --> B
Loading

Technical review

Best possible solution:

Retain the existing hydration and receipt owners with same-snapshot transcript validation and command-local entry reconstruction.

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

Base source reloads all three transcript windows after entry-only invalidation and offers no entry-only compression preimage; the supplied regressions report failures on that base, but no target code was executed during this review.

Is this the best way to solve the issue?

The change follows the existing owners and validity contracts, removes duplicate work without increasing residency allowances, and retains canonical fallback behavior for changed transcripts.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Bounded transcript hydration keeps the original intent (dd9cdee: Bound resident navigation, identity, and active-event collections while leaving historical reads with their canonical readers.)
  • Unchanged transcript accounting keeps the original intent (952c33e: Reuse accounting only when freshly admitted transcript identity and version facts match.)
  • Command-local entry compression keeps the original intent (6f8748a: Avoid retransmitting exact immutable entry preimages while preserving worker token confirmation and live admission checks.)
  • Changed-entry receipt reconstruction keeps the original intent (653c116: Transmit entry deltas and restore complete metadata enrichment before publication and replica consumers.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

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

PR surface

Source +108, Tests +21, Other +6. Total +135 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 197 89 +108
Tests 2 28 7 +21
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 9 3 +6
Total 8 234 99 +135

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.

Review metrics

Metric Value Why it matters
Production versus regression LOC Production +108 net; tests +21 net Production growth principally implements the same-snapshot validity predicate; regression growth extends existing hydration and receipt suites without introducing another state owner.

Labels

Label changes:

  • add P2: Measured session-storage CPU, allocation, and receipt improvements have a bounded performance scope without an established urgent user-facing 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:

  • P2: Measured session-storage CPU, allocation, and receipt improvements have a bounded performance scope without an established urgent user-facing 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 November 5, 2026, 3:42 AM ET / 08:42 UTC.

@steipete
steipete merged commit 7758c83 into main Nov 5, 2026
144 of 145 checks passed
@steipete
steipete deleted the steipete/perf-actor-residency-receipt-20261105 branch November 5, 2026 08:57
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 6, 2026
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