Skip to content

Conversation

@FUDCo
Copy link
Contributor

@FUDCo FUDCo commented Jan 29, 2026

Summary

This change makes kernel cranks fully transactional by buffering vat outputs (sends and notifications) during crank execution. On successful completion, the buffer is flushed to persist outputs. On rollback, the buffer is cleared without flushing.

  • Add crank buffer to hold sends and notifications during crank
  • Modify enqueueSend/enqueueNotify to buffer instead of immediate persist
  • Modify resolvePromises to buffer notifications and defer kernel callbacks
  • resolveKernelPromise now returns queued messages for caller to buffer
  • Flush buffer in run() on successful crank completion
  • Clear buffer on rollback

This ensures that network transmissions (via RemoteHandle) only happen after successful crank completion, supporting the Ken protocol's output validity guarantee.

Closes #786


Note

Medium Risk
Changes core kernel queuing/notification timing by deferring sends, promise notifications, and kernel subscription callbacks until crank commit. Bugs here could drop or reorder outputs, or alter promise-resolution side effects across local/remote paths.

Overview
Makes cranks transactional by buffering vat outputs. KernelQueue now supports buffered enqueueSend/enqueueNotify and a buffered mode for resolvePromises, flushing buffered run-queue items only after a successful crank and discarding them on rollback.

Promise-resolution side effects are deferred to commit. resolveKernelPromise no longer enqueues run-queue sends directly; it returns queued messages so KernelQueue can buffer/enqueue them consistently, and kernel-level promise subscription callbacks are invoked during buffer flush rather than immediately.

Updates KernelStore to maintain a per-crank output buffer (cleared on rollback/reset), adjusts vat syscalls to use buffered mode, and refreshes tests/docs to reflect the new crank-buffering model and remaining Ken-protocol gaps.

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

@FUDCo FUDCo requested a review from a team as a code owner January 29, 2026 22:48
@FUDCo FUDCo force-pushed the chip/crank-buffer branch from 556b89e to 844a8a4 Compare January 29, 2026 23:04
@github-actions
Copy link
Contributor

github-actions bot commented Jan 30, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 88.46%
⬆️ +0.05%
5911 / 6682
🔵 Statements 88.35%
⬆️ +0.05%
6008 / 6800
🔵 Functions 87.15%
⬆️ +0.03%
1533 / 1759
🔵 Branches 84.67%
⬆️ +0.08%
2143 / 2531
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/ocap-kernel/src/KernelQueue.ts 98.13%
⬆️ +0.49%
88.67%
⬆️ +3.67%
100%
🟰 ±0%
98.13%
⬆️ +0.49%
125, 313
packages/ocap-kernel/src/store/index.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
packages/ocap-kernel/src/store/types.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
packages/ocap-kernel/src/store/methods/crank.ts 100%
🟰 ±0%
93.75%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
packages/ocap-kernel/src/store/methods/promise.ts 100%
🟰 ±0%
94.44%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
packages/ocap-kernel/src/vats/VatSyscall.ts 100%
🟰 ±0%
95.45%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
Generated in workflow #3486 for commit d2d6c52 by the Vitest Coverage Report Action

@FUDCo FUDCo force-pushed the chip/crank-buffer branch from 780c285 to 063ad3f Compare January 30, 2026 02:23
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

@FUDCo FUDCo force-pushed the chip/crank-buffer branch from 063ad3f to be19c83 Compare January 30, 2026 02:59
FUDCo and others added 4 commits January 29, 2026 19:14
This change makes kernel cranks fully transactional by buffering vat
outputs (sends and notifications) during crank execution. On successful
completion, the buffer is flushed to persist outputs. On rollback, the
buffer is cleared without flushing.

Key changes:
- Add crank buffer to hold sends and notifications during crank
- Modify enqueueSend/enqueueNotify to buffer instead of immediate persist
- Modify resolvePromises to buffer notifications and defer kernel callbacks
- resolveKernelPromise now returns queued messages for caller to buffer
- Flush buffer in run() on successful crank completion
- Clear buffer on rollback

This ensures that network transmissions (via RemoteHandle) only happen
after successful crank completion, supporting the Ken protocol's output
validity guarantee.

Closes #786

Co-Authored-By: Claude Opus 4.5 <[email protected]>
When enqueueMessage creates a result promise, it stores a JavaScript
callback but doesn't add a kernel-level subscriber. When resolving
such promises, no notify items were buffered, so the callback was
never invoked at flush time.

Fix by tracking promises with kernel subscriptions during resolve
and invoking their callbacks at flush time, regardless of whether
they have kernel-level subscribers.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Remote message handling calls resolvePromises outside of crank execution.
With the previous changes that always buffered outputs, the notifications
and kernel subscriptions were never flushed because #flushCrankBuffer is
only called in the main run() loop.

This fix adds a buffer parameter (defaulting to false) to resolvePromises:
- When buffer=true (vat syscalls), outputs are buffered for crank completion
- When buffer=false (remote handling), outputs are processed immediately

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Rename the `buffer` parameter to `immediate` in enqueueSend, enqueueNotify,
and resolvePromises, inverting the boolean sense:
- immediate=true (default): process immediately
- immediate=false: buffer for crank completion

This naming is clearer since the parameter controls whether to act
immediately rather than naming a buffer that doesn't exist as a parameter.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@FUDCo FUDCo force-pushed the chip/crank-buffer branch from be19c83 to 5b53b35 Compare January 30, 2026 03:14
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.

Buffer vat outputs to make cranks transactional

2 participants