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.
Files changed (154) hide show
  1. package/dist/browser/client.d.ts +58 -9
  2. package/dist/browser/client.js +193 -23
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +1 -5
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/agent-os/index.cjs +3 -2652
  7. package/dist/tsup/agent-os/index.cjs.map +1 -1
  8. package/dist/tsup/agent-os/index.d.cts +1 -2758
  9. package/dist/tsup/agent-os/index.d.ts +1 -2758
  10. package/dist/tsup/agent-os/index.js +3 -2652
  11. package/dist/tsup/agent-os/index.js.map +1 -1
  12. package/dist/tsup/{chunk-PFLHGSS7.cjs → chunk-3JPXBFED.cjs} +4 -4
  13. package/dist/tsup/{chunk-PFLHGSS7.cjs.map → chunk-3JPXBFED.cjs.map} +1 -1
  14. package/dist/tsup/{chunk-VZPQBM4T.js → chunk-5X35FD2T.js} +4 -4
  15. package/dist/tsup/{chunk-62NMENN2.js → chunk-6QNBANXM.js} +3 -3
  16. package/dist/tsup/{chunk-TBVEI4CG.js → chunk-7HILY7QU.js} +185 -25
  17. package/dist/tsup/chunk-7HILY7QU.js.map +1 -0
  18. package/dist/tsup/{chunk-JI6GZ2C2.js → chunk-A2CF6PFH.js} +18 -1
  19. package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
  20. package/dist/tsup/{chunk-XU5FXL53.cjs → chunk-CT6GQRUN.cjs} +3 -3
  21. package/dist/tsup/{chunk-XU5FXL53.cjs.map → chunk-CT6GQRUN.cjs.map} +1 -1
  22. package/dist/tsup/{chunk-3XABSX7Z.js → chunk-DRZTELHJ.js} +10 -14
  23. package/dist/tsup/chunk-DRZTELHJ.js.map +1 -0
  24. package/dist/tsup/{chunk-S4JJAPRX.js → chunk-DUGEPEJO.js} +2 -2
  25. package/dist/tsup/{chunk-E443NPGV.cjs → chunk-EA6P3N4I.cjs} +3 -3
  26. package/dist/tsup/{chunk-E443NPGV.cjs.map → chunk-EA6P3N4I.cjs.map} +1 -1
  27. package/dist/tsup/{chunk-KNVSGCHJ.cjs → chunk-ERZDCOQ3.cjs} +10 -10
  28. package/dist/tsup/{chunk-KNVSGCHJ.cjs.map → chunk-ERZDCOQ3.cjs.map} +1 -1
  29. package/dist/tsup/{chunk-PFOK45LA.js → chunk-GHTA76HT.js} +2 -2
  30. package/dist/tsup/{chunk-74MPKC4U.js → chunk-ID5VJNZY.js} +2 -2
  31. package/dist/tsup/{chunk-FKJJX36M.cjs → chunk-PXIOH445.cjs} +326 -166
  32. package/dist/tsup/chunk-PXIOH445.cjs.map +1 -0
  33. package/dist/tsup/{chunk-MYWZCDML.cjs → chunk-RTWH3AX3.cjs} +19 -2
  34. package/dist/tsup/chunk-RTWH3AX3.cjs.map +1 -0
  35. package/dist/tsup/{chunk-WMBIR2SY.cjs → chunk-UV4KDO4W.cjs} +3 -3
  36. package/dist/tsup/{chunk-WMBIR2SY.cjs.map → chunk-UV4KDO4W.cjs.map} +1 -1
  37. package/dist/tsup/{chunk-4G6WPUYN.js → chunk-VI2S336K.js} +2 -2
  38. package/dist/tsup/{chunk-4AIU4P2C.cjs → chunk-W7NPIYWC.cjs} +10 -14
  39. package/dist/tsup/chunk-W7NPIYWC.cjs.map +1 -0
  40. package/dist/tsup/{chunk-BO74QMUL.cjs → chunk-ZZQM77UA.cjs} +7 -7
  41. package/dist/tsup/{chunk-BO74QMUL.cjs.map → chunk-ZZQM77UA.cjs.map} +1 -1
  42. package/dist/tsup/client/mod.cjs +6 -6
  43. package/dist/tsup/client/mod.d.cts +15 -3
  44. package/dist/tsup/client/mod.d.ts +15 -3
  45. package/dist/tsup/client/mod.js +5 -5
  46. package/dist/tsup/common/log.cjs +2 -2
  47. package/dist/tsup/common/log.js +1 -1
  48. package/dist/tsup/common/websocket.cjs +3 -3
  49. package/dist/tsup/common/websocket.js +2 -2
  50. package/dist/tsup/{config-DfVrAigH.d.ts → config-B4erdavw.d.ts} +43 -12
  51. package/dist/tsup/{config-BaUctMNL.d.cts → config-BfG1qpYz.d.cts} +7 -1
  52. package/dist/tsup/{config-BaUctMNL.d.ts → config-BfG1qpYz.d.ts} +7 -1
  53. package/dist/tsup/{config-D6T6Ud_V.d.cts → config-DK144OAw.d.cts} +43 -12
  54. package/dist/tsup/{context-CowF_zyQ.d.cts → context-Cvnf3BRe.d.cts} +2 -2
  55. package/dist/tsup/{context-BsFWwi3i.d.ts → context-Oxi6YWcG.d.ts} +2 -2
  56. package/dist/tsup/db/drizzle.cjs +2 -2
  57. package/dist/tsup/db/drizzle.d.cts +1 -1
  58. package/dist/tsup/db/drizzle.d.ts +1 -1
  59. package/dist/tsup/db/drizzle.js +1 -1
  60. package/dist/tsup/db/mod.cjs +3 -3
  61. package/dist/tsup/db/mod.d.cts +2 -2
  62. package/dist/tsup/db/mod.d.ts +2 -2
  63. package/dist/tsup/db/mod.js +2 -2
  64. package/dist/tsup/dynamic/mod.d.cts +2 -2
  65. package/dist/tsup/dynamic/mod.d.ts +2 -2
  66. package/dist/tsup/inspector/mod.cjs +5 -5
  67. package/dist/tsup/inspector/mod.js +4 -4
  68. package/dist/tsup/inspector/workflow.cjs +4 -4
  69. package/dist/tsup/inspector/workflow.js +3 -3
  70. package/dist/tsup/inspector-tab/mod.d.cts +3 -3
  71. package/dist/tsup/inspector-tab/mod.d.ts +3 -3
  72. package/dist/tsup/mod.cjs +256 -174
  73. package/dist/tsup/mod.cjs.map +1 -1
  74. package/dist/tsup/mod.d.cts +4 -4
  75. package/dist/tsup/mod.d.ts +4 -4
  76. package/dist/tsup/mod.js +170 -88
  77. package/dist/tsup/mod.js.map +1 -1
  78. package/dist/tsup/test/mod.cjs +7 -7
  79. package/dist/tsup/test/mod.d.cts +2 -2
  80. package/dist/tsup/test/mod.d.ts +2 -2
  81. package/dist/tsup/test/mod.js +5 -5
  82. package/dist/tsup/unstable/migrations.d.cts +1 -1
  83. package/dist/tsup/unstable/migrations.d.ts +1 -1
  84. package/dist/tsup/utils.cjs +2 -2
  85. package/dist/tsup/utils.js +1 -1
  86. package/dist/tsup/workflow/mod.cjs +17 -17
  87. package/dist/tsup/workflow/mod.d.cts +4 -4
  88. package/dist/tsup/workflow/mod.d.ts +4 -4
  89. package/dist/tsup/workflow/mod.js +5 -5
  90. package/package.json +9 -13
  91. package/src/actor/keys.ts +86 -0
  92. package/src/agent-os/index.ts +5 -65
  93. package/src/client/actor-conn.ts +92 -6
  94. package/src/client/actor-handle.ts +24 -4
  95. package/src/client/client.ts +14 -4
  96. package/src/client/config.ts +12 -1
  97. package/src/client/lifecycle-errors.ts +16 -1
  98. package/src/client/retry-budget.ts +78 -0
  99. package/src/client/utils.ts +13 -2
  100. package/src/common/database/config.ts +7 -1
  101. package/src/common/database/native-database.ts +17 -9
  102. package/src/common/router.ts +1 -1
  103. package/src/engine-api/actors.ts +3 -3
  104. package/src/engine-client/actor-websocket-client.ts +4 -2
  105. package/src/engine-client/api-endpoints.ts +44 -14
  106. package/src/engine-client/mod.ts +2 -2
  107. package/src/registry/config/envoy.ts +1 -1
  108. package/src/registry/config/index.ts +28 -31
  109. package/src/registry/index.ts +51 -19
  110. package/src/registry/napi-runtime.ts +3 -2
  111. package/src/registry/native.ts +129 -40
  112. package/src/registry/runtime.ts +27 -10
  113. package/src/registry/wasm-runtime.ts +6 -3
  114. package/src/utils/env-vars.ts +15 -10
  115. package/dist/tsup/chunk-3XABSX7Z.js.map +0 -1
  116. package/dist/tsup/chunk-4AIU4P2C.cjs.map +0 -1
  117. package/dist/tsup/chunk-FKJJX36M.cjs.map +0 -1
  118. package/dist/tsup/chunk-JI6GZ2C2.js.map +0 -1
  119. package/dist/tsup/chunk-MYWZCDML.cjs.map +0 -1
  120. package/dist/tsup/chunk-TBVEI4CG.js.map +0 -1
  121. package/src/actor/config.test.ts +0 -78
  122. package/src/actor/keys.test.ts +0 -275
  123. package/src/actor/utils.test.ts +0 -48
  124. package/src/agent-os/actor/cron.ts +0 -84
  125. package/src/agent-os/actor/db.ts +0 -54
  126. package/src/agent-os/actor/filesystem.ts +0 -131
  127. package/src/agent-os/actor/index.ts +0 -285
  128. package/src/agent-os/actor/network.ts +0 -58
  129. package/src/agent-os/actor/preview.ts +0 -190
  130. package/src/agent-os/actor/process.ts +0 -177
  131. package/src/agent-os/actor/session.ts +0 -518
  132. package/src/agent-os/actor/shell.ts +0 -60
  133. package/src/agent-os/config.ts +0 -79
  134. package/src/agent-os/fs/database-vfs.ts +0 -624
  135. package/src/agent-os/types.ts +0 -148
  136. package/src/client/test.ts +0 -44
  137. package/src/client/token-provider.test.ts +0 -86
  138. package/src/common/database/mod.test.ts +0 -364
  139. package/src/common/database/native-database.test.ts +0 -241
  140. package/src/common/inline-websocket-adapter.test.ts +0 -51
  141. package/src/db/drizzle.test.ts +0 -164
  142. package/src/registry/config/index.test.ts +0 -25
  143. package/src/registry/run-handler-coordinator.test.ts +0 -252
  144. package/src/registry/runtime.test.ts +0 -124
  145. package/src/unstable/migrations.test.ts +0 -170
  146. package/src/utils/endpoint-parser.test.ts +0 -206
  147. package/src/utils.test.ts +0 -34
  148. package/src/workflow/driver.test.ts +0 -62
  149. /package/dist/tsup/{chunk-VZPQBM4T.js.map → chunk-5X35FD2T.js.map} +0 -0
  150. /package/dist/tsup/{chunk-62NMENN2.js.map → chunk-6QNBANXM.js.map} +0 -0
  151. /package/dist/tsup/{chunk-S4JJAPRX.js.map → chunk-DUGEPEJO.js.map} +0 -0
  152. /package/dist/tsup/{chunk-PFOK45LA.js.map → chunk-GHTA76HT.js.map} +0 -0
  153. /package/dist/tsup/{chunk-74MPKC4U.js.map → chunk-ID5VJNZY.js.map} +0 -0
  154. /package/dist/tsup/{chunk-4G6WPUYN.js.map → chunk-VI2S336K.js.map} +0 -0
