Fix: strip tool messages from preloaded history (Gemini ordering error) + cast PRD param to text

Made-with: Cursor
This commit is contained in:
2026-03-03 20:36:41 -08:00
parent 3896eb671c
commit 9e4450e400

View File

@@ -55,7 +55,7 @@ async function savePrd(projectId: string, prdContent: string): Promise<void> {
try {
await query(
`UPDATE fs_projects
SET data = data || jsonb_build_object('prd', $2, 'stage', 'architecture'),
SET data = data || jsonb_build_object('prd', $2::text, 'stage', 'architecture'),
updated_at = NOW()
WHERE id = $1`,
[projectId, prdContent]
@@ -111,8 +111,13 @@ export async function POST(
const sessionId = `atlas_${projectId}`;
// Load conversation history from DB to persist across agent runner restarts
const history = await loadAtlasHistory(projectId);
// Load conversation history from DB to persist across agent runner restarts.
// Strip tool_call / tool_response messages — replaying them across sessions
// causes Gemini to reject the request with a turn-ordering error.
const rawHistory = await loadAtlasHistory(projectId);
const history = rawHistory.filter((m: any) =>
(m.role === "user" || m.role === "assistant") && m.content
);
// __init__ is a special internal trigger used only when there is no existing history.
// If history already exists, ignore the init request (conversation already started).