Repository navigation
perf(sessions): share resident actor entries across projections - #182934
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 shares one actor-owned session entry across internal projections while preserving detached public reads and commit receipts. Example: Four warmed durable actors with 36,514-byte session entries.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR removes demonstrated duplicate session-entry retention without introducing an actionable correctness or security defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe durable session worker receives actor commands, maintains resident database facts, and returns snapshots or committed receipts through the existing worker transport. flowchart LR
A[Gateway session actor] --> B[Worker transport]
B --> C[Durable actor owner]
C --> D[Shared owned entry]
D --> E[Stored row and hot projection]
C --> F[Detached reads and receipts]
C --> G[Existing database writer]
Technical reviewBest possible solution: Keep one immutable actor-owned entry internally and preserve copying at incoming postimages, public reads, and receipt publication. Do we have a high-confidence way to reproduce the issue? Current-main source independently shows the duplicate entry clones, and the PR reports paired native-worker measurements; this read-only review executed no target code. Is this the best way to solve the issue? The production diff is the smallest complete fix using the existing mutation and transaction owners, with distinct caller-isolation coverage retained at the worker boundary. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2c8189c63d3f. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -2, Tests +2, Docs +35, Other +208. Total +243 across 8 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 24, 2026, 6:04 PM ET / 22:04 UTC. |
af23e09 to
d89f3ec
Compare
d89f3ec to
f7a266d
Compare
Retain one actor-owned decoded entry across hot state and stored rows while preserving detached public reads, commit receipts, and rollback preimages. Five paired worker snapshots reduce the four-actor resident graph by 18.84%; add a reproducible native-owner probe and strengthen caller isolation coverage.
f7a266d to
e6b7e73
Compare
…claw#182934) * perf(sessions): share resident actor entries across projections Retain one actor-owned decoded entry across hot state and stored rows while preserving detached public reads, commit receipts, and rollback preimages. Five paired worker snapshots reduce the four-actor resident graph by 18.84%; add a reproducible native-owner probe and strengthen caller isolation coverage. * test(perf): synchronize paired actor command identities
What Problem This Solves
Durable session actors retained two decoded copies of their session entry: one in the stored-row map and another in hot state. Each copy includes nested skill and system-prompt snapshots. Hot-state projection cloned that entry again after mutations.
User Impact
Active durable sessions retain less worker memory, especially when skill and system-prompt snapshots are large. No migration or configuration change is required.
Why This Change Was Made
Keep one actor-owned entry across those internal views. Incoming postimages still detach once, writers replace entries, transaction forks preserve the previous entry for rollback, and public reads/commit receipts remain detached. The existing cache limits, persisted representation, transcript contents, and public APIs are unchanged. Runtime production code is net −2 lines; tests are +2, the reproducible benchmark is +208, and documentation is +35. The broad non-test/non-doc diff is +236 because it includes the benchmark and its README. This tooling growth supports the requested owner-level proof; it adds no production instrumentation hook.
Release-note context: lower retained worker memory for active sessions with large entry snapshots.
Evidence
Node 26.12.1; a synthetic Gateway fixture with 5,000 sessions and 6,000 retained runs. Four real synthetic-provider child sessions were warmed through agent/tool turns, producing 36,514-byte session entries. Five fresh-process pairs used alternating launch order, identical source-replacement instrumentation, and forced GC in the native worker. Snapshots were captured outside timing windows.
The comparison uses base
803ad1fdc36e3473b4a9c538fd3dfb4a15f4431awith only the three runtime owner files replaced for the candidate. Their measured bytes match the current PR head; rebasing did not change those runtime files. The resident-owner saving is consistent. In the initial source-loaded SQLite worker snapshot, 50,258,296 bytes belonged to tsx’s in-process transform cache; this does not establish that deployed builds retain that cache. Loaded code and source-runtime machinery dominate the whole worker, so this is not a claim of a large whole-worker reduction. Transcript history windows, actor residency, statement caches, and reply-transfer lifetimes were audited; this patch changes only the demonstrated duplicate actor entry.Latency and correctness
The candidate completed a full synthetic Gateway memory-soak run: 4 clients, 2 measured rounds, 8 completed measured turns and 8 session resets, plus warmup. The driver verified its edit-visibility control. Two simultaneous, CPU-swapped native-owner pairs completed with identical command identities and separate synthetic fixtures. Each side performed 1,200 native reads and 1,200 real patch commits. Shared quiet-slot and production guards remained healthy. The following are untraced results; percent changes are the mean of the two paired percentages.
Every read/commit tail has 1,200 samples per side per pair. Event-loop sample counts were 2,660→2,697 and 2,387→2,461. Read p99 deltas were −0.0731/+0.0964 ms; commit p99 deltas were +0.9084/−1.0365 ms. These mixed-sign tails are context, with no adverse paired-mean gate; CPU fell in both pairs (−6.27%/−7.05%).
GC pause percentiles are context: fewer than 200 collections per kind/side and fewer than 50 majors. Neither maximum GC pause reaches the max-pause safeguard. Loop maxima were 59.507→58.032 and 38.896→66.224 ms. Separate traced pairs, with identical instrumentation on both sides, measured allocation and promotion. Allocation sampling used a 32 KiB interval and included objects collected by both minor and major GC. Promotion came from complete, isolate-matched V8 trace windows; 75 collections from other isolates were excluded on each side in each pair. Both pairs completed all 1,200 reads and 1,200 committed writes per side.
Allocation sample counts were 54,389→48,866 and 54,552→49,027; allocation fell 9.93% and 10.26%. Target-isolate trace GC counts were 171→157 and 172→158; promotion fell 22.34% and 20.84%. Traced timings are not used as gates. One temporary traced-preload launch failed syntax parsing before the workload and is preserved as setup failure; the corrected probe passed independent review, and both complete measured pairs are included.
Decision: the owner retains 18.84% less memory, CPU falls consistently by 6.66%, estimated allocation falls 10.09%, and promotion falls 21.59%, with no adverse untraced latency or total-GC gate. No adverse GC/promotion/max-pause result required A/A rejection controls. Whole-worker retained-heap variation remains inconclusive. This is a small production simplification, ready for the lead's landing decision; it is intentionally unmerged.
The exact PR head
d89f3ecd709c30c526d88cfe7e13f7d2fafbdb4ehas an inherited PostgreSQL conformance (2/3) failure: seveninteractive-setup.integration.test.tscases fail before Gateway readiness because the isolated runtime omitsstandalone-runtime-profile.mjs. All seven test signatures and the missing-module cause match the newest scheduled main run at attribution time: main job 121006161355, main head87f00b1b5254861d944e524cdd8bb3a65f53b59f; compare PR job 121006359977. Both report 7 failed / 271 passed in that batch. The failing test, its fixture builder, the importing module, and the root helper have identical blobs on both heads. The root helper/import arrived in upstream #182856; the fixture's explicit copy list omits it. This lane does not change those files. Logs were fetched once per completed job; no CI reruns were requested. All other code checks completed successfully (62 successful check runs; skipped/neutral checks recorded separately). The aggregate CI gate remains red because of that shard. Its automatic classification used the older successful main run40134490303, which predates the upstream import; the newer matching main job above is the current attribution evidence.Focused proof: actor kernel and native worker tests (24 tests), export-name collision guard, and both eager-import/PR-wrapper closure files (22 tests) passed. Participant-repair and entry-residency consumer tests also passed (18 tests). Changed-file formatting/lint and the targeted scripts typecheck (
pnpm tsgo:scripts, native checker) passed.Independent subagent review (autoreview route unavailable): production/test/docs and the benchmark were reviewed in separate scopes, with no actionable P0/P1/P2 findings. The configured autoreview provider did not match the operator configuration; no configuration was changed.
Reproduction is documented in
scripts/perf/README.md; the new owner probe measures native reads after host-replica invalidation, real patch commits, operation counts, worker CPU/GC/event-loop samples, and post-GC heap. Promotion requires a separate traced pass and is not inferred from retained bytes.Worker attribution and cache bounds
Source owners:
session-transcript-worker-scopes.ts,session-accessor.sqlite-history-query.ts,session-accessor.sqlite-history-projection.worker.ts,session-model-context-pages.ts,session-actor-residency.worker.ts,session-accessor.sqlite-entry-cache-state.ts,src/infra/kysely-sync-cache-state.ts, andsrc/infra/sqlite-store.worker.ts.