Repository navigation
perf(sessions): avoid retaining raw snapshot columns in resident actors - #183203
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: blocked before merge. What this changesThis PR removes redundant serialized snapshots from resident session actors and reuses decoded lookup entries during initialization. Example: A synthetic working set contains 140 sessions with roughly 68 KiB skill prompts.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 2 items remain Keep this PR open: it provides a focused, useful memory improvement with no actionable correctness findings; the completed measurements leave a lead decision about inconclusive timing. Priority: P2 Decision needed
Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherSession database workers hydrate and update resident actors from persisted entries, then publish detached session facts and commit receipts to callers. flowchart LR
A[Session operations] --> B[Database worker]
C[Persisted entries and snapshots] --> B
B --> D[Decoded resident actor]
D --> E[Entry writer]
E --> C
D --> F[Detached reads and receipts]
Technical reviewBest possible solution: Retain decoded snapshots through the existing actor owner while preserving exact node comparisons, detached public results, and transaction rollback. Do we have a high-confidence way to reproduce the issue? Current-main source retains serialized snapshot columns beside decoded snapshots, and the supplied native-worker measurements demonstrate their residency cost; this review executed no target code. Is this the best way to solve the issue? The patch removes redundant representation at both existing retention producers and updates the sole raw-row initialization consumer without adding a cache, state owner, or durable format. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4f0fe4f6be21. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +20, Tests +116, Other +233. Total +369 across 11 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 HistoryReview history (1 earlier review cycle)
Reviewed October 25, 2026, 12:59 AM ET / 04:59 UTC (Revision 2). |
|
Completed the pinned-head measurement evidence and updated the PR body with memory/capacity results, separate allocation/promotion passes, all paired sample counts and GC maxima, and the final synchronized A/A controls. The memory/capacity improvement is established; timing remains inconclusive because an identical-source max-pause control failed. Exact-head CI is green. This PR remains open for the lead's decision and merge. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
What Problem This Solves
Resident session actors retain serialized snapshot JSON beside the same decoded snapshots, consuming the existing residency budget twice. Cold hydration and committed replacement now omit those three raw columns. Initialization consumes the scan's already decoded lookup entries; exact node columns and
entry_jsonremain for no-op SQL suppression.User Impact
At a fixed four-actor working set, resident graph memory falls 42.3%. Under pressure, 95 actors fit instead of 52 (+82.7%) under the unchanged 8 MiB serialized-byte cap. The saturated resident graph rises 4.15%; this is not a lower maximum-memory claim. The 140-actor circular scan exceeds both capacities and shows no rehydration reduction.
There are no schema, durable-data, permission, or configuration changes. Production delta is +20 lines: the decoded scan contract and a type that disallows retained raw snapshot columns account for the growth. No new cache or state owner is added.
Measurement Decision
Memory/capacity improvement is established; timing qualification is inconclusive. Keep this PR open for the lead to decide and merge. All declared measurements are complete. Short and longer serial candidate runs had adverse patch tails, but identical-source controls also crossed timing gates. The final synchronized comparison uses the same frozen-source loader on both sides, separate synthetic databases, four A/A controls and two counterbalanced A/B pairs. All sides completed 7,000 reads and 1,400 patches; timed overlap was at least 99.3%.
The final candidate pairs cross no eligible adverse gate: CPU/op +0.34%, total GC +0.00119 ms/op (+0.65%), read p99 −3.04%, patch p95 −2.44%, patch p99 −2.91%. However, an identical-source control had max pause 41.218 → 97.147 ms, exceeding the 82.436 ms safeguard. Under the predeclared stop rule the timing protocol remains INCONCLUSIVE, not a candidate pass or a proven regression. No additional experiments, sample exclusions, pause trimming, or CI reruns were used to seek a passing result.
Allocation is neutral (−0.59% at four actors, +0.86% at 140). Separate traced promotion changes are +4.74% and −37.26%, respectively. This is synthetic owner evidence on Node 26.12.1/macOS, not whole-Gateway, model-turn, Linux, or production-wide qualification. Full before/after tables, sample counts, per-kind GC and both maxima follow below.
Evidence
session-actor-entry-residency.test.ts: 17 passed.session-actor-initialization.test.ts: 3 passed.session-entry-patch.test.ts: 25 passed.eager-import-closure.test.tsandpr-wrapper-source-closure.test.ts: 22 passed.pnpm tsgo:core, changed-file lint/format, export-name collision guard, andgit diff --check: passed.The new capacity regression passes on the candidate and fails with baseline cold hydration and, independently, baseline committed replacement. It records versions immediately after each snapshot-changing patch so later reads cannot hide eviction. All three snapshots survive lookup-sibling initialization, warm metadata patches with zero snapshot-table writes, rollback, and database reopen. Sources were restored byte-for-byte after negative controls. No Testbox/Crabbox lease was used; focused local checks and PR CI provide validation.
Independent subagent review (autoreview route unavailable), GitHub Codex review, and ClawSweeper found no remaining actionable correctness/security findings on
1c82f49ff3df98d313f6a6d0f2071883b368e4b4. The autoreview provider mismatch was handled through the explicitly authorized fallback without changing operator configuration. ClawSweeper's earlier incomplete-measurement observation is addressed by the completed evidence below; the inconclusive timing limitation remains explicit.Deployment Signal and Open Risks
At comparable working sets, look for smaller resident actor graphs and less hydration/query churn where the larger resident capacity avoids eviction. Watch patch tails and total GC. Do not expect a guaranteed lower saturated worker-heap ceiling or infer a production-wide percentage reduction. The fixture does not establish production working-set distribution, Linux scheduling, native SQLite memory effects, or whole-Gateway/model-turn performance.
Completed measurement report and reproduction
Resident session snapshot columns: synthetic owner evidence
Candidate:
1c82f49ff3df98d313f6a6d0f2071883b368e4b4. Baseline:ee9b334166b4124292846ed10bdba79824e446a3. The five affected source modules were frozen from each revision; every other runtime module and dependency came from the same candidate checkout.frozen-source-hashes.jsonrecords their SHA256 hashes. No source changed during measurement.Runtime: Node 26.12.1 on macOS. This is a source-mode synthetic SQLite session-actor worker exercised through the real durable actor factory, not a whole-Gateway, model-turn, bundled-runtime or production-wide performance claim. The fixture has 5,000 stored sessions; 140 contain ~68 KiB skills prompts and 40 transcript messages. The two measured active sets contain 4 and 140 actors. Warm-up performs one read and two patches (on, then off) per actor, ending with
needsSystemIntro=false. Each process starts a fresh worker. Host scheduling load was recorded, and no run was excluded for load, maintenance or pauses.Memory and cache capacity
The four-actor set has five alternating baseline/candidate forced-GC worker snapshots per side. The pressured set has six per side: five original pairs plus the single predeclared mixed-sign timing follow-up. The resident-map count is obtained from its actual state wrappers, and bytes are its exclusive V8 dominator graph; no session-key-reference count is substituted for Map.size. Snapshots are taken after timing and analyzed with the existing dominator analyzer; task-owned snapshot files were deleted only after their numeric result was saved.
The fixed working set retains 42.3% fewer resident graph bytes. At pressure, capacity increases 52 → 95 actors (+82.7%), while the resident graph increases about 4.15%. This is not a lower saturated memory ceiling: the existing cap measures serialized bytes, and smaller residents fill that unchanged cap with more actors. Both capacities are below the 140-actor circular scan, so every timed operation still rehydrates; this workload does not demonstrate fewer rehydrations. Whole-worker heap includes substantial source/module/tooling overhead and is context, not the attributed saving.
Original untraced owner timing
Each short side performs 1,400 reads plus 280 patches (1,680 operations). Read p95/p99 each have n=1,400; patch p95 has n=280 and patch p99 is context-only. CPU is the SQLite worker's thread CPU. Full per-pair tail counts, per-kind GC totals/p95/p99, both maxima and loop sample counts are preserved in
timing-tables.md.The four-actor GC/min increase is only +1.923 ms/min, below the +50 ms/min materiality threshold; GC/op fell. No GC pauses were trimmed. The pressure patch p95 gate remained adverse after the predeclared sixth pair: +6.364 ms/+26.78%, with mixed signs. This was not waived or called passing.
Four same-workload baseline/baseline short controls then produced a false-positive read p99 gate on identical source: all-four mean +23.93%; first-two block +62.26%, both pairs ≥10% adverse (n=1,400 per side). Short timing is therefore INCONCLUSIVE, not proof that the candidate passed or regressed.
aa-tables.mdincludes all control deltas, counts and maxima;short-aa-detail-tables.mdpreserves each GC kind and percentile.Allocation and promotion (separate instrumentation)
Allocation sampling uses a 32,768-byte interval with objects collected by both minor and major GC included. There are two counterbalanced paired passes per working set, each with the same 1,680 operations. Their timings are context only; no timing gate uses allocation-profiled or traced runs.
Allocation is neutral; no allocation improvement is claimed. Promotion is measured in separate
--trace-gcpasses, using Node 26's marker-bounded JSON GC records matched to the identified PID, isolate address and worker thread. In all eight traced runs, matched trace collection counts exactly equal GCProfiler Scavenge plus MarkSweepCompact counts. Forced collections are outside the marked timed windows; no normalization by major-cycle count is used.Small-set promotion rose 4.74% (below the declared gate); pressured promotion fell 37.26% on the paired mean, with reductions in both counterbalanced comparisons. Traced timing includes a 170.043 ms candidate pause; v5.4 requires untraced timing/max-pause gates, so that traced pause is reported as context and never substituted for the untraced maxima.
Longer serial controls and candidate pairs
The declared refinement used 140 actors, 7,000 reads plus 1,400 patches (8,400 operations) per side. Read tails have n=7,000 and patch tails n=1,400; patch p99 now qualifies. Four fresh A/A pairs and two A/B pairs were interleaved AA1, AB1, AA2, AA3, AB2, AA4. Every pair is retained.
Candidate patch p95 was +17.54%; patch p99 was +4.118 ms/+23.79%, with paired deltas +8.594 and −0.358 ms. However, identical-source A/A pairs 3–4 falsely triggered the same patch p99 gate: 26.667 → 42.115 ms (+15.448 ms/+57.93%), both deltas adverse (+19.312 and +11.583 ms), n=1,400 per side. Longer serial timing is also INCONCLUSIVE. The reserved third serial A/B was not executed because failed controls make another identical serial repetition unable to validate the verdict. See
long-summary.json,long-timing-tables.md, andlong-aa-detail-tables.md.Final concurrent refinement — complete, timing inconclusive
The final bounded protocol addresses two identified confounders: changing host scheduling between serial windows, and asymmetric source-loader mode. It uses separate freshly seeded synthetic states, the same frozen-source override hook on both variants, a shared fixed start deadline, 140 actors and 7,000 reads/1,400 patches. It keeps forced collections before/after but omits post-window snapshots on both sides because memory graphs are already established.
All four fresh A/A and two counterbalanced A/B pairs completed in the declared order AA1, AB1, AA2, AA3, AB2, AA4, swapping launch/state roles. There were no failed startups or excluded runs. Actual start skews were 10–93 ms, and timed-window overlap was 99.342–99.965%.
concurrent-windows.mdrecords each actual start/end, overlap, launch role and work count.The final candidate pairs cross no declared gate, but timing remains INCONCLUSIVE because the identical-source controls fail the max-pause safeguard. A/A pair 1 has a maximum pause of 41.2178 → 97.1468 ms, exceeding max(50, 2×41.2178)=82.4356 ms. This is the only eligible control gate in the complete four-pair set. It is preserved as a false positive on identical source, not candidate harm or a reason to trim a pause. The reserved extra A/B was not executed; the bounded measurement campaign is finished.
Candidate max-pause comparisons are 83.2809 → 111.068 ms and 47.3261 → 56.3828 ms; neither crosses its max(50 ms, 2×baseline max) safeguard. The +0.00119 ms/op GC difference is far below the +1 ms/op materiality threshold. These candidate observations are not a protocol pass: failed controls leave the timing verdict inconclusive.
Each side completed exactly 7,000 reads and 1,400 patches, totaling 8,400 operations and 8,400 epoch-change rehydrations. That is 50 complete read rounds and 10 complete patch rounds (five on/off cycles). No reset commands are issued; zero resets is a workload-construction fact, not an independently sampled reset counter. Full per-pair GC kinds, totals, pause percentiles and counts, eligible latency counts, loop counts and both maxima are in
concurrent-aa-tables.mdandconcurrent-timing-tables.md. No heap snapshots were taken in this final protocol.Final machine-readable results are
concurrent-summary.jsonand the sixconcurrent-*-pair.jsonfiles;concurrent.logrecords successful completion. Full declared rules and every protocol transition are inprotocol.md.Reproduction
The committed entrypoints contain usage instructions; no build, dev Gateway, production state or credentials are needed. Freeze the five changed runtime files under separate variant trees preserving their
src/config/sessions/paths:session-accessor.sqlite-entry-read.ts,session-accessor.sqlite-initial-entry.ts,session-actor-hydration.worker.ts,session-actor-transaction.ts, andsession-actor-hydration.types.ts.Use
--sessions 140for pressure;--allocationor--trace-gcin separate passes without snapshots. For the final concurrent protocol, prepare two separate state directories sequentially, launch two measure commands with their own output/state/variant paths,--reads 7000 --writes 1400, and the same--start-at <epoch-ms>120 seconds ahead. Omit--snapshoton both sides. The local controllersrun-campaign.py,run-aa.py,run-long.pyandrun-concurrent.pypreserve the exact executed sequence; summary programs retain signed absolute deltas and all sample arrays.Interpretation and deployment signal
The reliable owner finding is fewer bytes at a fixed resident set and more actors fitting the same serialized residency cap, with unchanged durable data and operation counts. After deployment, inspect the session-actor resident graph and hydration/query behavior at comparable active working sets. Do not infer a production-wide percentage reduction or promise a lower aggregate worker heap ceiling. This owner fixture does not qualify whole-Gateway throughput, a model turn, Linux scheduling, native SQLite memory, or production workload distribution. Memory and capacity are proven for this synthetic owner fixture; allocation is neutral, and pressure promotion improves. Final candidate timing crosses no declared gate, but the timing verdict remains inconclusive because identical-source controls failed. The lead should retain that uncertainty when deciding whether to merge.
Original candidate pairs: all latency, GC, sample counts and maxima
4 actors: 5 paired repetitions
Every cell is baseline → candidate. Timed work per side: 1,400 reads + 280 patches. All timing/GC runs are untraced; snapshots are outside the timed phase.
GC kind details below retain every collection, including major collections. GC p95 needs ≥200 collections per side and p99 ≥1,000; major percentiles are context below 50. Values are n / total ms / p95 ms / p99 ms / max ms.
140 actors: 6 paired repetitions
Every cell is baseline → candidate. Timed work per side: 1,400 reads + 280 patches. All timing/GC runs are untraced; snapshots are outside the timed phase.
GC kind details below retain every collection, including major collections. GC p95 needs ≥200 collections per side and p99 ≥1,000; major percentiles are context below 50. Values are n / total ms / p95 ms / p99 ms / max ms.
Short identical-source controls: summary
All A/A sides execute baseline source through the same loader, 140 actors, 1,400 reads and 280 patches; n=280 per patch p95, n=1,400 per read p99.
pairs1-2: patch p95 37.919 → 23.026 ms, signed mean delta -14.893 ms (-39.28%); 20% mean gate=False, both-pairs 10% gate=False.
pairs3-4: patch p95 19.967 → 21.238 ms, signed mean delta +1.271 ms (+6.37%); 20% mean gate=False, both-pairs 10% gate=False.
all4: patch p95 28.943 → 22.132 ms, signed mean delta -6.811 ms (-23.53%); 20% mean gate=False, both-pairs 10% gate=False.
Same-source control gate: readP99 pairs1-2, 27.497 → 44.617 (+62.26%), mean=True, both-pairs=True.
Same-source control gate: readP99 all4, 29.519 → 36.584 (+23.93%), mean=True, both-pairs=False.
Short identical-source controls: per-kind GC
140 actors: 4 paired repetitions
Every cell is baseline A → identical baseline B. Timed work per side: 1,400 reads + 280 patches. All timing/GC runs are untraced; snapshots are outside the timed phase.
GC kind details below retain every collection, including major collections. GC p95 needs ≥200 collections per side and p99 ≥1,000; major percentiles are context below 50. Values are n / total ms / p95 ms / p99 ms / max ms.
Long serial candidate pairs
140 actors: 2 paired repetitions
Every cell is baseline → candidate. Timed work per side: 7,000 reads + 1,400 patches. All timing/GC runs are untraced; snapshots are outside the timed phase.
GC kind details below retain every collection, including major collections. GC p95 needs ≥200 collections per side and p99 ≥1,000; major percentiles are context below 50. Values are n / total ms / p95 ms / p99 ms / max ms.
Long serial identical-source controls
140 actors: 4 paired repetitions
Every cell is baseline A → identical baseline B. Timed work per side: 7,000 reads + 1,400 patches. All timing/GC runs are untraced; snapshots are outside the timed phase.
GC kind details below retain every collection, including major collections. GC p95 needs ≥200 collections per side and p99 ≥1,000; major percentiles are context below 50. Values are n / total ms / p95 ms / p99 ms / max ms.
Final synchronized candidate pairs
140 actors: 2 paired repetitions
Every cell is baseline → candidate. Timed work per side: 7,000 reads + 1,400 patches. All timing/GC runs are untraced; no heap snapshots are captured; forced collections stay before/after timing.
GC kind details below retain every collection, including major collections. GC p95 needs ≥200 collections per side and p99 ≥1,000; major percentiles are context below 50. Values are n / total ms / p95 ms / p99 ms / max ms.
Final synchronized identical-source controls
140 actors: 4 paired repetitions
Every cell is baseline A → identical baseline B. Timed work per side: 7,000 reads + 1,400 patches. All timing/GC runs are untraced; no heap snapshots are captured; forced collections stay before/after timing.
GC kind details below retain every collection, including major collections. GC p95 needs ≥200 collections per side and p99 ≥1,000; major percentiles are context below 50. Values are n / total ms / p95 ms / p99 ms / max ms.
Final synchronized timing windows and work counts
Final concurrent windows. Both sides perform 7,000 reads, 1,400 patches and observe 8,400 rehydrations; no reset command is issued (50 read rounds, 10 patch rounds). All start/end values are worker timestamps.