fix: recover session submissions and failed turn settlement
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { compactionInFlight, deleteChatSession, getChat, isTurnRunning, sessionCoverage, sessionCost, stores, type ChatDeleteMode } from "@/src/server";
|
||||
import { compactionInFlight, deleteChatSession, getChat, isTurnRunning, sessionCoverage, sessionCost, stores, turnFailure, type ChatDeleteMode } from "@/src/server";
|
||||
|
||||
export async function GET(_req: Request, { params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await params;
|
||||
@@ -19,6 +19,8 @@ export async function GET(_req: Request, { params }: { params: Promise<{ id: str
|
||||
messages: chat.messages,
|
||||
pricing: sessionCost(chat),
|
||||
turnInFlight: isTurnRunning(id),
|
||||
// Also reaches idle views that missed the failing turn's stream.
|
||||
turnError: turnFailure(id),
|
||||
compacting: compactionInFlight(id),
|
||||
coverage: sessionCoverage(id),
|
||||
});
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
* submitter too attaches here. One SSE stream per chat: a running turn →
|
||||
* subscribe to the live turn object: FULL replay of the event log, then
|
||||
* live chunks until settle ([DONE]). No running turn → the cheap terminal
|
||||
* ({"type":"turn-settled"} + [DONE]): the record is current, the client
|
||||
* refetches it.
|
||||
* ({"type":"turn-settled"} + [DONE]): the client refetches the record.
|
||||
* A retained settlement-failure notice precedes that terminal when a
|
||||
* reply could not be saved before the submitter attached.
|
||||
*
|
||||
* 404 mirrors the POST handler's unknown-chat. Framework route is a thin
|
||||
* wrapper over the server barrel (the import law); tests drive the seams
|
||||
@@ -18,6 +19,6 @@ export async function GET(_req: Request, ctx: { params: Promise<{ id: string }>
|
||||
const { id } = await ctx.params;
|
||||
if (!getChat(id)) return Response.json({ error: "Unknown chat" }, { status: 404 });
|
||||
const handle = runningTurn(id);
|
||||
if (!handle) return settledTurnResponse();
|
||||
if (!handle) return settledTurnResponse(id);
|
||||
return piTurnResponse(handle);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { Chat } from "@/components/chat";
|
||||
import { slotsConfigured } from "@/src/core";
|
||||
import { compactionInFlight, getChat, isTurnRunning, readSettingsRecord } from "@/src/server";
|
||||
import { compactionInFlight, getChat, isTurnRunning, readSettingsRecord, turnFailure } from "@/src/server";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
@@ -29,6 +29,7 @@ export default async function ChatPage({
|
||||
// derived app-side (core/view.ts projectView; GET serves the same
|
||||
// native messages).
|
||||
initialMessages={chat.messages}
|
||||
initialError={turnFailure(chat.id)}
|
||||
initialConfigured={slotsConfigured(record?.models)}
|
||||
initialPrompt={prompt}
|
||||
// A teacher turn that outlived its client: the remounted view must
|
||||
|
||||
Reference in New Issue
Block a user