rivetkit 0.0.0-feat-sqlite-sync.a2b9069 → 0.0.0-feat-sqlite-sync-3x.a00b07f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/client.d.ts +58 -9
- package/dist/browser/client.js +193 -23
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +1 -5
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/agent-os/index.cjs +3 -2652
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +1 -2758
- package/dist/tsup/agent-os/index.d.ts +1 -2758
- package/dist/tsup/agent-os/index.js +3 -2652
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-PFLHGSS7.cjs → chunk-3JPXBFED.cjs} +4 -4
- package/dist/tsup/{chunk-PFLHGSS7.cjs.map → chunk-3JPXBFED.cjs.map} +1 -1
- package/dist/tsup/{chunk-VZPQBM4T.js → chunk-5X35FD2T.js} +4 -4
- package/dist/tsup/{chunk-62NMENN2.js → chunk-6QNBANXM.js} +3 -3
- package/dist/tsup/{chunk-TBVEI4CG.js → chunk-7HILY7QU.js} +185 -25
- package/dist/tsup/chunk-7HILY7QU.js.map +1 -0
- package/dist/tsup/{chunk-JI6GZ2C2.js → chunk-A2CF6PFH.js} +18 -1
- package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
- package/dist/tsup/{chunk-XU5FXL53.cjs → chunk-CT6GQRUN.cjs} +3 -3
- package/dist/tsup/{chunk-XU5FXL53.cjs.map → chunk-CT6GQRUN.cjs.map} +1 -1
- package/dist/tsup/{chunk-3XABSX7Z.js → chunk-DRZTELHJ.js} +10 -14
- package/dist/tsup/chunk-DRZTELHJ.js.map +1 -0
- package/dist/tsup/{chunk-S4JJAPRX.js → chunk-DUGEPEJO.js} +2 -2
- package/dist/tsup/{chunk-E443NPGV.cjs → chunk-EA6P3N4I.cjs} +3 -3
- package/dist/tsup/{chunk-E443NPGV.cjs.map → chunk-EA6P3N4I.cjs.map} +1 -1
- package/dist/tsup/{chunk-KNVSGCHJ.cjs → chunk-ERZDCOQ3.cjs} +10 -10
- package/dist/tsup/{chunk-KNVSGCHJ.cjs.map → chunk-ERZDCOQ3.cjs.map} +1 -1
- package/dist/tsup/{chunk-PFOK45LA.js → chunk-GHTA76HT.js} +2 -2
- package/dist/tsup/{chunk-74MPKC4U.js → chunk-ID5VJNZY.js} +2 -2
- package/dist/tsup/{chunk-FKJJX36M.cjs → chunk-PXIOH445.cjs} +326 -166
- package/dist/tsup/chunk-PXIOH445.cjs.map +1 -0
- package/dist/tsup/{chunk-MYWZCDML.cjs → chunk-RTWH3AX3.cjs} +19 -2
- package/dist/tsup/chunk-RTWH3AX3.cjs.map +1 -0
- package/dist/tsup/{chunk-WMBIR2SY.cjs → chunk-UV4KDO4W.cjs} +3 -3
- package/dist/tsup/{chunk-WMBIR2SY.cjs.map → chunk-UV4KDO4W.cjs.map} +1 -1
- package/dist/tsup/{chunk-4G6WPUYN.js → chunk-VI2S336K.js} +2 -2
- package/dist/tsup/{chunk-4AIU4P2C.cjs → chunk-W7NPIYWC.cjs} +10 -14
- package/dist/tsup/chunk-W7NPIYWC.cjs.map +1 -0
- package/dist/tsup/{chunk-BO74QMUL.cjs → chunk-ZZQM77UA.cjs} +7 -7
- package/dist/tsup/{chunk-BO74QMUL.cjs.map → chunk-ZZQM77UA.cjs.map} +1 -1
- package/dist/tsup/client/mod.cjs +6 -6
- package/dist/tsup/client/mod.d.cts +15 -3
- package/dist/tsup/client/mod.d.ts +15 -3
- package/dist/tsup/client/mod.js +5 -5
- package/dist/tsup/common/log.cjs +2 -2
- package/dist/tsup/common/log.js +1 -1
- package/dist/tsup/common/websocket.cjs +3 -3
- package/dist/tsup/common/websocket.js +2 -2
- package/dist/tsup/{config-DfVrAigH.d.ts → config-B4erdavw.d.ts} +43 -12
- package/dist/tsup/{config-BaUctMNL.d.cts → config-BfG1qpYz.d.cts} +7 -1
- package/dist/tsup/{config-BaUctMNL.d.ts → config-BfG1qpYz.d.ts} +7 -1
- package/dist/tsup/{config-D6T6Ud_V.d.cts → config-DK144OAw.d.cts} +43 -12
- package/dist/tsup/{context-CowF_zyQ.d.cts → context-Cvnf3BRe.d.cts} +2 -2
- package/dist/tsup/{context-BsFWwi3i.d.ts → context-Oxi6YWcG.d.ts} +2 -2
- package/dist/tsup/db/drizzle.cjs +2 -2
- package/dist/tsup/db/drizzle.d.cts +1 -1
- package/dist/tsup/db/drizzle.d.ts +1 -1
- package/dist/tsup/db/drizzle.js +1 -1
- package/dist/tsup/db/mod.cjs +3 -3
- package/dist/tsup/db/mod.d.cts +2 -2
- package/dist/tsup/db/mod.d.ts +2 -2
- package/dist/tsup/db/mod.js +2 -2
- package/dist/tsup/dynamic/mod.d.cts +2 -2
- package/dist/tsup/dynamic/mod.d.ts +2 -2
- package/dist/tsup/inspector/mod.cjs +5 -5
- package/dist/tsup/inspector/mod.js +4 -4
- package/dist/tsup/inspector/workflow.cjs +4 -4
- package/dist/tsup/inspector/workflow.js +3 -3
- package/dist/tsup/inspector-tab/mod.d.cts +3 -3
- package/dist/tsup/inspector-tab/mod.d.ts +3 -3
- package/dist/tsup/mod.cjs +256 -174
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +4 -4
- package/dist/tsup/mod.d.ts +4 -4
- package/dist/tsup/mod.js +170 -88
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +7 -7
- package/dist/tsup/test/mod.d.cts +2 -2
- package/dist/tsup/test/mod.d.ts +2 -2
- package/dist/tsup/test/mod.js +5 -5
- package/dist/tsup/unstable/migrations.d.cts +1 -1
- package/dist/tsup/unstable/migrations.d.ts +1 -1
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.js +1 -1
- package/dist/tsup/workflow/mod.cjs +17 -17
- package/dist/tsup/workflow/mod.d.cts +4 -4
- package/dist/tsup/workflow/mod.d.ts +4 -4
- package/dist/tsup/workflow/mod.js +5 -5
- package/package.json +9 -13
- package/src/actor/keys.ts +86 -0
- package/src/agent-os/index.ts +5 -65
- package/src/client/actor-conn.ts +92 -6
- package/src/client/actor-handle.ts +24 -4
- package/src/client/client.ts +14 -4
- package/src/client/config.ts +12 -1
- package/src/client/lifecycle-errors.ts +16 -1
- package/src/client/retry-budget.ts +78 -0
- package/src/client/utils.ts +13 -2
- package/src/common/database/config.ts +7 -1
- package/src/common/database/native-database.ts +17 -9
- package/src/common/router.ts +1 -1
- package/src/engine-api/actors.ts +3 -3
- package/src/engine-client/actor-websocket-client.ts +4 -2
- package/src/engine-client/api-endpoints.ts +44 -14
- package/src/engine-client/mod.ts +2 -2
- package/src/registry/config/envoy.ts +1 -1
- package/src/registry/config/index.ts +28 -31
- package/src/registry/index.ts +51 -19
- package/src/registry/napi-runtime.ts +3 -2
- package/src/registry/native.ts +129 -40
- package/src/registry/runtime.ts +27 -10
- package/src/registry/wasm-runtime.ts +6 -3
- package/src/utils/env-vars.ts +15 -10
- package/dist/tsup/chunk-3XABSX7Z.js.map +0 -1
- package/dist/tsup/chunk-4AIU4P2C.cjs.map +0 -1
- package/dist/tsup/chunk-FKJJX36M.cjs.map +0 -1
- package/dist/tsup/chunk-JI6GZ2C2.js.map +0 -1
- package/dist/tsup/chunk-MYWZCDML.cjs.map +0 -1
- package/dist/tsup/chunk-TBVEI4CG.js.map +0 -1
- package/src/actor/config.test.ts +0 -78
- package/src/actor/keys.test.ts +0 -275
- package/src/actor/utils.test.ts +0 -48
- package/src/agent-os/actor/cron.ts +0 -84
- package/src/agent-os/actor/db.ts +0 -54
- package/src/agent-os/actor/filesystem.ts +0 -131
- package/src/agent-os/actor/index.ts +0 -285
- package/src/agent-os/actor/network.ts +0 -58
- package/src/agent-os/actor/preview.ts +0 -190
- package/src/agent-os/actor/process.ts +0 -177
- package/src/agent-os/actor/session.ts +0 -518
- package/src/agent-os/actor/shell.ts +0 -60
- package/src/agent-os/config.ts +0 -79
- package/src/agent-os/fs/database-vfs.ts +0 -624
- package/src/agent-os/types.ts +0 -148
- package/src/client/test.ts +0 -44
- package/src/client/token-provider.test.ts +0 -86
- package/src/common/database/mod.test.ts +0 -364
- package/src/common/database/native-database.test.ts +0 -241
- package/src/common/inline-websocket-adapter.test.ts +0 -51
- package/src/db/drizzle.test.ts +0 -164
- package/src/registry/config/index.test.ts +0 -25
- package/src/registry/run-handler-coordinator.test.ts +0 -252
- package/src/registry/runtime.test.ts +0 -124
- package/src/unstable/migrations.test.ts +0 -170
- package/src/utils/endpoint-parser.test.ts +0 -206
- package/src/utils.test.ts +0 -34
- package/src/workflow/driver.test.ts +0 -62
- /package/dist/tsup/{chunk-VZPQBM4T.js.map → chunk-5X35FD2T.js.map} +0 -0
- /package/dist/tsup/{chunk-62NMENN2.js.map → chunk-6QNBANXM.js.map} +0 -0
- /package/dist/tsup/{chunk-S4JJAPRX.js.map → chunk-DUGEPEJO.js.map} +0 -0
- /package/dist/tsup/{chunk-PFOK45LA.js.map → chunk-GHTA76HT.js.map} +0 -0
- /package/dist/tsup/{chunk-74MPKC4U.js.map → chunk-ID5VJNZY.js.map} +0 -0
- /package/dist/tsup/{chunk-4G6WPUYN.js.map → chunk-VI2S336K.js.map} +0 -0
package/src/registry/native.ts
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
} from "@/actor/config";
|
|
27
27
|
import type { AnyActorDefinition } from "@/actor/definition";
|
|
28
28
|
import {
|
|
29
|
+
actorStopping,
|
|
29
30
|
decodeBridgeRivetError,
|
|
30
31
|
encodeBridgeRivetError,
|
|
31
32
|
forbiddenError,
|
|
@@ -131,6 +132,7 @@ import type {
|
|
|
131
132
|
SqliteTransactionHandle,
|
|
132
133
|
WebSocketHandle,
|
|
133
134
|
} from "./runtime";
|
|
135
|
+
import { servicesBinaryUnavailable } from "./runtime";
|
|
134
136
|
import { loadWasmRuntime } from "./wasm-runtime";
|
|
135
137
|
import {
|
|
136
138
|
createWriteThroughProxy,
|
|
@@ -352,6 +354,11 @@ type NativeDestroyGate = {
|
|
|
352
354
|
type NativeDatabaseClientState = {
|
|
353
355
|
client: unknown;
|
|
354
356
|
};
|
|
357
|
+
type NativeActorAbort = {
|
|
358
|
+
signal: AbortSignal;
|
|
359
|
+
listeners: Set<() => void>;
|
|
360
|
+
};
|
|
361
|
+
|
|
355
362
|
type NativeActorRuntimeState = {
|
|
356
363
|
sql?: ReturnType<typeof wrapJsNativeDatabase>;
|
|
357
364
|
databaseClient?: NativeDatabaseClientState;
|
|
@@ -359,6 +366,17 @@ type NativeActorRuntimeState = {
|
|
|
359
366
|
vars?: unknown;
|
|
360
367
|
destroyGate?: NativeDestroyGate;
|
|
361
368
|
persistState?: NativePersistActorState;
|
|
369
|
+
// One native actor abort signal shared by every context of the actor. Each
|
|
370
|
+
// native signal parks a task and a callback handle until the actor stops,
|
|
371
|
+
// so creating one per request or action leaks both. Per-context listeners
|
|
372
|
+
// live in `listeners` so the shared signal never collects one listener per
|
|
373
|
+
// in-flight request.
|
|
374
|
+
actorAbort?: NativeActorAbort;
|
|
375
|
+
// Set once shutdown cleanup has cleared this generation's caches. Work that
|
|
376
|
+
// outlives the generation, such as an untracked timer or a late WebSocket
|
|
377
|
+
// message handler, then fails with `actor.stopping` instead of reading an
|
|
378
|
+
// empty bag as if `vars` or the database were never initialized.
|
|
379
|
+
cleared?: true;
|
|
362
380
|
};
|
|
363
381
|
|
|
364
382
|
// Keep JS-only actor caches on the NAPI ActorContext runtime-state bag instead
|
|
@@ -368,9 +386,10 @@ function getNativeRuntimeState(
|
|
|
368
386
|
runtime: CoreRuntime,
|
|
369
387
|
ctx: ActorContextHandle,
|
|
370
388
|
): NativeActorRuntimeState {
|
|
371
|
-
const runtimeState =
|
|
372
|
-
|
|
373
|
-
|
|
389
|
+
const runtimeState = readNativeRuntimeStateBag(runtime, ctx);
|
|
390
|
+
if (runtimeState.cleared) {
|
|
391
|
+
throw actorStopping(callNativeSync(() => runtime.actorId(ctx)));
|
|
392
|
+
}
|
|
374
393
|
if (!runtimeState.destroyGate) {
|
|
375
394
|
runtimeState.destroyGate = {};
|
|
376
395
|
}
|
|
@@ -384,6 +403,22 @@ function getNativeRuntimeState(
|
|
|
384
403
|
return runtimeState;
|
|
385
404
|
}
|
|
386
405
|
|
|
406
|
+
function readNativeRuntimeStateBag(
|
|
407
|
+
runtime: CoreRuntime,
|
|
408
|
+
ctx: ActorContextHandle,
|
|
409
|
+
): NativeActorRuntimeState {
|
|
410
|
+
return callNativeSync(() =>
|
|
411
|
+
runtime.actorRuntimeState(ctx),
|
|
412
|
+
) as NativeActorRuntimeState;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function isNativeRuntimeStateCleared(
|
|
416
|
+
runtime: CoreRuntime,
|
|
417
|
+
ctx: ActorContextHandle,
|
|
418
|
+
): boolean {
|
|
419
|
+
return readNativeRuntimeStateBag(runtime, ctx).cleared === true;
|
|
420
|
+
}
|
|
421
|
+
|
|
387
422
|
function getNativePersistState(
|
|
388
423
|
runtime: CoreRuntime,
|
|
389
424
|
ctx: ActorContextHandle,
|
|
@@ -526,7 +561,18 @@ function clearNativeRuntimeState(
|
|
|
526
561
|
runtime: CoreRuntime,
|
|
527
562
|
ctx: ActorContextHandle,
|
|
528
563
|
) {
|
|
564
|
+
// A coalesced save armed before the clear would otherwise fire against the
|
|
565
|
+
// cleared bag and throw outside any caller.
|
|
566
|
+
const pendingSaveHandle = readNativeRuntimeStateBag(runtime, ctx)
|
|
567
|
+
.persistState?.pendingSaveHandle;
|
|
568
|
+
if (pendingSaveHandle !== undefined) {
|
|
569
|
+
clearImmediate(pendingSaveHandle);
|
|
570
|
+
}
|
|
529
571
|
callNativeSync(() => runtime.actorClearRuntimeState(ctx));
|
|
572
|
+
// The runtime hands out a fresh bag after a clear. Each generation has its
|
|
573
|
+
// own bag, so marking it makes later access from this generation fail typed
|
|
574
|
+
// without touching any newer generation of the same actor.
|
|
575
|
+
readNativeRuntimeStateBag(runtime, ctx).cleared = true;
|
|
530
576
|
}
|
|
531
577
|
|
|
532
578
|
async function cleanupNativeSleepRuntimeState(
|
|
@@ -541,8 +587,7 @@ async function cleanupNativeSleepRuntimeState(
|
|
|
541
587
|
// the tracked work finishes without a deadline.
|
|
542
588
|
const drained = await runtime.actorWaitForTrackedShutdownWork(ctx);
|
|
543
589
|
if (!drained) {
|
|
544
|
-
await
|
|
545
|
-
await closeNativeSqlDatabase(runtime, ctx);
|
|
590
|
+
await detachNativeDatabaseForShutdown(runtime, ctx);
|
|
546
591
|
void runtime
|
|
547
592
|
.actorWaitForTrackedShutdownWorkUnbounded(ctx)
|
|
548
593
|
.then(async () => {
|
|
@@ -559,11 +604,26 @@ async function cleanupNativeSleepRuntimeState(
|
|
|
559
604
|
}
|
|
560
605
|
|
|
561
606
|
await afterTrackedWorkDrained?.();
|
|
562
|
-
await
|
|
563
|
-
await closeNativeSqlDatabase(runtime, ctx);
|
|
607
|
+
await detachNativeDatabaseForShutdown(runtime, ctx);
|
|
564
608
|
clearNativeRuntimeState(runtime, ctx);
|
|
565
609
|
}
|
|
566
610
|
|
|
611
|
+
async function detachNativeDatabaseForShutdown(
|
|
612
|
+
runtime: CoreRuntime,
|
|
613
|
+
ctx: ActorContextHandle,
|
|
614
|
+
): Promise<void> {
|
|
615
|
+
const runtimeState = getNativeRuntimeState(runtime, ctx);
|
|
616
|
+
// Stop JS access without closing the runtime-owned SQLite backend. Rust still
|
|
617
|
+
// needs it to reconcile scheduled alarms and performs the physical close after
|
|
618
|
+
// this lifecycle callback returns.
|
|
619
|
+
await runtimeState.sql?.detachForShutdown();
|
|
620
|
+
try {
|
|
621
|
+
await closeNativeDatabaseClient(runtime, ctx);
|
|
622
|
+
} finally {
|
|
623
|
+
runtimeState.sql = undefined;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
567
627
|
function closeNativeSqlDatabase(
|
|
568
628
|
runtime: CoreRuntime,
|
|
569
629
|
ctx: ActorContextHandle,
|
|
@@ -695,14 +755,11 @@ function getOrCreateNativeSqlDatabase(
|
|
|
695
755
|
open: () => runtime.actorSqlOpen(ctx),
|
|
696
756
|
commitTicket: () => runtime.actorSqlCommitTicket(ctx),
|
|
697
757
|
whenDurable: (ticket) => runtime.actorSqlWhenDurable(ctx, ticket),
|
|
698
|
-
abortGeneration: (reason) =>
|
|
758
|
+
abortGeneration: (reason) =>
|
|
759
|
+
runtime.actorSqlAbortGeneration(ctx, reason),
|
|
699
760
|
close: () => runtime.actorSqlClose(ctx),
|
|
700
761
|
};
|
|
701
|
-
const database = wrapJsNativeDatabase(bindings
|
|
702
|
-
// Core still needs its shared database for the final state save, and
|
|
703
|
-
// closes it after shutting down the Actor Runtime Socket.
|
|
704
|
-
ownsDatabase: false,
|
|
705
|
-
});
|
|
762
|
+
const database = wrapJsNativeDatabase(bindings);
|
|
706
763
|
runtimeState.sql = database;
|
|
707
764
|
return database;
|
|
708
765
|
}
|
|
@@ -817,7 +874,7 @@ async function loadEngineCli(): Promise<typeof import("@rivetkit/engine-cli")> {
|
|
|
817
874
|
return import(["@rivetkit", "engine-cli"].join("/"));
|
|
818
875
|
}
|
|
819
876
|
|
|
820
|
-
async function loadServices(): Promise<
|
|
877
|
+
async function loadServices(): Promise<{ getServicesPath: () => string }> {
|
|
821
878
|
// Keep the native binary opaque to edge bundlers for the same reason as
|
|
822
879
|
// engine-cli above.
|
|
823
880
|
return import(["@rivet-dev", "services"].join("/"));
|
|
@@ -3055,22 +3112,28 @@ export class ActorContextHandleAdapter {
|
|
|
3055
3112
|
|
|
3056
3113
|
get abortSignal(): AbortSignal {
|
|
3057
3114
|
if (!this.#abortSignal) {
|
|
3058
|
-
const
|
|
3115
|
+
const actorAbort = this.#actorAbort();
|
|
3116
|
+
const actorSignal = actorAbort.signal;
|
|
3059
3117
|
if (this.#dispatchCancelToken === undefined) {
|
|
3060
3118
|
this.#abortSignal = actorSignal;
|
|
3061
3119
|
} else {
|
|
3062
3120
|
const controller = new AbortController();
|
|
3063
3121
|
let cleanedUp = false;
|
|
3122
|
+
let releaseDispatchListener: (() => void) | undefined;
|
|
3064
3123
|
const onActorAbort = () => {
|
|
3065
3124
|
cleanup();
|
|
3066
3125
|
controller.abort();
|
|
3067
3126
|
};
|
|
3127
|
+
// Releasing the native listener on dispose frees it even when the
|
|
3128
|
+
// dispatch token is never cancelled.
|
|
3068
3129
|
const cleanup = () => {
|
|
3069
3130
|
if (cleanedUp) {
|
|
3070
3131
|
return;
|
|
3071
3132
|
}
|
|
3072
3133
|
cleanedUp = true;
|
|
3073
|
-
|
|
3134
|
+
actorAbort.listeners.delete(onActorAbort);
|
|
3135
|
+
releaseDispatchListener?.();
|
|
3136
|
+
releaseDispatchListener = undefined;
|
|
3074
3137
|
this.#abortSignalCleanup = undefined;
|
|
3075
3138
|
};
|
|
3076
3139
|
|
|
@@ -3084,10 +3147,8 @@ export class ActorContextHandleAdapter {
|
|
|
3084
3147
|
} else {
|
|
3085
3148
|
const dispatchCancelToken = this.#dispatchCancelToken;
|
|
3086
3149
|
this.#abortSignalCleanup = cleanup;
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
});
|
|
3090
|
-
callNativeSync(() =>
|
|
3150
|
+
actorAbort.listeners.add(onActorAbort);
|
|
3151
|
+
releaseDispatchListener = callNativeSync(() =>
|
|
3091
3152
|
this.#runtime.onCancellationTokenCancelled(
|
|
3092
3153
|
dispatchCancelToken,
|
|
3093
3154
|
() => {
|
|
@@ -3541,24 +3602,49 @@ export class ActorContextHandleAdapter {
|
|
|
3541
3602
|
|
|
3542
3603
|
async dispose(): Promise<void> {
|
|
3543
3604
|
// Flush any save coalesced for this tick before the context is torn
|
|
3544
|
-
// down so the request-save and onStateChange always run.
|
|
3545
|
-
|
|
3605
|
+
// down so the request-save and onStateChange always run. Shutdown
|
|
3606
|
+
// cleanup may already have cleared the generation, which leaves no
|
|
3607
|
+
// pending save to flush.
|
|
3608
|
+
if (!isNativeRuntimeStateCleared(this.#runtime, this.#ctx)) {
|
|
3609
|
+
this.#flushStateChange();
|
|
3610
|
+
}
|
|
3546
3611
|
this.#abortSignalCleanup?.();
|
|
3547
3612
|
}
|
|
3548
3613
|
|
|
3549
|
-
#
|
|
3614
|
+
#actorAbort(): NativeActorAbort {
|
|
3615
|
+
// An aborted cached signal may belong to a previous generation, so
|
|
3616
|
+
// only a live one is reused.
|
|
3617
|
+
const runtimeState = readNativeRuntimeStateBag(
|
|
3618
|
+
this.#runtime,
|
|
3619
|
+
this.#ctx,
|
|
3620
|
+
);
|
|
3621
|
+
const cached = runtimeState.actorAbort;
|
|
3622
|
+
if (cached && !cached.signal.aborted) {
|
|
3623
|
+
return cached;
|
|
3624
|
+
}
|
|
3625
|
+
|
|
3550
3626
|
const nativeSignal = callNativeSync(() =>
|
|
3551
3627
|
this.#runtime.actorAbortSignal(this.#ctx),
|
|
3552
3628
|
);
|
|
3553
3629
|
const controller = new AbortController();
|
|
3554
|
-
|
|
3630
|
+
const actorAbort: NativeActorAbort = {
|
|
3631
|
+
signal: controller.signal,
|
|
3632
|
+
listeners: new Set(),
|
|
3633
|
+
};
|
|
3634
|
+
const abort = () => {
|
|
3555
3635
|
controller.abort();
|
|
3636
|
+
for (const listener of actorAbort.listeners) {
|
|
3637
|
+
listener();
|
|
3638
|
+
}
|
|
3639
|
+
actorAbort.listeners.clear();
|
|
3640
|
+
};
|
|
3641
|
+
if (nativeSignal.aborted) {
|
|
3642
|
+
abort();
|
|
3556
3643
|
} else {
|
|
3557
|
-
nativeSignal.addEventListener("abort",
|
|
3558
|
-
once: true,
|
|
3559
|
-
});
|
|
3644
|
+
nativeSignal.addEventListener("abort", abort, { once: true });
|
|
3560
3645
|
}
|
|
3561
|
-
|
|
3646
|
+
runtimeState.actorAbort = actorAbort;
|
|
3647
|
+
return actorAbort;
|
|
3562
3648
|
}
|
|
3563
3649
|
|
|
3564
3650
|
#readState(): unknown {
|
|
@@ -4889,7 +4975,7 @@ export function buildNativeFactory(
|
|
|
4889
4975
|
}
|
|
4890
4976
|
} finally {
|
|
4891
4977
|
resolveNativeDestroy(runtime, ctx);
|
|
4892
|
-
await
|
|
4978
|
+
await detachNativeDatabaseForShutdown(runtime, ctx);
|
|
4893
4979
|
clearNativeRuntimeState(runtime, ctx);
|
|
4894
4980
|
await actorCtx.dispose();
|
|
4895
4981
|
}
|
|
@@ -5641,11 +5727,12 @@ export async function buildServeConfig(
|
|
|
5641
5727
|
}
|
|
5642
5728
|
|
|
5643
5729
|
const serveConfig: RuntimeServeConfig = {
|
|
5644
|
-
version: config.
|
|
5730
|
+
version: config.node.version,
|
|
5645
5731
|
endpoint: config.endpoint,
|
|
5732
|
+
engineSpawn: config.engineSpawn,
|
|
5646
5733
|
token: config.token,
|
|
5647
5734
|
namespace: config.namespace,
|
|
5648
|
-
poolName: config.
|
|
5735
|
+
poolName: config.node.poolName,
|
|
5649
5736
|
startServices: resolveServicesBinary && config.startServices,
|
|
5650
5737
|
handleInspectorHttpInRuntime: true,
|
|
5651
5738
|
serverlessBasePath: config.serverless.basePath,
|
|
@@ -5659,7 +5746,7 @@ export async function buildServeConfig(
|
|
|
5659
5746
|
|
|
5660
5747
|
// Always best-effort resolve the npm-installed engine binary and hand its
|
|
5661
5748
|
// path to the core. The core alone decides whether to actually spawn a local
|
|
5662
|
-
// engine
|
|
5749
|
+
// engine using the resolved spawn decision, so
|
|
5663
5750
|
// JS must not duplicate that decision here. Only JS knows the npm
|
|
5664
5751
|
// `node_modules` layout, so it resolves the path; if no binary is available
|
|
5665
5752
|
// (remote-only install, unsupported platform, optional deps skipped), leave
|
|
@@ -5679,14 +5766,16 @@ export async function buildServeConfig(
|
|
|
5679
5766
|
});
|
|
5680
5767
|
}
|
|
5681
5768
|
if (resolveServicesBinary && config.startServices) {
|
|
5682
|
-
|
|
5683
|
-
|
|
5684
|
-
serveConfig.servicesBinaryPath =
|
|
5685
|
-
}
|
|
5686
|
-
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
})
|
|
5769
|
+
const servicesBinary = getEnvUniversal("RIVET_SERVICES_BINARY");
|
|
5770
|
+
if (servicesBinary) {
|
|
5771
|
+
serveConfig.servicesBinaryPath = servicesBinary;
|
|
5772
|
+
} else {
|
|
5773
|
+
try {
|
|
5774
|
+
const { getServicesPath } = await loadServices();
|
|
5775
|
+
serveConfig.servicesBinaryPath = getServicesPath();
|
|
5776
|
+
} catch (error) {
|
|
5777
|
+
throw servicesBinaryUnavailable(error);
|
|
5778
|
+
}
|
|
5690
5779
|
}
|
|
5691
5780
|
}
|
|
5692
5781
|
serveConfig.engineHost = config.engineHost;
|
package/src/registry/runtime.ts
CHANGED
|
@@ -407,6 +407,8 @@ export interface RuntimeServeConfig {
|
|
|
407
407
|
engineBinaryPath?: string;
|
|
408
408
|
startServices?: boolean;
|
|
409
409
|
servicesBinaryPath?: string;
|
|
410
|
+
/** Whether config resolution selected a managed local development engine. */
|
|
411
|
+
engineSpawn?: boolean;
|
|
410
412
|
engineHost?: string;
|
|
411
413
|
enginePort?: number;
|
|
412
414
|
handleInspectorHttpInRuntime?: boolean;
|
|
@@ -552,10 +554,15 @@ export interface CoreRuntime {
|
|
|
552
554
|
createCancellationToken(): CancellationTokenHandle;
|
|
553
555
|
cancellationTokenAborted(token: CancellationTokenHandle): boolean;
|
|
554
556
|
cancelCancellationToken(token: CancellationTokenHandle): void;
|
|
557
|
+
/**
|
|
558
|
+
* Calls `callback` once when `token` is cancelled. Returns a release
|
|
559
|
+
* function that drops the registration without calling `callback`; call it
|
|
560
|
+
* once cancellation no longer matters so the native listener is freed.
|
|
561
|
+
*/
|
|
555
562
|
onCancellationTokenCancelled(
|
|
556
563
|
token: CancellationTokenHandle,
|
|
557
564
|
callback: (...args: unknown[]) => unknown,
|
|
558
|
-
): void;
|
|
565
|
+
): () => void;
|
|
559
566
|
|
|
560
567
|
actorState(ctx: ActorContextHandle): RuntimeBytes;
|
|
561
568
|
actorBeginOnStateChange(ctx: ActorContextHandle): void;
|
|
@@ -928,6 +935,13 @@ export interface RuntimeBundle {
|
|
|
928
935
|
runtime: CoreRuntime;
|
|
929
936
|
}
|
|
930
937
|
|
|
938
|
+
export function servicesBinaryUnavailable(cause: unknown): Error {
|
|
939
|
+
return new Error(
|
|
940
|
+
"services.binary_unavailable: Install @rivet-dev/services yourself to run local Services, or set RIVET_SERVICES_BINARY to its executable path.",
|
|
941
|
+
{ cause },
|
|
942
|
+
);
|
|
943
|
+
}
|
|
944
|
+
|
|
931
945
|
export async function buildServeConfig(
|
|
932
946
|
config: RegistryConfig,
|
|
933
947
|
loadEnginePath: () => Promise<string>,
|
|
@@ -939,11 +953,12 @@ export async function buildServeConfig(
|
|
|
939
953
|
}
|
|
940
954
|
|
|
941
955
|
const serveConfig: RuntimeServeConfig = {
|
|
942
|
-
version: config.
|
|
956
|
+
version: config.node.version,
|
|
943
957
|
endpoint: config.endpoint,
|
|
958
|
+
engineSpawn: config.engineSpawn,
|
|
944
959
|
token: config.token,
|
|
945
960
|
namespace: config.namespace,
|
|
946
|
-
poolName: config.
|
|
961
|
+
poolName: config.node.poolName,
|
|
947
962
|
startServices: config.startServices,
|
|
948
963
|
handleInspectorHttpInRuntime: true,
|
|
949
964
|
serverlessBasePath: config.serverless.basePath,
|
|
@@ -973,13 +988,15 @@ export async function buildServeConfig(
|
|
|
973
988
|
});
|
|
974
989
|
}
|
|
975
990
|
if (config.startServices) {
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
})
|
|
991
|
+
const servicesBinary = process.env.RIVET_SERVICES_BINARY;
|
|
992
|
+
if (servicesBinary) {
|
|
993
|
+
serveConfig.servicesBinaryPath = servicesBinary;
|
|
994
|
+
} else {
|
|
995
|
+
try {
|
|
996
|
+
serveConfig.servicesBinaryPath = await loadServicesPath();
|
|
997
|
+
} catch (error) {
|
|
998
|
+
throw servicesBinaryUnavailable(error);
|
|
999
|
+
}
|
|
983
1000
|
}
|
|
984
1001
|
}
|
|
985
1002
|
serveConfig.engineHost = config.engineHost;
|
|
@@ -66,7 +66,9 @@ type WasmWebSocketHandle = object;
|
|
|
66
66
|
interface WasmCancellationToken {
|
|
67
67
|
aborted(): boolean;
|
|
68
68
|
cancel(): void;
|
|
69
|
-
onCancelled(callback: (...args: unknown[]) => unknown):
|
|
69
|
+
onCancelled(callback: (...args: unknown[]) => unknown): {
|
|
70
|
+
release(): void;
|
|
71
|
+
};
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
interface WasmCoreRegistry {
|
|
@@ -410,10 +412,11 @@ export class WasmCoreRuntime implements CoreRuntime {
|
|
|
410
412
|
onCancellationTokenCancelled(
|
|
411
413
|
token: CancellationTokenHandle,
|
|
412
414
|
callback: (...args: unknown[]) => unknown,
|
|
413
|
-
): void {
|
|
414
|
-
callWasmSync(() =>
|
|
415
|
+
): () => void {
|
|
416
|
+
const listener = callWasmSync(() =>
|
|
415
417
|
asWasmCancellationToken(token).onCancelled(callback),
|
|
416
418
|
);
|
|
419
|
+
return () => callWasmSync(() => listener.release());
|
|
417
420
|
}
|
|
418
421
|
|
|
419
422
|
actorState(ctx: ActorContextHandle): RuntimeBytes {
|
package/src/utils/env-vars.ts
CHANGED
|
@@ -30,14 +30,15 @@ export const getRivetRunEnginePort = (): number | undefined => {
|
|
|
30
30
|
};
|
|
31
31
|
export const getRivetRunEngineVersion = (): string | undefined =>
|
|
32
32
|
getEnvUniversal("RIVET_RUN_ENGINE_VERSION");
|
|
33
|
-
export const getRivetRunServices = (): boolean
|
|
34
|
-
|
|
35
|
-
return value === undefined ? undefined : value === "1";
|
|
36
|
-
};
|
|
33
|
+
export const getRivetRunServices = (): boolean =>
|
|
34
|
+
getEnvUniversal("RIVET_RUN_SERVICES") === "1";
|
|
37
35
|
export const getRivetEnvoyKind = (): string | undefined =>
|
|
38
|
-
getEnvUniversal("RIVET_ENVOY_KIND");
|
|
36
|
+
getEnvUniversal("RIVET_NODE_KIND") ?? getEnvUniversal("RIVET_ENVOY_KIND");
|
|
39
37
|
export const getRivetEnvoyVersion = (): number | undefined => {
|
|
40
|
-
|
|
38
|
+
// The legacy platform deployment still sets the old name.
|
|
39
|
+
const value =
|
|
40
|
+
getEnvUniversal("RIVET_NODE_VERSION") ??
|
|
41
|
+
getEnvUniversal("RIVET_ENVOY_VERSION");
|
|
41
42
|
return value !== undefined ? parseInt(value, 10) : undefined;
|
|
42
43
|
};
|
|
43
44
|
export const getRivetPublicEndpoint = (): string | undefined =>
|
|
@@ -54,14 +55,18 @@ export const getRivetkitStoragePath = (): string | undefined =>
|
|
|
54
55
|
getEnvUniversal("RIVETKIT_STORAGE_PATH");
|
|
55
56
|
export const getRivetkitRuntime = (): string | undefined =>
|
|
56
57
|
getEnvUniversal("RIVETKIT_RUNTIME");
|
|
57
|
-
export type RuntimeMode = "
|
|
58
|
+
export type RuntimeMode = "node" | "serverless";
|
|
58
59
|
|
|
59
60
|
export const getRivetkitRuntimeMode = (): RuntimeMode => {
|
|
60
61
|
const value = getEnvUniversal("RIVETKIT_RUNTIME_MODE");
|
|
61
|
-
if (value === undefined) return "
|
|
62
|
-
|
|
62
|
+
if (value === undefined || value === "envoy") return "node";
|
|
63
|
+
// Serverless is disabled for v3.
|
|
64
|
+
if (value === "serverless") {
|
|
65
|
+
throw new Error("serverless is disabled in this version");
|
|
66
|
+
}
|
|
67
|
+
if (value === "node") return value;
|
|
63
68
|
throw new Error(
|
|
64
|
-
`RIVETKIT_RUNTIME_MODE env var must be "
|
|
69
|
+
`RIVETKIT_RUNTIME_MODE env var must be "node" or "serverless"; got "${value}"`,
|
|
65
70
|
);
|
|
66
71
|
};
|
|
67
72
|
|