Skip to content

fix(browser): release abandoned native messaging startup payloads - #35344

Merged
OrcaWin merged 1 commit into
mainfrom
OrcaWin/native-messaging-startup-queue-release-independent
Oct 29, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
OrcaWin/native-messaging-startup-queue-release-independent

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 0 0 0 0
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2

ELI5

An extension can retain an old native messaging port after startup fails or it disconnects. That closed port still holds every message queued during startup, even though none can ever be sent. Clear the queue on both terminal paths so keeping the port no longer keeps its abandoned payloads.

Change

Add entry.queued.length = 0 immediately after the transition to closed in the shared endPort() path and explicit disconnect(). Reuse the existing lifecycle, map removal, event delivery and late-connect cleanup. Healthy startup still sends every queued message once, in order.

This is a two-line cleanup fix in the installer used by both extension pages and service workers, introduced with native messaging in #30940. It does not bound startup admission or change the native-host wire.

Measurements

48 fresh serial forced-GC probes exercise the actual production installer, transformed and serialized into a real V8 VM, across page/worker contexts, four startup outcomes and 1/10/100 messages. Each message contains 128 KiB of unique payload; the largest serialized workload is 13,118,990 bytes.

At 100 page messages, after the connect reply settles and while the returned closed port remains retained:

Startup outcome Baseline heap delta Fixed heap delta Published messages, both
Explicit early disconnect 13,208,056 B 86,968 B 0
Failed connect 13,211,400 B 90,344 B 0
Early host disconnect 13,211,400 B 90,344 B 0
Healthy startup, then disconnect 164,592 B 164,632 B 100

Eight heap snapshots independently establish the retaining path: returned port → postMessage closure → entry → queued JSON strings. At ten messages, each aborted baseline retains ten tagged strings / 1,312,000 self bytes; the fixed and healthy cases retain zero. Releasing the port makes it collectible in all 48 rows, including baseline, which controls for harness retention.

Validation

  • External retained-string regression: baseline three failures and one healthy pass; fixed four passes.
  • All 48 behavior probes preserve FIFO byte lengths/hashes, exactly-once healthy delivery, zero abandoned publication, late-event rejection, idempotent disconnect and callback/lastError behavior.
  • Existing installer tests pass 7/7 on both versions. Final focused preload/main-world/native-port/host/framing suites pass 42 tests across five files.
  • Node typecheck, explicit formatting, diff check and all nine changed-code quality groups pass. No precommit-hook claim; the standalone clone did not prepare Husky.
  • All eight source/trace inputs match the measured proposal and pinned baseline. The committed production file has the exact measured SHA256.
  • Required ORCA_BACKGROUND_LAUNCH=1 pnpm check:changed --maxWorkers=2 passed on the author head 9c4f7ad (13/13 checks, 194.0s vs main bbd635e). After a clean rebase onto main 58f9523 it passed again on 3c31f8b (14/14 checks, 166.8s).

Scope and evidence

Executed on Linux Node 26.8.1 / V8 14.6. This is actual-installer heap evidence with controlled bridge replies/events, not a real native host, Electron contextBridge installation, full Orca flow, whole-app heap/RSS, CPU or latency measurement. Worker contexts have forced-GC evidence; snapshots cover page contexts. Cleanup is platform-neutral; macOS and Windows were not executed. No remote protocol, mobile behavior or workspace assumptions change.

Independent tmpfs author clone, frozen-lock dependencies and verified pinned Bun 1.4.4. Evidence: /home/neil/.local/state/orca-electron-audit/native-messaging-startup-queue-candidate/report.md, source manifests, forced-GC rows and heap snapshots, baseline/fixed logs, author verification and implementation.bundle. The original sealed read-only archive is preserved.

@OrcaWin
OrcaWin force-pushed the OrcaWin/native-messaging-startup-queue-release-independent branch from 9c4f7ad to 3c31f8b Compare October 29, 2026 00:36
@OrcaWin
OrcaWin marked this pull request as ready for review October 29, 2026 00:36
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] This PR appears safe to merge.

Summary

Clears abandoned startup messages when a native messaging port closes.

  • Closed native messaging ports release messages queued during startup.

Reviews (1) · Last reviewed commit: "fix(browser): release native messaging s..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 74a183f9-3364-4697-97bf-26d2c3b7c88e
Commits

Reviewing files that changed from the base of the PR and between 828fe5f and 3c31f8b.

Files selected for processing: 1
  • src/preload/browser-extension-native-messaging.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Walkthrough

endPort and local disconnect now clear queued messages when they close a port.

Priority: Low

Merge Risk: Minimal · up to 3c31f

The change releases queued startup messages without altering healthy FIFO delivery or existing disconnect behavior.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: releasing abandoned native messaging startup payloads.
Description check Passed The description provides detailed scope, rationale, implementation details, measurements, testing, and limitations. It does not include an explicit Linked Issue entry, Visual Proof entry with N/A, or …
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description provides detailed scope, rationale, implementation details, measurements, testing, and limitations. It does not include an explicit Linked Issue entry, Visual Proof entry with N/A, or the template checklist and review sections.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@OrcaWin
OrcaWin merged commit 43cf7b4 into main Oct 29, 2026
83 of 85 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant