Repository navigation
improve(auth): reduce temporary allocations during profile reads - #163245
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: needs maintainer review before merge. Reviewed October 2, 2026, 12:33 AM ET / 04:33 UTC. ClawSweeper reviewWhat this changesThe PR removes an extra byte-buffer copy when encoding auth-profile transfer frames and adds tests for byte-range boundaries and independent string results. Merge readiness✅ Ready for maintainer review Keep open: this is a useful, bounded optimization absent from current main, with no actionable correctness or security findings. The MEMBER-authored PR remains subject to normal landing gates. Priority: P3 Review scores
Verification
How this fits togetherOpenClaw reads auth profiles in a SQLite worker process and transfers serialized records to the requesting process. This encoder turns bounded binary frames into base64 strings for JSON IPC before the receiver reassembles the records. flowchart LR
A[Auth profile request] --> B[SQLite read worker]
B --> C[Owned binary frames]
C --> D[Exact-range base64 encoding]
D --> E[JSON process transport]
E --> F[Validated record reassembly]
F --> G[Auth profile results]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +10, Tests +22. Total +32 across 2 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Retain the existing transfer owner and wire contract while avoiding the redundant copy during synchronous encoding. Do we have a high-confidence way to reproduce the issue? Not applicable as a behavioral bug reproduction: source confirms the redundant copy on current main, and this read-only review ran no benchmark or tests. Is this the best way to solve the issue? Yes: encoding the exact backing-buffer range synchronously is a narrow optimization consistent with producer ownership and the existing wire format. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 5e81e62b87d1. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
What Problem This Solves
Auth-profile reads create an extra byte-buffer copy for every JSON IPC frame before encoding it.
User Impact
Reduces temporary allocation and copying in auth-profile transfers. Returned credentials, cancellation, child cleanup, and database behavior remain unchanged. No configuration or migration is required. End-to-end latency and peak-memory improvements are not claimed.
Why This Change Was Made
Encode a view of the frame's exact backing-buffer range synchronously; only the resulting immutable base64 string escapes. Producer-frame ownership and receiver reassembly remain intact. The same pattern already exists in
src/infra/node-duplex-framing.ts, and follows the Node Buffer contract.Production delta is +10 lines, including formatting and one ownership comment; there is no new helper, cache, worker, or fallback. Tests add 22 lines protecting offset/sentinel boundaries and string independence for both Uint8Array and Buffer views.
Evidence
52/52 tests passed across the new encoder test, real auth-worker tests, read-only session lifecycle tests, and generic transfer tests on Node 24.16.0 / macOS arm64. Coverage includes complete oversized native/broker/snapshot results, source freshness, database-byte preservation, cancellation, child joins, malformed frames, and results over 64 MiB.
Targeted oxfmt, oxlint with the core configuration, and
git diff --checkpassed. Independent review found no actionable issue.A bounded encoder-only screen compared three fresh baseline/candidate process pairs per runtime, alternating order, with three warmups and GC before each cell. All 12 children joined and byte equivalence checks passed. Each paired wall cell improved at 1 KiB, 64 KiB and 8 MiB. For eight 8 MiB encodes, Node 26.7.0 baseline 12.671/12.161/12.890 ms became 9.766/9.191/8.944 ms; Bun 1.3.14 baseline 16.186/16.402/15.624 ms became 8.613/9.920/11.802 ms. This isolates encoding and does not measure complete auth acquisition.
The Node proof command took 76.92 s wall, 73.55 s user and 37.72 s system CPU, including a 33.6 s cold worker build. These are validation costs, not before/after performance results.
Testbox remained queued without a runner for five minutes, so that owned lease was stopped and the same focused proof ran in an independent frozen installation. No remote test result is claimed.
A local Bun 1.3.14 Vitest attempt failed before executing tests because its worker thread streams were unavailable. The repository's supported test runtime is the checksum-pinned Linux/X64 OpenClaw Bun 1.4.3 fork in
.github/actions/setup-test-bun/action.yml; its exact-head CI proof is recorded below. No pool, timeout, assertions or runtime pin was weakened.Exact-head CI attempt 1 passed for
42de5b9e85d5291f011f35b67f2a200996565845, testing merge2079d6977c33596eda8a5efd070b7b4b910144f0overcc618e0e7be6c02ab7f53e2487641fe2fe6b8f0c. The changed-file job actually ran the encoder cases on pinned Bun1.4.3-canary.1+fc90aa4d9: 2/2 passed, 501 ms Vitest / 1.68 s wrapper. Session lifecycle ran on Node 24.19.0: 14/14 passed, 2.04 s / 3.35 s. Both exited 0 with completed worker-generation cleanup. Auth-worker and generic-transfer coverage comes from the separate focused Node proof above; those two files were not observed executing in this CI run.Exact-head ClawSweeper review has no actionable finding or remaining rank-up move. Native squash landed as
76832258508202d51fc5d1b8c384d0f733ee0de4; live main reachability and both changed-file hashes were verified. No CI exception or merge bypass was used.