Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.
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
26 changes: 16 additions & 10 deletions packages/rivetkit/src/drivers/engine/actor-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,9 @@ export class EngineActorDriver implements ActorDriver {
async readPersistedData(actorId: string): Promise<Uint8Array | undefined> {
const handler = this.#actors.get(actorId);
if (!handler) throw new Error(`Actor ${actorId} not loaded`);
if (handler.persistedData) return handler.persistedData;

const [value] = await this.#runner.kvGet(actorId, [KEYS.PERSIST_DATA]);

if (value !== null) {
handler.persistedData = value;
return value;
} else {
return undefined;
}
// This was loaded during actor startup
return handler.persistedData;
}

async writePersistedData(actorId: string, data: Uint8Array): Promise<void> {
Expand Down Expand Up @@ -251,11 +244,24 @@ export class EngineActorDriver implements ActorDriver {
// Get or create handler
let handler = this.#actors.get(actorId);
if (!handler) {
// IMPORTANT: We must set the handler in the map synchronously before doing any
// async operations to avoid race conditions where multiple calls might try to
// create the same handler simultaneously.
handler = {
actorStartPromise: promiseWithResolvers(),
persistedData: serializeEmptyPersistData(input),
persistedData: undefined,
};
this.#actors.set(actorId, handler);

// Load persisted data from storage
const [persistedValue] = await this.#runner.kvGet(actorId, [
KEYS.PERSIST_DATA,
]);

handler.persistedData =
persistedValue !== null
? persistedValue
: serializeEmptyPersistData(input);
}

const name = runConfig.name as string;
Expand Down
2 changes: 1 addition & 1 deletion packages/rivetkit/src/manager/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ function addManagerRoutes(
});
}

router.get("/health", (c) => handleHealthRequest(c, runConfig));
router.get("/health", (c) => handleHealthRequest(c));

router.get("/metadata", (c) => handleMetadataRequest(c, runConfig));

Expand Down
11 changes: 9 additions & 2 deletions packages/rivetkit/tests/driver-engine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ runDriverTests({
join(__dirname, "../fixtures/driver-test-suite/registry.ts"),
async (registry) => {
// Get configuration from environment or use defaults
const endpoint = process.env.RIVET_ENDPOINT || "http://localhost:6420";
const endpoint = process.env.RIVET_ENDPOINT || "http://127.0.0.1:6420";
const namespace = `test-${crypto.randomUUID().slice(0, 8)}`;
const runnerName = "test-runner";
const token = "dev";

// Create namespace
const response = await fetch(`${endpoint}/namespaces`, {
Expand All @@ -44,6 +45,10 @@ runDriverTests({
// Start the actor driver
const runConfig = RunnerConfigSchema.parse({
driver: driverConfig,
endpoint,
namespace,
runnerName,
token,
getUpgradeWebSocket: () => undefined,
});
const managerDriver = driverConfig.manager(registry.config, runConfig);
Expand All @@ -55,12 +60,14 @@ runDriverTests({
inlineClient,
);

await new Promise((resolve) => setTimeout(resolve, 1000));

return {
rivetEngine: {
endpoint: "http://127.0.0.1:6420",
namespace: namespace,
runnerName: runnerName,
token: "dev",
token,
},
driver: driverConfig,
cleanup: async () => {
Expand Down
Loading