Repository navigation
perf(sessions): transfer changed fields for warm entry patches - #183276
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 transfers changed session-entry fields instead of complete warm snapshots while preserving publication and mutable return values. Example: Rename a warm session from “warm” to “changed” while retaining a 60 KiB skills snapshot.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains Keep open: this PR provides a distinct allocation reduction absent from current main, with no definite introduced defect found; performance acceptance remains explicitly pending. Priority: P2 Before merge
FindingsNone. Agent review detailsHow this fits togetherSession metadata callers submit patches to the agent database worker, which commits stored entries and returns publication facts for Gateway replicas, observers, and callers. flowchart LR
A[Metadata caller] --> B[Existing patch owner]
B --> C[Agent database worker]
C --> D[Session database]
C --> E[Delta or complete candidate]
E --> F[Gateway reconstruction]
F --> G[Commit admission and publication]
G --> H[Replica and mutable caller result]
Technical reviewBest possible solution: Retain the existing revision-validated replica and publication owners, and land the delta optimization only after its performance tradeoff is resolved. Do we have a high-confidence way to reproduce the issue? Current-main source transfers complete publication entries on changed patches, and the PR reports a baseline-failing wire-size regression; no target code was executed during this read-only review. Is this the best way to solve the issue? The approach removes redundant transport through existing owners while preserving cold and superseded-preimage behavior; its net runtime benefit remains subject to performance acceptance. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 274a86d02feb. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +131, Tests +58, Other +38. Total +227 across 6 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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, 1:30 AM ET / 05:30 UTC. |
f9641d4 to
9b0a2f9
Compare
Reuse the existing revision-validated session replica for unchanged fields. Restore complete publication facts before admission and keep returned JSON containers independently mutable. Cold and superseded preimages retain complete replies.
9b0a2f9 to
b23f329
Compare
|
@clawsweeper re-review The branch and evidence are current. Exact-head CI and independent review pass. Four twenty-minute untraced controls and two swapped candidate comparisons resolve the earlier GC/latency concern without a rejecting regression. Patch-owner allocation improves 12.2–24.3%, and transfer bytes per patch fall 86.0%. The body retains the separate promotion limitation: identical-source trace controls are unstable, the longer screen stopped explicitly at two of four planned controls, and no valid candidate promotion comparison is claimed. Landing relies on the scoped allocation benefit, correctness, and valid untraced cost evidence. |
|
🦞👀 Re-review progress:
|
…law#183276) Reuse the existing revision-validated session replica for unchanged fields. Restore complete publication facts before admission and keep returned JSON containers independently mutable. Cold and superseded preimages retain complete replies.
Performance decision: land the measured patch-owner allocation reduction with passing untraced costs. Candidate promotion remains unproven because identical-source calibration is unstable; it is not reported as passed.
The repeatable benefit is 12.2–24.3% less main-thread allocation per patch and 86.0% fewer transferred bytes per patch. Two twenty-minute concurrent, CPU-swapped Gateway comparisons followed four successful matching untraced controls: mean main CPU +0.109 percentage points, GC −10.636 ms/min, event-loop p99 −0.197 ms, and sessions.list p99 +0.598 ms. No valid-control rejection threshold was triggered. This is an owner-local allocation improvement, not a claim of a whole-Gateway speedup.
Promotion attribution is a limitation: four ten-minute identical-source controls were inconclusive; the first two longer controls still varied +62.552% and +7.777%. After the first longer result, before the second result, the campaign was explicitly bounded to finish control 2 and stop at two of four planned longer controls. No candidate promotion comparison ran. All completed observations are retained below. The landing decision relies on the repeatable scoped allocation benefit, proven correctness, and valid untraced comparisons; unreliable promotion attribution remains an explicit limitation rather than evidence of a candidate regression. Exact-head CI is green.
What Problem This Solves
Warm session metadata patches repeatedly transfer and decode unchanged session-entry snapshots on the Gateway thread.
User Impact
Internal allocation reduction with the existing session contents, write ordering, authority checks, and mutable return-value contract preserved.
Why This Change Was Made
The writer validates the existing resident entry’s scoped revision before returning changed fields and removals. The receiver restores the complete publication before admission, reuses unchanged frozen fields, and copies only mutable JSON containers for caller results. Cold or superseded preimages still require a complete postimage.
Production code grows by 131 lines to preserve revision validation, bounded publication, and independently mutable results. The change uses the existing replica and invalidation owner.
Evidence
The wire-size regression fails on the pinned baseline (133,553 bytes for a synthetic 128 KiB snapshot). All 35 focused patch/operation/settlement tests pass on the final candidate, including newer writes, field removal, and nested object/array result isolation. Changed-file formatting/lint pass. Production/test typechecks and the full applicable PR CI passed on exact head
b23f329e21a03edc15f92eac49cc5ab5cf6284e8. Independent subagent review (autoreview route unavailable) has no remaining actionable findings.Fixed-work native-worker measurements use 256 patches after cold setup and 32 warmups, a 60 KiB retained snapshot, fresh isolated state, and counterbalanced launch order. Timing and allocation sampling are separate. Whole-main allocation includes reconstruction and mutable-result copying:
CPU differences vary between runs; the repeatable claim is reduced allocation in the patch owner, not a whole-Gateway speedup. The unchanged no-result path reuses its prior paired measurement.
Sustained local proof used separate base and candidate dev Gateways with 10,000 synthetic sessions, 8,000 settled runs, 40 plugins, 65 WebSocket clients, four concurrent mock-provider turns with tool calls, and sidebar/list/search plus metadata churn. Each untraced timing run and separate allocation run completed 40 cohorts and at least ten minutes. Normal resets and maintenance stayed enabled. Both timing runs completed 160 turns, 160 tool calls/results, and 40 metadata patches.
These sequential runs on a heavily shared Mac retain adverse GC/latency signals and differing background-work counts; they do not establish a Gateway-wide speedup or regression. The subsequent twenty-minute controlled protocol passed four A/A controls and two CPU-swapped candidate comparisons, reported below. Promotion remains separately unresolved. Local measurements are pinned to 728cdc0; the paired application builds use a939b1d.
Separate long allocation captures lasted 646.8 / 792.3 seconds. Sampled allocation rates were 94.81 / 87.42 MiB/s, but total allocation was 64.30 / 72.63 GB with 4,262 / 5,245 list calls and 21 / 26 cron runs. The lower rate is not a net-workload reduction claim. Patch replies carried 91,947,641 bytes over 1,379 transfers versus 13,357,729 over 1,428: 66,677 → 9,354 bytes per patch (−86.0%). Whole-main owner sampling above includes reconstruction and result-container copying.
The benchmark command shape is in the script header. The latest conflict integration incorporates main
4d13deccf923c9e5470a787a885e6736c62f9b7f. All three production files remain byte-identical to measured V2. Upstream now owns list-filter scheduling, metadata churn, request timestamps and whole-run CPU reporting; this PR removes its duplicate harness code and retains filter-coverage counters plus nonmixed-soak admission. Independent integration review is clean. All 35 focused tests passed after the harness conflict integration (190 seconds), and changed-script lint/format passed. A subsequent conflict-free rebase adds a private JSON title-refinement record and unrelated changes; independent review confirmed compatibility with the existing delta and mutable-copy contract. CI run 40175480685 passed on exact headb23f329e21a03edc15f92eac49cc5ab5cf6284e8: 41 successful jobs, 26 skipped, no failures. No schema or public configuration change.Original 10-minute controlled Linux comparisons used synchronized post-warm starts, 16 interleaved CPUs per arm, reversed launch order and CPU assignment in pair 2, and fresh identical fixtures. Every arm completed 160 turns/tool calls/results, 40 metadata patches, and 20 successful cron runs in 600 seconds. No guard failure occurred. A port-preflight setup attempt before pair 2 was stopped before measurement; both fixtures were regenerated and new ports selected.
Paired mean relative deltas are main CPU +1.19%, GC +1.07%, loop p99 +1.30%, and list p99 +2.98%. CPU, GC, and list-p99 deltas have mixed signs. No candidate rejection threshold is triggered by these A/B pairs, but identical-source controls subsequently produced a false latency rejection signal. These remain valid observations under an inconclusive protocol, not landing evidence. The repeatable benefit remains owner allocation and wire size.
Per-kind GC and workload counts for the two untraced pairs
Major/incremental tails have fewer than 200 samples and are context only. Filter counts follow the script’s seven fixed shapes; index 3 is search.
The original identical-source controls exposed list-p99 instability: control 2 measured 93.773 versus 193.482 ms with unchanged code. Its largest delays cluster in one cohort around 108–112 seconds on both arms; cohort GC maxima were only 31.992/24.134 ms. The single shared-guard warning did not interrupt the run, so the full window and every slow request are retained. This is protocol noise, not candidate rejection.
Before collecting any revised result, the untraced protocol was fixed at 80 cohorts / minimum 1,200 seconds, with all other source, fixture, workload, pacing, warmup, maintenance, instrumentation, CPU-placement and start-barrier settings unchanged. Four new A/A controls preceded two new swapped A/B pairs. The separate initial trace-only promotion protocol planned four matching A/A controls and two A/B pairs at 40 cohorts/600 seconds; its controls proved inconclusive, so no traced candidate comparisons ran. Timing is never compared across modes.
Original identical-source controls, retained without exclusions
Each arm completed 160 primary turns/tool calls/results, 40 metadata patches, and 20 successful cron runs. Both sides of control 2 also recorded 560 total model-stream requests, including 240 utility requests.
Major/incremental tails remain context only because their counts are below 200; major-GC comparisons are contextual where either side has fewer than 50 collections. All aggregate GC remains included.
Prior-head CI attribution: CI run 40164788599 on head
f9641d4912992ff8070affaec5f4c8d30ff83958had an inherited failure inchecks-node-compact-small-2:test/scripts/check-deadcode-exports.test.ts→ “models exact generated and module-hook named consumers.” The expected Doctor import is absent from the audit's generated consumer text. Running that single file reproduces the identical assertion on the PR head and CI's unchanged main parent86a37d7f443601011923069fbc0edd5bdb5c45b7(16 passed / 1 failed on each). The failing parser/test/Doctor producer are unchanged by this PR; the cached optional-module import form came from #183208. The inherited audit issue was subsequently fixed on main in #183272 (418c2ba3b39200ba38e14da0c28b2e1e2cb1abe0), verified merged; no fix was copied into this branch. The CI run completed with 39 successful jobs, 26 skipped jobs, this inherited failed job, and its downstream CI gate. All three PostgreSQL conformance shards passed. Security-sensitive review and security-fast passed; no CI rerun was requested.Prior-head CI attribution: run 40170808009, head
9b0a2f948cfb6ea6c984035597f367a732ca20c9, has an unrelated intermittent failure intest/scripts/gateway-bench-profile.test.ts: “separates discarded allocation churn from retained objects and cleans up failed captures” expected zero retained bytes under an allocation function and observed 32,832. The single file passed five times on the PR head and five times on CI’s exact unchanged main parent6a628215b3607629cbc68885d7e307259eff6a5a, 15 tests per run, locally on Node 26.12.1/macOS; CI used Node 24.22.1/Linux. These replays establish same-host consistency, not an exact CI-environment reproduction. The test, profile helper/preload, worker profiler and diagnostics are byte-identical. Its standalone Node fixture creates no worker, imports no session-patch implementation, and cannot use the added message label. This meets the campaign’s unrelated-flake attribution rule; passing replays do not claim to fix the intermittent assertion. The failed profile was not retained by CI, so the exact retained object remains unknown. No assertion was weakened and no CI rerun was requested.Run 40170808009 finished with 39 successful jobs, 26 skipped jobs, the profiling-test failure, and its downstream CI gate. All PostgreSQL conformance shards and security checks passed. The automated failure table marks the job “new” because the matching scheduled-main job passed and selected scope was not compared; the explicit source-path inspection and five-per-side replays above supply the unrelated-flake attribution.
Four completed 20-minute control pairs and eligibility
Longer-window identical-source controls
Both arms used application base
a939b1d4e0f26c827dd17028d2cb899a1ea20247, Node 26.12.1, and the identical reviewed harness (415dae8c18e853e0e8c7fd0bd03f49866b6916d5777e99ed147e8e1b9c4a1388). These are four fresh A/A controls, not candidate measurements. Each ran 80 fixed cohorts with a minimum 1,200-second natural-GC window after 60-second warmup, a common start barrier, and counterbalanced launch order and interleaved 16-CPU placements. Normal maintenance stayed enabled; all samples and maxima are retained. The earlier 40-cohort controls remain separately reported as inconclusive.Within each cell, values are first arm / second arm. Percentile counts are shown alongside tails.
Both control windows remain below the declared paired rejection thresholds. All four pairs completed without shared-guard warnings. No maximum GC pause exceeded max(50 ms, twice the first-arm maximum). This screen does not establish absence of regression; candidate comparisons remain separate. Both GC time/minute and GC/primary-turn are reported; background work is counted separately. The ordinary paired relative thresholds pass, so the absolute-floor distinction does not affect this verdict. No whole-Gateway allocation reduction is inferred from owner microbenchmarks.
Paired deltas are second minus first; percentage values are the mean of the two paired relative deltas, not a ratio chosen after the result. Pooled GC/work is summed untrimmed GC time divided by summed completed turns. Major-GC pause percentiles remain context when their collection counts are below the general tail-sample minima (p95: 200; p99: 1,000). Sub-millisecond pause-tail changes are context under v5.3.
Filter order: unfiltered, active, archived, search, agent, exclude subagents, exclude system/cron. Background request counts are observed rather than assumed equal.
Measurement provenance: the remote experiment retains the committed harness from
f9641d4912992ff8070affaec5f4c8d30ff83958, SHA-256415dae8c18e853e0e8c7fd0bd03f49866b6916d5777e99ed147e8e1b9c4a1388, on both arms. Later upstream harness changes alter churn scheduling; current-head script runs must not be presented as reproducing those exact work counts. The frozen application base remainsa939b1d4e0f26c827dd17028d2cb899a1ea20247; comparisons are prior-base evidence, not a newly built latest-main measurement.Completed 20-minute candidate comparisons
Longer-window candidate comparisons
Both arms used application base
a939b1d4e0f26c827dd17028d2cb899a1ea20247, Node 26.12.1, and the identical reviewed harness (415dae8c18e853e0e8c7fd0bd03f49866b6916d5777e99ed147e8e1b9c4a1388). The second arm contains the reviewed three-file session-entry patch change. Two fresh A/B pairs followed four successful identical-source controls. Each ran 80 fixed cohorts with a minimum 1,200-second natural-GC window after 60-second warmup, a common start barrier, and counterbalanced launch order and interleaved 16-CPU placements. Normal maintenance stayed enabled; all samples and maxima are retained. The earlier 40-cohort protocol remains separate inconclusive evidence. The application and harness were sealed before subsequent rebases; this is measured-source proof, not an exact-current-head build.Within each cell, values are baseline / candidate. Percentile counts are shown alongside tails.
The untraced paired cost screen does not trigger a rejection threshold: main CPU is effectively neutral, mean GC time is lower, and both loop/list paired mean tail shifts are below 1 ms. No maximum GC pause exceeds max(50 ms, twice baseline). The ordinary paired latency relative thresholds pass without relying on a whole-Gateway benefit of at least 10%. These are scoped natural-GC timing results; allocation and promotion are separate experiments. Both GC time/minute and GC/primary-turn are reported; background work is counted separately. The ordinary paired relative thresholds pass, so the absolute-floor distinction does not affect this verdict. No whole-Gateway allocation reduction is inferred from owner microbenchmarks.
With equal primary-turn counts, pooled GC/primary-turn changes by -0.696488 ms (-1.857%), from 37.510354 to 36.813866. This is a cost ratio, not a pooled percentile.
Paired deltas are second minus first; percentage values are the mean of the two paired relative deltas, not a ratio chosen after the result. Pooled GC/work is summed untrimmed GC time divided by summed completed turns. Major-GC pause percentiles remain context when their collection counts are below the general tail-sample minima (p95: 200; p99: 1,000). Sub-millisecond pause-tail changes are context under v5.3.
Filter order: unfiltered, active, archived, search, agent, exclude subagents, exclude system/cron. Background request counts are observed rather than assumed equal.
Promotion calibration and predeclared longer experiment
The separate 40-cohort/minimum-600-second trace-only controls expose unresolved between-process promotion variability. Control 1 promoted 3,861,853,872 / 3,459,495,816 bytes; control 2 promoted 7,231,817,384 / 3,543,770,640 bytes (−51.0%); control 3 promoted 4,494,800,912 / 5,919,450,728 bytes (+31.7%). Every arm completed 160 primary turns/tool calls/results, 560 total model requests, 40 metadata patches, and 20 successful cron runs. Control 4 completed the original declared set; all four results are retained below. These are identical-source controls, not candidate comparisons.
A bounded inspection of control 2 reproduced the canonical main-isolate totals, verified the capture markers, and found no worker contamination or startup spill. Excess spans all ten time bins. Both arms had four warmup cohorts, the same runtime flags and baseline-GC preparation, and barrier releases 1 ms apart. Setup/warmup allocation and promotion were similar. During capture, scavenge allocation was 58.476 / 53.973 GB, scavenge promotion 6.162 / 2.896 GB, and major-collection promotion 1.069 / 0.648 GB. Nursery capacity was predominantly 32 MiB on both sides. Survival behavior differed persistently; its cause remains unproven. No sample was removed or normalized by GC count.
Before any result from a longer traced experiment, freeze 80 cohorts / minimum 1,200 seconds, 320 primary turns/tool calls/results. Keep all other traced-mode inputs, source and harness hashes, Node version, fixtures, pacing, 60-second warmup, maintenance, pre-warm isolate-identification GC, post-warm baseline GC, and common start barrier unchanged. Both preparation collections stay outside capture. Use four fresh A/A controls before two fresh swapped A/B comparisons; no candidate run uses the unstable short protocol. Retain every valid result and all background-work counts, counterbalance launch order/CPU placement, and apply the existing guard and v5–v5.6 thresholds unchanged. Trace parsing follows process exit and stdout drain. Traced timing never replaces the passing untraced cost evidence.
This is the first longer calibration for the separately traced mode under v5.4, not a claim that longer duration will cure the observed variability. If the longer controls remain inconclusive, stop before candidate runs or another redesign and report the unresolved promotion gate. Prior short controls remain separate evidence. Independent review confirmed this protocol before launch.
All four short promotion controls, retained as inconclusive
First trace-only promotion controls — inconclusive
Four fresh identical-source controls used 40 cohorts / minimum 600 seconds with trace-GC only, the same pinned application/harness and preparation/barrier. All completed without guard warnings. Timing and pause metrics from these traced runs are attribution-only. The protocol is inconclusive because substantial identical-source promotion variation remains unresolved regardless of its direction; no candidate comparison used this mode. All data is retained.
Values are first arm / second arm; MB is decimal 1,000,000 bytes.
Every arm completed 160 primary turns, 160 tool calls/results, 40 metadata patches and 20 successful cron runs. Background request counts are observed, not assumed equal.
Window 1–2: mean signed delta −12.782515 MB/turn; mean paired relative delta −30.708%; pooled promotion 34.667723→21.885208 MB/primary-turn. These directional summaries do not make the unresolved control sensitivity valid.
Window 3–4: mean signed delta +2.671383 MB/turn; mean paired relative delta +8.909%; pooled promotion 26.877029→29.548412 MB/primary-turn. These directional summaries do not make the unresolved control sensitivity valid.
A bounded read of control 2 reproduced the canonical main-isolate totals and boundaries. Its excess spans all ten 60-second bins, with no worker contamination or startup spill. Setup/warmup flags, four warmup cohorts, preparation collection and barrier match. During capture, median new-space capacity is 32 MiB on both arms, while allocation and survival differ persistently. The cause is unresolved; a longer window is not a demonstrated cure. The separately declared first longer traced calibration retains this evidence and changes only fixed duration/work; its result and bounded early-stop decision are reported below.
Longer trace-only promotion controls — incomplete and inconclusive
Two of four declared identical-source controls completed before an explicit budget closeout. Each used 80 fixed cohorts and a minimum 1,200-second window with trace-GC only. Controls 3–4 and all candidate promotion comparisons were not started. This is an incomplete calibration, not a completed passing protocol or a candidate rejection. No valid candidate promotion comparison is available. Both completed pairs and every sample remain retained.
The pinned application is
a939b1d4e0f26c827dd17028d2cb899a1ea20247; the measured harness SHA-256 is415dae8c18e853e0e8c7fd0bd03f49866b6916d5777e99ed147e8e1b9c4a1388. Preparation GC, warmup, common barrier, normal maintenance and counterbalanced CPU placement/launch order remained unchanged. No shared-guard warnings occurred. Traced timing and pause metrics are attribution-only.Values are first arm / second arm; MB is decimal 1,000,000 bytes.
Every arm completed 320 primary turns, 320 tool calls/results, 80 metadata patches and 40 successful cron runs. List/filter and utility request counts remain separately recorded; no normalization by GC collection count was performed.
Window 1–2 has a mean signed delta of +8.541676 MB/primary-turn and a mean paired relative delta of +35.165%. Pooled promotion is 23.432002 → 31.973678 MB/primary-turn (+36.453%). These are descriptive results of an incomplete control screen. Substantial identical-source variation remains unresolved, including the first pair’s adverse direction; no claim that promotion passed is made.
Filter order: unfiltered, active, archived, search, agent, exclude subagents, exclude system/cron. Passing untraced cost measurements, owner allocation measurements, correctness tests and CI remain separate evidence; they are not substituted for a promotion result.