Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions rivetkit-typescript/packages/rivetkit/src/drivers/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export function chooseDefaultDriver(
return createEngineDriver();
}

loggerWithoutContext().debug({ msg: "using default file system driver" });
return createFileSystemOrMemoryDriver(true);
loggerWithoutContext().debug({
msg: "using default file system driver",
storagePath: config.storagePath,
});
return createFileSystemOrMemoryDriver(true, {
path: config.storagePath,
});
}
13 changes: 13 additions & 0 deletions rivetkit-typescript/packages/rivetkit/src/registry/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { tryParseEndpoint } from "@/utils/endpoint-parser";
import {
getRivetEndpoint,
getRivetEngine,
getRivetkitStoragePath,
getRivetNamespace,
getRivetToken,
isDev,
Expand Down Expand Up @@ -45,6 +46,17 @@ export const RegistryConfigSchema = z

// MARK: Driver
driver: DriverConfigSchema.optional(),
/**
* Storage path for RivetKit file-system state when using the default driver.
*
* If not set, RivetKit uses the platform default data location.
*
* Can also be set via RIVETKIT_STORAGE_PATH.
*/
storagePath: z
.string()
.optional()
.transform((val) => val ?? getRivetkitStoragePath()),

// MARK: Networking
/** @experimental */
Expand Down Expand Up @@ -331,6 +343,7 @@ export const DocRunnerConfigSchema = z.object({
export const DocRegistryConfigSchema = z
.object({
use: z.record(z.string(), z.unknown()).describe("Actor definitions. Keys are actor names, values are actor definitions."),
storagePath: z.string().optional().describe("Storage path for RivetKit file-system state when using the default driver. Can also be set via RIVETKIT_STORAGE_PATH."),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The storagePath field in DocRegistryConfigSchema is missing the .transform() call that exists in the main RegistryConfigSchema (lines 56-59). This inconsistency means the environment variable RIVETKIT_STORAGE_PATH will not be used as a fallback when parsing with DocRegistryConfigSchema, causing different behavior depending on which schema is used.

Fix: Add the transform to match the main schema:

storagePath: z.string().optional()
  .transform((val) => val ?? getRivetkitStoragePath())
  .describe("Storage path for RivetKit file-system state when using the default driver. Can also be set via RIVETKIT_STORAGE_PATH."),

Spotted by Graphite Agent

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

maxIncomingMessageSize: z.number().optional().describe("Maximum size of incoming WebSocket messages in bytes. Default: 65536"),
maxOutgoingMessageSize: z.number().optional().describe("Maximum size of outgoing WebSocket messages in bytes. Default: 1048576"),
noWelcome: z.boolean().optional().describe("Disable the welcome message on startup. Default: false"),
Expand Down
2 changes: 2 additions & 0 deletions rivetkit-typescript/packages/rivetkit/src/utils/env-vars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export const getRivetkitInspectorToken = (): string | undefined =>
getEnvUniversal("RIVET_INSPECTOR_TOKEN");
export const getRivetkitInspectorDisable = (): boolean =>
getEnvUniversal("RIVET_INSPECTOR_DISABLE") === "1";
export const getRivetkitStoragePath = (): string | undefined =>
getEnvUniversal("RIVETKIT_STORAGE_PATH");

// Logging configuration
// DEPRECATED: LOG_LEVEL will be removed in a future version
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { RegistryConfigSchema } from "@/registry/config";
import { describe, expect, test } from "vitest";

describe.sequential("registry config storagePath", () => {
test("reads storagePath from RIVETKIT_STORAGE_PATH when unset in config", () => {
const previous = process.env.RIVETKIT_STORAGE_PATH;
try {
process.env.RIVETKIT_STORAGE_PATH = "/tmp/rivetkit-storage-env";
const parsed = RegistryConfigSchema.parse({
use: {},
});

expect(parsed.storagePath).toBe("/tmp/rivetkit-storage-env");
} finally {
if (previous === undefined) {
delete process.env.RIVETKIT_STORAGE_PATH;
} else {
process.env.RIVETKIT_STORAGE_PATH = previous;
}
}
});

test("config storagePath overrides RIVETKIT_STORAGE_PATH", () => {
const previous = process.env.RIVETKIT_STORAGE_PATH;
try {
process.env.RIVETKIT_STORAGE_PATH = "/tmp/rivetkit-storage-env";
const parsed = RegistryConfigSchema.parse({
use: {},
storagePath: "/tmp/rivetkit-storage-config",
});

expect(parsed.storagePath).toBe("/tmp/rivetkit-storage-config");
} finally {
if (previous === undefined) {
delete process.env.RIVETKIT_STORAGE_PATH;
} else {
process.env.RIVETKIT_STORAGE_PATH = previous;
}
}
});
});
7 changes: 6 additions & 1 deletion website/src/content/docs/general/environment-variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ These variables configure how clients connect to your actors.
| `RIVET_INSPECTOR_TOKEN` | Token for accessing the Rivet Inspector |
| `RIVET_INSPECTOR_DISABLE` | Set to `1` to disable the inspector |

## Storage

| Environment Variable | Description |
|---------------------|-------------|
| `RIVETKIT_STORAGE_PATH` | Overrides the default file-system storage path used by RivetKit when using the default driver. |

## Logging

| Environment Variable | Description |
Expand All @@ -55,4 +61,3 @@ These variables configure how clients connect to your actors.
| `RIVET_LOG_MESSAGE` | Set to `1` to include message formatting |
| `RIVET_LOG_ERROR_STACK` | Set to `1` to include error stack traces |
| `RIVET_LOG_HEADERS` | Set to `1` to log request headers |

Loading