Repository navigation
perf(state): avoid async task context for synchronous reply decoding - #184831
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 changesUse the existing synchronous monitor phase API to avoid async-context allocation while decoding SQLite worker replies. Example: A monitored SQLite reply decodes the value {"count":42}.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR is a focused, maintainer-directed optimization with no actionable correctness or security findings; exact-head CI remains pending. Priority: P3 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe Gateway's SQLite broker receives serialized worker replies, decodes values or transfer frames, and passes completed results to the existing settlement owner. flowchart LR
A[SQLite worker] --> B[Broker reply receiver]
B --> C[Synchronous monitored decode]
C --> D[Transfer continuation]
D --> A
C --> E[Existing settlement owner]
E --> F[Waiting caller]
Technical reviewBest possible solution: Retain this minimal use of the existing synchronous phase owner and complete the normal exact-head CI gates. Do we have a high-confidence way to reproduce the issue? Current main enters AsyncLocalStorage for this synchronous decoder when monitoring is enabled; source inspection establishes the unnecessary entry, and the PR reports a baseline-failing regression. Is this the best way to solve the issue? The smallest complete change uses the monitor's existing phase argument, preserves the diagnostic label, and adds no competing owner or retained state. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against cd3bcc017653. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +1, Tests +24, Other +4. Total +29 across 3 files. Added test files: 0. View PR surface stats
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 26, 2026, 1:28 PM ET / 17:28 UTC. |
Related: #184101
What Problem This Solves
SQLite worker reply decoding creates a fresh async task context for a wholly synchronous operation whenever Gateway stall monitoring is enabled.
User Impact
No user-visible behavior change. This removes a small allocation and CPU cost from each decoded reply while preserving the existing
worker:sqlite:reply-decodestall label. Decoding, transport, admission, custody, ordering, transactions, and integrity checks are unchanged.Why This Change Was Made
Use the task monitor's existing synchronous phase API: task
worker:sqlite, phasereply-decode. That retains elapsed-time attribution without enteringAsyncLocalStorage. Reply decoding and its transfer helpers are synchronous; continuation posting, settlement, and dispatch remain outside the phase.This is residual work after #184101, which is already in the measured baseline. Most allocation under the decoder remains necessary V8 deserialization; this change only removes async-context setup. Runtime production delta is +1 line (2 added / 1 removed): the extra phase argument selects an existing API and deletes per-call work. No new owner, cache, helper, or compatibility path. The requested non-test/non-doc diff is net +5 lines including the benchmark update; tests add 24 lines.
Evidence
Acceptance declared before the paired comparison: reduce allocation in the monitored reply owner without consistently adverse CPU, preserve reply output and stall attribution, and eliminate async-context entry from synchronous decoding.
Five counterbalanced base/candidate pairs on Node 26.12.1, synthetic scalar/session-entry/64-row-page replies, 10,000 replies per pass. Each process runs five untraced timing passes and one separate allocation-sampling pass including collected objects. Fixtures/jobs are prepared before measurement. Each side therefore has 250,000 timed and 50,000 allocation-sampled replies per shape. Table reports mean sampled bytes/reply and mean of each process's median CPU/reply.
Allocation and CPU improved in all five pairs for all shapes. Host 1-minute load ranged approximately 21.1–24.0. The page result is a small improvement, as expected when deserialization dominates. Baseline:
c00af62f03e6ab9929234a998693f53341a4e126; comparison toggles only the two production hunks while running the same updated benchmark.Reproduce on base and candidate with the updated benchmark:
The added regression fails on the baseline because decoding calls
AsyncLocalStorage.runonce. It passes with the change and also checks decoded output and the unchanged stall label.node scripts/run-vitest.mjs src/infra/sqlite-worker-broker-reply.test.ts src/infra/main-thread-stall.test.ts --maxWorkers=1— 16 passed, 33.08 seconds wrapper wall time (29.60 seconds Vitest, mostly transform).pnpm tsgo:core, andgit diff --check— passed.Measurement gap: no whole-Gateway load/stress run, GC/tail claim, or end-to-end speedup claim. This follows the task's explicit fast-path exception for deletion of redundant synchronous context setup. CI supplies broader proof; no remote validation lease was allocated.