Skip to content

fix(rivetkit): wire CancellationToken through waitForNamesAvailable to eliminate KV busy-polling#5063

Merged
abcxff merged 1 commit into
mainfrom
05-18-fix_rivetkit_wire_cancellationtoken_through_waitfornamesavailable_to_eliminate_kv_busy-polling
Jun 3, 2026
Merged

fix(rivetkit): wire CancellationToken through waitForNamesAvailable to eliminate KV busy-polling#5063
abcxff merged 1 commit into
mainfrom
05-18-fix_rivetkit_wire_cancellationtoken_through_waitfornamesavailable_to_eliminate_kv_busy-polling

Conversation

@abcxff
Copy link
Copy Markdown
Contributor

@abcxff abcxff commented May 18, 2026

Fixes RVT-6297

@railway-app
Copy link
Copy Markdown

railway-app Bot commented May 18, 2026

🚅 Deployed to the rivet-pr-5063 environment in rivet-frontend

Service Status Web Updated (UTC)
frontend-inspector ❌ Build Failed (View Logs) Web Jun 3, 2026 at 1:06 am
frontend-cloud ❌ Build Failed (View Logs) Web Jun 3, 2026 at 1:06 am
kitchen-sink ❌ Build Failed (View Logs) Web Jun 3, 2026 at 1:05 am
website 😴 Sleeping (View Logs) Web May 31, 2026 at 3:08 pm
mcp-hub ✅ Success (View Logs) Web May 18, 2026 at 5:01 pm
ladle ✅ Success (View Logs) Web May 18, 2026 at 5:01 pm

@railway-app railway-app Bot temporarily deployed to rivet-frontend / rivet-pr-5063 May 18, 2026 16:58 Destroyed
@abcxff abcxff mentioned this pull request May 18, 2026
11 tasks
Copy link
Copy Markdown
Contributor Author

abcxff commented May 18, 2026

@abcxff abcxff marked this pull request as ready for review May 18, 2026 17:00
@linear
Copy link
Copy Markdown

linear Bot commented May 18, 2026

RVT-6297

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 18, 2026

Code Review

This PR eliminates a busy-polling anti-pattern from waitForNamesAvailable by wiring a CancellationToken through to Rust core — the same pattern already used by waitForNames, nextBatch, and enqueueAndWait. The change is clean and well-scoped.

Bug: missing asNativeCancellationToken cast in napi-runtime.ts

Every other queue method that passes a signal to the NAPI layer wraps it with:

signal ? asNativeCancellationToken(signal) : signal,

The new actorQueueWaitForNamesAvailable skips this cast and passes signal (typed as CancellationTokenHandle | undefined | null) directly to the NAPI Queue.waitForNamesAvailable method, which expects NativeCancellationToken | undefined | null:

// napi-runtime.ts line 684 — inconsistent with lines 654, 671, 700
.waitForNamesAvailable(names, options, signal);   // ← should use asNativeCancellationToken(signal)

asNativeCancellationToken is a pure type cast (as unknown as NativeCancellationToken), so runtime behaviour is unaffected — but the TypeScript compiler will reject this unless the generated NAPI types are loose enough to accept CancellationTokenHandle directly. It also breaks the established convention used by every sibling method.

Fix: apply the same pattern as the other three methods:

async actorQueueWaitForNamesAvailable(
    ctx: ActorContextHandle,
    names: string[],
    options?: RuntimeQueueWaitOptions | undefined | null,
    signal?: CancellationTokenHandle | undefined | null,
): Promise<void> {
    await asNativeActorContext(ctx)
        .queue()
        .waitForNamesAvailable(
            names,
            options,
            signal ? asNativeCancellationToken(signal) : signal,
        );
}

Everything else looks good

  • Rust (queue.rs) — The new signal parameter is passed through queue_wait_opts exactly like wait_for_names. No issues.
  • native.ts — The old busy-poll loop (100 ms slices, Date.now() arithmetic, manual timeout tracking) is replaced with the shared createCancellationTokenHandle + try/finally cleanup pattern. This matches the adjacent waitForNames and enqueueAndWait implementations precisely.
  • runtime.ts — The signal parameter is added to the CoreRuntime interface, keeping it consistent with the other queue method signatures.
  • wasm-runtime.ts — The additional signal argument is forwarded to callHandleAsync. Whether the wasm backend actually honours it depends on the wasm implementation, but the interface change is correct.
  • No unintentional scope creep — the diff is tightly scoped to the one missing cancellation path.

