Skip to content

Commit cd73cbf

Browse files
fix(acp): align unauth tenantId fallback with SYSTEM_TENANT (#3237)
Closes #3237 - Replace 4 sendPrompt() fallbacks from 'system' to SYSTEM_TENANT ('_system') - Add missing SYSTEM_TENANT import to session-actions.ts - Fixes ACP prompt delivery for unauthenticated requests - Locally validated with two-round trip
1 parent 613fc30 commit cd73cbf

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/routes/session-actions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
7+
import { SYSTEM_TENANT } from '../config.js';
78
import { sendMessageSchema, commandSchema, permissionRuleSchema, permissionProfileSchema, type PermissionProfile } from '../validation.js';
89
import type { PermissionPolicy } from '../validation.js';
910
import { registerPermissionRoutes } from '../permission-routes.js';
@@ -54,7 +55,7 @@ export function registerSessionActionRoutes(app: FastifyInstance, ctx: RouteCont
5455
}
5556
try {
5657
const result = acpBackend && config.acpEnabled
57-
? await acpBackend.sendPrompt(sessionId, text, { tenantId: (req as any).tenantId ?? 'system', ownerKeyId: (req as any).authKeyId ?? 'master' })
58+
? await acpBackend.sendPrompt(sessionId, text, { tenantId: (req as any).tenantId ?? SYSTEM_TENANT, ownerKeyId: (req as any).authKeyId ?? 'master' })
5859
: await sessions.sendMessage(sessionId, text);
5960
// Issue #1809: Re-fetch stall info AFTER delivery to avoid false-positive.
6061
// Previously we called getStallInfo BEFORE send, capturing a stale state
@@ -272,7 +273,7 @@ export function registerSessionActionRoutes(app: FastifyInstance, ctx: RouteCont
272273
try {
273274
const cmd = command.startsWith('/') ? command : `/${command}`;
274275
const cmdResult = acpBackend && config.acpEnabled
275-
? await acpBackend.sendPrompt(session.id, cmd, { tenantId: (req as any).tenantId ?? 'system', ownerKeyId: (req as any).authKeyId ?? 'master' })
276+
? await acpBackend.sendPrompt(session.id, cmd, { tenantId: (req as any).tenantId ?? SYSTEM_TENANT, ownerKeyId: (req as any).authKeyId ?? 'master' })
276277
: await sessions.sendMessage(session.id, cmd);
277278
return { ok: true };
278279
} catch (e: unknown) {

src/routes/sessions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ export function registerSessionRoutes(app: FastifyInstance, ctx: RouteContext):
398398
}
399399
}
400400
promptDelivery = acpBackend && ctx.config.acpEnabled
401-
? await acpBackend.sendPrompt(existing.id, finalPrompt, { tenantId: req.tenantId ?? 'system', ownerKeyId: req.authKeyId ?? 'master' })
401+
? await acpBackend.sendPrompt(existing.id, finalPrompt, { tenantId: req.tenantId ?? SYSTEM_TENANT, ownerKeyId: req.authKeyId ?? 'master' })
402402
: await sessions.sendInitialPrompt(existing.id, finalPrompt);
403403
metrics.promptSent(promptDelivery.delivered);
404404
}
@@ -469,7 +469,7 @@ export function registerSessionRoutes(app: FastifyInstance, ctx: RouteContext):
469469
}
470470
}
471471
promptDelivery = acpBackend && ctx.config.acpEnabled
472-
? await acpBackend.sendPrompt(session.id, finalPrompt, { tenantId: req.tenantId ?? 'system', ownerKeyId: req.authKeyId ?? 'master' })
472+
? await acpBackend.sendPrompt(session.id, finalPrompt, { tenantId: req.tenantId ?? SYSTEM_TENANT, ownerKeyId: req.authKeyId ?? 'master' })
473473
: await sessions.sendInitialPrompt(session.id, finalPrompt);
474474
metrics.promptSent(promptDelivery.delivered);
475475
}

0 commit comments

Comments
 (0)