Repository navigation
perf(sessions): charge shared actor entry fields once in the replica pool - #199748
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 Summary: ✅ CompletedThis 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. |
7fba73c to
e60041e
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e60041e30a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for (const field of reportFields) { | ||
| const value = internSessionEntryField(report[field]); |
There was a problem hiding this comment.
Skip absent report sections when sharing entry fields
When a persisted entry contains a sparse report such as systemPromptReport: { source: "run" }—an existing storage shape exercised in session-accessor.sqlite-prepared-reads.test.ts:57—report[field] is undefined. Passing it to internSessionEntryField throws TypeError: Cannot use 'in' operator to search for 'prompt' in undefined. Snapshot decoding does not populate missing sections, so previously readable entries now fail replica retention; the identical unconditional hashing in projectSessionActorEntryFields also prevents cold commands from reaching admission. Only intern and project sections that are present, preserving omitted sections unchanged.
Useful? React with 👍 / 👎.
|
Codex review: needs changes before merge. What this changesThis PR shares immutable session-entry fields across replicas and compresses worker admission messages using their content keys. Example: 100 active sessions share the same skills inventory and prompt-report sections.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep open: this maintainer-authored PR provides a measured performance improvement, but a confirmed sparse-report regression needs repair before merge. Priority: P2 Before merge
Findings
Agent review detailsHow this fits togetherThe session actor connects session operations to the database worker; replicas retain immutable entry facts, and admission messages deliver those facts to host authority callbacks before writes settle. flowchart LR
A[Session operations] --> B[Actor executor]
C[Replica pool] --> B
B --> D[Database worker]
D --> E[Admission restoration]
C --> E
E --> F[Authority callbacks]
D --> G[Committed receipts]
Technical reviewBest possible solution: Preserve omitted report sections in both sharing loops while retaining the existing interner, replica accounting, and command-local reference restoration. Do we have a high-confidence way to reproduce the issue? Source establishes the failure: the existing persisted {source:"run"} report reaches unconditional hashing of undefined sections; no target code or tests were executed during this read-only review. Is this the best way to solve the issue? Extending the existing immutable-field interner and replica owner is coherent; the necessary invariant is that compression preserves every accepted entry shape and restores complete authority facts. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against abaf2ced62fc. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +199, Tests +95, Other +75. Total +369 across 16 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: No label 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 15, 2026, 3:41 PM ET / 20:41 UTC. |
e60041e to
967ab87
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 967ab87c1f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| capture = round >= 0; | ||
| before = captured.length, | ||
| admissionsBefore = admissions.length; | ||
| capture = round >= 0 && !measureAppends; |
There was a problem hiding this comment.
Limit receipt replay to modes that retain captured receipts
Running --mode append-timing or --mode append-allocation leaves captured empty because capture is disabled here; --mode heap also empties it after each append. However, the replay block still runs for every mode other than census. Its worker consequently sends undefined from the empty receipts array, causing the committed-receipt assertion to throw before result.json is written. All three new measurement modes therefore fail to report their results. Restrict receipt replay to the existing timing and allocation modes.
Useful? React with 👍 / 👎.
…pool Count interned skills and immutable report sections once per pool, releasing the shared charge with its last resident reference. Keep admission, receipt and command encoders unchanged. Synthetic 100-session residency rises from 27 to 100 while post-GC main heap falls 3.57 MiB.
967ab87 to
bcc0e28
Compare
…ntry-interning-20261115 # Conflicts: # scripts/perf/session-append-receipt-measure.ts
|
Merged current The residency numbers in the description were measured at |
…pool (openclaw#199748) * perf(sessions): charge shared actor entry fields once in the replica pool Count interned skills and immutable report sections once per pool, releasing the shared charge with its last resident reference. Keep admission, receipt and command encoders unchanged. Synthetic 100-session residency rises from 27 to 100 while post-GC main heap falls 3.57 MiB. * perf(sessions): match residency test allocation to net growth
…pt report Upstream eee22b4 (openclaw#199748) interns every system-prompt report subtree (systemPrompt, injectedWorkspaceFiles, skills, tools) when it shares an actor entry. This fixture cast a report holding only `tools`, so each case failed with "snapshot is not an Object". Supply the four required subtrees. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rk fixtures Compile and behavior follow-through for upstream APIs the merge brought in, each red on ddd0ec7 and green here: - sessions-spawn-cloud: upstream's new paired-device case (openclaw#197469) mocks registerRun as void; the fork's registration returns ownership, so the mock returns a committed-row ownership (tsgo agents-tools TS2322; 16/16). - finishPendingInput now takes an end cause (openclaw#200533): the fork's recorder case and transcript-events case pass "failed" (tsgo other TS2554). - postcompaction-autocompaction: upstream's SessionMaintenanceRequest needs sourceTarget/sourceIdentities (prepareSessionMaintenanceRequest), so the command case prepares the request before scheduling (TS2739); the pressure-handoff report supplies the four subtrees upstream interns (openclaw#199748; 10 cases "snapshot is not an Object" without it, from chain 47edd05); and the required-compaction-failure case crosses the 200k window with a new fitting-request case for openclaw#200714's fit-only preflight failure (from staging ead2225; red at 150k without it). 13/13. (cherry picked from commit 47edd05) Refs openclaw#129388 Co-Authored-By: Claude Opus 5.5 <[email protected]>
What Problem This Solves
The session actor replica budget charges each session for large skills snapshots that are already shared on the main heap. Repeated immutable prompt-report sections are also retained separately. This causes avoidable eviction within the existing 8 MiB / 128-replica limits.
User Impact
More session replicas fit within the existing memory budget. Stored entries, model context, authority checks and all wire encoders remain unchanged. Existing resident-entry references may be used more often because fewer replicas are evicted.
Why This Change Was Made
Charge each interned field once per replica pool, counting resident references and releasing the shared charge when the last resident reference goes away. Extend the existing bounded weak interner to immutable report sections while keeping session-specific report provenance separate.
The full wire-reference proposal is held separately at
steipete/perf-actor-entry-wire-refs-20261115, commite60041e30a5da06f5f6c21afdadb75b26e2e31f5. This PR contains no advertised field keys, command pins, worker field references or admission restoration. The coordinating maintainer will decide whether to revive that proposal after production component counters are available.Evidence
Measurement acceptance: run the existing native append fixture on current main and the residency-only candidate at 2, 100, 200 and 400 sessions; record resident replicas and pool bytes, then measure post-GC main heap at 100 sessions. Compare resident and evicted native request/admission/receipt byte counts with identical fixture paths. Five actual-append rounds of 100 sessions per side measure main-thread CPU and allocation separately, including replica updates and excluding wire-capture instrumentation. The expected win is residency and memory accounting; per-append CPU/allocation should remain neutral or improve. Preserve model-context hashes and the existing wire shapes.
Baseline:
987c04a0086963d301cb4e440c758acc7178c7b6(current main when measurement began). The synthetic entry contains a ~110 KB skills snapshot and a ~20 KB prompt report. Across 100 sessions there is one skills snapshot, 100 reports with distinct session provenance, and one value for each of four immutable report sections.Pool bytes are the owner's heap estimate, not physical heap measurements. The separate 100-session post-GC pass measured main heap 146.880 → 143.306 MiB (−3.574 MiB), and whole-process RSS 1,520.474 → 1,444.718 MiB. RSS includes native workers and is contextual.
At 100 sessions, fewer replica misses also reduce append work through the existing resident-token protocol. With 200 sessions, both sides still miss during sequential churn. Allocation fell 2.25% and 1.96% in the two cold-path pairs. CPU changed +201 µs then −117 µs per append (+12.8%, −7.3%); the signed absolute mean is +42 µs (+2.7%), so CPU is inconclusive rather than an adverse result. One-minute host load varied roughly 15–24. Untraced GC at 100 sessions fell 0.0381 → 0.0120 ms/append (10 → 5 collections; max 2.885 → 1.849 ms). At 200 sessions, total GC was effectively flat at 0.06375 → 0.06348 ms/append, 70 collections per side across both pairs, with maximum pauses 4.950 → 4.079 ms. No percentile gates are claimed from these small collection counts.
Wire equality: with matching residency, every captured admission/receipt byte count and every model-context hash matches main. Main→worker totals also match. At 2 resident sessions, per-append mean request/admission/receipt sizes are 1,931 / 1,990 / 5,260 B on both sides. At 200 evicted sessions they are 1,922.66 / 133,195.6 / 5,564.45 B on both sides; the 400-session comparison also matches. At 100 sessions, retaining all entries uses the existing resident-token path more often: admission bytes fall 133,191.2 → 2,003.4 B, request bytes rise 1,918.02 → 2,169.82 B, and receipts remain 5,553.05 B. This is a change in existing path selection, not an encoding change. All admission, command, worker, receipt and authority implementations are unchanged from main. The current authority Prometheus byte counter omits ordinary native admissions; no production counter improvement is claimed.
Reproduction (same
--outputpath for both arms, move each completed report aside before running the other):The existing pool-budget regression fails on main because replicas with a shared large prompt are evicted before reaching 128 entries. It also exercises retiring distinct shared values before admitting the next cohort. The former 16 KiB admission-budget regression is removed from this PR and remains on the held branch.
Runtime production delta: +86 LOC. Growth implements explicit shared-value accounting and immutable report-section interning; the former skills-only sharing path is replaced. The interner retains at most 256 weak lookup entries, and resident pool references are released with their last cell. No persisted shape, schema, configuration, or public contract changes. Author simplification removed command pinning, advertised keys, worker projections, admission restoration, wire-only tests and replay tooling from this PR. The remaining benchmark measures actual native appends.
All 106 focused tests passed: 68 actor/replica/worker tests, 14 prefix-stability tests and 24 eager-import/wrapper-closure tests. The matching session test typecheck and
pnpm tsgo:test:rootpassed, as did changed-file lint/format, the assertion-safety and export-collision guards, andgit diff --check. The test delta is +7 lines with an exact allocation entry. Runtime source is +86 LOC; the prescribed non-test diff including benchmark tooling is +196 LOC. On final headbcc0e285c84422a45f0aa06a1d3033110ade3e5d, CI run 43763608489 completed with one infrastructure failure: check-test-types timed out during all five checkout attempts and never ran TypeScript. The other required build, lint, typecheck and test jobs passed, including PostgreSQL conformance and its PostgreSQL 16 smoke.pnpm tsgo:test:rootwas rerun locally on this exact head and all four scopes passed (4.6/4.8/4.8/5.5 seconds). The local retry command was refused; no CI rerun was executed. The aggregate CI gate therefore remains red and needs checkout-job recovery by the coordinating maintainer. No production load or full Gateway stress was run; this is the requested residency-only owner/native-transport comparison. Independent review and merging remain with the coordinating maintainer.