fix(sync-continuation): improve error handling and toast cleanup
- Add proper error handling in executeSyncContinuation with try-catch blocks - Ensure toast cleanup happens in all error paths via finally block - Add anchorMessageCount tracking for accurate result fetching after continuation - Improve fetchSyncResult to filter messages after anchor point - Add silent failure detection when no new response is generated
This commit is contained in:
@@ -3,7 +3,8 @@ import type { SessionMessage } from "./executor-types"
|
||||
|
||||
export async function fetchSyncResult(
|
||||
client: OpencodeClient,
|
||||
sessionID: string
|
||||
sessionID: string,
|
||||
anchorMessageCount?: number
|
||||
): Promise<{ ok: true; textContent: string } | { ok: false; error: string }> {
|
||||
const messagesResult = await client.session.messages({
|
||||
path: { id: sessionID },
|
||||
@@ -15,11 +16,27 @@ export async function fetchSyncResult(
|
||||
|
||||
const messages = ((messagesResult as { data?: unknown }).data ?? messagesResult) as SessionMessage[]
|
||||
|
||||
const assistantMessages = messages
|
||||
const messagesAfterAnchor = anchorMessageCount !== undefined ? messages.slice(anchorMessageCount) : messages
|
||||
|
||||
if (anchorMessageCount !== undefined && messagesAfterAnchor.length === 0) {
|
||||
return {
|
||||
ok: false,
|
||||
error: `Session completed but no new response was generated. The model may have failed silently.\n\nSession ID: ${sessionID}`,
|
||||
}
|
||||
}
|
||||
|
||||
const assistantMessages = messagesAfterAnchor
|
||||
.filter((m) => m.info?.role === "assistant")
|
||||
.sort((a, b) => (b.info?.time?.created ?? 0) - (a.info?.time?.created ?? 0))
|
||||
const lastMessage = assistantMessages[0]
|
||||
|
||||
if (anchorMessageCount !== undefined && !lastMessage) {
|
||||
return {
|
||||
ok: false,
|
||||
error: `Session completed but no new response was generated. The model may have failed silently.\n\nSession ID: ${sessionID}`,
|
||||
}
|
||||
}
|
||||
|
||||
if (!lastMessage) {
|
||||
return { ok: false, error: `No assistant response found.\n\nSession ID: ${sessionID}` }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user