Skip to content

perf(browser): count encoded envelopes without a second serialization - #140882

Merged
steipete merged 1 commit into
mainfrom
codex/perf14-browser-envelope-count
Sep 7, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf14-browser-envelope-count

Conversation

@steipete

@steipete steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Closes #140881

Additional instructions

Maintainer edits are enabled on this repository-owned branch.

What Problem This Solves

Browser node responses build a second full JSON string solely to measure the serialized payload inside the outer node frame. That allocation is discarded after budget admission.

Why This Change Was Made

Keep native serialization once, then count its exact quoted byte length with UTF-8 byteLength, statics-free quote/backslash scans and typed toUSVString handling for raw lone surrogates. The private helper accepts native compact JSON output; actual final framing and receiver validation stay unchanged.

User Impact

Twenty actual delegated-command/framing/receiver flows preserve returned and wire hashes, native errors, file handling and exact 24 MiB admission. Sampled allocation falls by about 22.55 MB per owner operation for an 8 MiB PDF and 44.79 MB for 16 MiB aggregate files; corresponding framing/receiver observations are consistent.

Owner retention matches baseline. Malformed raw JSON can still require a replacement string, with no demonstrated allocation saving in that control. No small-output throughput, strict non-regression, peak/RSS or whole-Gateway claim is made.

Evidence

  • 63 focused tests, full changed-file checks and final P2 review pass. Three exact-limit cases cover minus one/equal/plus one with controls, Unicode, escapes and lone surrogates.
  • 27 private counter oracle cases and 134 native serialization-domain checks preserve native JSON/rawJSON behavior. Native serialization still owns unknown-object traversal and its errors.
  • Actual control service, routes, file read/MIME/base64, Gateway request framing and receiver validation/persistence are exercised. Playwright/CDP and RPC transport/ack boundaries are synthetic.
  • The rejected sticky-RegExp prototype is excluded; no gain against that prototype is credited. A longer small-output control failed fixture validation and is excluded entirely, so it supplies no throughput or parity claim.
  • Production net +34 lines; tests net zero. Per-file/aggregate/encoded limits, routes and authorization remain unchanged. No new public serializer, SDK/configuration or full build requirement.

Related #103328 established the budget. Active #128289 and #126870 change independent invocation authority/lifecycle behavior; preserve those guards if they land first.

@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 7, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 7, 2026, 2:14 AM ET / 06:14 UTC.

ClawSweeper review

What this changes

The browser plugin measures encoded node responses without serializing them twice and adds exact-limit coverage while consolidating existing tests.

Merge readiness

✅ Ready for maintainer review

The optimization remains useful: current main and the latest release still allocate the second JSON string. No actionable correctness or security defect was found in the introduced patch.

Priority: P2
Reviewed head: 90e3cada354bef4ded98823b55ae9c37eeb38378

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with meaningful boundary coverage and no identified blocking defect; reported measurements remain contributor-supplied.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied MEMBER status exempts this PR from contributor proof requirements, and the patch does not change authority. Its body reports producer/framing/receiver parity and allocation measurements with synthetic transport boundaries; those measurements were not independently rerun.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied MEMBER status exempts this PR from contributor proof requirements, and the patch does not change authority. Its body reports producer/framing/receiver parity and allocation measurements with synthetic transport boundaries; those measurements were not independently rerun.
Evidence reviewed 7 items Introduced production change: The pinned merge-base-to-head diff changes only size accounting: native payload serialization and the 24 MiB comparison remain. The counter adds outer quotes, quote/backslash expansion, and the three-byte difference between UTF-8 replacement and JSON escaping for each raw lone surrogate.
Current main still performs the extra serialization: The fetched main revision still measures Buffer.byteLength(JSON.stringify(serialized)); this PR's central optimization is absent.
Latest release retains the original implementation: The v2026.9.2 source also performs the second serialization at line 512; the optimization is not already shipped in the supplied latest release.
Findings None None.
Security None None.

How this fits together

The browser plugin executes delegated browser commands on a connected node and packages results and downloaded files for the Gateway. Its encoded-size check limits responses before transport; the Gateway validates files before saving them.

flowchart LR
  A[Delegated browser command] --> B[Node browser routes]
  B --> C[Result and bounded files]
  C --> D[Native JSON serialization]
  D --> E{Encoded size within limit}
  E -->|Yes| F[Gateway framing and file validation]
  E -->|No| G[Payload limit error]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +34, Tests 0. Total +34 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 35 1 +34
Tests 1 32 32 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 67 33 +34

