-
Notifications
You must be signed in to change notification settings - Fork 6
feat(extension): Move Kernel instance to kernel-worker #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(extension): Move Kernel instance to kernel-worker #141
Conversation
373bdbe to
dc78c18
Compare
d3f155a to
724d2c6
Compare
732004d to
773957f
Compare
724d2c6 to
cb6e33f
Compare
cb6e33f to
70e43cc
Compare
rekmarks
left a comment
There was a problem hiding this 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)}`); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| await reply({ | ||
| method: KernelCommandMethod.InitKernel, | ||
| params: { defaultVat: defaultVatId, initTime: performance.now() - start }, | ||
| }); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
8d57666 to
4113bec
Compare
packages/extension/src/offscreen.ts
Outdated
| await handleKernelCommand(message); | ||
| isKernelCommand(message) | ||
| ? await kernelWorker.sendMessage(message) | ||
| : logger.debug('Received unexpected message', message); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
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 |
rekmarks
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
217cb81 to
cc274b8
Compare
Changes
@ocap/kernel@ocap/extension