Skip to content

Commit 46ac74b

Browse files
grypezclaude
andcommitted
fix(kernel-utils): bind method calls in makeRemoteSection via E proxy
Detaching a method via destructuring or assignment strips the CapTP receiver binding and the remote rejects the call as an "Unexpected receiver". Invoke each method through a fresh E(remote)[method] access so the receiver is preserved on every dispatch. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent ac60eeb commit 46ac74b

3 files changed

Lines changed: 14 additions & 9 deletions

File tree

packages/kernel-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
"@chainsafe/libp2p-yamux": "8.0.1",
122122
"@endo/captp": "^4.4.8",
123123
"@endo/errors": "^1.2.13",
124-
"@endo/eventual-send": "^1.3.0",
124+
"@endo/eventual-send": "^1.3.4",
125125
"@endo/exo": "^1.5.12",
126126
"@endo/patterns": "^1.7.0",
127127
"@endo/promise-kit": "^1.1.13",

packages/kernel-utils/src/sheaf/remote.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { GET_INTERFACE_GUARD, makeExo } from '@endo/exo';
33
import { getInterfaceGuardPayload } from '@endo/patterns';
44
import type { InterfaceGuard, MethodGuard } from '@endo/patterns';
55

6-
import type { MetaDataSpec, PresheafSection } from './types.ts';
6+
import { ifDefined } from '../misc.ts';
7+
import type { MetaDataSpec, PresheafSection, Section } from './types.ts';
78

89
/**
910
* Wrap a remote (CapTP) reference as a PresheafSection.
@@ -24,10 +25,10 @@ export const makeRemoteSection = async <M extends Record<string, unknown>>(
2425
remoteRef: object,
2526
metadata?: MetaDataSpec<M>,
2627
): Promise<PresheafSection<M>> => {
27-
const eProxy = E(remoteRef);
28-
2928
const interfaceGuard: InterfaceGuard = await (
30-
eProxy as unknown as { [GET_INTERFACE_GUARD](): Promise<InterfaceGuard> }
29+
E(remoteRef) as unknown as {
30+
[GET_INTERFACE_GUARD](): Promise<InterfaceGuard>;
31+
}
3132
)[GET_INTERFACE_GUARD]();
3233

3334
const { methodGuards } = getInterfaceGuardPayload(
@@ -36,15 +37,18 @@ export const makeRemoteSection = async <M extends Record<string, unknown>>(
3637
methodGuards: Record<string, MethodGuard>;
3738
};
3839

39-
const remote = eProxy as unknown as Record<
40+
const remote = remoteRef as unknown as Record<
4041
string,
4142
(...args: unknown[]) => Promise<unknown>
4243
>;
4344
const handlers: Record<string, (...args: unknown[]) => Promise<unknown>> = {};
4445
for (const method of Object.keys(methodGuards)) {
45-
handlers[method] = async (...args: unknown[]) => remote[method](...args);
46+
handlers[method] = async (...args: unknown[]) =>
47+
(E(remote) as Record<string, (...a: unknown[]) => Promise<unknown>>)[
48+
method
49+
](...args);
4650
}
4751

48-
const exo = makeExo(name, interfaceGuard, handlers);
49-
return { exo, metadata };
52+
const exo = makeExo(name, interfaceGuard, handlers) as unknown as Section;
53+
return ifDefined({ exo, metadata }) as PresheafSection<M>;
5054
};

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,6 +2639,7 @@ __metadata:
26392639
"@chainsafe/libp2p-yamux": "npm:8.0.1"
26402640
"@endo/captp": "npm:^4.4.8"
26412641
"@endo/errors": "npm:^1.2.13"
2642+
"@endo/eventual-send": "npm:^1.3.4"
26422643
"@endo/exo": "npm:^1.5.12"
26432644
"@endo/patterns": "npm:^1.7.0"
26442645
"@endo/promise-kit": "npm:^1.1.13"

0 commit comments

Comments
 (0)