Review metrics

Metric Value Why it matters
Production versus test growth Production +34 net lines; tests 0 net lines The added private counter has a stated allocation-reduction purpose, while test consolidation offsets the new boundary cases.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #140881
Summary: This PR directly implements the linked allocation-reduction request; the earlier merged download work established the contract it preserves.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Keep size accounting private to the browser response producer while preserving native serialization, exact admission limits, and existing transport validation.

Do we have a high-confidence way to reproduce the issue?

Yes, source establishes that every successful response through this admission path creates a second JSON string solely to count bytes; no runtime reproduction was executed during this read-only review.

Is this the best way to solve the issue?

Yes, the private counter removes the discarded serialization while retaining native object traversal, serialization errors, and the existing wire contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against d8b597be60c4.

Labels

Label justifications:

  • P2: This is a bounded allocation improvement for browser node responses, with no demonstrated urgent user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied MEMBER status exempts this PR from contributor proof requirements, and the patch does not change authority. Its body reports producer/framing/receiver parity and allocation measurements with synthetic transport boundaries; those measurements were not independently rerun.

Evidence

What I checked:

  • Introduced production change: The pinned merge-base-to-head diff changes only size accounting: native payload serialization and the 24 MiB comparison remain. The counter adds outer quotes, quote/backslash expansion, and the three-byte difference between UTF-8 replacement and JSON escaping for each raw lone surrogate. (extensions/browser/src/node-host/invoke-browser.ts:89, 90e3cada354b)
  • Current main still performs the extra serialization: The fetched main revision still measures Buffer.byteLength(JSON.stringify(serialized)); this PR's central optimization is absent. (extensions/browser/src/node-host/invoke-browser.ts:512, d8b597be60c4)
  • Latest release retains the original implementation: The v2026.9.2 source also performs the second serialization at line 512; the optimization is not already shipped in the supplied latest release. (extensions/browser/src/node-host/invoke-browser.ts:512, 3928bad9badf)
  • Independent boundary oracle: Three cases compare native nested-JSON byte lengths at limit minus one, exactly the limit, and limit plus one, covering controls, escapes, Unicode and lone surrogates. Existing dense-backslash rejection remains, and the consolidated profile tests retain both rejection scenarios. Tests were inspected, not executed. (extensions/browser/src/node-host/invoke-browser.test.ts:704, 90e3cada354b)
  • Producer and receiver boundaries: The complete producer retains shallow route-owned file collection and existing file limits. The receiver validates references and decodes all files before persistence. The private counter adds no public plugin API, configuration, storage format, or authority-bearing value. (extensions/browser/src/browser/proxy-files.ts:86, 90e3cada354b)
  • Reported performance evidence and review continuity: The complete captured PR body reports 20 delegated-command/framing/receiver flows with matching result and wire hashes, and sampled allocation reductions for large file envelopes. It explicitly identifies synthetic CDP/RPC boundaries and excludes throughput, peak-memory and whole-Gateway claims. No raw measurement artifact is linked. The previous completed review covered this same head and retained no findings or published rank-up moves. (90e3cada354b)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-07T05:42:56.329Z sha 90e3cad :: needs maintainer review before merge. :: none

@steipete
steipete marked this pull request as ready for review September 7, 2026 06:10
@steipete
steipete merged commit 1a970dc into main Sep 7, 2026
160 checks passed
@steipete
steipete deleted the codex/perf14-browser-envelope-count branch September 7, 2026 06:57
@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Oct 13, 2026
Consolidate image traversal, request observation ownership, bus waiters,
Slack response classification, Node selection and WebSocket decoding.
Retire the generic Windows executable export after its Node caller moved;
keep trusted taskkill/PowerShell paths and all environment validation.
Remove duplicate planner validation and unsupported private lifecycle guards.
Keep external evidence validation, security authority, resource limits and
ordinary write-capable shutdown settlement.

Also preserve WhatsApp audio preflight when enabling message actions and
avoid recording a POSIX pipe-drain failure during the normal TERM grace.

Best-effort tradeoffs accepted:
- Bus cloning trusts its private typed event union. 0ebeee8 added the
  unsupported-kind throw only for lint; fabricated internal kinds now fail
  naturally, and a new typed variant must update this owner at compile time.
- Overlapping private QA driver transitions are unsupported; callers await
  them. #113855 introduced synthetic interleavings, not a human incident.
- Canonical smoke selection is trusted instead of revalidated; #114055 was
  an ownership cutover. A future selector defect belongs at that owner.
