Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit 439cc09

Browse files
authored
fix(core): fix querying actor by id (#1417)
1 parent 4381ae1 commit 439cc09

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

packages/rivetkit/src/manager/router.ts

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ function addManagerRoutes(
262262
path: "/actors",
263263
request: {
264264
query: z.object({
265-
name: z.string(),
265+
name: z.string().optional(),
266266
actor_ids: z.string().optional(),
267267
key: z.string().optional(),
268268
}),
@@ -282,6 +282,37 @@ function addManagerRoutes(
282282

283283
const actors: ActorOutput[] = [];
284284

285+
// Validate: cannot provide both actor_ids and (name or key)
286+
if (actorIdsParsed && (name || key)) {
287+
return c.json(
288+
{
289+
error:
290+
"Cannot provide both actor_ids and (name + key). Use either actor_ids or (name + key).",
291+
},
292+
400,
293+
);
294+
}
295+
296+
// Validate: when key is provided, name must also be provided
297+
if (key && !name) {
298+
return c.json(
299+
{
300+
error: "When providing 'key', 'name' must also be provided.",
301+
},
302+
400,
303+
);
304+
}
305+
306+
// Validate: must provide either actor_ids or (name + key)
307+
if (!actorIdsParsed && !key) {
308+
return c.json(
309+
{
310+
error: "Must provide either 'actor_ids' or both 'name' and 'key'.",
311+
},
312+
400,
313+
);
314+
}
315+
285316
if (actorIdsParsed) {
286317
if (actorIdsParsed.length > 32) {
287318
return c.json(
@@ -298,8 +329,10 @@ function addManagerRoutes(
298329
});
299330
}
300331

332+
// Fetch actors by ID
301333
for (const actorId of actorIdsParsed) {
302334
if (name) {
335+
// If name is provided, use it directly
303336
const actorOutput = await managerDriver.getForId({
304337
c,
305338
name,
@@ -308,12 +341,27 @@ function addManagerRoutes(
308341
if (actorOutput) {
309342
actors.push(actorOutput);
310343
}
344+
} else {
345+
// If no name is provided, try all registered actor types
346+
// Actor IDs are globally unique, so we'll find it in one of them
347+
for (const actorName of Object.keys(registryConfig.use)) {
348+
const actorOutput = await managerDriver.getForId({
349+
c,
350+
name: actorName,
351+
actorId,
352+
});
353+
if (actorOutput) {
354+
actors.push(actorOutput);
355+
break; // Found the actor, no need to check other names
356+
}
357+
}
311358
}
312359
}
313360
} else if (key) {
361+
// At this point, name is guaranteed to be defined due to validation above
314362
const actorOutput = await managerDriver.getWithKey({
315363
c,
316-
name,
364+
name: name!,
317365
key: [key], // Convert string to ActorKey array
318366
});
319367
if (actorOutput) {

packages/rivetkit/src/remote-manager-driver/api-endpoints.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export async function getActor(
2121
return apiCall<never, ActorsListResponse>(
2222
config,
2323
"GET",
24-
`/actors?name=${name}&actor_ids=${encodeURIComponent(actorId)}`,
24+
`/actors?actor_ids=${encodeURIComponent(actorId)}`,
2525
);
2626
}
2727

packages/rivetkit/src/remote-manager-driver/mod.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ export class RemoteManagerDriver implements ManagerDriver {
7070
if (!runConfig.disableHealthCheck) {
7171
this.#metadataPromise = this.#performMetadataCheck(runConfig);
7272
this.#metadataPromise.catch((error) => {
73-
// TODO: Promot to error after metadata endpoint merged on prod
74-
logger().info({
73+
logger().error({
7574
msg: "metadata check failed",
7675
error: error instanceof Error ? error.message : String(error),
7776
});

0 commit comments

Comments
 (0)