Skip to content

feat(kernel-errors): standardize kernel errors observable in vat-land#913

Open
rekmarks wants to merge 3 commits intomainfrom
rekm/standardize-kernel-errors
Open

feat(kernel-errors): standardize kernel errors observable in vat-land#913
rekmarks wants to merge 3 commits intomainfrom
rekm/standardize-kernel-errors

Conversation

@rekmarks
Copy link
Copy Markdown
Member

@rekmarks rekmarks commented Apr 1, 2026

Summary

Kernel errors surfaced to vats as promise rejections previously had no consistent format — some were plain strings, some Error objects, with no way for vat code to programmatically identify or categorize them.

This PR introduces a machine-readable error format: [KERNEL:<CODE>] detail for expected errors (vat code can handle gracefully) and [KERNEL:VAT_FATAL:<CODE>] detail for fatal errors (vat gets terminated).

  • Add kernel-error.ts to @metamask/kernel-errors with KernelErrorCode types, KERNEL_ERROR_PATTERN regex, and isKernelError/getKernelErrorCode/isFatalKernelError detection utilities
  • Add makeKernelError and makeFatalKernelError helpers to kernel-marshal.ts, importing shared types from @metamask/kernel-errors
  • Migrate all error sites across KernelRouter, RemoteManager, VatHandle, VatSyscall, and KernelServiceManager
  • Remove kernel-internal details (peer IDs) from error messages sent to vats

Note: Four sites previously used kser('string') which serialized a plain string as the rejection value. These now use makeKernelError(...) which serializes an Error object. This is an intentional wire-format change — vat code that deserialized the rejection and checked typeof reason === 'string' would need updating.

Testing

New unit tests cover the detection utilities (kernel-error.test.ts) and factory functions (kernel-marshal.test.ts), including round-trip verification through the @metamask/kernel-errors detection utilities. All existing unit tests in @metamask/ocap-kernel and integration tests in @ocap/kernel-test pass with updated assertions matching the new [KERNEL:*] format.


Note

Medium Risk
Changes the rejection wire format for multiple kernel promise failures from ad-hoc strings/errors to structured [KERNEL:*] Error messages, which may break vat code that inspects rejection values. Touches core message routing, remote handling, vat termination, and syscall fatal-error reporting paths.

Overview
Standardizes errors surfaced to vat-land as promise rejections by introducing a machine-readable kernel error message format: expected errors as [KERNEL:<CODE>] <detail> and fatal errors as [KERNEL:VAT_FATAL:<CODE>] <detail>.

Adds @metamask/kernel-errors utilities and types (KernelErrorCode, KERNEL_ERROR_PATTERN, isKernelError, getKernelErrorCode, isFatalKernelError) plus tests, and updates kernel-marshal with makeKernelError/makeFatalKernelError (deprecating makeError).

Migrates key kernel rejection sites (KernelRouter, RemoteManager, VatHandle, VatSyscall, KernelServiceManager) to emit these coded errors and updates integration/unit tests to assert against the new [KERNEL:...] strings (including removing peerId details from some remote-connection-loss messages).

Written by Cursor Bugbot for commit 3b6db98. This will update automatically on new commits. Configure here.

rekmarks and others added 3 commits April 1, 2026 16:43
Introduce a machine-readable error format for kernel errors surfaced to
vats as promise rejections: `[KERNEL:<CODE>] detail` for expected errors
and `[KERNEL:FATAL:<CODE>] detail` for fatal ones.

- Add `kernel-error.ts` to `@metamask/kernel-errors` with
  `ExpectedKernelErrorCode`, `FatalKernelErrorCode`, `KernelErrorCode`
  types, `KERNEL_ERROR_PATTERN` regex, and `isKernelError`,
  `getKernelErrorCode`, `isFatalKernelError` detection utilities
- Add `makeKernelError` and `makeFatalKernelError` to `kernel-marshal.ts`,
  importing the shared types from `@metamask/kernel-errors`
- Migrate all 17+ error sites in KernelRouter, RemoteManager, VatHandle,
  VatSyscall, and KernelServiceManager to the new helpers
- Update all affected test assertions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fatal kernel errors terminate the offending vat, not the kernel itself.
Rename the infix from FATAL to VAT_FATAL to reflect this:
`[KERNEL:VAT_FATAL:<CODE>] detail`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Import FatalKernelErrorCode in VatSyscall.ts instead of inline union
- Add unit tests for makeKernelError and makeFatalKernelError with
  round-trip verification through kernel-errors detection utilities

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rekmarks rekmarks requested a review from a team as a code owner April 1, 2026 23:56
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 78.3%
⬆️ +0.01%
8498 / 10852
🔵 Statements 78.12%
⬆️ +0.01%
8634 / 11051
🔵 Functions 75.89%
⬆️ +0.04%
1984 / 2614
🔵 Branches 76.06%
⬇️ -0.01%
3648 / 4796
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/kernel-errors/src/index.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
packages/kernel-errors/src/kernel-error.ts 100% 100% 100% 100%
packages/ocap-kernel/src/KernelRouter.ts 84.44%
🟰 ±0%
73.13%
🟰 ±0%
100%
🟰 ±0%
84.44%
🟰 ±0%
110, 174, 191, 243-267, 273, 300-310, 317, 363, 378, 381
packages/ocap-kernel/src/KernelServiceManager.ts 92.15%
⬇️ -1.72%
77.27%
⬇️ -11.61%
100%
🟰 ±0%
92.15%
⬇️ -1.72%
195-202
packages/ocap-kernel/src/liveslots/kernel-marshal.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
packages/ocap-kernel/src/remotes/kernel/RemoteManager.ts 97.77%
🟰 ±0%
100%
🟰 ±0%
95.65%
🟰 ±0%
97.77%
🟰 ±0%
190, 377-379
packages/ocap-kernel/src/vats/VatHandle.ts 90%
🟰 ±0%
85.71%
🟰 ±0%
100%
🟰 ±0%
90%
🟰 ±0%
308, 359-364, 370-376
packages/ocap-kernel/src/vats/VatSyscall.ts 100%
🟰 ±0%
95.45%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
Generated in workflow #4163 for commit 3b6db98 by the Vitest Coverage Report Action

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.

1 participant