Repository navigation
perf(approvals): index and reuse pending replay by session - #184453
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 real behavior proof before merge. What this changesThis PR indexes pending approvals by session and reuses completed replay preparation while the approval store confirms its currency. Example: 40 authenticated sockets reconnect with 10,000 pending approvals across 1,000 audiences.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 3 items remain Keep open: this maintainer-authored PR addresses evidenced reconnect overhead that remains on current main; no definite introduced code defect was found. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherGateway message subscriptions request pending approvals from the approval store, which reads persisted rows through workers and returns sanitized replay after reviewer and session authorization. flowchart TD
A[Authenticated subscribers] --> B[Subscription handler]
B --> C[Session and reviewer replay scopes]
C --> D[Pending approval index]
E[Database read worker] --> D
F[Committed writer receipts] --> D
C --> G[Final disclosure checks]
G --> H[Subscription response]
Technical reviewBest possible solution: Keep the index under the existing approval store and complete final-response authority validation before landing. Do we have a high-confidence way to reproduce the issue? Current-main source repeats pending selection after in-flight sharing ends, and the supplied real-Gateway measurements establish the reported reconnect overhead. Is this the best way to solve the issue? The index uses existing writer receipts and physical-owner lifecycle rather than adding another persistence owner, and the retained SQL path remains necessary for repair and maintenance. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1a7c8156dc64. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: shipped entry point. SecurityNeeds attention: No concrete bypass was found, but retained replay disclosure needs final-response authority proof. EvidenceWhat I checked:
PR surfaceSource +482, Tests +70, Docs +2, Other +595. Total +1149 across 13 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 26, 2026, 5:46 AM ET / 09:46 UTC. |
|
Landing with the authorized inherited-failure exception for head The sole non-aggregate failure in CI run 40302829656 is I reproduced the same cold-build deadline failure on the CI merge's unchanged main parent, Independent review is clean. The approval change passes 58 focused/sibling tests, 26 closure tests, targeted core typecheck, lint and format, plus 24,320 exact ordered replay checks on isolated built Gateways. No CI rerun was requested. The PR body contains the full reconnect latency, CPU, allocation, memory and host-load evidence. Native workspace preflight resolves to a separate canonical checkout outside this lane; the lane explicitly forbids creating or using that checkout. Landing therefore uses the task-authorized exact-head squash API fallback. No required product review or security gate is waived. |
…184453) * perf(approvals): index and reuse pending replay by session * fix(perf): keep diagnostic IPC listener synchronous
What Problem This Solves
A reconnect burst with approval replay repeatedly scans and decodes every pending approval. The authenticated subscribe scheduler admits four preparations at a time, so sharing only unsettled promises still repeats the scan across successive groups of a 40-socket burst.
User Impact
Reconnects with approval replay complete sooner while delivering the same pending approvals in the same order. No configuration or migration is required.
Why This Change Was Made
The approval store now owns a pending-approval view indexed by persisted session audience. It hydrates once in bounded read-worker pages, updates from committed postimages/tombstones, and retires with the physical database owner. Warm selection walks the selected session's pending approvals. The runtime retains at most 64 idle session/reviewer replays while the store confirms their currency, sharing completed preparation across scheduling groups.
Queued approval writes prevent reuse from FIFO admission through settlement. Expiry, visible receipt changes, unknown outcomes and owner retirement invalidate snapshots. Existing expiry reconciliation, corrupt-row repair, reviewer filtering, delivery order and per-client authority checks remain intact. No schema, retention or protocol changes.
Evidence
Reconnect measurement
Real built Gateway, synthetic 10,000 sessions and 10,000 live pending approvals across 1,000 audiences, 40 authenticated sockets reconnecting simultaneously. The committed harness verifies exact ordered IDs and sanitized payload equality on every reply. Five alternating AB/BA rounds, 1,000 warm subscriptions per arm/case/round; initial bursts are separate. The first distinct-session burst has cold replay scopes and an already hydrated pending index.
All 24,320 ordered-payload checks passed across the timing and separate allocation runs. Base:
798570bc460f96d8321744be7bb99637d44a5b7d; measured candidate:b5966f91df4578cb503136f25ca0bdc02bb4383e. Final head only fixes the benchmark probe's promise-returning event listener; production sources and measurement behavior are unchanged.Every timing pair improves. Candidate same-session p99 ranges from 6.03 to 174.94 ms; the outlier is retained. The initial same-session burst, including index hydration, improves client p50/p99 451.02/904.51 → 186.64/189.26 ms (40 samples; context only). First distinct-session burst: 3544.00/5667.11 → 8.48/13.08 ms, with the index already hydrated.
Tradeoff: first-burst main CPU rises 63.95→76.36 ms, and sampled allocation 17.52→40.44 MiB, to populate the pending index. Warm observed heap is higher; RSS/heap were sampled after bursts without forced collection and do not establish retained-memory deltas. This focused FAST PATH proof does not claim whole-Gateway GC, event-loop, sessions.list, or worker-CPU improvements.
Run instructions and fixture details are in
scripts/perf/approval-replay-burst-measure.ts. Allocation sampling runs separately from untraced timing; CPU/allocation claims cover the Gateway main thread, not worker CPU or whole-Gateway load.Correctness and checks
The necessary production growth implements the requested session index and its receipt/expiry/physical-owner lifecycle. The author simplification pass removed redundant seed-promise sharing because the existing FIFO already serializes seeding. The retained SQL reader is the existing corruption/expiry/maintenance repair path, not a second warm replay policy.
Source production delta: +482 LOC (507 added, 25 deleted). This growth is required by the explicitly requested session index plus its existing FIFO, corruption, expiry and physical-owner contracts; bounded replay retention uses those owner facts. The committed real-socket benchmark is separate tooling.
CI follow-up: the first run caught the probe listener lint issue, now fixed and independently reviewed; both IPC modes pass a focused smoke and the exact scripts typed-lint configuration passes. On final head
0bcfdac168ec72e2dbdecc518de847c223410028, all 40 other CI jobs passed. The remaining failure in run 40302829656 isui/src/e2e/stale-build-recovery.production.e2e.test.ts:command timed out after 120000ms: node scripts/run-node.mjs --help, during cold build preparation before Gateway startup.The same single test file reproduces the identical timeout on the CI merge's unchanged main parent
1b6eb7bf2e7f7cb31ce9ee71c6f1d778f7ee6ce0, using providerblacksmith-testbox, leasetbx_01m5vtf6p6m6wfkxy28b3yjdxr(Linux x64, Node 24.22.1, four CPUs, 15.4 GiB RAM). Command:taskset -c 0,1,2,3 node scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts --configLoader runner ui/src/e2e/stale-build-recovery.production.e2e.test.ts --maxWorkers=1, with isolated synthetic state and a cold dist tree. Result: exit 1, exact 120000ms CLI-build timeout; total remote command 211.5 s. The test, suite helper, CLI bootstrap and build orchestrator are unchanged by this PR. The lease is stopped. An earlier Mac baseline passed, so the failure is host-sensitive; the matching four-CPU Linux baseline establishes it as inherited. No CI rerun was requested. Landing uses the authorized inherited-failure exception, retaining the red result.All timing pairs, per-arm memory and host load
Per-round latency and CPU
Memory and host context