rivetkit 0.0.0-sqlite-sync-3x-release.a00b07f → 0.0.0-sqlite-query-metrics-v2.f5d3605

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.
Files changed (137) hide show
  1. package/dist/browser/client.d.ts +59 -99
  2. package/dist/browser/client.js +20 -193
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +2 -1
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/{chunk-D5WUPE47.js → chunk-3URZ4UV5.js} +2 -2
  7. package/dist/tsup/{chunk-TSQTI6H6.js → chunk-D4G35VTO.js} +4 -4
  8. package/dist/tsup/{chunk-OTVJYZ2L.cjs → chunk-DDS7OOVF.cjs} +166 -326
  9. package/dist/tsup/chunk-DDS7OOVF.cjs.map +1 -0
  10. package/dist/tsup/{chunk-6KXVLIXL.cjs → chunk-DHL2M2E2.cjs} +3 -3
  11. package/dist/tsup/{chunk-6KXVLIXL.cjs.map → chunk-DHL2M2E2.cjs.map} +1 -1
  12. package/dist/tsup/{chunk-ZYK4B5WV.js → chunk-E2CUROR3.js} +2 -2
  13. package/dist/tsup/{chunk-JUWMP5O3.js → chunk-EPRA2TCT.js} +2 -2
  14. package/dist/tsup/{chunk-3DONDAMG.js → chunk-F7IGTKGM.js} +2 -2
  15. package/dist/tsup/{chunk-BTSDFFDC.cjs → chunk-FYDB45YU.cjs} +10 -10
  16. package/dist/tsup/{chunk-BTSDFFDC.cjs.map → chunk-FYDB45YU.cjs.map} +1 -1
  17. package/dist/tsup/{chunk-73RNTXHB.cjs → chunk-HO76AEDH.cjs} +3 -3
  18. package/dist/tsup/{chunk-73RNTXHB.cjs.map → chunk-HO76AEDH.cjs.map} +1 -1
  19. package/dist/tsup/{chunk-A2CF6PFH.js → chunk-JI6GZ2C2.js} +1 -18
  20. package/dist/tsup/chunk-JI6GZ2C2.js.map +1 -0
  21. package/dist/tsup/{chunk-Z7E2G3JZ.cjs → chunk-JW2WPE6Z.cjs} +4 -4
  22. package/dist/tsup/{chunk-Z7E2G3JZ.cjs.map → chunk-JW2WPE6Z.cjs.map} +1 -1
  23. package/dist/tsup/{chunk-2MOLY6AM.cjs → chunk-KDT56V3Y.cjs} +11 -10
  24. package/dist/tsup/chunk-KDT56V3Y.cjs.map +1 -0
  25. package/dist/tsup/{chunk-DJUBJQEQ.js → chunk-KSP3NXGY.js} +3 -3
  26. package/dist/tsup/{chunk-JUHXV3HF.cjs → chunk-L3Z3W44Q.cjs} +3 -3
  27. package/dist/tsup/{chunk-JUHXV3HF.cjs.map → chunk-L3Z3W44Q.cjs.map} +1 -1
  28. package/dist/tsup/{chunk-RTWH3AX3.cjs → chunk-MYWZCDML.cjs} +2 -19
  29. package/dist/tsup/chunk-MYWZCDML.cjs.map +1 -0
  30. package/dist/tsup/{chunk-TRUHDXOU.js → chunk-PJ5EXY6F.js} +25 -185
  31. package/dist/tsup/chunk-PJ5EXY6F.js.map +1 -0
  32. package/dist/tsup/{chunk-TM76Z7XT.cjs → chunk-QR6EAWEC.cjs} +7 -7
  33. package/dist/tsup/{chunk-TM76Z7XT.cjs.map → chunk-QR6EAWEC.cjs.map} +1 -1
  34. package/dist/tsup/{chunk-BRH4PQS5.js → chunk-USKGKQZM.js} +11 -10
  35. package/dist/tsup/chunk-USKGKQZM.js.map +1 -0
  36. package/dist/tsup/client/mod.cjs +6 -6
  37. package/dist/tsup/client/mod.d.cts +3 -15
  38. package/dist/tsup/client/mod.d.ts +3 -15
  39. package/dist/tsup/client/mod.js +5 -5
  40. package/dist/tsup/common/log.cjs +2 -2
  41. package/dist/tsup/common/log.js +1 -1
  42. package/dist/tsup/common/websocket.cjs +3 -3
  43. package/dist/tsup/common/websocket.js +2 -2
  44. package/dist/tsup/{config-DK144OAw.d.cts → config-CkmVg2fG.d.cts} +12 -58
  45. package/dist/tsup/{config-B4erdavw.d.ts → config-Cw_BwH_G.d.ts} +12 -58
  46. package/dist/tsup/{config-BfG1qpYz.d.cts → config-D4clT6mq.d.cts} +52 -34
  47. package/dist/tsup/{config-BfG1qpYz.d.ts → config-D4clT6mq.d.ts} +52 -34
  48. package/dist/tsup/{context-Oxi6YWcG.d.ts → context-BYOKTQJi.d.ts} +2 -2
  49. package/dist/tsup/{context-Cvnf3BRe.d.cts → context-_xIcgBnE.d.cts} +2 -2
  50. package/dist/tsup/db/drizzle.cjs +2 -2
  51. package/dist/tsup/db/drizzle.d.cts +1 -1
  52. package/dist/tsup/db/drizzle.d.ts +1 -1
  53. package/dist/tsup/db/drizzle.js +1 -1
  54. package/dist/tsup/db/mod.cjs +3 -3
  55. package/dist/tsup/db/mod.d.cts +2 -2
  56. package/dist/tsup/db/mod.d.ts +2 -2
  57. package/dist/tsup/db/mod.js +2 -2
  58. package/dist/tsup/dynamic/mod.d.cts +2 -2
  59. package/dist/tsup/dynamic/mod.d.ts +2 -2
  60. package/dist/tsup/inspector/mod.cjs +5 -5
  61. package/dist/tsup/inspector/mod.js +4 -4
  62. package/dist/tsup/inspector/workflow.cjs +4 -4
  63. package/dist/tsup/inspector/workflow.js +3 -3
  64. package/dist/tsup/inspector-tab/mod.d.cts +3 -3
  65. package/dist/tsup/inspector-tab/mod.d.ts +3 -3
  66. package/dist/tsup/mod.cjs +201 -548
  67. package/dist/tsup/mod.cjs.map +1 -1
  68. package/dist/tsup/mod.d.cts +4 -4
  69. package/dist/tsup/mod.d.ts +4 -4
  70. package/dist/tsup/mod.js +116 -463
  71. package/dist/tsup/mod.js.map +1 -1
  72. package/dist/tsup/test/mod.cjs +7 -7
  73. package/dist/tsup/test/mod.d.cts +2 -2
  74. package/dist/tsup/test/mod.d.ts +2 -2
  75. package/dist/tsup/test/mod.js +5 -5
  76. package/dist/tsup/unstable/migrations.d.cts +1 -1
  77. package/dist/tsup/unstable/migrations.d.ts +1 -1
  78. package/dist/tsup/utils.cjs +2 -2
  79. package/dist/tsup/utils.js +1 -1
  80. package/dist/tsup/workflow/mod.cjs +17 -17
  81. package/dist/tsup/workflow/mod.cjs.map +1 -1
  82. package/dist/tsup/workflow/mod.d.cts +4 -4
  83. package/dist/tsup/workflow/mod.d.ts +4 -4
  84. package/dist/tsup/workflow/mod.js +5 -5
  85. package/package.json +10 -9
  86. package/src/actor/config.test.ts +78 -0
  87. package/src/actor/keys.test.ts +275 -0
  88. package/src/actor/keys.ts +0 -86
  89. package/src/actor/utils.test.ts +48 -0
  90. package/src/client/actor-conn.ts +6 -92
  91. package/src/client/actor-handle.ts +3 -21
  92. package/src/client/client.ts +0 -6
  93. package/src/client/config.ts +1 -12
  94. package/src/client/lifecycle-errors.ts +1 -16
  95. package/src/client/test.ts +44 -0
  96. package/src/client/token-provider.test.ts +86 -0
  97. package/src/client/utils.ts +2 -13
  98. package/src/common/database/config.ts +52 -46
  99. package/src/common/database/mod.test.ts +364 -0
  100. package/src/common/database/native-database.test.ts +220 -0
  101. package/src/common/database/native-database.ts +27 -247
  102. package/src/common/inline-websocket-adapter.test.ts +51 -0
  103. package/src/common/router.ts +1 -1
  104. package/src/db/drizzle.test.ts +164 -0
  105. package/src/db/mod.ts +1 -0
  106. package/src/engine-api/actors.ts +3 -3
  107. package/src/engine-client/actor-websocket-client.ts +2 -4
  108. package/src/engine-client/api-endpoints.ts +14 -44
  109. package/src/engine-client/mod.ts +2 -2
  110. package/src/registry/config/envoy.ts +1 -1
  111. package/src/registry/config/index.test.ts +25 -0
  112. package/src/registry/config/index.ts +31 -28
  113. package/src/registry/index.ts +19 -51
  114. package/src/registry/napi-runtime.ts +2 -81
  115. package/src/registry/native.ts +51 -183
  116. package/src/registry/run-handler-coordinator.test.ts +252 -0
  117. package/src/registry/runtime.test.ts +124 -0
  118. package/src/registry/runtime.ts +10 -79
  119. package/src/registry/wasm-runtime.ts +3 -94
  120. package/src/unstable/migrations.test.ts +170 -0
  121. package/src/utils/endpoint-parser.test.ts +206 -0
  122. package/src/utils/env-vars.ts +10 -15
  123. package/src/utils.test.ts +34 -0
  124. package/src/workflow/driver.test.ts +62 -0
  125. package/dist/tsup/chunk-2MOLY6AM.cjs.map +0 -1
  126. package/dist/tsup/chunk-A2CF6PFH.js.map +0 -1
  127. package/dist/tsup/chunk-BRH4PQS5.js.map +0 -1
  128. package/dist/tsup/chunk-OTVJYZ2L.cjs.map +0 -1
  129. package/dist/tsup/chunk-RTWH3AX3.cjs.map +0 -1
  130. package/dist/tsup/chunk-TRUHDXOU.js.map +0 -1
  131. package/src/client/retry-budget.ts +0 -78
  132. /package/dist/tsup/{chunk-D5WUPE47.js.map → chunk-3URZ4UV5.js.map} +0 -0
  133. /package/dist/tsup/{chunk-TSQTI6H6.js.map → chunk-D4G35VTO.js.map} +0 -0
  134. /package/dist/tsup/{chunk-ZYK4B5WV.js.map → chunk-E2CUROR3.js.map} +0 -0
  135. /package/dist/tsup/{chunk-JUWMP5O3.js.map → chunk-EPRA2TCT.js.map} +0 -0
  136. /package/dist/tsup/{chunk-3DONDAMG.js.map → chunk-F7IGTKGM.js.map} +0 -0
  137. /package/dist/tsup/{chunk-DJUBJQEQ.js.map → chunk-KSP3NXGY.js.map} +0 -0
