Skip to content

Conversation

@grypez
Copy link
Contributor

@grypez grypez commented Oct 10, 2024

Changes

@ocap/kernel

  • Adds the InitKernel command, which for now is intended to be used only as a reply. The reply contains information about how long the kernel took to initialize, as well as the id of its default vat.

@ocap/extension

  • Moves the kernel types in kernel-worker to a separate file.
  • Moves the Kernel instance into the kernel-worker file.
  • The kernel-worker sends an InitKernel reply to offscreen once it has finished setting up.

@grypez grypez changed the base branch from main to grypez/abstract-message-channel-init October 10, 2024 15:59
@grypez grypez force-pushed the grypez/abstract-message-channel-init branch from 373bdbe to dc78c18 Compare October 10, 2024 17:43
@grypez grypez force-pushed the grypez/move-kernel-to-dedicated-worker-with-message-channel branch from d3f155a to 724d2c6 Compare October 10, 2024 17:44
@grypez grypez force-pushed the grypez/abstract-message-channel-init branch 2 times, most recently from 732004d to 773957f Compare October 10, 2024 18:02
Base automatically changed from grypez/abstract-message-channel-init to main October 10, 2024 18:06
@grypez grypez force-pushed the grypez/move-kernel-to-dedicated-worker-with-message-channel branch from 724d2c6 to cb6e33f Compare October 10, 2024 18:08
@grypez grypez marked this pull request as ready for review October 10, 2024 18:10
@grypez grypez requested a review from a team as a code owner October 10, 2024 18:10
@grypez grypez force-pushed the grypez/move-kernel-to-dedicated-worker-with-message-channel branch from cb6e33f to 70e43cc Compare October 10, 2024 18:37
@grypez grypez changed the title Move kernel to dedicated worker with message channel feat(extension): Move kernel to dedicated worker Oct 10, 2024
@grypez grypez changed the title feat(extension): Move kernel to dedicated worker feat(extension): Move Kernel instance to kernel-worker Oct 10, 2024
Copy link
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

Overall a great step forward!

await handleKernelCommand(message);
} else {
console.error('Received unexpected message', message);
logger.debug(`Received unexpected message ${stringify(message)}`);
Copy link
Member

Choose a reason for hiding this comment

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

When do we expect to hit this now, and why do we downgrade it to a debug log?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missed this from the previous approach I was taking. We don't expect to hit it, and it should be an error.

More broadly I have been thinking about what log levels we should use when, and I think in the case where we expect to sometimes receive and ignore unhandleable messages the right log level is info or log, and the string .debug( ought to be more or less uncommitable to our codebase.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think logs should be either error (as necessary, when undefined / invalid / unexpected states occur), info (sparingly, to provide feedback for actions), or probably not be committed. warn can useful for third parties, which isn't relevant to us just yet.

Comment on lines 72 to 78
await reply({
method: KernelCommandMethod.InitKernel,
params: { defaultVat: defaultVatId, initTime: performance.now() - start },
});
Copy link
Member

Choose a reason for hiding this comment

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

The introduction of the InitKernel method creates an unfortunate asymmetry in the kernel commands and our notion of "replies" from the kernel to the background ("console"). We probably will want to establish a notion of unprompted messages ("notifications"?) from the kernel to the console, but I think it would be better if we deferred that until later. We don't need this method to exist now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If by 'this method' you mean the unprompted messages you referred to, I agree we don't need them now. But I am using the InitKernel method to prevent the offscreen from sending messages to the kernel before it is ready to receive them, so some form of init message is necessary for this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, we shouldn't need to do that. Specifically, it should be a concern of the streams. In other words, by the time the offscreen has a reference to the kernel worker and can send it messages, the kernel worker should be ready to receive them. Right now, there would be interval where messages could theoretically be sent before the kernel worker's stream is initialized, so we can leave it in for now. However, I will try to fundamentally solve the issue by modifying the message channel protocol following #142.

@rekmarks rekmarks force-pushed the grypez/move-kernel-to-dedicated-worker-with-message-channel branch from 8d57666 to 4113bec Compare October 10, 2024 21:29
await handleKernelCommand(message);
isKernelCommand(message)
? await kernelWorker.sendMessage(message)
: logger.debug('Received unexpected message', message);
Copy link
Member

Choose a reason for hiding this comment

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

Should this also be an error?

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 don't think so. The background stream passes any Json and may reasonably receive messages which are not KernelCommands. It should be an info though.

Copy link
Member

Choose a reason for hiding this comment

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

It may do so in the future if we decide to make it so, but for now, in this context, I think it's fine to let it be an error. In the production setting, there'll be a different connection entirely in place here.

@rekmarks
Copy link
Member

I agree it would be reasonable to decide that different messages can be sent over the streams. However, we don't intend for that to be the case right now, and it's therefore an error state: #146

Copy link
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

LGTM!

@grypez grypez enabled auto-merge (squash) October 10, 2024 22:35
@grypez grypez force-pushed the grypez/move-kernel-to-dedicated-worker-with-message-channel branch from 217cb81 to cc274b8 Compare October 10, 2024 22:36
@grypez grypez merged commit 033ea62 into main Oct 10, 2024
@grypez grypez deleted the grypez/move-kernel-to-dedicated-worker-with-message-channel branch October 10, 2024 22:38
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.

3 participants