Skip to content

Conversation

@rekmarks
Copy link
Member

@rekmarks rekmarks commented Jan 17, 2025

Closes #280

Establishes a BroadcastChannel channel between the UI and kernel worker for kernel-UI messages. This removes the necessity of routing this traffic through the offscreen page, and entirely removes the need for stream multiplexing, which is removed. In order to handle reloading the UI (which closes and then reopens the stream and BroadcastChannel on that end), extends the duplex stream synchronization protocol to support "re-synchronization". In consequence, the UI no longer returns its stream before it closes, in order to keep the remote (i.e. kernel) side open for when the UI reopens.

In addition:

  • ensures that DuplexStream.drain() is completely orthogonal to synchronization (i.e. it can be called at any time, before, during, or after (re-)synchronization).
  • uses jsdom and the mock endo environment for @ocap/streams unit tests.
    • The devex isn't worth it.

This currently prevents us from having multiple UI instances at once, but
we will fix this in #371.

For reviewers

To test this PR, just build the branch and check that everything is functioning normally.

@rekmarks rekmarks force-pushed the rekm/broadcast-channel branch from 3c8dc92 to e710d96 Compare January 18, 2025 06:06
@rekmarks rekmarks changed the base branch from main to rekm/sqlite-wasm-to-extension January 18, 2025 06:09
Base automatically changed from rekm/sqlite-wasm-to-extension to main January 21, 2025 17:44
@rekmarks rekmarks force-pushed the rekm/broadcast-channel branch from e710d96 to b16d809 Compare January 21, 2025 21:22
@rekmarks rekmarks changed the title feat: Replace kernel <> UI communication with BroadcastChannel feat: Replace kernel-UI communication with BroadcastChannel Jan 21, 2025
@rekmarks rekmarks changed the title feat: Replace kernel-UI communication with BroadcastChannel refactor: Replace kernel-UI communication with BroadcastChannel Jan 21, 2025
@rekmarks rekmarks marked this pull request as ready for review January 21, 2025 22:18
@rekmarks rekmarks requested a review from a team as a code owner January 21, 2025 22:18
sirtimid
sirtimid previously approved these changes Jan 22, 2025
Copy link
Contributor

@sirtimid sirtimid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the broadcast API supports one-to-many connections, I initially thought that opening the kernel panel both from the extension button and directly from the popup URL would create two channels connecting to the kernel. However, this is not the case. It appears that only one connection at a time is supported. If a second connection is attempted, the stream encounters errors, requiring a restart of the extension. This issue might be outside the scope of this PR, so I am approving it, but I wanted to highlight this concern.

@rekmarks
Copy link
Member Author

Follow-up: #371

@rekmarks rekmarks enabled auto-merge (squash) January 22, 2025 18:08
@rekmarks rekmarks requested a review from sirtimid January 22, 2025 18:09
@rekmarks rekmarks merged commit 12171b2 into main Jan 22, 2025
16 checks passed
@rekmarks rekmarks deleted the rekm/broadcast-channel branch January 22, 2025 18:10
rekmarks added a commit that referenced this pull request Feb 6, 2025
Closes #370 

#349 surfaced a number of long-standing issues with our unit tests.
These issues stemmed from a lack of standardization between packages,
and impedance mismatches between SES / lockdown and Vitest. This PR
performs a variety of changes with a view to standardizing our unit test
setups, and making it easier to debug tests locally.

First and foremost, a `development` mode is introduced to our unit (and
some e2e) tests. This is accessible via the `test:dev` command in all
packages except the root. For all packages, running tests in this mode
disables test coverage, which is generally a distraction during
debugging. For `streams`, it also replaces the `endoify` environment
with the mock version thereof. `development` mode tests do not run in
CI, and do not necessarily pass, since some unit tests (again in
`streams`) must run under lockdown.

Most importantly, we now have a pattern for optionally not running tests
under lockdown. I will perhaps follow up with a conversion of the
extension unit test suite to running under lockdown by default.

Second (and already implied), `streams` tests once again run in the
browser under lockdown.

Third, the extension unit test `mock-endoify` imports have been
consolidated into the extension's test setup file.

Finally, sundry tweaks are made to the test suite for cleanliness
purposes, such as dead code removal.
rekmarks added a commit that referenced this pull request Apr 29, 2025
We removed stream multiplexing in #349 because we no longer had a use
for it. With some of the plans we have for our logger, we once again
find ourselves in a position where we'd like to differentiate traffic
over a single stream. Multiplexing was pretty complex, so we'd prefer
not to go back to it if possible. With these requirements in mind, this
PR introduces "stream splitting" via the function `split()` exported
from `@ocap/streams`.

The idea is simple: pass `split()` a duplex stream and a number of type
predicates, and receive an array of streams in return. Each stream
represents the subset of the parent stream's traffic satisfying the
corresponding predicate. Not very efficient for large numbers of
channels or complex predicates, but our usage should be simple enough.
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.

Replace Kernel Panel-Worker Communication with BroadcastChannel API

3 participants