From cf3f3623e6c783de99d6f0eb84960ff8520f1187 Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Thu, 29 Jan 2026 04:12:38 -0800 Subject: [PATCH] fix(rivetkit): deserialize actor keys properly in manager router Bug: c.key returned ['a/b/c'] instead of ['a', 'b', 'c'] The manager router was wrapping serialized key strings in single-element arrays instead of deserializing them back to ActorKey arrays. Changes: - Import deserializeActorKey - GET /actors: deserialize key query param - PUT /actors: deserialize body.key for getWithKey and getOrCreateWithKey - POST /actors: deserialize body.key, generate UUID only if null/undefined --- .../packages/rivetkit/src/manager/router.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/rivetkit-typescript/packages/rivetkit/src/manager/router.ts b/rivetkit-typescript/packages/rivetkit/src/manager/router.ts index 6f83c788f9..2a5d1a2620 100644 --- a/rivetkit-typescript/packages/rivetkit/src/manager/router.ts +++ b/rivetkit-typescript/packages/rivetkit/src/manager/router.ts @@ -6,7 +6,7 @@ import invariant from "invariant"; import { z } from "zod"; import { Forbidden, RestrictedFeature } from "@/actor/errors"; -import { serializeActorKey } from "@/actor/keys"; +import { deserializeActorKey, serializeActorKey } from "@/actor/keys"; import type { Encoding } from "@/client/mod"; import { @@ -171,7 +171,7 @@ export function buildManagerRouter( const actorOutput = await managerDriver.getWithKey({ c, name, - key: [key], // Convert string to ActorKey array + key: deserializeActorKey(key), }); if (actorOutput) { actors.push(actorOutput); @@ -242,10 +242,11 @@ export function buildManagerRouter( const body = c.req.valid("json"); // Check if actor already exists + const actorKey = deserializeActorKey(body.key); const existingActor = await managerDriver.getWithKey({ c, name: body.name, - key: [body.key], // Convert string to ActorKey array + key: actorKey, }); if (existingActor) { @@ -259,7 +260,7 @@ export function buildManagerRouter( const newActor = await managerDriver.getOrCreateWithKey({ c, name: body.name, - key: [body.key], // Convert string to ActorKey array + key: actorKey, input: body.input ? cbor.decode(Buffer.from(body.input, "base64")) : undefined, @@ -288,10 +289,14 @@ export function buildManagerRouter( const body = c.req.valid("json"); // Create actor using the driver + const key = + body.key === undefined || body.key === null + ? [crypto.randomUUID()] + : deserializeActorKey(body.key); const actorOutput = await managerDriver.createActor({ c, name: body.name, - key: [body.key || crypto.randomUUID()], // Generate key if not provided, convert to ActorKey array + key, input: body.input ? cbor.decode(Buffer.from(body.input, "base64")) : undefined,