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
@@ -0,0 +1,164 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import type {
3
+ DatabaseProviderContext,
4
+ SqliteBatchStatement,
5
+ SqliteBindings,
6
+ SqliteDatabase,
7
+ SqliteExecuteResult,
8
+ SqliteTransactionDatabase,
9
+ } from "@/common/database/config";
10
+ import { db } from "./drizzle";
11
+
12
+ class FakeSqliteDatabase implements SqliteDatabase {
13
+ executeCalls: Array<{ sql: string; params?: SqliteBindings }> = [];
14
+ transactionTimeouts: Array<number | undefined> = [];
15
+ transactionNames: Array<string | undefined> = [];
16
+
17
+ async exec(): Promise<void> {}
18
+
19
+ async execute(
20
+ sql: string,
21
+ params?: SqliteBindings,
22
+ ): Promise<SqliteExecuteResult> {
23
+ this.executeCalls.push({ sql, params });
24
+ return emptyResult();
25
+ }
26
+
27
+ async executeBatch(
28
+ statements: SqliteBatchStatement[],
29
+ ): Promise<SqliteExecuteResult[]> {
30
+ const transaction = await this.beginTransaction();
31
+ try {
32
+ const results: SqliteExecuteResult[] = [];
33
+ for (const statement of statements) {
34
+ results.push(
35
+ await transaction.execute(statement.sql, statement.params),
36
+ );
37
+ }
38
+ await transaction.commit();
39
+ return results;
40
+ } catch (error) {
41
+ await transaction.rollback();
42
+ throw error;
43
+ }
44
+ }
45
+
46
+ async beginTransaction(
47
+ timeoutMs?: number,
48
+ name?: string,
49
+ ): Promise<SqliteTransactionDatabase> {
50
+ this.transactionTimeouts.push(timeoutMs);
51
+ this.transactionNames.push(name);
52
+ this.executeCalls.push({ sql: "BEGIN" });
53
+ return {
54
+ exec: async () => {},
55
+ execute: async (sql, params) => {
56
+ this.executeCalls.push({ sql, params });
57
+ return emptyResult();
58
+ },
59
+ commit: async () => {
60
+ this.executeCalls.push({ sql: "COMMIT" });
61
+ },
62
+ rollback: async () => {
63
+ this.executeCalls.push({ sql: "ROLLBACK" });
64
+ },
65
+ };
66
+ }
67
+
68
+ async run(sql: string, params?: SqliteBindings): Promise<void> {
69
+ await this.execute(sql, params);
70
+ }
71
+
72
+ async query(sql: string, params?: SqliteBindings) {
73
+ const { columns, rows } = await this.execute(sql, params);
74
+ return { columns, rows };
75
+ }
76
+
77
+ async close(): Promise<void> {}
78
+ }
79
+
80
+ function emptyResult(): SqliteExecuteResult {
81
+ return {
82
+ columns: [],
83
+ rows: [],
84
+ changes: 0,
85
+ lastInsertRowId: null,
86
+ };
87
+ }
88
+
89
+ function testProviderContext(
90
+ database: SqliteDatabase,
91
+ ): DatabaseProviderContext {
92
+ return {
93
+ actorId: "actor-a",
94
+ kv: {
95
+ batchPut: async () => {},
96
+ batchGet: async (keys) => keys.map(() => null),
97
+ batchDelete: async () => {},
98
+ deleteRange: async () => {},
99
+ },
100
+ nativeDatabaseProvider: { open: async () => database },
101
+ };
102
+ }
103
+
104
+ describe("Drizzle database transactions", () => {
105
+ test("runs migrations in the shared transaction with a generous timeout", async () => {
106
+ const nativeDb = new FakeSqliteDatabase();
107
+ const provider = db({
108
+ onMigrate: async (client) => {
109
+ await client.execute(
110
+ "CREATE TABLE items(id INTEGER PRIMARY KEY)",
111
+ );
112
+ },
113
+ });
114
+ const client = await provider.createClient(
115
+ testProviderContext(nativeDb),
116
+ );
117
+ await provider.onMigrate(client);
118
+
119
+ expect(nativeDb.transactionTimeouts).toEqual([300_000]);
120
+ expect(nativeDb.transactionNames).toEqual([
121
+ "rivetkit-drizzle-migration",
122
+ ]);
123
+ expect(nativeDb.executeCalls.map(({ sql }) => sql)).toEqual([
124
+ "BEGIN",
125
+ "SAVEPOINT __rivet_on_migrate",
126
+ "CREATE TABLE items(id INTEGER PRIMARY KEY)",
127
+ "RELEASE SAVEPOINT __rivet_on_migrate",
128
+ "COMMIT",
129
+ ]);
130
+ });
131
+
132
+ test("routes transaction work through the transaction handle", async () => {
133
+ const nativeDb = new FakeSqliteDatabase();
134
+ const client = await db().createClient(testProviderContext(nativeDb));
135
+ await client.transaction(
136
+ async (tx) => {
137
+ await tx.execute(
138
+ "INSERT INTO items(value) VALUES (?)",
139
+ "inside",
140
+ );
141
+ },
142
+ { name: "drizzle-insert", timeout: 120_000 },
143
+ );
144
+
145
+ expect(nativeDb.transactionTimeouts).toEqual([120_000]);
146
+ expect(nativeDb.transactionNames).toEqual(["drizzle-insert"]);
147
+ expect(nativeDb.executeCalls.map(({ sql }) => sql)).toEqual([
148
+ "BEGIN",
149
+ "INSERT INTO items(value) VALUES (?)",
150
+ "COMMIT",
151
+ ]);
152
+ });
153
+
154
+ test("validates zero, negative, and non-finite transaction timeouts", async () => {
155
+ const client = await db().createClient(
156
+ testProviderContext(new FakeSqliteDatabase()),
157
+ );
158
+ for (const timeout of [0, -1, Number.NaN, Number.POSITIVE_INFINITY]) {
159
+ await expect(
160
+ client.transaction(async () => {}, { timeout }),
161
+ ).rejects.toThrow("positive finite");
162
+ }
163
+ });
164
+ });
package/src/db/mod.ts CHANGED
@@ -10,6 +10,7 @@ export type {
10
10
  SqliteDatabase,
11
11
  SqliteNativeMetrics,
12
12
  SqliteProfilingOptions,
13
+ SqliteProfilingMetricsOptions,
13
14
  SqliteQueryResult,
14
15
  SqliteTransactionOptions,
15
16
  } from "@/common/database/config";