@@ -481,9 +481,8 @@ export class NapiCoreRuntime implements CoreRuntime {
481
481
  onCancellationTokenCancelled(
482
482
  token: CancellationTokenHandle,
483
483
  callback: (...args: unknown[]) => unknown,
484
- ): () => void {
485
- const listener = asNativeCancellationToken(token).onCancelled(callback);
486
- return () => listener.release();
484
+ ): void {
485
+ asNativeCancellationToken(token).onCancelled(callback);
487
486
  }
488
487
 
489
488
  actorState(ctx: ActorContextHandle): Buffer {
@@ -860,13 +859,6 @@ export class NapiCoreRuntime implements CoreRuntime {
860
859
  return await this.#actorSql(ctx).exec(sql);
861
860
  }
862
861
 
863
- actorSqlExecSync(
864
- ctx: ActorContextHandle,
865
- sql: string,
866
- ): RuntimeSqlExecResult {
867
- return this.#actorSql(ctx).execSync(sql);
868
- }
869
-
870
862
  async actorSqlExecute(
871
863
  ctx: ActorContextHandle,
872
864
  sql: string,
@@ -879,18 +871,6 @@ export class NapiCoreRuntime implements CoreRuntime {
879
871
  return normalizeRuntimeSqlExecuteResult(result);
880
872
  }
881
873
 
882
- actorSqlExecuteSync(
883
- ctx: ActorContextHandle,
884
- sql: string,
885
- params?: RuntimeSqlBindParams,
886
- ): RuntimeSqlExecuteResult {
887
- const result = this.#actorSql(ctx).executeSync(
888
- sql,
889
- toNapiSqlBindParams(params),
890
- );
891
- return normalizeRuntimeSqlExecuteResult(result);
892
- }
893
-
894
874
  async actorSqlExecuteBatch(
895
875
  ctx: ActorContextHandle,
896
876
  statements: RuntimeSqlBatchStatement[],
@@ -912,17 +892,6 @@ export class NapiCoreRuntime implements CoreRuntime {
912
892
  )) as unknown as SqliteTransactionHandle;
913
893
  }
914
894
 
915
- actorSqlBeginTransactionSync(
916
- ctx: ActorContextHandle,
917
- timeoutMs?: number,
918
- name?: string,
919
- ): SqliteTransactionHandle {
920
- return this.#actorSql(ctx).beginTransactionSync(
921
- timeoutMs,
922
- name,
923
- ) as unknown as SqliteTransactionHandle;
924
- }
925
-
926
895
  async actorSqlTransactionExec(
927
896
  transaction: SqliteTransactionHandle,
928
897
  sql: string,
@@ -930,13 +899,6 @@ export class NapiCoreRuntime implements CoreRuntime {
930
899
  return await asNativeSqlTransaction(transaction).exec(sql);
931
900
  }
932
901
 
933
- actorSqlTransactionExecSync(
934
- transaction: SqliteTransactionHandle,
935
- sql: string,
936
- ): RuntimeSqlExecResult {
937
- return asNativeSqlTransaction(transaction).execSync(sql);
938
- }
939
-
940
902
  async actorSqlTransactionExecute(
941
903
  transaction: SqliteTransactionHandle,
942
904
  sql: string,
@@ -949,39 +911,17 @@ export class NapiCoreRuntime implements CoreRuntime {
949
911
  return normalizeRuntimeSqlExecuteResult(result);
950
912
  }
951
913
 
952
- actorSqlTransactionExecuteSync(
953
- transaction: SqliteTransactionHandle,
954
- sql: string,
955
- params?: RuntimeSqlBindParams,
956
- ): RuntimeSqlExecuteResult {
957
- const result = asNativeSqlTransaction(transaction).executeSync(
958
- sql,
959
- toNapiSqlBindParams(params),
960
- );
961
- return normalizeRuntimeSqlExecuteResult(result);
962
- }
963
-
964
914
  async actorSqlTransactionCommit(
965
915
  transaction: SqliteTransactionHandle,
966
916
  ): Promise<void> {
967
917
  await asNativeSqlTransaction(transaction).commit();
968
918
  }
969
919
 
970
- actorSqlTransactionCommitSync(transaction: SqliteTransactionHandle): void {
971
- asNativeSqlTransaction(transaction).commitSync();
972
- }
973
-
974
920
  async actorSqlTransactionRollback(
975
921
  transaction: SqliteTransactionHandle,
976
922
  ): Promise<void> {
977
923
  await asNativeSqlTransaction(transaction).rollback();
978
924
  }
979
-
980
- actorSqlTransactionRollbackSync(
981
- transaction: SqliteTransactionHandle,
982
- ): void {
983
- asNativeSqlTransaction(transaction).rollbackSync();
984
- }
985
925
  async actorBeginStateTransaction(
986
926
  ctx: ActorContextHandle,
987
927
  timeoutMs?: number,
@@ -1045,25 +985,6 @@ export class NapiCoreRuntime implements CoreRuntime {
1045
985
  return this.#actorSql(ctx).takeLastKvError?.() ?? null;
1046
986
  }
1047
987
 
1048
- async actorSqlOpen(ctx: ActorContextHandle): Promise<void> {
1049
- await this.#actorSql(ctx).open();
1050
- }
1051
-
1052
- actorSqlCommitTicket(ctx: ActorContextHandle): number {
1053
- return this.#actorSql(ctx).commitTicket();
1054
- }
1055
-
1056
- actorSqlAbortGeneration(ctx: ActorContextHandle, reason: string): void {
1057
- this.#actorSql(ctx).abortGeneration(reason);
1058
- }
1059
-
1060
- async actorSqlWhenDurable(
1061
- ctx: ActorContextHandle,
1062
- ticket: number,
1063
- ): Promise<void> {
1064
- await this.#actorSql(ctx).whenDurable(ticket);
1065
- }
1066
-
1067
988
  async actorSqlClose(ctx: ActorContextHandle): Promise<void> {
1068
989
  const nativeCtx = asNativeActorContext(ctx);
1069
990
  if (!this.#sqlOpened.delete(nativeCtx)) {
@@ -26,7 +26,6 @@ import {
26
26
  } from "@/actor/config";
27
27
  import type { AnyActorDefinition } from "@/actor/definition";
28
28
  import {
29
- actorStopping,
30
29
  decodeBridgeRivetError,
31
30
  encodeBridgeRivetError,
32
31
  forbiddenError,
@@ -61,11 +60,7 @@ import {
61
60
  db as defaultDb,
62
61
  registerNativeStateTransactionOpener,
63
62
  } from "@/common/database/mod";
64
- import {
65
- type JsNativeDatabaseLike,
66
- type JsNativeSynchronousTransactionLike,
67
- wrapJsNativeDatabase,
68
- } from "@/common/database/native-database";
63
+ import { wrapJsNativeDatabase } from "@/common/database/native-database";
69
64
  import { assertJsonCompatValue, type JsonCompatValue } from "@/common/encoding";
70
65
  import { isResponseLike } from "@/common/fetch-like";
71
66
  import {
@@ -129,10 +124,8 @@ import type {
129
124
  RuntimeScheduledFireInfo,
130
125
  RuntimeServeConfig,
131
126
  RuntimeStateDeltaPayload,
132
- SqliteTransactionHandle,
133
127
  WebSocketHandle,
134
128
  } from "./runtime";
135
- import { servicesBinaryUnavailable } from "./runtime";
136
129
  import { loadWasmRuntime } from "./wasm-runtime";
137
130
  import {
138
131
  createWriteThroughProxy,
@@ -354,11 +347,6 @@ type NativeDestroyGate = {
354
347
  type NativeDatabaseClientState = {
355
348
  client: unknown;
356
349
  };
357
- type NativeActorAbort = {
358
- signal: AbortSignal;
359
- listeners: Set<() => void>;
360
- };
361
-
362
350
  type NativeActorRuntimeState = {
363
351
  sql?: ReturnType<typeof wrapJsNativeDatabase>;
364
352
  databaseClient?: NativeDatabaseClientState;
@@ -366,17 +354,6 @@ type NativeActorRuntimeState = {
366
354
  vars?: unknown;
367
355
  destroyGate?: NativeDestroyGate;
368
356
  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;
380
357
  };
381
358
 
382
359
  // Keep JS-only actor caches on the NAPI ActorContext runtime-state bag instead
@@ -386,10 +363,9 @@ function getNativeRuntimeState(
386
363
  runtime: CoreRuntime,
387
364
  ctx: ActorContextHandle,
388
365
  ): NativeActorRuntimeState {
389
- const runtimeState = readNativeRuntimeStateBag(runtime, ctx);
390
- if (runtimeState.cleared) {
391
- throw actorStopping(callNativeSync(() => runtime.actorId(ctx)));
392
- }
366
+ const runtimeState = callNativeSync(() =>
367
+ runtime.actorRuntimeState(ctx),
368
+ ) as NativeActorRuntimeState;
393
369
  if (!runtimeState.destroyGate) {
394
370
  runtimeState.destroyGate = {};
395
371
  }
@@ -403,22 +379,6 @@ function getNativeRuntimeState(
403
379
  return runtimeState;
404
380
  }
405
381
 
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
-
422
382
  function getNativePersistState(
423
383
  runtime: CoreRuntime,
424
384
  ctx: ActorContextHandle,
@@ -561,18 +521,7 @@ function clearNativeRuntimeState(
561
521
  runtime: CoreRuntime,
562
522
  ctx: ActorContextHandle,
563
523
  ) {
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
- }
571
524
  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;
576
525
  }
577
526
 
578
527
  async function cleanupNativeSleepRuntimeState(
@@ -587,7 +536,8 @@ async function cleanupNativeSleepRuntimeState(
587
536
  // the tracked work finishes without a deadline.
588
537
  const drained = await runtime.actorWaitForTrackedShutdownWork(ctx);
589
538
  if (!drained) {
590
- await detachNativeDatabaseForShutdown(runtime, ctx);
539
+ await closeNativeDatabaseClient(runtime, ctx);
540
+ await closeNativeSqlDatabase(runtime, ctx);
591
541
  void runtime
592
542
  .actorWaitForTrackedShutdownWorkUnbounded(ctx)
593
543
  .then(async () => {
@@ -604,26 +554,11 @@ async function cleanupNativeSleepRuntimeState(
604
554
  }
605
555
 
606
556
  await afterTrackedWorkDrained?.();
607
- await detachNativeDatabaseForShutdown(runtime, ctx);
557
+ await closeNativeDatabaseClient(runtime, ctx);
558
+ await closeNativeSqlDatabase(runtime, ctx);
608
559
  clearNativeRuntimeState(runtime, ctx);
609
560
  }
610
561
 
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
-
627
562
  function closeNativeSqlDatabase(
628
563
  runtime: CoreRuntime,
629
564
  ctx: ActorContextHandle,
@@ -660,26 +595,6 @@ async function closeNativeDatabaseClient(
660
595
  }
661
596
  }
662
597
 
663
- function createNativeSqlTransaction(
664
- runtime: CoreRuntime,
665
- transaction: SqliteTransactionHandle,
666
- ): JsNativeSynchronousTransactionLike {
667
- return {
668
- exec: (sql) => runtime.actorSqlTransactionExec(transaction, sql),
669
- execSync: (sql) =>
670
- runtime.actorSqlTransactionExecSync(transaction, sql),
671
- execute: (sql, params) =>
672
- runtime.actorSqlTransactionExecute(transaction, sql, params),
673
- executeSync: (sql, params) =>
674
- runtime.actorSqlTransactionExecuteSync(transaction, sql, params),
675
- commit: () => runtime.actorSqlTransactionCommit(transaction),
676
- commitSync: () => runtime.actorSqlTransactionCommitSync(transaction),
677
- rollback: () => runtime.actorSqlTransactionRollback(transaction),
678
- rollbackSync: () =>
679
- runtime.actorSqlTransactionRollbackSync(transaction),
680
- };
681
- }
682
-
683
598
  function getOrCreateNativeSqlDatabase(
684
599
  runtime: CoreRuntime,
685
600
  ctx: ActorContextHandle,
@@ -690,12 +605,9 @@ function getOrCreateNativeSqlDatabase(
690
605
  return cachedDatabase;
691
606
  }
692
607
 
693
- const bindings: JsNativeDatabaseLike = {
608
+ const database = wrapJsNativeDatabase({
694
609
  exec: (sql) => runtime.actorSqlExec(ctx, sql),
695
- execSync: (sql) => runtime.actorSqlExecSync(ctx, sql),
696
610
  execute: (sql, params) => runtime.actorSqlExecute(ctx, sql, params),
697
- executeSync: (sql, params) =>
698
- runtime.actorSqlExecuteSync(ctx, sql, params),
699
611
  executeBatch: (statements) =>
700
612
  runtime.actorSqlExecuteBatch(ctx, statements),
701
613
  beginTransaction: async (timeoutMs, name) => {
@@ -704,15 +616,19 @@ function getOrCreateNativeSqlDatabase(
704
616
  timeoutMs,
705
617
  name,
706
618
  );
707
- return createNativeSqlTransaction(runtime, transaction);
708
- },
709
- beginTransactionSync: (timeoutMs, name) => {
710
- const transaction = runtime.actorSqlBeginTransactionSync(
711
- ctx,
712
- timeoutMs,
713
- name,
714
- );
715
- return createNativeSqlTransaction(runtime, transaction);
619
+ return {
620
+ exec: (sql) =>
621
+ runtime.actorSqlTransactionExec(transaction, sql),
622
+ execute: (sql, params) =>
623
+ runtime.actorSqlTransactionExecute(
624
+ transaction,
625
+ sql,
626
+ params,
627
+ ),
628
+ commit: () => runtime.actorSqlTransactionCommit(transaction),
629
+ rollback: () =>
630
+ runtime.actorSqlTransactionRollback(transaction),
631
+ };
716
632
  },
717
633
  beginStateTransaction: async (timeoutMs, context) => {
718
634
  const scope = context as NativeStateTransactionScope | undefined;
@@ -752,14 +668,8 @@ function getOrCreateNativeSqlDatabase(
752
668
  run: (sql, params) => runtime.actorSqlRun(ctx, sql, params),
753
669
  metrics: () => runtime.actorSqlMetrics(ctx),
754
670
  takeLastKvError: () => runtime.actorSqlTakeLastKvError(ctx),
755
- open: () => runtime.actorSqlOpen(ctx),
756
- commitTicket: () => runtime.actorSqlCommitTicket(ctx),
757
- whenDurable: (ticket) => runtime.actorSqlWhenDurable(ctx, ticket),
758
- abortGeneration: (reason) =>
759
- runtime.actorSqlAbortGeneration(ctx, reason),
760
671
  close: () => runtime.actorSqlClose(ctx),
761
- };
762
- const database = wrapJsNativeDatabase(bindings);
672
+ });
763
673
  runtimeState.sql = database;
764
674
  return database;
765
675
  }
@@ -874,7 +784,7 @@ async function loadEngineCli(): Promise<typeof import("@rivetkit/engine-cli")> {
874
784
  return import(["@rivetkit", "engine-cli"].join("/"));
875
785
  }
876
786
 
877
- async function loadServices(): Promise<{ getServicesPath: () => string }> {
787
+ async function loadServices(): Promise<typeof import("@rivet-dev/services")> {
878
788
  // Keep the native binary opaque to edge bundlers for the same reason as
879
789
  // engine-cli above.
880
790
  return import(["@rivet-dev", "services"].join("/"));
@@ -3112,28 +3022,22 @@ export class ActorContextHandleAdapter {
3112
3022
 
3113
3023
  get abortSignal(): AbortSignal {
3114
3024
  if (!this.#abortSignal) {
3115
- const actorAbort = this.#actorAbort();
3116
- const actorSignal = actorAbort.signal;
3025
+ const actorSignal = this.#createActorAbortSignal();
3117
3026
  if (this.#dispatchCancelToken === undefined) {
3118
3027
  this.#abortSignal = actorSignal;
3119
3028
  } else {
3120
3029
  const controller = new AbortController();
3121
3030
  let cleanedUp = false;
3122
- let releaseDispatchListener: (() => void) | undefined;
3123
3031
  const onActorAbort = () => {
3124
3032
  cleanup();
3125
3033
  controller.abort();
3126
3034
  };
3127
- // Releasing the native listener on dispose frees it even when the
3128
- // dispatch token is never cancelled.
3129
3035
  const cleanup = () => {
3130
3036
  if (cleanedUp) {
3131
3037
  return;
3132
3038
  }
3133
3039
  cleanedUp = true;
3134
- actorAbort.listeners.delete(onActorAbort);
3135
- releaseDispatchListener?.();
3136
- releaseDispatchListener = undefined;
3040
+ actorSignal.removeEventListener("abort", onActorAbort);
3137
3041
  this.#abortSignalCleanup = undefined;
3138
3042
  };
3139
3043
 
@@ -3147,8 +3051,10 @@ export class ActorContextHandleAdapter {
3147
3051
  } else {
3148
3052
  const dispatchCancelToken = this.#dispatchCancelToken;
3149
3053
  this.#abortSignalCleanup = cleanup;
3150
- actorAbort.listeners.add(onActorAbort);
3151
- releaseDispatchListener = callNativeSync(() =>
3054
+ actorSignal.addEventListener("abort", onActorAbort, {
3055
+ once: true,
3056
+ });
3057
+ callNativeSync(() =>
3152
3058
  this.#runtime.onCancellationTokenCancelled(
3153
3059
  dispatchCancelToken,
3154
3060
  () => {
@@ -3215,12 +3121,10 @@ export class ActorContextHandleAdapter {
3215
3121
  {
3216
3122
  open: async (requestedActorId) => {
3217
3123
  void requestedActorId;
3218
- const database = getOrCreateNativeSqlDatabase(
3124
+ return getOrCreateNativeSqlDatabase(
3219
3125
  this.#runtime,
3220
3126
  this.#ctx,
3221
3127
  );
3222
- await database.open();
3223
- return database;
3224
3128
  },
3225
3129
  },
3226
3130
  async (timeoutMs, context) =>
@@ -3602,49 +3506,24 @@ export class ActorContextHandleAdapter {
3602
3506
 
3603
3507
  async dispose(): Promise<void> {
3604
3508
  // Flush any save coalesced for this tick before the context is torn
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
- }
3509
+ // down so the request-save and onStateChange always run.
3510
+ this.#flushStateChange();
3611
3511
  this.#abortSignalCleanup?.();
3612
3512
  }
3613
3513
 
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
-
3514
+ #createActorAbortSignal(): AbortSignal {
3626
3515
  const nativeSignal = callNativeSync(() =>
3627
3516
  this.#runtime.actorAbortSignal(this.#ctx),
3628
3517
  );
3629
3518
  const controller = new AbortController();
3630
- const actorAbort: NativeActorAbort = {
3631
- signal: controller.signal,
3632
- listeners: new Set(),
3633
- };
3634
- const abort = () => {
3635
- controller.abort();
3636
- for (const listener of actorAbort.listeners) {
3637
- listener();
3638
- }
3639
- actorAbort.listeners.clear();
3640
- };
3641
3519
  if (nativeSignal.aborted) {
3642
- abort();
3520
+ controller.abort();
3643
3521
  } else {
3644
- nativeSignal.addEventListener("abort", abort, { once: true });
3522
+ nativeSignal.addEventListener("abort", () => controller.abort(), {
3523
+ once: true,
3524
+ });
3645
3525
  }
3646
- runtimeState.actorAbort = actorAbort;
3647
- return actorAbort;
3526
+ return controller.signal;
3648
3527
  }
3649
3528
 
3650
3529
  #readState(): unknown {
@@ -4017,8 +3896,6 @@ function buildActorTracingConfig(
4017
3896
  };
4018
3897
  }
4019
3898
 
4020
- const SQLITE_DEFERRED_COMMITS = Symbol.for("rivetkit.sqlite.deferredCommits");
4021
-
4022
3899
  function buildActorConfig(
4023
3900
  definition: AnyActorDefinition,
4024
3901
  registryConfig: RegistryConfig,
@@ -4032,18 +3909,12 @@ function buildActorConfig(
4032
3909
  const sqliteProfiling = (
4033
3910
  config.db as { sqliteProfiling?: SqliteProfilingOptions } | undefined
4034
3911
  )?.sqliteProfiling;
4035
- // Internal opt-in for embedders, such as Open Orange, that gate outputs on `whenDurable`.
4036
- const sqliteDeferredCommits =
4037
- (config.db as Record<symbol, unknown> | undefined)?.[
4038
- SQLITE_DEFERRED_COMMITS
4039
- ] === true;
4040
3912
 
4041
3913
  return {
4042
3914
  name: options.name as string | undefined,
4043
3915
  icon: options.icon as string | undefined,
4044
3916
  hasDatabase: true,
4045
3917
  remoteSqlite: usesRemoteSqlite,
4046
- sqliteDeferredCommits: sqliteDeferredCommits || undefined,
4047
3918
  sqliteProfiling,
4048
3919
  tracing: buildActorTracingConfig(
4049
3920
  definition.config.actions,
@@ -4975,7 +4846,7 @@ export function buildNativeFactory(
4975
4846
  }
4976
4847
  } finally {
4977
4848
  resolveNativeDestroy(runtime, ctx);
4978
- await detachNativeDatabaseForShutdown(runtime, ctx);
4849
+ await actorCtx.closeDatabase();
4979
4850
  clearNativeRuntimeState(runtime, ctx);
4980
4851
  await actorCtx.dispose();
4981
4852
  }
@@ -5727,12 +5598,11 @@ export async function buildServeConfig(
5727
5598
  }
5728
5599
 
5729
5600
  const serveConfig: RuntimeServeConfig = {
5730
- version: config.node.version,
5601
+ version: config.envoy.version,
5731
5602
  endpoint: config.endpoint,
5732
- engineSpawn: config.engineSpawn,
5733
5603
  token: config.token,
5734
5604
  namespace: config.namespace,
5735
- poolName: config.node.poolName,
5605
+ poolName: config.envoy.poolName,
5736
5606
  startServices: resolveServicesBinary && config.startServices,
5737
5607
  handleInspectorHttpInRuntime: true,
5738
5608
  serverlessBasePath: config.serverless.basePath,
@@ -5746,7 +5616,7 @@ export async function buildServeConfig(
5746
5616
 
5747
5617
  // Always best-effort resolve the npm-installed engine binary and hand its
5748
5618
  // path to the core. The core alone decides whether to actually spawn a local
5749
- // engine using the resolved spawn decision, so
5619
+ // engine (its `should_manage_engine`, based on the endpoint + spawn mode), so
5750
5620
  // JS must not duplicate that decision here. Only JS knows the npm
5751
5621
  // `node_modules` layout, so it resolves the path; if no binary is available
5752
5622
  // (remote-only install, unsupported platform, optional deps skipped), leave
@@ -5766,16 +5636,14 @@ export async function buildServeConfig(
5766
5636
  });
5767
5637
  }
5768
5638
  if (resolveServicesBinary && config.startServices) {
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
- }
5639
+ try {
5640
+ const { getServicesPath } = await loadServices();
5641
+ serveConfig.servicesBinaryPath = getServicesPath();
5642
+ } catch (error) {
5643
+ logger().warn({
5644
+ msg: "could not resolve the Services binary; a local engine will fail with services.binary_unavailable — set RIVET_RUN_SERVICES=0 to disable Services or RIVET_SERVICES_BINARY to a local rivet-services binary",
5645
+ error: stringifyError(error),
5646
+ });
5779
5647
  }
5780
5648
  }
5781
5649
  serveConfig.engineHost = config.engineHost;