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:
@@ -83,6 +83,7 @@ import {
|
||||
checkpointSessionContextSummary,
|
||||
generateSessionContextSummaryText,
|
||||
} from "@/lib/session-context-summary";
|
||||
import { persistGuardedSessionTitle } from "@/lib/session-title-guard";
|
||||
import { generateSessionTitle, shouldGenerateSessionTitle } from "@/lib/session-title-agent";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -565,6 +566,14 @@ export async function POST(request: Request) {
|
||||
);
|
||||
}
|
||||
|
||||
const expectedTitle = typeof chatSession.title === "string" ? chatSession.title : "";
|
||||
const { data: titleRow } = await supabase
|
||||
.from("chat_sessions")
|
||||
.select("title")
|
||||
.eq("id", sessionId)
|
||||
.eq("user_id", userId)
|
||||
.maybeSingle();
|
||||
|
||||
const usageStartedAt = Date.now();
|
||||
async function checkpointConsultationContext() {
|
||||
try {
|
||||
@@ -690,7 +699,7 @@ export async function POST(request: Request) {
|
||||
// its settle-and-log entry point here so the request-level catch below can
|
||||
// still emit it.
|
||||
const agenticFailure: { report?: (error: unknown) => Promise<void> } = {};
|
||||
const expectedTitle = typeof chatSession.title === "string" ? chatSession.title : "";
|
||||
const titleAfterRpc = typeof titleRow?.title === "string" ? titleRow.title : expectedTitle;
|
||||
const titleSideEvent = shouldGenerateSessionTitle({
|
||||
title: expectedTitle,
|
||||
sessionType: chatSession.session_type,
|
||||
@@ -703,15 +712,13 @@ export async function POST(request: Request) {
|
||||
signal: request.signal,
|
||||
}).then(async (title) => {
|
||||
if (!title) return null;
|
||||
try {
|
||||
const { error } = await supabase.from("chat_sessions").update({ title })
|
||||
.eq("id", sessionId)
|
||||
.eq("user_id", userId)
|
||||
.eq("title", expectedTitle);
|
||||
if (error) console.warn("session title persist failed", error);
|
||||
} catch (error) {
|
||||
console.warn("session title persist failed", error);
|
||||
}
|
||||
await persistGuardedSessionTitle({
|
||||
client: supabase,
|
||||
sessionId,
|
||||
userId,
|
||||
expectedTitle: titleAfterRpc,
|
||||
title,
|
||||
});
|
||||
return { type: "session.title" as const, title };
|
||||
}).catch((error) => {
|
||||
console.warn("session title failed", error);
|
||||
|
||||
Reference in New Issue
Block a user