Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/opencode/src/session/compaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ export namespace SessionCompaction {
model,
})

if (result === "continue" && input.auto) {
if (processor.message.error) return "stop"
if (input.auto) {
const continueMsg = await Session.updateMessage({
id: Identifier.ascending("message"),
role: "user",
Expand All @@ -188,7 +189,6 @@ export namespace SessionCompaction {
},
})
}
if (processor.message.error) return "stop"
Bus.publish(Event.Compacted, { sessionID: input.sessionID })
return "continue"
}
Expand Down
11 changes: 8 additions & 3 deletions packages/opencode/src/session/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export namespace SessionProcessor {
needsCompaction = false
const shouldBreak = (await Config.get()).experimental?.continue_loop_on_deny !== true
while (true) {
if (input.abort.aborted) break
try {
let currentText: MessageV2.TextPart | undefined
let reasoningMap: Record<string, MessageV2.ReasoningPart> = {}
Expand Down Expand Up @@ -343,7 +344,7 @@ export namespace SessionProcessor {
})
const error = MessageV2.fromError(e, { providerID: input.model.providerID })
const retry = SessionRetry.retryable(error)
if (retry !== undefined) {
if (retry !== undefined && !input.abort.aborted) {
attempt++
const delay = SessionRetry.delay(attempt, error.name === "APIError" ? error : undefined)
SessionStatus.set(input.sessionID, {
Expand All @@ -353,9 +354,11 @@ export namespace SessionProcessor {
next: Date.now() + delay,
})
await SessionRetry.sleep(delay, input.abort).catch(() => {})
continue
if (!input.abort.aborted) continue
}
input.assistantMessage.error = error
input.assistantMessage.error = input.abort.aborted
? new MessageV2.AbortedError({ message: "Aborted" }).toObject()
: error
Bus.publish(Session.Event.Error, {
sessionID: input.assistantMessage.sessionID,
error: input.assistantMessage.error,
Expand Down Expand Up @@ -397,9 +400,11 @@ export namespace SessionProcessor {
await Session.updateMessage(input.assistantMessage)
if (needsCompaction) return "compact"
if (blocked) return "stop"
if (input.abort.aborted) return "stop"
if (input.assistantMessage.error) return "stop"
return "continue"
}
return "stop"
},
}
return result
Expand Down
1 change: 1 addition & 0 deletions packages/opencode/src/session/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ export namespace SessionPrompt {
if (
lastAssistant?.finish &&
!["tool-calls", "unknown"].includes(lastAssistant.finish) &&
!lastAssistant.summary &&
lastUser.id < lastAssistant.id
) {
log.info("exiting loop", { sessionID })
Expand Down
Loading