Commit c1464ed
fix(ocap-kernel): enforce one delivery per crank, fix rollback cache staleness (#879)
As it turns out, we have been violating the invariant that a crank
consists of the delivery of a single message or notification. Since at
least the introduction of `KernelQueue.ts` in #484, one iteration of the
kernel's run queue—which should be equivalent to a crank—has actually
been able to deliver an unbounded number of messages.
This means that, if a delivery aborts mid-crank,
`rollbackCrank('start')` reverts all deliveries in the crank (including
earlier successful ones), creating inconsistency with vat in-memory
state and leaving promise subscriptions permanently dangling.
This PR ensures that we correctly implement cranks via the kernel's run
queue loop as described below.
## Summary
- Enforce one run-queue item per crank (change `while` to `if` in
KernelQueue generator) and fix stale `StoredQueue` caches after
`rollbackCrank` by refreshing the run queue and invalidating
`runQueueLengthCache`
- Reject JS promise subscriptions when a crank aborts with vat
termination; fix `terminateVat` callback in Kernel to avoid deadlock by
bypassing `VatManager.terminateVat()` (which calls `waitForCrank()`)
- Simplify the run queue implementation; in lieu of an async generator +
loop, use a single loop with helper functions
- Improve error messages for splat cases (revoked, no owner, no object,
endpoint gone) and handle vanished endpoints in KernelRouter delivery
- Fix SubclusterManager to catch rejected bootstrap promises
- Add orphaned ephemeral exo tests (unit + e2e)
- Glossary formatting and crank definition correction
## Test plan
- [x] Existing unit tests updated and passing (`KernelQueue.test.ts`,
`KernelRouter.test.ts`, `crank.test.ts`, `syscall-validation.test.ts`,
`vat-lifecycle.test.ts`)
- [x] New unit test for orphaned ephemeral exos
(`orphaned-ephemeral-exo.test.ts`)
- [x] New e2e test for orphaned ephemeral exos
(`orphaned-ephemeral-exo.test.ts` in kernel-node-runtime)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **High Risk**
> High risk because it changes core `KernelQueue`/`KernelRouter` crank
semantics, rollback behavior, and how message failures propagate
(resolve vs reject), which can affect delivery ordering, retries, and
many callers/tests.
>
> **Overview**
> **Kernel crank semantics are tightened and error propagation is made
consistent.** `KernelQueue.run` is rewritten to process *exactly one*
run-queue item per crank, and JS-side subscriptions created by
`enqueueMessage` now support both `resolve` and `reject` so rejected
kernel promises reject the returned promise.
>
> **Rollback and termination handling are hardened.** `rollbackCrank`
now refreshes the stored run-queue and invalidates length caches to
avoid stale in-memory state after DB rollback, and abort+terminate paths
immediately reject the aborted send’s subscription. Kernel vat
termination during a crank bypasses `terminateVat()` to avoid deadlock.
>
> **Message “splat” cases are clearer and better handled.**
`KernelRouter` improves errors for
revoked/no-owner/no-object/endpoint-gone cases, resolves splat
rejections using the current promise decider, and treats vanished
endpoints as a splat with promise rejection.
>
> **Tests/docs updated and expanded.** Many tests are updated to expect
promise rejections (including remote comms, revocation, lifecycle), new
unit+e2e coverage is added for orphaned ephemeral exos across vat
restart, `kernel-utils` exports a new `isCapData` guard used to rethrow
bootstrap errors as real `Error`s, and the glossary is
expanded/clarified (kernel promises/decider/crank definition).
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
233587c. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 6600be0 commit c1464ed
31 files changed
Lines changed: 988 additions & 316 deletions
File tree
- docs
- packages
- evm-wallet-experiment/test/integration
- extension/test/e2e
- kernel-node-runtime/test
- e2e
- vats
- kernel-test/src
- vats
- kernel-ui/src/components
- kernel-utils/src
- ocap-kernel/src
- remotes/kernel
- store
- methods
- vats
Large diffs are not rendered by default.
Lines changed: 15 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
274 | 273 | | |
275 | 274 | | |
276 | 275 | | |
| |||
281 | 280 | | |
282 | 281 | | |
283 | 282 | | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
294 | 290 | | |
295 | 291 | | |
296 | 292 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
| 127 | + | |
128 | 128 | | |
129 | 129 | | |
Lines changed: 71 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
Lines changed: 43 additions & 50 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
582 | 582 | | |
583 | 583 | | |
584 | 584 | | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
593 | | - | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
594 | 590 | | |
595 | | - | |
| 591 | + | |
| 592 | + | |
596 | 593 | | |
597 | | - | |
598 | | - | |
599 | | - | |
| 594 | + | |
| 595 | + | |
600 | 596 | | |
601 | 597 | | |
602 | 598 | | |
| |||
761 | 757 | | |
762 | 758 | | |
763 | 759 | | |
764 | | - | |
765 | | - | |
766 | | - | |
767 | | - | |
768 | | - | |
769 | | - | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
770 | 765 | | |
771 | 766 | | |
772 | 767 | | |
| |||
844 | 839 | | |
845 | 840 | | |
846 | 841 | | |
847 | | - | |
848 | | - | |
849 | | - | |
850 | | - | |
851 | | - | |
852 | | - | |
853 | | - | |
854 | | - | |
855 | | - | |
856 | | - | |
857 | | - | |
858 | | - | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
859 | 853 | | |
860 | 854 | | |
861 | 855 | | |
| |||
920 | 914 | | |
921 | 915 | | |
922 | 916 | | |
923 | | - | |
924 | | - | |
925 | | - | |
926 | | - | |
927 | | - | |
928 | | - | |
929 | | - | |
930 | 917 | | |
931 | 918 | | |
932 | 919 | | |
933 | | - | |
934 | | - | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
935 | 929 | | |
936 | 930 | | |
937 | 931 | | |
| |||
970 | 964 | | |
971 | 965 | | |
972 | 966 | | |
973 | | - | |
974 | | - | |
975 | | - | |
976 | | - | |
977 | | - | |
978 | | - | |
979 | | - | |
980 | | - | |
981 | | - | |
982 | | - | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
983 | 976 | | |
984 | 977 | | |
985 | 978 | | |
| |||
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
Lines changed: 21 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
53 | 57 | | |
54 | 58 | | |
55 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
0 commit comments