- Wire image inputs are parsed JSON trees. #71311 introduced no human
  cyclic-input incident; unsupported internal cyclic objects are best effort.
- Fabricated cyclic/BigInt tool outputs now fail clearly instead of becoming
  empty evidence. 195e721 added stabilization, not a human incident.
- Reinstalling the private AIMock mount is unsupported. bdc9c60 added
  speculative guards; the actual owner installs it once before start.
- Obsolete repeated observer disposal after port reuse can remove the newer
  QA lookup. 6386dc4 was an affinity repair, not a disposal incident;
  normal unique-port ownership and stop ordering prevent that lifecycle.
- Local non-federated Matrix joins fail immediately on setup errors; #64489
  added initial coverage, not a reported transient-join incident. Rerun the
  QA command after an unusual setup fault.
- Artifact publication is trusted after its awaited atomic writer. #92606
  added suite execution, not a missing-write incident; deletion afterward
  is reported by normal readers.
- Native browser JSON needs no branded rawJSON surrogate workaround.
  #140882 added that generality without a human incident; a future branded
  producer must own its serialization contract.
- Insertion-only pending caches clear directly on settlement. #113926 and
  #128379 supplied no human successor-eviction incident; no replacement can
  precede these finalizers. Real close-time successor checks stay.
- Re-registering the identical private borrowed-relay handle is unsupported.
  #128379/#133706 introduced no such incident; the owner creates fresh handles
  and current authority and distinct-successor comparisons remain.
- Inconclusive Linux process snapshots conservatively stay alive until the
  next check. #132230/#131643 used controlled fault injection, not a human
  actual-use incident. Final unconfirmed settlement retains state for retry.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
…0889)

Consolidate image traversal, request observation ownership, bus waiters,
Slack response classification, Node selection and WebSocket decoding.
Retire the generic Windows executable export after its Node caller moved;
keep trusted taskkill/PowerShell paths and all environment validation.
Remove duplicate planner validation and unsupported private lifecycle guards.
Keep external evidence validation, security authority, resource limits and
ordinary write-capable shutdown settlement.

Also preserve WhatsApp audio preflight when enabling message actions and
avoid recording a POSIX pipe-drain failure during the normal TERM grace.

Best-effort tradeoffs accepted:
- Bus cloning trusts its private typed event union. f993a27 added the
  unsupported-kind throw only for lint; fabricated internal kinds now fail
  naturally, and a new typed variant must update this owner at compile time.
- Overlapping private QA driver transitions are unsupported; callers await
  them. openclaw#113855 introduced synthetic interleavings, not a human incident.
- Canonical smoke selection is trusted instead of revalidated; openclaw#114055 was
  an ownership cutover. A future selector defect belongs at that owner.
- Wire image inputs are parsed JSON trees. openclaw#71311 introduced no human
  cyclic-input incident; unsupported internal cyclic objects are best effort.
- Fabricated cyclic/BigInt tool outputs now fail clearly instead of becoming
  empty evidence. 5929e9a added stabilization, not a human incident.
- Reinstalling the private AIMock mount is unsupported. e98e098 added
  speculative guards; the actual owner installs it once before start.
- Obsolete repeated observer disposal after port reuse can remove the newer
  QA lookup. ace0e05 was an affinity repair, not a disposal incident;
  normal unique-port ownership and stop ordering prevent that lifecycle.
- Local non-federated Matrix joins fail immediately on setup errors; openclaw#64489
  added initial coverage, not a reported transient-join incident. Rerun the
  QA command after an unusual setup fault.
- Artifact publication is trusted after its awaited atomic writer. openclaw#92606
  added suite execution, not a missing-write incident; deletion afterward
  is reported by normal readers.
- Native browser JSON needs no branded rawJSON surrogate workaround.
  openclaw#140882 added that generality without a human incident; a future branded
  producer must own its serialization contract.
- Insertion-only pending caches clear directly on settlement. openclaw#113926 and
  openclaw#128379 supplied no human successor-eviction incident; no replacement can
  precede these finalizers. Real close-time successor checks stay.
- Re-registering the identical private borrowed-relay handle is unsupported.
  openclaw#128379/openclaw#133706 introduced no such incident; the owner creates fresh handles
  and current authority and distinct-successor comparisons remain.
- Inconclusive Linux process snapshots conservatively stay alive until the
  next check. openclaw#132230/openclaw#131643 used controlled fault injection, not a human
  actual-use incident. Final unconfirmed settlement retains state for retry.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: browser maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Browser node responses allocate a second string only to count encoded bytes

1 participant