refactor(ocap-kernel): transport-neutral channel seam (netlayer phase 1)#970
Draft
rekmarks wants to merge 2 commits into
Draft
refactor(ocap-kernel): transport-neutral channel seam (netlayer phase 1)#970rekmarks wants to merge 2 commits into
rekmarks wants to merge 2 commits into
Conversation
…ayer phase 1) Phase 1 of the pluggable-netlayer effort (issue #968). Mechanical, behavior- preserving refactor of the remote-comms subsystem to create a transport-neutral internal seam that later phases extract into standalone @metamask/netlayer* packages. - Replace the libp2p-typed `Channel` with a neutral `NetworkChannel` (`{ peerId, read, write, close, setInactivityTimeout }`) and add a `ChannelProvider` type describing a channel-based transport. - Move all libp2p touchpoints (lpStream framing, inactivity timeout, close-event diagnostics, read-error sniffing/mapping) into `connection-factory.ts`, the sole `ChannelProvider`. `transport.ts`, `channel-utils.ts`, `handshake.ts`, and `types.ts` are libp2p-import-free. - Add neutral error classes to @metamask/kernel-errors: `ChannelResetError`, `IntentionalDisconnectError`, `MessageTooLargeError`; the provider maps raw libp2p read errors onto them so the engine never imports libp2p error types. - Split `transport.ts` into `makeChannelNetlayer` (synchronous engine) plus a signature-compatible `initTransport` wrapper; runtimes are untouched. Deviations recorded in docs/plans/netlayer/master.md; phase-2.md revised against the landed code. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Coverage Report
File Coverage |
Add Unreleased changelog entries for the netlayer phase 1 changes: the three neutral transport error classes in @metamask/kernel-errors and the transport-neutral channel seam refactor in @MetaMask/ocap-kernel. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Netlayer Phase 1 — internal seam refactor
Phase 1 of the 6-phase pluggable-netlayer effort (issue #968; see
docs/plans/netlayer/master.mdanddocs/plans/netlayer/phase-1.md). This is thefirst PR in the stack; Phases 2–6 build on it.
Mechanical, behavior-preserving refactor of the ocap-kernel remote-comms subsystem
to create a transport-neutral internal seam that later phases extract into standalone
@metamask/netlayer*packages. No runtime behavior changes; log strings anderror-classification outcomes are preserved.
What changed
Channelwith a neutralNetworkChannel(
{ peerId, read, write, close, setInactivityTimeout }) and introduced aChannelProvidertype describing a channel-based transport.diagnostics, raw read-error sniffing/mapping) into
connection-factory.ts, now thesole
ChannelProvider.transport.ts,channel-utils.ts,handshake.ts, andtypes.tsare libp2p-import-free.@metamask/kernel-errors:ChannelResetError,IntentionalDisconnectError,MessageTooLargeError.connection-factory.tsmaps rawlibp2p read errors onto them so the engine never imports libp2p error types.
transport.tsintomakeChannelNetlayer(synchronous engine) plus asignature-compatible
initTransportwrapper. The runtimes'initTransportcall sitesare unchanged.
Deviations from the phase-1 plan (recorded in
master.md)ChannelProvider.closeChannel(channel)is single-arg (peerId dropped; carried byNetworkChannel.peerId). Graceful-close/abort body moved to private#closeStream.dialIdempotent→dial;onInboundConnection→onInboundChannel.data(cause-only).initTransportowns the controller, sharessignalwith the provider and the wholestopControllerwith the engine.makeChannelNetlayeris intentionally not exported from the package barrel.Verification
yarn lint:fix,yarn build,yarn test:dev:quiet(root) all green.@metamask/kernel-errorsand@metamask/ocap-kernelunit suites pass; coverage is ator above baseline on all four metrics for both packages.
@ocap/kernel-testintegration,@metamask/kernel-node-runtime, and@metamask/kernel-browser-runtimesuites pass.transport.ts/channel-utils.ts/handshake.ts/types.ts; libp2p error types named only inconnection-factory.ts(+ its test); runtimes'
initTransportcall sites unchanged.🤖 Generated with Claude Code