Repository navigation
perf(sessions): retain unchanged transcript windows and compact entry receipts - #193326
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 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.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe 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
Technical reviewBest 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
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +108, Tests +21, Other +6. Total +135 across 8 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. Review metrics
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, 3:42 AM ET / 08:42 UTC. |
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.
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 allocationseparately and the header's original-source overlay for baseline. The existing receipt regression matrix reproduces real publication and restoration behavior.952c33eaee9754e0a08cf45d16dc42dfbc699acc. The configured helper refused the provider/operator configuration mismatch; configuration was not changed. Exact-head CI passed on18c57bf25b8a887c85b6e043573e479d3b412f12: 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.