fix(api): suppress no-op session_renamed publish on PATCH /api/sessions/:id
The v1.4 publisher fired whenever the PATCH body included `name`,
including no-op rename calls (PATCH { name } where name ===
currentName). Read the prior name with a fast SELECT before the
UPDATE and only publish session_renamed when the post-update name
actually differs.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -120,6 +120,15 @@ export function registerSessionRoutes(
|
|||||||
return { error: 'invalid body', details: parsed.error.flatten() };
|
return { error: 'invalid body', details: parsed.error.flatten() };
|
||||||
}
|
}
|
||||||
const { name, model, system_prompt } = parsed.data;
|
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[]>`
|
const rows = await sql<Session[]>`
|
||||||
UPDATE sessions
|
UPDATE sessions
|
||||||
SET
|
SET
|
||||||
@@ -135,7 +144,7 @@ export function registerSessionRoutes(
|
|||||||
return { error: 'session not found' };
|
return { error: 'session not found' };
|
||||||
}
|
}
|
||||||
const session = rows[0]!;
|
const session = rows[0]!;
|
||||||
if (name !== undefined) {
|
if (name !== undefined && session.name !== priorName) {
|
||||||
broker.publishUser('default', {
|
broker.publishUser('default', {
|
||||||
type: 'session_renamed',
|
type: 'session_renamed',
|
||||||
session_id: session.id,
|
session_id: session.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user