@abcxff abcxff force-pushed the 05-18-fix_rivetkit_wire_cancellationtoken_through_waitfornamesavailable_to_eliminate_kv_busy-polling branch from fea950d to 5e99ca7 Compare May 18, 2026 17:10
@abcxff abcxff force-pushed the 05-14-fix_rivetkit_fix_bigint_serialization_in_inspector_workflow_history_and_state_deserialization branch from d9123c0 to 50b18ec Compare May 18, 2026 17:10
@railway-app railway-app Bot temporarily deployed to rivet-frontend / rivet-pr-5063 May 18, 2026 17:10 Destroyed
@abcxff abcxff force-pushed the 05-14-fix_rivetkit_fix_bigint_serialization_in_inspector_workflow_history_and_state_deserialization branch from 50b18ec to e7602e1 Compare May 18, 2026 19:23
@abcxff abcxff force-pushed the 05-18-fix_rivetkit_wire_cancellationtoken_through_waitfornamesavailable_to_eliminate_kv_busy-polling branch from 5e99ca7 to 0e4c8f5 Compare May 18, 2026 19:23
@railway-app railway-app Bot temporarily deployed to rivet-frontend / rivet-pr-5063 May 18, 2026 19:23 Destroyed
Copy link
Copy Markdown
Contributor Author

abcxff commented May 19, 2026

Merge activity

  • May 19, 8:06 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 19, 8:08 PM UTC: The Graphite merge of this pull request was cancelled.
  • Jun 3, 1:04 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 3, 1:06 AM UTC: Graphite rebased this pull request as part of a merge.
  • Jun 3, 1:06 AM UTC: @abcxff merged this pull request with Graphite.

@abcxff abcxff force-pushed the 05-14-fix_rivetkit_fix_bigint_serialization_in_inspector_workflow_history_and_state_deserialization branch 2 times, most recently from e64e5c1 to 2be6cad Compare May 19, 2026 20:14
@abcxff abcxff force-pushed the 05-18-fix_rivetkit_wire_cancellationtoken_through_waitfornamesavailable_to_eliminate_kv_busy-polling branch from 0e4c8f5 to 73cbe67 Compare May 19, 2026 20:15
@railway-app railway-app Bot temporarily deployed to rivet-frontend / rivet-pr-5063 May 19, 2026 20:15 Destroyed
@abcxff abcxff force-pushed the 05-14-fix_rivetkit_fix_bigint_serialization_in_inspector_workflow_history_and_state_deserialization branch from 2be6cad to f359aca Compare May 21, 2026 00:35
@abcxff abcxff force-pushed the 05-18-fix_rivetkit_wire_cancellationtoken_through_waitfornamesavailable_to_eliminate_kv_busy-polling branch from 73cbe67 to 9dc7e20 Compare May 21, 2026 00:35
@railway-app railway-app Bot temporarily deployed to rivet-frontend / rivet-pr-5063 May 21, 2026 00:35 Destroyed
@abcxff abcxff force-pushed the 05-18-fix_rivetkit_wire_cancellationtoken_through_waitfornamesavailable_to_eliminate_kv_busy-polling branch from 9dc7e20 to 9a50acb Compare May 22, 2026 04:17
@abcxff abcxff force-pushed the 05-14-fix_rivetkit_fix_bigint_serialization_in_inspector_workflow_history_and_state_deserialization branch from f359aca to 7b1acff Compare May 22, 2026 04:17
@railway-app railway-app Bot temporarily deployed to rivet-frontend / rivet-pr-5063 May 22, 2026 04:17 Destroyed
@abcxff abcxff mentioned this pull request May 22, 2026
11 tasks
@abcxff abcxff force-pushed the 05-18-fix_rivetkit_wire_cancellationtoken_through_waitfornamesavailable_to_eliminate_kv_busy-polling branch from 9a50acb to 8f91d91 Compare May 22, 2026 05:08
@abcxff abcxff force-pushed the 05-14-fix_rivetkit_fix_bigint_serialization_in_inspector_workflow_history_and_state_deserialization branch from 7b1acff to 4a3e9a9 Compare May 22, 2026 05:08
@railway-app railway-app Bot temporarily deployed to rivet-frontend / rivet-pr-5063 May 22, 2026 05:08 Destroyed
@abcxff abcxff force-pushed the 05-18-fix_rivetkit_wire_cancellationtoken_through_waitfornamesavailable_to_eliminate_kv_busy-polling branch from 8f91d91 to f83acdc Compare June 2, 2026 20:09
@railway-app railway-app Bot temporarily deployed to rivet-frontend / rivet-pr-5063 June 2, 2026 20:09 Destroyed
@abcxff abcxff changed the base branch from 05-14-fix_rivetkit_fix_bigint_serialization_in_inspector_workflow_history_and_state_deserialization to graphite-base/5063 June 3, 2026 01:04
@abcxff abcxff changed the base branch from graphite-base/5063 to main June 3, 2026 01:05
@abcxff abcxff force-pushed the 05-18-fix_rivetkit_wire_cancellationtoken_through_waitfornamesavailable_to_eliminate_kv_busy-polling branch from f83acdc to ef82c05 Compare June 3, 2026 01:05
@railway-app railway-app Bot temporarily deployed to rivet-frontend / rivet-pr-5063 June 3, 2026 01:05 Destroyed
@abcxff abcxff merged commit d994260 into main Jun 3, 2026
8 of 17 checks passed
@abcxff abcxff deleted the 05-18-fix_rivetkit_wire_cancellationtoken_through_waitfornamesavailable_to_eliminate_kv_busy-polling branch June 3, 2026 01:06
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