Skip to content

Conversation

@grypez grypez force-pushed the grypez/offscreen-doc branch 4 times, most recently from 17bf8ef to ed408be Compare October 1, 2024 19:29
@grypez grypez changed the title (draft) offscreen doc (draft) Move kernel to dedicated worker Oct 1, 2024
@grypez grypez force-pushed the grypez/offscreen-doc branch 2 times, most recently from c68bf18 to c5dce79 Compare October 1, 2024 20:08
Copy link
Contributor

@FUDCo FUDCo left a comment

Choose a reason for hiding this comment

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

Not done looking at this, but after making three or four comments I realized that since it's a big PR it would be better to issue these comments as they come instead of letting the pile up.

@grypez grypez force-pushed the grypez/offscreen-doc branch from c5dce79 to 13ccd91 Compare October 1, 2024 21:14
Copy link
Contributor

@FUDCo FUDCo left a comment

Choose a reason for hiding this comment

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

For some reason GitHub spontaneously put me into review mode when I tried to post an individual comment.

Comment on lines 311 to 320
case CommandMethod.LaunchVat:
await kernel
.launchVat({
id: params,
port: command.ports[0],
})
.then((vat) => params === defaultVatId && resolveDefaultVat(vat));
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Further thought: my comments above notwithstanding, I don't think the port should be parameter to LaunchVat in this way at all. The kernel should never even see a port (quite possibly this is already on your roadmap). Instead (1) the communications pathway to the vat should already be whatever our general abstraction for a communications pathway is (a stream, I think? Or a stream pair? I'm still a little fuzzy on the unidirectional vs. bidirectional affordances of the stream abstraction), and (2) the kernel ought to be in the driver's seat, in that the invoker of LaunchVat should not be assumed to be the provider of the run-time container (iframe, process, whatever) that the vat will run in, but that should be separately provisioned for the kernel in response to a service call that the kernel makes; the entity that provides the kernel with this service should be provisioned at kernel startup time as an initialization parameter by whoever creates the kernel in the first place. This way the we decouple the Kernel class itself from the fact that in the base use case it runs in a web browser. In the standalone server use case, a vat process may get launched by an entirely different entity from the entity that launched the kernel itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with both thoughts you've laid out and hope to see the kernel there soon. I think a clean worker provisioning service falls under #99, though to the best of my knowledge it will need to implement something similar to what I have here to set up both ends of the channel. To (2), in this PR the background does not have access to launchVat, rather createVat, and the provision of the worker is handled via communications between the glue and the kernel. But this should definitely go away in the future. To (1), I think our ideal path forward involves reading and writing messages over a stream, but since we cannot pass a stream over *.postMessage or a message port over a (generic) stream I am willing to be a little in the ditch in this PR as long as we're getting closer to our destination.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. This PR doesn't have to be the final word. I just wanted to make sure we were pointed in the same direction, which it sounds like we are.

const { method, params } = systemCall;
console.log('received message: ', method, params);

switch (method) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This may be a good spot to point out something that's been bothering me for a while about how we have defined the various message types: I don't think we should be dispatching to reply handlers based on method, but rather on the specific request that they are the reply to, and probably used to resolve a promise from the original message send operation that issued the request in the first place.

@grypez grypez force-pushed the grypez/offscreen-doc branch from 13ccd91 to 329cfd7 Compare October 1, 2024 22:57
@grypez grypez changed the base branch from main to grypez/structured-types October 1, 2024 22:57
Comment on lines 258 to 268
const command = port
? { params: paramsArg, method: methodArg, ports: [port] }
: { params: paramsArg, method: methodArg };

if (!isKernelCommand(command)) {
console.error('invalid command', command);
return;
}

const { method, params } = event.data;
console.log('received message: ', method, params);
const { method, params } = command as KernelCommand;
Copy link
Contributor

@FUDCo FUDCo Oct 1, 2024

Choose a reason for hiding this comment

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

Why build up the command object only to destructure it again 10 lines later? It seems like its only utility is to have a thing to pass to isKernelCommand, which is already a bit of a mess. At this point I don't think it adds value as a separate function in a separate module. RIght here the default case of the switch checks method and the various method cases should validate their args themselves so that all the logic w.r.t a given command is in just one place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In principle the destructuring enforces that { method, params } is on the diagonal of the product type matrix, which makes the type inference work properly in the switch-case blocks.

Copy link
Contributor

Choose a reason for hiding this comment

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

This sounds like the tail wagging the dog. Probably worth a deeper conversation.

@grypez grypez force-pushed the grypez/offscreen-doc branch 3 times, most recently from faa3c1f to f2ce5e6 Compare October 3, 2024 18:24
@grypez grypez force-pushed the grypez/structured-types branch from e1256d5 to 54a0c2b Compare October 3, 2024 18:25
@grypez grypez force-pushed the grypez/offscreen-doc branch 2 times, most recently from 79d13d9 to 09469c3 Compare October 3, 2024 18:29
@grypez grypez force-pushed the grypez/structured-types branch from 54a0c2b to 0d2d329 Compare October 3, 2024 18:44
Base automatically changed from grypez/structured-types to main October 3, 2024 18:47
@grypez grypez force-pushed the grypez/offscreen-doc branch from 09469c3 to 71fcb90 Compare October 4, 2024 00:25
@grypez grypez force-pushed the grypez/offscreen-doc branch from 71fcb90 to 01d8684 Compare October 4, 2024 07:32
@rekmarks rekmarks changed the title (draft) Move kernel to dedicated worker Do Not Merge: Move kernel to dedicated worker Oct 8, 2024
@grypez grypez force-pushed the grypez/offscreen-doc branch 3 times, most recently from f79d526 to 02999f3 Compare October 10, 2024 03:17
@rekmarks
Copy link
Member

All components of this have been merged.

@rekmarks rekmarks closed this Oct 11, 2024
@rekmarks rekmarks deleted the grypez/offscreen-doc branch October 11, 2024 05:44
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.

feat(extension): Move kernel to dedicated worker

4 participants