Fix: strip tool messages from preloaded history (Gemini ordering error) + cast PRD param to text
Made-with: Cursor
This commit is contained in:
@@ -55,7 +55,7 @@ async function savePrd(projectId: string, prdContent: string): Promise<void> {
|
|||||||
try {
|
try {
|
||||||
await query(
|
await query(
|
||||||
`UPDATE fs_projects
|
`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()
|
updated_at = NOW()
|
||||||
WHERE id = $1`,
|
WHERE id = $1`,
|
||||||
[projectId, prdContent]
|
[projectId, prdContent]
|
||||||
@@ -111,8 +111,13 @@ export async function POST(
|
|||||||
|
|
||||||
const sessionId = `atlas_${projectId}`;
|
const sessionId = `atlas_${projectId}`;
|
||||||
|
|
||||||
// Load conversation history from DB to persist across agent runner restarts
|
// Load conversation history from DB to persist across agent runner restarts.
|
||||||
const history = await loadAtlasHistory(projectId);
|
// 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.
|
// __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).
|
// If history already exists, ignore the init request (conversation already started).
|
||||||
|
|||||||
Reference in New Issue
Block a user