@@ -6,7 +6,7 @@ export const ActorSchema = z.object({
6
6
  name: z.string(),
7
7
  key: z.string(),
8
8
  namespace_id: RivetIdSchema,
9
- pool: z.string(),
9
+ runner_name_selector: z.string(),
10
10
  create_ts: z.number(),
11
11
  connectable_ts: z.number().nullable().optional(),
12
12
  destroy_ts: z.number().nullable().optional(),
@@ -31,7 +31,7 @@ export type ActorsListResponse = z.infer<typeof ActorsListResponseSchema>;
31
31
  export const ActorsCreateRequestSchema = z.object({
32
32
  datacenter: z.string().optional(),
33
33
  name: z.string(),
34
- pool: z.string(),
34
+ runner_name_selector: z.string(),
35
35
  crash_policy: z.string(),
36
36
  key: z.string().nullable().optional(),
37
37
  input: z.string().nullable().optional(),
@@ -48,7 +48,7 @@ export const ActorsGetOrCreateRequestSchema = z.object({
48
48
  datacenter: z.string().optional(),
49
49
  name: z.string(),
50
50
  key: z.string(),
51
- pool: z.string(),
51
+ runner_name_selector: z.string(),
52
52
  crash_policy: z.string(),
53
53
  input: z.string().nullable().optional(),
54
54
  });
@@ -1,4 +1,3 @@
1
- import { actorKeyToGatewayQuery } from "@/actor/keys";
2
1
  import {
3
2
  type ClientConfig,
4
3
  DEFAULT_MAX_QUERY_INPUT_SIZE,
@@ -290,9 +289,8 @@ export function buildActorQueryGatewayUrl(
290
289
  }
291
290
 
292
291
  function pushKeyQueryParams(params: URLSearchParams, key: string[]): void {
293
- const rvtKey = actorKeyToGatewayQuery(key);
294
- if (rvtKey !== undefined) {
295
- params.append("rvt-key", rvtKey);
292
+ if (key.length > 0) {
293
+ params.append("rvt-key", key.join(","));
296
294
  }
297
295
  }
298
296
 
@@ -167,6 +167,17 @@ 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
+
170
181
  // MARK: Update runner config
171
182
  export interface RegistryConfigRequest {
172
183
  datacenters: Record<
@@ -201,11 +212,11 @@ export async function updateRunnerConfig(
201
212
  runnerName: string,
202
213
  request: RegistryConfigRequest,
203
214
  ): Promise<void> {
204
- return apiCall<unknown, void>(
215
+ return apiCall<RegistryConfigRequest, void>(
205
216
  config,
206
217
  "PUT",
207
- `/pools/${encodeURIComponent(runnerName)}`,
208
- Object.values(request.datacenters)[0],
218
+ `/runner-configs/${runnerName}`,
219
+ request,
209
220
  );
210
221
  }
211
222
 
@@ -226,44 +237,3 @@ export async function kvGet(
226
237
  `/actors/${encodeURIComponent(actorId)}/kv/keys/${encodeURIComponent(key)}`,
227
238
  );
228
239
  }
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
- pool: poolName ?? this.#config.poolName,
257
+ runner_name_selector: 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
- pool: poolName ?? this.#config.poolName,
328
+ runner_name_selector: 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
- nodeKey: z.string().optional(),
14
+ envoyKey: z.string().optional(),
15
15
  });
16
16
  export type EnvoyConfigInput = z.input<typeof EnvoyConfigSchema>;
17
17
  export type EnvoyConfig = z.infer<typeof EnvoyConfigSchema>;
@@ -0,0 +1,25 @@
1
+ import { afterEach, describe, expect, test } from "vitest";
2
+ import { RegistryConfigSchema } from "./index";
3
+
4
+ const ORIGINAL_RIVET_TOKEN = process.env.RIVET_TOKEN;
5
+
6
+ afterEach(() => {
7
+ if (ORIGINAL_RIVET_TOKEN === undefined) {
8
+ delete process.env.RIVET_TOKEN;
9
+ } else {
10
+ process.env.RIVET_TOKEN = ORIGINAL_RIVET_TOKEN;
11
+ }
12
+ });
13
+
14
+ describe("RegistryConfigSchema", () => {
15
+ test("defaults local Engine token", () => {
16
+ delete process.env.RIVET_TOKEN;
17
+
18
+ const config = RegistryConfigSchema.parse({
19
+ use: {},
20
+ startEngine: true,
21
+ });
22
+
23
+ expect(config.token).toBe("default");
24
+ });
25
+ });
@@ -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: Node Configuration
161
+ // MARK: Runner 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. Disabled by default. Set RIVET_RUN_SERVICES=1
255
- * or startServices: true to enable it.
254
+ * a local engine. Defaults to the local-engine decision. Set
255
+ * RIVET_RUN_SERVICES=0 or 1 to override it.
256
256
  */
257
257
  startServices: z.boolean().optional(),
258
258
  /**
259
259
  * @experimental
260
260
  *
261
- * Automatically configure serverless nodes in the engine.
261
+ * Automatically configure serverless envoys 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
- node: EnvoyConfigSchema.optional().default(() =>
269
+ envoy: 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 node is running (Mode A, started via `registry.start()`),
277
+ * When a persistent envoy 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 node to drain
279
+ * `shutdown()` and wait up to `gracePeriodMs` for the envoy 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,11 +289,9 @@ 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 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.
292
+ * engine-provided actor stop threshold once the envoy connects.
295
293
  *
296
- * Set a longer period when a complete graceful node drain is required.
294
+ * Must be long enough for rivetkit-core to drain the envoy.
297
295
  */
298
296
  gracePeriodMs: z.number().int().min(1_000).optional(),
299
297
  /**
@@ -350,12 +348,12 @@ export const RegistryConfigSchema = z
350
348
  });
351
349
  }
352
350
 
353
- // Serverless pool configuration is disabled for v3.
354
- if (config.configurePool) {
351
+ // configurePool requires an engine (via endpoint or startEngine).
352
+ if (config.configurePool && !parsedEndpoint && !config.startEngine) {
355
353
  ctx.addIssue({
356
354
  code: "custom",
357
- message: "serverless is disabled in this version",
358
- path: ["configurePool"],
355
+ message:
356
+ "configurePool requires either endpoint or startEngine",
359
357
  });
360
358
  }
361
359
 
@@ -368,7 +366,13 @@ export const RegistryConfigSchema = z
368
366
  ? localEngineEndpoint
369
367
  : (parsedEndpoint?.endpoint ??
370
368
  (isDevEnv ? localEngineEndpoint : undefined));
371
- const startServices = config.startServices ?? getRivetRunServices();
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));
372
376
  const validateServerlessEndpoint = Boolean(
373
377
  config.startEngine || parsedEndpoint,
374
378
  );
@@ -418,7 +422,6 @@ export const RegistryConfigSchema = z
418
422
  ...config,
419
423
  sqlite,
420
424
  endpoint,
421
- engineSpawn: !parsedEndpoint && Boolean(endpoint),
422
425
  startServices,
423
426
  namespace,
424
427
  token,
@@ -465,10 +468,10 @@ export function buildActorNames(
465
468
 
466
469
  export const DocConfigurePoolSchema = z
467
470
  .object({
468
- name: z.string().optional().describe("Name of the node pool."),
471
+ name: z.string().optional().describe("Name of the runner pool."),
469
472
  url: z
470
473
  .string()
471
- .describe("URL of the serverless platform to configure nodes."),
474
+ .describe("URL of the serverless platform to configure runners."),
472
475
  headers: z
473
476
  .record(z.string(), z.string())
474
477
  .optional()
@@ -501,7 +504,7 @@ export const DocConfigurePoolSchema = z
501
504
  .boolean()
502
505
  .optional()
503
506
  .describe(
504
- "Drain nodes when a new version is deployed. Defaults to true.",
507
+ "Drain runners when a new version is deployed. Defaults to true.",
505
508
  ),
506
509
  })
507
510
  .optional();
@@ -544,17 +547,17 @@ export const DocEnvoyConfigSchema = z
544
547
  poolName: z
545
548
  .string()
546
549
  .optional()
547
- .describe("Name of this node pool. Default: 'default'"),
548
- nodeKey: z
550
+ .describe("Name of this envoy pool. Default: 'default'"),
551
+ envoyKey: z
549
552
  .string()
550
553
  .optional()
551
- .describe("Deprecated. Authentication key for the node."),
554
+ .describe("Deprecated. Authentication key for the envoy."),
552
555
  version: z
553
556
  .number()
554
557
  .optional()
555
- .describe("Version number of this node. Default: 1"),
558
+ .describe("Version number of this envoy. Default: 1"),
556
559
  })
557
- .describe("Configuration for node mode.");
560
+ .describe("Configuration for envoy mode.");
558
561
 
559
562
  export const DocSqliteConfigSchema = z
560
563
  .object({
@@ -655,12 +658,12 @@ export const DocRegistryConfigSchema = z
655
658
  .boolean()
656
659
  .optional()
657
660
  .describe(
658
- "Starts Services when RivetKit manages a local Engine. Disabled by default. Set RIVET_RUN_SERVICES=1 or startServices: true to enable.",
661
+ "Starts Services when RivetKit manages a local Engine. Defaults to the local-Engine decision. Set RIVET_RUN_SERVICES=0 or 1 to override.",
659
662
  ),
660
663
  configurePool: DocConfigurePoolSchema.describe(
661
- "Automatically configure serverless nodes in the engine.",
664
+ "Automatically configure serverless runners in the engine.",
662
665
  ),
663
666
  serverless: DocServerlessConfigSchema.optional(),
664
- node: DocEnvoyConfigSchema.optional(),
667
+ envoy: DocEnvoyConfigSchema.optional(),
665
668
  })
666
669
  .describe("RivetKit registry configuration.");
@@ -30,11 +30,6 @@ 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
-
38
33
  function signalExitCode(signal: ShutdownSignal): number {
39
34
  switch (signal) {
40
35
  case "SIGINT":
@@ -195,7 +190,6 @@ export class Registry<A extends RegistryActors> {
195
190
  config: RegistryConfig,
196
191
  ): Promise<void> | undefined {
197
192
  if (!config.configurePool) return undefined;
198
- rejectServerless();
199
193
 
200
194
  if (!this.#configureServerlessPoolPromise) {
201
195
  this.#configureServerlessPoolPromise = configureServerlessPool(
@@ -221,7 +215,6 @@ export class Registry<A extends RegistryActors> {
221
215
  * ```
222
216
  */
223
217
  public async handler(request: Request): Promise<Response> {
224
- rejectServerless();
225
218
  const config = this.parseConfig();
226
219
  this.#printWelcome(config, "serverless");
227
220
 
@@ -420,7 +413,6 @@ export class Registry<A extends RegistryActors> {
420
413
  * ```
421
414
  */
422
415
  public serve(): ServerlessHandler {
423
- rejectServerless();
424
416
  return {
425
417
  fetch: (request) => this.handler(request),
426
418
  };
@@ -446,9 +438,6 @@ export class Registry<A extends RegistryActors> {
446
438
  * ```
447
439
  */
448
440
  public async listen(opts: RegistryListenOptions = {}): Promise<void> {
449
- if (!opts.application) {
450
- rejectServerless();
451
- }
452
441
  const port = opts.port ?? parsePortEnv(process.env.RIVET_PORT) ?? 3000;
453
442
  const publicDir = opts.publicDir ?? getRivetkitPublicDir();
454
443
  const config = this.parseConfig();
@@ -565,7 +554,6 @@ export class Registry<A extends RegistryActors> {
565
554
  * Returns serverless metadata suitable for mounting in a user-owned router.
566
555
  */
567
556
  async #metadataRoute(): Promise<Response> {
568
- rejectServerless();
569
557
  const configured = await this.#activeConfiguredRegistry();
570
558
  if (!configured) {
571
559
  return new Response("registry not started\n", {
@@ -638,7 +626,7 @@ export class Registry<A extends RegistryActors> {
638
626
  */
639
627
  #startEnvoy(config: RegistryConfig, printWelcome: boolean) {
640
628
  if (!this.#runtimeServePromise) {
641
- const configuredEnvoyVersion = this.#config.node?.version;
629
+ const configuredEnvoyVersion = this.#config.envoy?.version;
642
630
  const envoyVersionSource =
643
631
  configuredEnvoyVersion !== undefined
644
632
  ? "config"
@@ -649,7 +637,7 @@ export class Registry<A extends RegistryActors> {
649
637
  logger().info({
650
638
  msg: "starting rivetkit envoy",
651
639
  rivetkitVersion: VERSION,
652
- envoyVersion: config.node.version,
640
+ envoyVersion: config.envoy.version,
653
641
  envoyVersionSource,
654
642
  });
655
643
 
@@ -658,8 +646,8 @@ export class Registry<A extends RegistryActors> {
658
646
  getNodeEnv() === "production"
659
647
  ) {
660
648
  logger().error({
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,
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,
663
651
  envoyVersionSource,
664
652
  });
665
653
  }
@@ -678,13 +666,7 @@ export class Registry<A extends RegistryActors> {
678
666
  // rejection unhandled. Downstream awaits (e.g. #runShutdown's
679
667
  // Promise.race) attach their own catches and still observe
680
668
  // resolution via the race.
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
- }
669
+ logger().warn({ error }, "runtime registry serve errored");
688
670
  });
689
671
  // Install signal handlers once an envoy lifecycle has begun. Only
690
672
  // Mode A ever reaches here. Mode B (handler(request)) intentionally
@@ -732,7 +714,7 @@ export class Registry<A extends RegistryActors> {
732
714
  finishShutdownSignal(signal);
733
715
  return;
734
716
  }
735
- this.#shutdownInFlight = this.#drain(config, true)
717
+ this.#shutdownInFlight = this.#drain(config)
736
718
  .catch((err) => {
737
719
  logger().warn({ err }, "shutdown error");
738
720
  })
@@ -775,28 +757,18 @@ export class Registry<A extends RegistryActors> {
775
757
  return this.#shutdownInFlight;
776
758
  }
777
759
 
778
- async #drain(config: RegistryConfig, signalDriven = false): Promise<void> {
760
+ async #drain(config: RegistryConfig): Promise<void> {
779
761
  const modeAPromise = this.#runtimeServeConfiguredPromise;
780
762
  const modeBPromise = this.#runtimeServerlessPromise;
781
763
  const runtimes = new Set<CoreRuntime>();
782
764
 
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
- }
765
+ const gracePeriodMs =
766
+ config.shutdown?.gracePeriodMs ??
767
+ (await this.#actorStopThresholdMs(modeAPromise ?? modeBPromise)) ??
768
+ 30 * 60 * 1000;
797
769
  // Race the entire drain sequence (both modes + serve promise) against
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.
770
+ // a single grace ceiling. By default, this uses the engine-provided
771
+ // actor stop threshold, matching Pegboard's hard cutoff for actors.
800
772
  const drain = async () => {
801
773
  // Shut down every live `CoreRegistry` we know about. Mode A
802
774
  // (`start()`) and Mode B (`handler()`) each build a separate
@@ -915,16 +887,12 @@ export class Registry<A extends RegistryActors> {
915
887
  );
916
888
  }
917
889
  if (this.#runtimeReadyPromise) return this.#runtimeReadyPromise;
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);
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
+ );
928
896
  }
929
897
 
930
898
  const config = this.parseConfig();