@@ -167,17 +167,6 @@ export interface RunnerConfigsResponse {
167
167
  runner_configs: Record<string, RunnerConfigDatacenters>;
168
168
  }
169
169
 
170
- export async function getRunnerConfig(
171
- config: ClientConfig,
172
- name: string,
173
- ): Promise<RunnerConfigsResponse> {
174
- return apiCall<never, RunnerConfigsResponse>(
175
- config,
176
- "GET",
177
- `/runner-configs?runner_name=${name}`,
178
- );
179
- }
180
-
181
170
  // MARK: Update runner config
182
171
  export interface RegistryConfigRequest {
183
172
  datacenters: Record<
@@ -212,11 +201,11 @@ export async function updateRunnerConfig(
212
201
  runnerName: string,
213
202
  request: RegistryConfigRequest,
214
203
  ): Promise<void> {
215
- return apiCall<RegistryConfigRequest, void>(
204
+ return apiCall<unknown, void>(
216
205
  config,
217
206
  "PUT",
218
- `/runner-configs/${runnerName}`,
219
- request,
207
+ `/pools/${encodeURIComponent(runnerName)}`,
208
+ Object.values(request.datacenters)[0],
220
209
  );
221
210
  }
222
211
 
@@ -237,3 +226,44 @@ export async function kvGet(
237
226
  `/actors/${encodeURIComponent(actorId)}/kv/keys/${encodeURIComponent(key)}`,
238
227
  );
239
228
  }
229
+
230
+ /** Pool changes apply when each node next connects. */
231
+ export interface PoolConfig {
232
+ drain_on_version_upgrade?: boolean;
233
+ actor_eviction_delay?: number;
234
+ actor_eviction_period?: number;
235
+ actor_eviction_rate?: number;
236
+ metadata?: unknown;
237
+ }
238
+
239
+ export function upsertPool(
240
+ config: ClientConfig,
241
+ name: string,
242
+ pool: PoolConfig,
243
+ ): Promise<{ pool: PoolConfig & { name: string } }> {
244
+ return apiCall(config, "PUT", `/pools/${encodeURIComponent(name)}`, pool);
245
+ }
246
+
247
+ export function getPool(
248
+ config: ClientConfig,
249
+ name: string,
250
+ ): Promise<{ pool: PoolConfig & { name: string } }> {
251
+ return apiCall(config, "GET", `/pools/${encodeURIComponent(name)}`);
252
+ }
253
+
254
+ export function listPools(
255
+ config: ClientConfig,
256
+ page?: { limit?: number; cursor?: string },
257
+ ): Promise<{
258
+ pools: Array<PoolConfig & { name: string }>;
259
+ pagination: { cursor: string | null };
260
+ }> {
261
+ const query = new URLSearchParams();
262
+ if (page?.limit !== undefined) query.set("limit", String(page.limit));
263
+ if (page?.cursor !== undefined) query.set("cursor", page.cursor);
264
+ return apiCall(config, "GET", `/pools?${query}`);
265
+ }
266
+
267
+ export function deletePool(config: ClientConfig, name: string): Promise<void> {
268
+ return apiCall(config, "DELETE", `/pools/${encodeURIComponent(name)}`);
269
+ }
@@ -254,7 +254,7 @@ export class RemoteEngineControlClient implements EngineControlClient {
254
254
  datacenter: region,
255
255
  name,
256
256
  key: serializeActorKey(key),
257
- runner_name_selector: poolName ?? this.#config.poolName,
257
+ pool: poolName ?? this.#config.poolName,
258
258
  input: actorInput
259
259
  ? uint8ArrayToBase64(
260
260
  encodeCborCompat(actorInput as JsonCompatValue),
@@ -325,7 +325,7 @@ export class RemoteEngineControlClient implements EngineControlClient {
325
325
  createActor(config, {
326
326
  datacenter: region,
327
327
  name,
328
- runner_name_selector: poolName ?? this.#config.poolName,
328
+ pool: poolName ?? this.#config.poolName,
329
329
  key: serializeActorKey(key),
330
330
  input: input
331
331
  ? uint8ArrayToBase64(
@@ -11,7 +11,7 @@ export const EnvoyConfigSchema = z.object({
11
11
 
12
12
  // Deprecated.
13
13
  totalSlots: z.number().default(() => getRivetTotalSlots() ?? 100000),
14
- envoyKey: z.string().optional(),
14
+ nodeKey: z.string().optional(),
15
15
  });
16
16
  export type EnvoyConfigInput = z.input<typeof EnvoyConfigSchema>;
17
17
  export type EnvoyConfig = z.infer<typeof EnvoyConfigSchema>;
@@ -158,7 +158,7 @@ export const RegistryConfigSchema = z
158
158
  // // created or must be imported async using `await import(...)`
159
159
  // getUpgradeWebSocket: z.custom<GetUpgradeWebSocket>().optional(),
160
160
 
161
- // MARK: Runner Configuration
161
+ // MARK: Node Configuration
162
162
  /**
163
163
  * Endpoint to connect to for Rivet Engine.
164
164
  *
@@ -251,14 +251,14 @@ export const RegistryConfigSchema = z
251
251
  .default(() => getRivetRunEngineVersion() ?? VERSION),
252
252
  /**
253
253
  * Starts the first-party Services actor host when RivetKit manages
254
- * a local engine. Defaults to the local-engine decision. Set
255
- * RIVET_RUN_SERVICES=0 or 1 to override it.
254
+ * a local engine. Disabled by default. Set RIVET_RUN_SERVICES=1
255
+ * or startServices: true to enable it.
256
256
  */
257
257
  startServices: z.boolean().optional(),
258
258
  /**
259
259
  * @experimental
260
260
  *
261
- * Automatically configure serverless envoys in the engine.
261
+ * Automatically configure serverless nodes in the engine.
262
262
  */
263
263
  configurePool: ConfigurePoolSchema.optional(),
264
264
 
@@ -266,7 +266,7 @@ export const RegistryConfigSchema = z
266
266
  serverless: ServerlessConfigSchema.optional().default(() =>
267
267
  ServerlessConfigSchema.parse({}),
268
268
  ),
269
- envoy: EnvoyConfigSchema.optional().default(() =>
269
+ node: EnvoyConfigSchema.optional().default(() =>
270
270
  EnvoyConfigSchema.parse({}),
271
271
  ),
272
272
 
@@ -274,9 +274,9 @@ export const RegistryConfigSchema = z
274
274
  /**
275
275
  * Graceful shutdown configuration for SIGINT/SIGTERM.
276
276
  *
277
- * When a persistent envoy is running (Mode A, started via `registry.start()`),
277
+ * When a persistent node is running (Mode A, started via `registry.start()`),
278
278
  * rivetkit installs Node SIGINT/SIGTERM handlers that call into core's
279
- * `shutdown()` and wait up to `gracePeriodMs` for the envoy to drain
279
+ * `shutdown()` and wait up to `gracePeriodMs` for the node to drain
280
280
  * before re-raising the signal to let Node exit via its default path.
281
281
  *
282
282
  * Handlers are NOT installed when `handler(request)` is used alone
@@ -289,9 +289,11 @@ export const RegistryConfigSchema = z
289
289
  /**
290
290
  * Wait this many milliseconds for the serve promise to resolve
291
291
  * after calling `CoreRegistry::shutdown()`. Defaults to the
292
- * engine-provided actor stop threshold once the envoy connects.
292
+ * engine-provided actor stop threshold once the node connects. A
293
+ * signal-driven shutdown of a managed local development engine waits
294
+ * one second by default so a file watcher can restart promptly.
293
295
  *
294
- * Must be long enough for rivetkit-core to drain the envoy.
296
+ * Set a longer period when a complete graceful node drain is required.
295
297
  */
296
298
  gracePeriodMs: z.number().int().min(1_000).optional(),
297
299
  /**
@@ -348,12 +350,12 @@ export const RegistryConfigSchema = z
348
350
  });
349
351
  }
350
352
 
351
- // configurePool requires an engine (via endpoint or startEngine).
352
- if (config.configurePool && !parsedEndpoint && !config.startEngine) {
353
+ // Serverless pool configuration is disabled for v3.
354
+ if (config.configurePool) {
353
355
  ctx.addIssue({
354
356
  code: "custom",
355
- message:
356
- "configurePool requires either endpoint or startEngine",
357
+ message: "serverless is disabled in this version",
358
+ path: ["configurePool"],
357
359
  });
358
360
  }
359
361
 
@@ -366,13 +368,7 @@ export const RegistryConfigSchema = z
366
368
  ? localEngineEndpoint
367
369
  : (parsedEndpoint?.endpoint ??
368
370
  (isDevEnv ? localEngineEndpoint : undefined));
369
- // Services is another local development actor host. Its default
370
- // follows the same local-endpoint decision that causes core to manage the
371
- // Engine, while explicit config and RIVET_RUN_SERVICES take precedence.
372
- const startServices =
373
- config.startServices ??
374
- getRivetRunServices() ??
375
- Boolean(endpoint && isLocalEngineEndpoint(endpoint));
371
+ const startServices = config.startServices ?? getRivetRunServices();
376
372
  const validateServerlessEndpoint = Boolean(
377
373
  config.startEngine || parsedEndpoint,
378
374
  );
@@ -422,6 +418,7 @@ export const RegistryConfigSchema = z
422
418
  ...config,
423
419
  sqlite,
424
420
  endpoint,
421
+ engineSpawn: !parsedEndpoint && Boolean(endpoint),
425
422
  startServices,
426
423
  namespace,
427
424
  token,
@@ -468,10 +465,10 @@ export function buildActorNames(
468
465
 
469
466
  export const DocConfigurePoolSchema = z
470
467
  .object({
471
- name: z.string().optional().describe("Name of the runner pool."),
468
+ name: z.string().optional().describe("Name of the node pool."),
472
469
  url: z
473
470
  .string()
474
- .describe("URL of the serverless platform to configure runners."),
471
+ .describe("URL of the serverless platform to configure nodes."),
475
472
  headers: z
476
473
  .record(z.string(), z.string())
477
474
  .optional()
@@ -504,7 +501,7 @@ export const DocConfigurePoolSchema = z
504
501
  .boolean()
505
502
  .optional()
506
503
  .describe(
507
- "Drain runners when a new version is deployed. Defaults to true.",
504
+ "Drain nodes when a new version is deployed. Defaults to true.",
508
505
  ),
509
506
  })
510
507
  .optional();
@@ -547,17 +544,17 @@ export const DocEnvoyConfigSchema = z
547
544
  poolName: z
548
545
  .string()
549
546
  .optional()
550
- .describe("Name of this envoy pool. Default: 'default'"),
551
- envoyKey: z
547
+ .describe("Name of this node pool. Default: 'default'"),
548
+ nodeKey: z
552
549
  .string()
553
550
  .optional()
554
- .describe("Deprecated. Authentication key for the envoy."),
551
+ .describe("Deprecated. Authentication key for the node."),
555
552
  version: z
556
553
  .number()
557
554
  .optional()
558
- .describe("Version number of this envoy. Default: 1"),
555
+ .describe("Version number of this node. Default: 1"),
559
556
  })
560
- .describe("Configuration for envoy mode.");
557
+ .describe("Configuration for node mode.");
561
558
 
562
559
  export const DocSqliteConfigSchema = z
563
560
  .object({
@@ -658,12 +655,12 @@ export const DocRegistryConfigSchema = z
658
655
  .boolean()
659
656
  .optional()
660
657
  .describe(
661
- "Starts Services when RivetKit manages a local Engine. Defaults to the local-Engine decision. Set RIVET_RUN_SERVICES=0 or 1 to override.",
658
+ "Starts Services when RivetKit manages a local Engine. Disabled by default. Set RIVET_RUN_SERVICES=1 or startServices: true to enable.",
662
659
  ),
663
660
  configurePool: DocConfigurePoolSchema.describe(
664
- "Automatically configure serverless runners in the engine.",
661
+ "Automatically configure serverless nodes in the engine.",
665
662
  ),
666
663
  serverless: DocServerlessConfigSchema.optional(),
667
- envoy: DocEnvoyConfigSchema.optional(),
664
+ node: DocEnvoyConfigSchema.optional(),
668
665
  })
669
666
  .describe("RivetKit registry configuration.");
@@ -30,6 +30,11 @@ type ShutdownSignal = "SIGINT" | "SIGTERM";
30
30
 
31
31
  const REGISTRY_READY_TIMEOUT_MS = 30_000;
32
32
 
33
+ // Serverless is disabled for v3; keep the implementation for a later release.
34
+ function rejectServerless(): void {
35
+ throw new Error("serverless is disabled in this version");
36
+ }
37
+
33
38
  function signalExitCode(signal: ShutdownSignal): number {
34
39
  switch (signal) {
35
40
  case "SIGINT":
@@ -190,6 +195,7 @@ export class Registry<A extends RegistryActors> {
190
195
  config: RegistryConfig,
191
196
  ): Promise<void> | undefined {
192
197
  if (!config.configurePool) return undefined;
198
+ rejectServerless();
193
199
 
194
200
  if (!this.#configureServerlessPoolPromise) {
195
201
  this.#configureServerlessPoolPromise = configureServerlessPool(
@@ -215,6 +221,7 @@ export class Registry<A extends RegistryActors> {
215
221
  * ```
216
222
  */
217
223
  public async handler(request: Request): Promise<Response> {
224
+ rejectServerless();
218
225
  const config = this.parseConfig();
219
226
  this.#printWelcome(config, "serverless");
220
227
 
@@ -413,6 +420,7 @@ export class Registry<A extends RegistryActors> {
413
420
  * ```
414
421
  */
415
422
  public serve(): ServerlessHandler {
423
+ rejectServerless();
416
424
  return {
417
425
  fetch: (request) => this.handler(request),
418
426
  };
@@ -438,6 +446,9 @@ export class Registry<A extends RegistryActors> {
438
446
  * ```
439
447
  */
440
448
  public async listen(opts: RegistryListenOptions = {}): Promise<void> {
449
+ if (!opts.application) {
450
+ rejectServerless();
451
+ }
441
452
  const port = opts.port ?? parsePortEnv(process.env.RIVET_PORT) ?? 3000;
442
453
  const publicDir = opts.publicDir ?? getRivetkitPublicDir();
443
454
  const config = this.parseConfig();
@@ -554,6 +565,7 @@ export class Registry<A extends RegistryActors> {
554
565
  * Returns serverless metadata suitable for mounting in a user-owned router.
555
566
  */
556
567
  async #metadataRoute(): Promise<Response> {
568
+ rejectServerless();
557
569
  const configured = await this.#activeConfiguredRegistry();
558
570
  if (!configured) {
559
571
  return new Response("registry not started\n", {
@@ -626,7 +638,7 @@ export class Registry<A extends RegistryActors> {
626
638
  */
627
639
  #startEnvoy(config: RegistryConfig, printWelcome: boolean) {
628
640
  if (!this.#runtimeServePromise) {
629
- const configuredEnvoyVersion = this.#config.envoy?.version;
641
+ const configuredEnvoyVersion = this.#config.node?.version;
630
642
  const envoyVersionSource =
631
643
  configuredEnvoyVersion !== undefined
632
644
  ? "config"
@@ -637,7 +649,7 @@ export class Registry<A extends RegistryActors> {
637
649
  logger().info({
638
650
  msg: "starting rivetkit envoy",
639
651
  rivetkitVersion: VERSION,
640
- envoyVersion: config.envoy.version,
652
+ envoyVersion: config.node.version,
641
653
  envoyVersionSource,
642
654
  });
643
655
 
@@ -646,8 +658,8 @@ export class Registry<A extends RegistryActors> {
646
658
  getNodeEnv() === "production"
647
659
  ) {
648
660
  logger().error({
649
- msg: "envoy version defaulted because neither config.envoy.version nor RIVET_ENVOY_VERSION is set; actors will not drain automatically across deploys. See https://rivet.dev/docs/actors/versions",
650
- envoyVersion: config.envoy.version,
661
+ msg: "node version defaulted because neither config.node.version nor RIVET_NODE_VERSION is set; actors will not drain automatically across deploys. See https://rivet.dev/docs/actors/versions",
662
+ envoyVersion: config.node.version,
651
663
  envoyVersionSource,
652
664
  });
653
665
  }
@@ -666,7 +678,13 @@ export class Registry<A extends RegistryActors> {
666
678
  // rejection unhandled. Downstream awaits (e.g. #runShutdown's
667
679
  // Promise.race) attach their own catches and still observe
668
680
  // resolution via the race.
669
- logger().warn({ error }, "runtime registry serve errored");
681
+ logger().error({ error }, "runtime registry serve errored");
682
+ if (
683
+ typeof process !== "undefined" &&
684
+ typeof process.exit === "function"
685
+ ) {
686
+ process.exit(1);
687
+ }
670
688
  });
671
689
  // Install signal handlers once an envoy lifecycle has begun. Only
672
690
  // Mode A ever reaches here. Mode B (handler(request)) intentionally
@@ -714,7 +732,7 @@ export class Registry<A extends RegistryActors> {
714
732
  finishShutdownSignal(signal);
715
733
  return;
716
734
  }
717
- this.#shutdownInFlight = this.#drain(config)
735
+ this.#shutdownInFlight = this.#drain(config, true)
718
736
  .catch((err) => {
719
737
  logger().warn({ err }, "shutdown error");
720
738
  })
@@ -757,18 +775,28 @@ export class Registry<A extends RegistryActors> {
757
775
  return this.#shutdownInFlight;
758
776
  }
759
777
 
760
- async #drain(config: RegistryConfig): Promise<void> {
778
+ async #drain(config: RegistryConfig, signalDriven = false): Promise<void> {
761
779
  const modeAPromise = this.#runtimeServeConfiguredPromise;
762
780
  const modeBPromise = this.#runtimeServerlessPromise;
763
781
  const runtimes = new Set<CoreRuntime>();
764
782
 
765
- const gracePeriodMs =
766
- config.shutdown?.gracePeriodMs ??
767
- (await this.#actorStopThresholdMs(modeAPromise ?? modeBPromise)) ??
768
- 30 * 60 * 1000;
783
+ const localDevSignal =
784
+ signalDriven &&
785
+ getNodeEnv() !== "production" &&
786
+ config.engineSpawn &&
787
+ config.endpoint !== undefined &&
788
+ isLocalEngineEndpoint(config.endpoint);
789
+ let gracePeriodMs = config.shutdown?.gracePeriodMs;
790
+ if (gracePeriodMs === undefined) {
791
+ gracePeriodMs = localDevSignal
792
+ ? 1_000
793
+ : ((await this.#actorStopThresholdMs(
794
+ modeAPromise ?? modeBPromise,
795
+ )) ?? 30 * 60 * 1000);
796
+ }
769
797
  // Race the entire drain sequence (both modes + serve promise) against
770
- // a single grace ceiling. By default, this uses the engine-provided
771
- // actor stop threshold, matching Pegboard's hard cutoff for actors.
798
+ // a single grace ceiling. Local dev signal shutdowns allow the watcher
799
+ // to restart promptly; other shutdowns use the engine's actor stop threshold.
772
800
  const drain = async () => {
773
801
  // Shut down every live `CoreRegistry` we know about. Mode A
774
802
  // (`start()`) and Mode B (`handler()`) each build a separate
@@ -887,12 +915,16 @@ export class Registry<A extends RegistryActors> {
887
915
  );
888
916
  }
889
917
  if (this.#runtimeReadyPromise) return this.#runtimeReadyPromise;
890
- if (getRivetkitRuntimeMode() === "serverless") {
891
- return Promise.reject(
892
- new Error(
893
- "registry.startAndWait() requires envoy runtime mode; serverless registries become ready per request",
894
- ),
895
- );
918
+ try {
919
+ if (getRivetkitRuntimeMode() === "serverless") {
920
+ return Promise.reject(
921
+ new Error(
922
+ "registry.startAndWait() requires envoy runtime mode; serverless registries become ready per request",
923
+ ),
924
+ );
925
+ }
926
+ } catch (error) {
927
+ return Promise.reject(error);
896
928
  }
897
929
 
898
930
  const config = this.parseConfig();
@@ -481,8 +481,9 @@ export class NapiCoreRuntime implements CoreRuntime {
481
481
  onCancellationTokenCancelled(
482
482
  token: CancellationTokenHandle,
483
483
  callback: (...args: unknown[]) => unknown,
484
- ): void {
485
- asNativeCancellationToken(token).onCancelled(callback);
484
+ ): () => void {
485
+ const listener = asNativeCancellationToken(token).onCancelled(callback);
486
+ return () => listener.release();
486
487
  }
487
488
 
488
489
  actorState(ctx: ActorContextHandle): Buffer {