Merge branch 'v1.6.5-session-rename-publish'

This commit is contained in:
2026-05-16 15:34:47 +00:00

View File

@@ -120,6 +120,15 @@ export function registerSessionRoutes(
return { error: 'invalid body', details: parsed.error.flatten() };
}
const { name, model, system_prompt } = parsed.data;
// Read the prior name so the post-update publish can skip no-op renames
// (PATCH { name: "Foo" } where the session is already "Foo"). The window
// between SELECT and UPDATE is sub-millisecond in the same request handler;
// a concurrent rename in that gap would just mean one stale publish, which
// existing clients dedup by id.
const before = await sql<{ name: string }[]>`
SELECT name FROM sessions WHERE id = ${req.params.id}
`;
const priorName = before[0]?.name;
const rows = await sql<Session[]>`
UPDATE sessions
SET
@@ -135,7 +144,7 @@ export function registerSessionRoutes(
return { error: 'session not found' };
}
const session = rows[0]!;
if (name !== undefined) {
if (name !== undefined && session.name !== priorName) {
broker.publishUser('default', {
type: 'session_renamed',
session_id: session.id,