fix(web): persist generated session titles against the post-RPC title (BUG-557)

The first-round title guard compared the pre-RPC snapshot, so append_consultation_question had already rewritten the title and the model name never landed.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jesse_Chen
2026-09-06 19:22:43 +08:00
co-authored by Cursor
parent e2d6f20361
commit 0102a973a3
9 changed files with 243 additions and 11 deletions
+40
View File
@@ -0,0 +1,40 @@
type GuardedTitleUpdate = {
eq: (column: string, value: string) => GuardedTitleUpdate;
select: (columns: "id") => PromiseLike<{ data: Array<{ id?: string }> | null; error: unknown }>;
};
export type GuardedTitleClient = {
from: (table: "chat_sessions") => {
update: (values: { title: string }) => GuardedTitleUpdate;
};
};
export async function persistGuardedSessionTitle(input: {
client: GuardedTitleClient;
sessionId: string;
userId: string;
expectedTitle: string;
title: string;
warn?: (message: string, extra?: unknown) => void;
}): Promise<"updated" | "missed" | "failed"> {
const warn = input.warn ?? ((message: string, extra?: unknown) => console.warn(message, extra));
try {
const { data, error } = await input.client.from("chat_sessions").update({ title: input.title })
.eq("id", input.sessionId)
.eq("user_id", input.userId)
.eq("title", input.expectedTitle)
.select("id");
if (error) {
warn("session title persist failed", error);
return "failed";
}
if (!data?.length) {
warn("session title guard missed");
return "missed";
}
return "updated";
} catch (error) {
warn("session title persist failed", error);
return "failed";
}
}