fix(chat): scope chatStore in stream+messages session guards

The session existence checks in GET /stream and POST /messages were using
options?.chatStore (global DB), so secondary-project sessions would throw
notFound before the scoped ChatManager ran. Replaces with resolveScopedChatStore.
This commit is contained in:
Josemi Liebana
2026-05-26 18:11:44 +02:00
parent d6d5bf098d
commit 30e14650cd

View File

@@ -478,10 +478,7 @@ export function registerChatRoutes(ctx: ApiRoutesContext, deps: ChatRouteDeps):
*/ */
router.get("/chat/sessions/:id/stream", rateLimit(RATE_LIMITS.sse), async (req, res) => { router.get("/chat/sessions/:id/stream", rateLimit(RATE_LIMITS.sse), async (req, res) => {
try { try {
const chatStore = options?.chatStore; const { chatStore } = await resolveScopedChatStore(req.query.projectId as string | undefined);
if (!chatStore) {
throw internalError("Chat store not available");
}
const chatManager = await resolveScopedChatManager(req.query.projectId as string | undefined); const chatManager = await resolveScopedChatManager(req.query.projectId as string | undefined);
const sessionId = String(req.params.id); const sessionId = String(req.params.id);
@@ -567,10 +564,7 @@ export function registerChatRoutes(ctx: ApiRoutesContext, deps: ChatRouteDeps):
*/ */
router.post("/chat/sessions/:id/messages", rateLimit(RATE_LIMITS.sse), async (req, res) => { router.post("/chat/sessions/:id/messages", rateLimit(RATE_LIMITS.sse), async (req, res) => {
try { try {
const chatStore = options?.chatStore; const { chatStore } = await resolveScopedChatStore(req.query.projectId as string | undefined);
if (!chatStore) {
throw internalError("Chat store not available");
}
const { content, modelProvider, modelId, attachments } = req.body as { const { content, modelProvider, modelId, attachments } = req.body as {
content?: string; content?: string;