Repository navigation
improve: reduce Gateway allocation while draining SQLite receipts - #195129
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: ❌ FailedThis 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 changes before merge. What this changesThis PR restores the captured owner context once per synchronous SQLite message drain while preserving callback isolation and per-message authority checks. Example: Drain 64 queued SQLite commit receipts.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR open: the allocation reduction is useful and preserves the existing runtime checks, but its new lint suppressions cause a confirmed CI failure. Priority: P3 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe Gateway-side SQLite admission owner receives worker requests and committed receipts through MessagePorts, checks live database authority, and publishes grants or committed facts. flowchart LR
A[SQLite worker] --> B[MessagePort queue]
B --> C[Gateway admission drain]
C --> D[Captured owner context]
D --> E[Live authority checks]
E --> F[Native grant]
D --> G[Committed fact observers]
Technical reviewBest possible solution: Keep the focused batching change and reconcile its five justified instrumentation suppressions with the existing explicit allowlist. Do we have a high-confidence way to reproduce the issue? Current-main source restores context for every queued message, and the supplied measurements quantify that repeated work; the introduced CI failure is independently recorded in its test annotation. Is this the best way to solve the issue? Batching at the existing drain owner is the smallest complete optimization; callback restoration, live authority checks, retention cleanup, and the distinct regression cases remain justified. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 64b382cf3d73. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
PR surfaceSource +13, Tests +98, Other +446. Total +557 across 6 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:
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 8, 2026, 3:55 AM ET / 08:55 UTC. |
Restore the captured owner once per synchronous drain while preserving live authority checks and callback isolation. Skip the empty request-observer dispatch. Keep registry expiry and generation checks effective between queued messages.
3a11acb to
8ecfcfd
Compare
|
@codex ^D review validate and execute |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Landing note: ClawSweeper's P2 "register the new instrumentation suppressions" applied to the earlier head. At head 8ecfcfd all six |
…tooling-lint-selection-20261108 * commit 'b0e90e6a4b359fff7756698067fdce4758b1907b': (38 commits) fix(android): Talk button demands a realtime provider on a native Talk setup (#191194) chore: trace first-run Gateway work and verify later replies (#195185) fix(knowledge): keep deleted messages out of reply previews (#195126) fix(agents): preserve streamed replies across Gateway restarts (#195164) perf(ci): reuse SDK transport path boundaries (#195180) fix(sandbox): avoid pauses for unchanged command checkpoints (#195120) fix(test): make retention checks portable across runtimes (#195091) fix(knowledge): clarify temporal kind filters (#194995) improve: reduce Gateway allocation while draining SQLite receipts (#195129) fix: reduce streaming CPU after reply and voice directives (#195145) fix: reduce Markdown reparsing during streamed tool-call checks (#195161) fix: restore the main dead-export gate (#195158) improve(ci): pack small UI selections into fewer jobs (#195107) fix(muse): quota and sign-in failures end with no reply (#195148) fix: allow first release push with shipped patch bytes (#195174) fix(ci): narrow single-config tooling selections (#195147) fix(packaging): reject incompatible prepublish plugin cohorts (#195152) fix(ci): prepare verified Bun before parity checks (#195155) fix: Incognito agent turns stall before execution (#195005) fix: credentialed search and speech providers work without picking a provider (#195169) ...
…enclaw#195129) * perf(sqlite): batch worker admission context restoration Restore the captured owner once per synchronous drain while preserving live authority checks and callback isolation. Skip the empty request-observer dispatch. Keep registry expiry and generation checks effective between queued messages. * fix(perf): preserve native receivers without lint suppressions
What Problem This Solves
Queued SQLite worker receipts repeatedly restore the same owner context on the Gateway main thread.
User Impact
Less main-thread allocation and dispatch work during receipt bursts. Behavior, authority checks, schemas, and configuration remain unchanged; whole-Gateway latency is not measured here.
Why This Change Was Made
Enter the captured context once per nonempty synchronous drain. Keep callback context restoration and every per-message authority check, including after asynchronous preparation. Give relay creation callbacks their own restoration boundary, and skip context dispatch for an absent request observer.
The state-store and transcript-lifecycle audit found no redundant Gateway-scope copies or identical-current entries to remove. Their separate lifetime frames remain intact. Production code grows by 13 lines, including moving existing callback/authority types into the worker contract to keep the admission owner below its line cap.
Evidence
Five serial AB/BA samples per variant, plus two A/A controls, on Node 26 with 26 ambient stores and 4,096 synthetic session identities. CPU and allocation used separate uninstrumented passes; counts were measured separately.
A/A controls: single-admission: sampled host B/message 3721.006 → 3823.875, main CPU us/message 3.179 → 3.134; local-receipts: sampled host B/message 1576.293 → 1582.598, main CPU us/message 0.975 → 0.962; worker-receipts: sampled host B/message 1388.773 → 1376.810, main CPU us/message 1.002 → 1.004. The small single-admission CPU change overlaps sample spread; allocation gains are repeatable.
Run
node --expose-gc --import ./scripts/tsx.mjs scripts/perf/sqlite-admission-context-measure.mjs --iterations 2000 --batch 64 --receipts --worker; omit--workerfor local receipts or use--iterations 20000 --batch 1for admission. Run unchanged on base/candidate, or pass--ownera baseline module with resolved imports.--cpu-profile <path>profiles the timing pass.The sibling census (
scripts/perf/sqlite-context-siblings-measure.mjs) uses real SQLite worker writes with 1,000 synthetic workspace rows and persisted readback. Per warm write: 2 snapshots created / 3 restored, unchanged across A/A arms. Lifecycle callbacks each enter one distinct owner. All measured owner flows make zero Gateway-scope copies. These are owner/transport measurements, not a large-database or full-Gateway throughput benchmark; sampled allocation excludes native and worker heap allocation.Focused suites: 87 tests pass (admission 51, retention 6, lifecycle 4, Gateway scope 12, lint-suppressions 14; final five-shard run 26.57 s harness wall time). New tests refuse the second message after registry rotation or weak-target expiry and verify ambient callback isolation. Existing real-GC expiry, asynchronous revocation, and reentrant finish coverage remains passing. Added test budget: 99 lines for registry cases and a cursor-reset isolation regression. That error-path regression failed on the earlier batching candidate and passes after restoring the callback context. The baseline fails the performance count target; this is not a pre-existing authorization bug.
Rebased onto
306bf7730b0108e863a6ecfc549bc8289d9bddc7. Final head:8ecfcfd7d8d7d1a1a9450baf941e627652087011.The original CI run exposed a real failure introduced by this PR: its native-method capture suppressions increased the production suppression inventory from 213 to 215 entries. The same test failed locally before repair. All six new suppressions are removed, including the test-only capture, using structurally checked callable types with explicit receivers. Native function identity and exact restoration are preserved; the allowlist is unchanged.
Final local proof: all 87 focused tests, changed-source/script lint, and formatting pass.
pnpm check:changedwas rerun; its changelog-attribution gate fails on existing release records (exact-parent proof below). The two original CI infrastructure failures (check-lint-extensions-3andcheck-additional-boundaries) could not stage the pinned Bun fork. Their local equivalents now pass:node --import ./scripts/tsx.mjs scripts/run-oxlint-shards.mts --only=extensions --extension-stripe=3/6 --threads=1andnode --import ./scripts/tsx.mjs scripts/run-additional-boundary-checks.mts. The same 20 attribution violations reproduce in a clean checkout of exact main parent306bf7730b0108e863a6ecfc549bc8289d9bddc7usingnode --import ./scripts/tsx.mjs scripts/check-changelog-attributions.mts. The forbidden-handle expansion in266a7aa0fe69e2b5fe6445c4ceb1e15b5360c957(#194364) introduced these rejections without repairing the existing records. This is a main regression needing follow-up; it is not a green changed-check run or a merge waiver.The dead-export scan also fails on main-owned exports. Exact-parent reproduction uses
node --import ./scripts/tsx.mjs scripts/check-deadcode-exports.mtson the same main SHA. Introducing commits:c9e6370bb19157bb2dbadc6cb5ccd6fc95ea0e2e(#195099),scripts/plugin-npm-evidence-reuse.mjs:NPM_EVIDENCE_FILE;ce840d8a82902f0bff3eea5f1885f51c4ef16e01(#195061),src/infra/path-containment.ts:canonicalizeForContainmentSyncandUncanonicalReason;754b41c65df0f72d3a6df1eb6abd810644b60190(#195064),src/test-utils/retention.ts:expectCollected,expectLiveObjects, andforceFullGc. These are main gate regressions to repair, not ignored noise. All other changed checks pass.After the capture repair, both measurement scripts passed smoke runs on Node 24.22.1: the real-worker 64-message batch still restores 65 snapshots with zero scope entries/copies; 1,000 synthetic SQLite workspace rows and both warm-write arms pass persisted readback. These smoke runs verify instrumentation behavior; the controlled performance figures above remain the original Node 26 AB/BA and A/A results.
Codex autoreview of the complete rebased candidate against
306bf7730b0108e863a6ecfc549bc8289d9bddc7: scoped-clean at P0–P2, no accepted/actionable findings. The reviewer verified exact native restoration, WeakRef receiver semantics, and preserved expiry and authority/lifecycle guards. Runtime production delta remains +13 lines; this repair adds no runtime production code.Ready for review; intentionally left unmerged. New exact-head CI is pending.