feat(kernel-utils): narrow - #1052
Draft
ci-belphegor wants to merge 1 commit into
Draft
Conversation
Wrap the derived interface guard in an exo whose methods forward to the base through E(). The base's guard is read over E() too, so one code path serves a local base and a base that later becomes a cross-vat presence. Enforcement is the returned exo's own guard checking; there is no separate check step. A module-level WeakMap records what each narrowing was minted from. It caches the base's guard, so narrowing a narrowing needs no read, and it flattens: the result forwards straight to the original base under both deltas conjoined, keeping a chain of any depth one hop deep. conjoinDeltas takes its keys from the incoming delta alone and refuses one the existing delta dropped, so flattening cannot reinstate authority an intermediate narrowing gave up. A forward for a method the base lacks rejects rather than yielding undefined, so a caller can tell absent authority from a call that returned nothing. narrow has no unit tests in this package: E reads globalThis.HandledPromise when it loads, and these tests run under mock-endoify, which sets that to plain Promise. The three narrowing cases in @ocap/kernel-test cover it end to end in a real vat instead. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ci-belphegor
force-pushed
the
grypez/narrowing-6-narrow
branch
from
September 11, 2026 11:42
900834e to
2285b4d
Compare
ci-belphegor
added this pull request to stack #1060
September 11, 2026 11:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
Wraps the guard algebra in an exo.
narrowreads the base's interface guard throughE(), derives the narrowed guard, and returns an exo whose methods forward to the base.Enforcement is the returned exo's own guard checking — there is no separate check step. That is not only an economy: because
narrowconstructsAND(guard(base), X)rather than verifying a caller-supplied guard,guard(B) ≤ guard(A)holds by construction, which is what makesjoinsound without a pattern subtyping decision procedure.The guard is fetched over
E()whether or not the base is local, so one code path survives the base later being a cross-vat presence.Provenance and flattening. A module-level
WeakMaprecords{ base, delta, baseGuard }per minted exo. Narrowing a narrowing flattens: the result forwards straight to the original base under the conjunction of both deltas, so a chain of any depth costs one guard fetch and stays one hop deep, andjoinreaches across the whole narrowing tree rather than only between siblings.Unmarks three ratchet cases.
Notes for reviewers
The forwarder cannot be hoisted, and this is load-bearing. An earlier attempt lifted the lookup out of the returned closure:
That looks equivalent and is not —
E()refuses an invoker called detached from the proxy that produced it, and the working case came backrejected:Unexpected receiver for "read" method of E("[Alleged: Store]"). The JSDoc records this so it is not reintroduced.The non-null assertion on the method lookup is deliberate and narrowly disabled:
noUncheckedIndexedAccessmakes indexing a string-keyed record yield| undefined, but theE()proxy'sgethandler manufactures an invoker for any property name and never returnsundefined, so the optionality is purely type-level. An optional call (?.) was rejected here on purpose — after PR 8, a misspelled method on a default-guarded base must reject, not silently returnundefined.conjoinDeltastakes its keys from the incoming delta alone and throws when the incoming names a key the existing lacks. Without that, narrowing a narrowing that had dropped a method would compute against the original base's guard and hand back authority the intermediate never had.Observed after unmarking:
ok:read:srv/data/x;rejected:… arg 0: "etc" - Must be: "srv";rejected:target has no method "stat", has ["__getInterfaceGuard__","__getMethodNames__","read"].Stack
PR 6 of 12. Base: #1051.