Repository navigation
perf(ui): use native Base64 conversion for Talk audio - #184879
Conversation
Use Uint8Array.toBase64 within the supported Control UI browser and WebView floor. Preserve standard padded output and subarray view boundaries, with a JSDOM-only shim for the Node 24 dual-runtime test lane.
Use the native typed-array encoder and decoder when available, preserving the original fallback behavior for admitted older browsers. Repair the PCM benchmark cancellation contract and retain strict delivery, visibility, and Stop proof.
|
🦞👀 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 changes before merge. What this changesThis PR uses native Base64 conversion when available and extends the Talk benchmark to observe native PCM capture, playback, cancellation, and cleanup. Example: Talk encodes a 4,096-sample PCM16 microphone frame containing 8,192 bytes.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR open: it provides a useful, narrowly scoped performance improvement, but its new lint suppressions cause a confirmed CI failure. Priority: P2 Before merge
Findings
Agent review detailsHow this fits togetherThe shared browser helper converts byte arrays and Base64 strings for Talk audio and other Control UI consumers; the benchmark exercises production UI bundles with native audio and synthetic Gateway responses. flowchart LR
A[Microphone PCM] --> B[Shared Base64 helper]
B --> C[Gateway client]
C --> D[Relay audio events]
D --> B
B --> E[Native audio playback]
F[Talk benchmark] --> A
F --> D
Technical reviewBest possible solution: Retain the shared helper fast paths and original fallbacks, and account for the three justified native-method forwarding suppressions in the existing inventory. Do we have a high-confidence way to reproduce the issue? Current main visibly performs the repeated conversion loops, and the supplied browser measurements exercise that path; this review ran no target code. Is this the best way to solve the issue? The native branches are the smallest production change within the existing owner, preserve older-browser behavior, and match the documented native API defaults (encoder, decoder). Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b33227f35cce. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceAcceptance criteria:
What I checked:
PR surfaceSource +8, Tests +172, Docs +42, Other +573. Total +795 across 6 files. Added test files: 0. View PR surface stats
Review metrics
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, 2:32 PM ET / 18:32 UTC. |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
* perf(ui): use native base64 encoding Use Uint8Array.toBase64 within the supported Control UI browser and WebView floor. Preserve standard padded output and subarray view boundaries, with a JSDOM-only shim for the Node 24 dual-runtime test lane. * test(ui): measure native PCM Talk capture and playback * perf(ui): use compatible native base64 conversions for Talk Use the native typed-array encoder and decoder when available, preserving the original fallback behavior for admitted older browsers. Repair the PCM benchmark cancellation contract and retain strict delivery, visibility, and Stop proof. * test(ui): satisfy Talk fixture toolchain contracts
Problem and change
Talk repeatedly encodes microphone PCM chunks and decodes playback chunks through the shared Base64 helper. Use the native typed-array APIs when available, preserving the original encoder and decoder as the exact fallback for older browsers admitted by the current capability gate. In particular, that gate admits Chromium 135–139, while the native APIs arrived in Chromium 140. This PR does not change browser admission or add a dependency. Standard padded output, typed-array view boundaries, accepted decode inputs, and malformed-input rejection are preserved; exception class/message is not a public contract.
Extend the existing Talk benchmark with native gateway-relay PCM observations, truthful matching/stale/idle cancellation, silent-input setup before playback, and retained failure diagnostics. This fixes the synthetic cancellation contract without changing production Talk transport behavior. Every observed cancellation, delivery, actual visibility, traffic, and Stop gate remains enforced.
Result and proof
Main-thread script CPU improves in all four measured cells (paired medians −24% to −39%), with lower script p95s. Task CPU improves most during playback; speaking task CPU changes are small. The initial desktop playback task-p95 outlier remains in the data; ten additional AB and AA pairs bring this cell to n=20, where both task and script medians/p95s improve. The result is a focused reduction in script work; it does not establish a 40% total active-task CPU reduction or a battery-duration improvement.
Both cohorts use source-identical commit
7571279012140fe19355783957109da21e7ae801, the same frozen bundles and validator, headless desktop/mobile at 4× CPU, five-second observations, and interleaved independent A/A controls. Desktop playback combines twenty pairs per comparison; other cells retain ten. Pair identity is(cohort, original pair). All 200 observations and 120 browser identities are retained; no row or outlier is filtered. At n=10 nearest-rank p95 is the maximum; at n=20 it is the second-largest.Main-thread CPU
CPU uses CDP
Performance.enablewithtimeDomain: "threadTicks":TaskDurationandScriptDurationmeasure main-thread CPU, normalized by the elapsed probe interval. Values are ms per second. Each side shows median / p95 [min–max]; paired change is the median of individual pair percentages.Desktop playback’s original candidate maximum 31.3414 ms/s is retained in the n=20 range. Task p95 now improves 28.1387→24.2722 ms/s; A/A task p95 moves 30.5387→30.5994 ms/s (+0.20%). The mobile-speaking script A/A paired median is +5.81%, showing shared-host noise; no clean wall-time result is claimed.
The unchanged style owner has a small absolute desktop-playback style-p95 movement: 0.4022→0.4316 ms/s; A/A moves 0.4806→0.5329 ms/s. This is not a claim that every CPU subphase improves.
Local latency probes
Each row summarizes per-observation latency medians or p95s, rather than pooling native frames. Values are milliseconds, shown as median / p95 across observations. Scheduled lead is compared absolutely; percentages against near-zero baselines are omitted.
Production computes
startAt=max(context.currentTime,playhead)before decoding; the observer reads currentTime after nativestart(). Recorded lead values have approximately 1.333 ms steps. In mobile playback, every per-observation median remains 0; the distribution of per-observation p95 moves from median 0 / maximum 1.333 ms to median 1.333 / maximum 2.667 ms. Across 490 starts per side, maximum lead remains 4 ms, with requested-start spacing 100–106.667 ms on both sides. Same-source A/A shows comparable step movement. Desktop playback at n=20 has median 0 and p95≈2.667 ms on both sides. These are clock/phase-sensitive local scheduling observations, not proof of identical acoustic latency.Delivery, cleanup, and boundary
Every native input callback reached its FIFO-matched asynchronous mock
talk.session.appendAudiohandler after production PCM conversion, Base64 encoding, and GatewayClient serialization through the mock WebSocket. Observations retain 29–30 input frames, byte length/session identity, timestamp order, and sustained cadence. Playback retains native scheduling, buffer shape, cadence, and natural-completion checks. Helper tests establish Base64 byte correctness; this benchmark does not compare decoded server waveform samples or prove real-server/provider acknowledgement.Late mock receipts counts receipts after the observation’s end, not total appends. There are two across all 200 observations: initial cohort
AB-mobile-4x-0-1-responding, frame 154, arrived 3.5 ms after the boundary (4.9 ms callback-to-receipt); extension cohortAA-desktop-4x-4-1-responding, frame 118, also arrived 3.5 ms after the boundary (5.6 ms callback-to-receipt). Both receipts are paired deliveries, not lost frames. All other observation gates and both strict validator reports remain complete. Post-Stop receipts require ended tracks, closed native contexts, and no new owned callbacks/appends/starts across two input-block periods. All 120 observed browser roots exited.Each run used its own
caffeinate -dassertion and removed only that owned process. Actual visibility was never faked. Initial run: 17:23:58.369521–17:59:07.164179Z; assertion removed 17:59:07.164135Z. Extension: 18:03:00.894195–18:14:57.057844Z; assertion removed 18:14:57.057784Z. Both final aggregate display assertions were 0.Host load and coverage
No coordinated task-owned browser/build workload overlapped the measurements; other shared-host activity cannot be excluded. Host load distributions are recorded below as min / median / p95 / max.
Separate 1/5/15-minute endpoint readings:
[42.26318359375, 36.76416015625, 32.349609375]; end[40.34130859375, 42.1279296875, 40.53369140625].[37.03564453125, 40.93212890625, 40.53271484375]; end[35.7939453125, 35.13232421875, 37.08935546875].Both runs began after coordinated task-owned builds and source verification finished. Earlier interrupted attempts remain preserved and excluded. The extension launcher’s descriptive
grid.browsers=20arithmetic error is retained with a correction: its actual command and strict validator require 40 browsers. No measurement gate changed.This proof covers 4× CPU speaking and native playback on desktop/mobile. FPS, GC-event, wakeup and compositor probes were disabled for this CPU comparison. It makes no direct idle/hidden, quiet-transcript, visible-caption, battery-duration, hardware microphone, acoustic, real-provider, or 100 ms RTT claim. The fixture unit proof is timer/cancellation proof, not native audio proof. The synthetic append/schedule probes are not end-to-end audio latency.
Build size and scope
The base is
36c5aa11d1006576765d506c0438c97c124516bb. Its existing frozen output was reused after all 5,933 emitted-file hashes matched. Node 26.12.1, dependencies, build configuration and deliberately fixed build metadata match the candidate. Only the Base64 helper changes among production build inputs; source/diff hashes stayed fixed through build, and the emitted source map matches helper SHA-25657e067427c3aff8c84f010ad3807ca78f2caa45469f7e96d30a61546392a6e92. Commit/source/validator hashes matched again at both run completions; the working tree is clean. Fixed embedded build metadata is not a source-commit attestation.No startup budget is raised, lazy boundary changed, or dependency added. No UI markup/CSS changes. The old test shim is removed, leaving no net
dom.setup.tschange against the baseline.The production helper adds 8 lines; most of the net 800-line growth is native PCM observation, cancellation and cleanup proof in the existing benchmark. No new production owner is introduced. Release-note context: reduce repeated Talk PCM Base64 conversion work through available native APIs while preserving older admitted browsers through the original fallbacks.
CI repair and baseline attribution
Initial CI run
40376449648passed both real-Gateway shards and the Control UI performance check. It found two PR-owned harness issues: the native-method suppression inventory needed to include the three new wrappers, and the fixture test's partial PlaywrightPagecast did not satisfy the installed API. The repair gives the installer its actual two-method contract, supplies the disposable handles required by both stub methods, and updates the explicit inventory. Production audio and the injected browser fixture behavior are unchanged.That run also failed
check-test-types-core-2withTS2345atsrc/auto-reply/reply/reply-agent-turn-preparation.test.ts:646:9: theprovidedReplyOperationtest double lacks requiredReplyOperationproperties. This exact diagnostic reproduces as the sole error on the run's clean main parent584e043803862a1df0b7765d76f495058f10329d, after a frozen install, withOPENCLAW_LOCAL_CHECK=0 NODE_DISABLE_COMPILE_CACHE=1 node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.messaging.json --incremental(exit 2). It is separate from the two repaired PR-owned failures; no unrelated source fix is included.Replacement run 40383910396, on corrected head
2be939dee8bc23490d7ee1bb69ce01ebc404be14, passes the repaired checks, all UI unit shards, performance and both real-Gateway shards. Its sole failing test isui/src/e2e/chat-session-file-pdf.e2e.test.ts > Session file PDFs > previews linked PDFs above and below the inline cap and downloads fresh bytes:download.path()reports “Path is not available when connecting remotely. Use saveAs() to save a local copy.” The same sole test and error fail in the latest completed scheduled main run 40380874869, job121776723303. There are no PR-only failing names. Both the PDF test and its E2E support file have identical Git blobs between the tested main parentcfb41dddac89dcf40325273b98ffb1c7a9d209a2and tested mergedc00b70a693f7e3b27fd68205e371acacacca5d4. Current CI remains failed; landing uses the native inherited-failure recovery after confirmed cancellation of the earlier auto request. All logs, exact-name comparison, checkout and source-object evidence are retained locally with the native evidence record.