Repository navigation
perf(sessions): reuse exact actor admission entries - #184071
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. |
f9e8c84 to
ffda894
Compare
|
Codex review: needs maintainer review before merge. What this changesThis PR replaces repeated unchanged session-entry admission payloads with references to the command’s retained preimage. Example: A warm tool-result append with a 32 KiB skills snapshot.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it provides a measured, focused optimization that current main lacks, with no actionable correctness or security findings. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherSession actors execute mutations in the existing database writer; admission facts travel to the main thread for live policy checks before native commit and receipt settlement. flowchart LR
A[Session command] --> B[Main thread replica]
B --> C[Database writer actor]
C --> D[Entry or exact reference]
D --> E[Live admission policy]
E --> F[Native commit and settlement]
Technical reviewBest possible solution: Retain this command-local compression path with full changed-entry fallback and the existing live admission owner. Do we have a high-confidence way to reproduce the issue? Current-main source unconditionally serializes complete entries at admission, and the PR supplies a baseline byte-budget failure; no target code was executed during this review. Is this the best way to solve the issue? The change reuses the settlement preimage and existing projection owner, preserves complete policy facts, and avoids a second cache or delta protocol. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b9fecb8982aa. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +36, Tests +26, Docs +6, Other +58. Total +126 across 12 files. Added test files: 0. View PR surface stats
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 October 25, 2026, 10:12 PM ET / October 26, 2026, 02:12 UTC. |
* perf(sessions): reuse exact actor admission entries * test(sessions): match admission benchmark identity types
What Problem This Solves
Warm session actor commands resend the complete session entry at transaction and commit admission even when main already retains that exact immutable entry. A synthetic 32 KiB skills snapshot dominates those messages.
User Impact
Less worker-message allocation during session activity, with no user-visible behavior change, schema migration, or new configuration. Cold commands and commands whose entries change keep their complete policy payloads.
Why This Change Was Made
The command borrows the replica preimage already retained for settlement. Its write token is a compression hint: the worker must match that token against its authoritative preimage, and may reference it only while entry object identity remains unchanged. Main resolves the reference only within that command. Target validation, live authority checks before and after policy callbacks, final grants, FIFO ordering, and rollback/unknown settlement remain intact. This also preserves accepted commands whose snapshot disclosure has been revoked.
Version fields alone are insufficient: they still describe the old revision during intermediate mutations. Changed entries therefore travel in full, rather than introducing a delta protocol or another cache. This is the residual after #184018, whose authority projection is already in the measured baseline.
Runtime production delta: +36 LOC (48 additions, 12 deletions). Exact-revision matching, fail-closed reference resolution, and complete changed-entry fallback account for the growth. Benchmark tooling adds 58 net lines; the requested non-test/non-doc diff including tooling is +94 LOC (143 additions, 49 deletions). No shared performance README edit.
Evidence
The real actor/native-admission regression fails on baseline
18d2633de8abd677ae1852b48950701bce8ff302: 33,276 snapshot bytes, exceeding the <1,024-byte budget. With the candidate, both transaction and commit admissions of the warmed tool append satisfy that budget (2/2 references), while the complete entry remains available to policy. This is a targeted warm-flow result, not a production-wide hit-rate estimate.66 focused tests pass: actor integration (28), worker and replica (38). Coverage includes stale reference fallback, changed-entry commit rejection/rollback, stale actor versions, live authority revocation, native settlement recovery, and accepted work after disclosure revocation. Actor file wall time 50.41 s; worker/replica invocation 61.69 s, dominated by worker compilation. Changed-file lint/format,
git diff --check, and core/scripts typechecks pass. A callback parameter type error found by typecheck was corrected; an earlier compiled-subprocess setup failure ran no tests and is not counted as product evidence. The first CI run caught a numeric birthtime in the synthetic benchmark fixture; it now matches the string identity contract. The scripts type lane passes locally, and all measurement pairs were repeated on that corrected fixture (the table below uses only the complete fresh run). Production code was unchanged by that correction. PR CI supplies broad validation; no Testbox lease was used.Independent subagent review (autoreview route unavailable): fresh-context Codex review found no actionable P0–P2 findings. The helper refused the requested provider because it did not match operator configuration; configuration was not changed. The reviewed change rebased cleanly; the intervening replica change only factors an unrelated transcript reader.
Owner measurement
Acceptance declared before measurement: equivalent reconstruction, lower bytes, consistent CPU/allocation improvement. Native MessageChannel sends, a synthetic 32 KiB skills prompt, 1,000 warmups, five alternating AB/BA pairs of 5,000 admissions per arm per mode (25,000 per arm per mode). Timing is untraced; allocation is a separate collected-object sampling pass.
Every pair improved: CPU reductions 53.36–71.61%, allocation reductions 95.51–95.71%. One-minute host load was 41.51–46.46. These numbers cover matched-entry owner transport, not total Gateway CPU or all admissions. The benchmark uses a short synthetic token; the production-path test above checks real token size.
Reproduce using
scripts/perf/session-actor-admission-measure.ts --synthetic --mode timing(vianode --import ./scripts/tsx.mjs), repeat with--mode allocation;--owner <baseline-command.ts>selects the baseline projection. Existing synthetic Gateway state mode is preserved.The lane's fast-path exception applies: this removes duplicate serialization without changing policy decisions, so no multi-pair ten-minute Gateway stress campaign was run. Whole-Gateway event-loop/list latency, server handler latency, allocation rate and steady-state RSS/heap are unmeasured. The short owner harness observed zero GC samples, so it supports no GC conclusion. No live Team load was started.