Skip to content

Conversation

grypez
Copy link
Contributor

@grypez grypez commented Sep 2, 2025

This PR integrates the @ocap/kernel-platforms package across the various monorepo packages which should use it, enabling platform-specific capabilities and endowments for vats. The platformOptions parameter is supplied by the vat worker constructing the vat's supervisor, while the platformConfig parameter is delivered from the kernel as part of the vat initialization command.

Key Changes

  • Extend VatSupervisor to accept optional makePlatform and platformOptions parameters
  • Extend VatConfig type to include optional platformConfig field
  • Integrate platform endowments into vat initialization
  • Integrate platform factories in browser and Node.js runtimes

Note to Reviewers

This diff shows how to endow a host-constrained fetch capability to a vat.

@grypez grypez force-pushed the grypez/use-kernel-platforms branch 2 times, most recently from e464774 to 0c2d4a8 Compare September 2, 2025 18:32
return message;
},
async fetch(url) {
const response = await fetch(url);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The constrained fetch is endowed i.e. available in the global namespace of the vat.

@grypez grypez marked this pull request as ready for review September 3, 2025 16:49
@grypez grypez requested a review from a team as a code owner September 3, 2025 16:49
@grypez grypez enabled auto-merge (squash) September 3, 2025 18:03
@grypez grypez force-pushed the grypez/use-kernel-platforms branch from 9366a07 to 1bd527a Compare September 4, 2025 18:38
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.

A couple of questions.

@grypez do you mind putting up a draft of how you're using this feature so reviewers can better understand where this is going?

Update: Or ah, that's what this diff is?

Comment on lines +305 to +303
...platformEndowments,
// Important, liveslots endowments should be last so they override
...lsEndowments,
Copy link
Member

Choose a reason for hiding this comment

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

Should we just throw an error in case of collisions here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. That would be less silent. Since the comment only makes explicit the strategy we already employed, I think this can be its own (small) issue.

Copy link
Member

Choose a reason for hiding this comment

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

Specifying platform endowments that collide with inescapable global properties should be forbidden. I would prefer if we make this validity check here, or at least create a high-priority issue to it immediately after this PR is merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made a start here, and welcome further discussion and finer requirements.

@grypez grypez force-pushed the grypez/use-kernel-platforms branch from 1bd527a to 9e05cef Compare September 4, 2025 19:21
id: vatId,
kernelStream,
logger: logger.subLogger(vatId),
makePlatform,
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps we can do a dynamic import and use it directly inside VatSupervisor like we do here (you can make a utility isNodeEnv())? It's not ideal that we are making users do this.

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 we are making users do this.

There is certainly a tradeoff between explicitness and simplicity. IMO we should prefer statically analyzable dependencies for the TCB, which in our model includes the worker files. The vat usercode is outside the TCB, and remains simple, i.e. agnostic to these choices.

That said, we should package together choices which must be made jointly but are kept separate for maintainability. See makeNodeJsVatSupervisor for an ergonomic alternative to new VatSupervisor({ ... }).

We can ultimately offer a handful of out-of-the-box workers that provide most users with an ocap kernel that 'just works'.

Copy link
Member

@rekmarks rekmarks Sep 5, 2025

Choose a reason for hiding this comment

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

Hm, this is partially my fault. On second thought, I think we shouldn't force users to specify platform capabilities (i.e. it should be an optional feature). It's not ideal that you can specify a platform config to a vat that cannot satisfy it, but that's okay for now. We should probably store some kind of vat metadata on the kernel side to know which platform capabilities a vat has, if any.

Here's a diff to make the makePlatform argument optional again, but more succinctly:

diff --git a/packages/ocap-kernel/src/VatSupervisor.ts b/packages/ocap-kernel/src/VatSupervisor.ts
index 43e3a194..7e40255f 100644
--- a/packages/ocap-kernel/src/VatSupervisor.ts
+++ b/packages/ocap-kernel/src/VatSupervisor.ts
@@ -41,7 +41,7 @@ type SupervisorConstructorProps = {
   id: VatId;
   kernelStream: DuplexStream<JsonRpcMessage, JsonRpcMessage>;
   logger: Logger;
-  makePlatform: PlatformFactory;
+  makePlatform?: PlatformFactory;
   platformOptions?: Record<string, unknown>;
   vatPowers?: Record<string, unknown> | undefined;
   fetchBlob?: FetchBlob;
@@ -105,7 +105,9 @@ export class VatSupervisor {
     kernelStream,
     logger,
     vatPowers,
-    makePlatform,
+    makePlatform = () => {
+      throw new Error('No platform capabilities provided');
+    },
     platformOptions,
     fetchBlob,
   }: SupervisorConstructorProps) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should probably store some kind of vat metadata on the kernel side to know which platform capabilities a vat has, if any.

We store the vatConfig for each vat, and the platformConfig is a part of the vatConfig.

@rekmarks
Copy link
Member

rekmarks commented Sep 8, 2025

This could use a test for the error thrown since 1099f48. Once that and the merge conflicts are fixed I'll approve!

@grypez
Copy link
Contributor Author

grypez commented Sep 8, 2025

This could use a test for the error thrown since 1099f48. Once that and the merge conflicts are fixed I'll approve!

I think it is due to an architectural constraint that we don't unit test VatSupervisor.#initVat, but I promise to add a test for missing platform in the e2e tests PR.

@grypez grypez force-pushed the grypez/use-kernel-platforms branch from 13162c4 to 88f8f25 Compare September 8, 2025 16:40
@grypez grypez force-pushed the grypez/use-kernel-platforms branch from 88f8f25 to 5017064 Compare September 8, 2025 16:47
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 merged commit 47ee65b into main Sep 8, 2025
23 checks passed
@grypez grypez deleted the grypez/use-kernel-platforms branch September 8, 2025 17:38
grypez added a commit that referenced this pull request Sep 15, 2025
#633)

Closes: #589
Refs: #610 #615 

This PR introduces a new `@ocap/nodejs-test-workers` package and
provides an integration test of the `@ocap/kernel-platforms` endowment
functionality.

## Changes
### `@ocap/nodejs-test-workers`
- Exports the `getWorkerFile` function, which maps a name to a built
worker
- Defines the `mock-fetch` worker, which mocks fetch using the
platformOptions parameter

### `@ocap/kernel-test`
- Adds a test that the kernel endows a vat with a caveated fetch
capability
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