Repository navigation
perf(sessions): reuse unchanged transcript accounting during actor hydration - #193274
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis 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. |
|
Codex review: needs maintainer review before merge. What this changesThis 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.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +16, Tests +30, Other +166. Total +212 across 6 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 5, 2026, 2:34 AM ET / 07:34 UTC. |
4b4e3c7 to
7bd86db
Compare
…dration (openclaw#193274) * perf(sessions): reuse unchanged transcript accounting during actor hydration * perf(sessions): consolidate actor accounting regression coverage
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.
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 allocationseparately. The script's header describes the original-source overlay for baseline runs.session-actor-entry-residency.test.tsfails 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.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.