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 scheduling semantics by buffering vat-generated sends/notifications and deferring promise subscription callbacks until crank commit, which could impact message ordering, wakeups, and timing-sensitive logic despite test coverage.

Overview
Makes kernel cranks transactional by introducing a per-crank output buffer in KernelStore and routing vat syscalls (send, resolve, and resolved-subscribe notifications) through buffered enqueueSend/enqueueNotify paths.

On successful crank completion KernelQueue.run() now flushes buffered outputs into the run queue and only then invokes kernel promise subscription callbacks; on abort/rollback the buffer and any queued kernel-subscription invocations are discarded. Promise resolution is adjusted so resolveKernelPromise() returns queued messages for the caller to enqueue/buffer instead of directly enqueuing them.

Updates tests accordingly and expands docs/ken-protocol-assessment.md to document the crank-buffering improvement and remaining gaps around RemoteHandle deferred network transmission.

Written by Cursor Bugbot for commit 520cbe8. 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 #3489 for commit 520cbe8 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

3 participants