fix(chat): fallback vers un nouveau lancement quand la session structurée reattach est morte (#147)
reattachAgentChat pouvait échouer avec NOT_FOUND (session structurée fermée
ou jamais vivante) et laisser fuiter l'erreur brute jusqu'à l'utilisateur
("not found: structured session ... not found") au lieu de relancer une
session fraîche. Le fallback ne s'applique qu'au code NOT_FOUND ; toute
autre erreur de reattach continue de remonter telle quelle.
QA vert 2026-08-05 : npx vitest run CustomAgentChatView.test.tsx,
npx vitest run agents.test.tsx CustomAgentChatView.test.tsx, npm run typecheck.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -154,11 +154,18 @@ export function CustomAgentChatView({
|
||||
setError(null);
|
||||
try {
|
||||
if (sessionId) {
|
||||
const reattached = await agent.reattachAgentChat!(sessionId, receive);
|
||||
if (cancelled) return;
|
||||
setCurrentSession(reattached.sessionId);
|
||||
setTurns(reattached.scrollback.reduce(foldChunk, [] as ChatTurn[]));
|
||||
return;
|
||||
try {
|
||||
const reattached = await agent.reattachAgentChat!(sessionId, receive);
|
||||
if (cancelled) return;
|
||||
setCurrentSession(reattached.sessionId);
|
||||
setTurns(reattached.scrollback.reduce(foldChunk, [] as ChatTurn[]));
|
||||
return;
|
||||
} catch (e) {
|
||||
// The backend contract for `reattach_agent_chat` (NOT_FOUND) is that
|
||||
// the session is gone (closed/never live) and the caller falls back
|
||||
// to a fresh launch — any other error still surfaces to the user.
|
||||
if ((e as GatewayError)?.code !== "NOT_FOUND") throw e;
|
||||
}
|
||||
}
|
||||
const launched = await agent.launchAgentChat!(projectId, agentId, {
|
||||
cwd,
|
||||
|
||||
Reference in New Issue
Block a user