mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 21:15:57 +03:00
fix(core): reset empty reply recovery after output
This commit is contained in:
@@ -341,6 +341,7 @@ const layer = Layer.effect(
|
||||
assistantMessageID,
|
||||
}),
|
||||
Continue: Effect.fnUntraced(function* (outcome) {
|
||||
if (!outcome.empty) recoverEmpty = true
|
||||
yield* retry.wait({
|
||||
decision: outcome.decision,
|
||||
error: outcome.error,
|
||||
@@ -350,6 +351,7 @@ const layer = Layer.effect(
|
||||
assistantMessageID = SessionMessage.ID.create()
|
||||
}),
|
||||
OutputLimit: Effect.fn("SessionRunner.continueOutputLimit")(function* (outcome) {
|
||||
if (!outcome.empty) recoverEmpty = true
|
||||
// The current response is included. User input or any other finish breaks the streak.
|
||||
const recent = yield* db
|
||||
.select({
|
||||
|
||||
@@ -34,10 +34,11 @@ export type Outcome = Data.TaggedEnum<{
|
||||
Continue: {
|
||||
readonly error: SessionError.Error
|
||||
readonly decision: SessionRunnerRetry.Decision
|
||||
readonly empty: boolean
|
||||
}
|
||||
RecoverFull: {}
|
||||
Compacted: {}
|
||||
OutputLimit: { readonly needsContinuation: boolean }
|
||||
OutputLimit: { readonly needsContinuation: boolean; readonly empty: boolean }
|
||||
}>
|
||||
export const Outcome = Data.taggedEnum<Outcome>()
|
||||
|
||||
@@ -278,7 +279,7 @@ export const make = Effect.gen(function* () {
|
||||
tools.declines.length === 0 &&
|
||||
!tools.interrupted
|
||||
)
|
||||
return Outcome.Continue({ error: llmError, decision: retry })
|
||||
return Outcome.Continue({ error: llmError, decision: retry, empty: record.empty })
|
||||
|
||||
if (Exit.isFailure(stream)) return yield* Effect.failCause(stream.cause)
|
||||
if (tools.declines.length > 0) {
|
||||
@@ -289,7 +290,7 @@ export const make = Effect.gen(function* () {
|
||||
if (tools.interrupted && Exit.isFailure(joined)) return yield* Effect.failCause(joined.cause)
|
||||
if (record.failure) return yield* new StepFailedError({ error: record.failure })
|
||||
const needsContinuation = input.prepared.request.toolChoice?.type !== "none" && record.needsContinuation
|
||||
if (record.finish?.finish === "length") return Outcome.OutputLimit({ needsContinuation })
|
||||
if (record.finish?.finish === "length") return Outcome.OutputLimit({ needsContinuation, empty: record.empty })
|
||||
if (record.finish?.finish === "stop" && record.empty) return Outcome.Empty()
|
||||
return Outcome.Completed({ needsContinuation })
|
||||
}),
|
||||
|
||||
@@ -6096,6 +6096,46 @@ describe("SessionRunnerLLM", () => {
|
||||
})
|
||||
}
|
||||
|
||||
for (const recovery of ["output limit", "incomplete stream"] as const) {
|
||||
scenario(`resets empty response recovery after nonempty ${recovery} output`, function* (s) {
|
||||
const partial = [
|
||||
LLMEvent.textStart({ id: "partial" }),
|
||||
LLMEvent.textDelta({ id: "partial", text: "Progress" }),
|
||||
LLMEvent.textEnd({ id: "partial" }),
|
||||
]
|
||||
yield* s.llm.push(
|
||||
TestLLM.stop(),
|
||||
recovery === "output limit"
|
||||
? TestLLM.complete({ reason: { normalized: "length" } }, ...partial)
|
||||
: TestLLM.failAfter(incompleteStream(), LLMEvent.stepStart({ index: 0 }), ...partial),
|
||||
TestLLM.stop(),
|
||||
TestLLM.text("Finished", "finished"),
|
||||
)
|
||||
|
||||
const scheduled = yield* subscribeRetries(s)
|
||||
const run = yield* s.runPrompt("Finish the task").pipe(Effect.forkChild)
|
||||
if (recovery === "incomplete stream") {
|
||||
yield* Queue.take(scheduled)
|
||||
yield* TestClock.adjust("2400 millis")
|
||||
}
|
||||
yield* Fiber.join(run)
|
||||
|
||||
expect(s.requests).toHaveLength(4)
|
||||
expect(userTexts(s.requests[1]).at(-1)).toBe(userTexts(s.requests[3]).at(-1))
|
||||
expect((yield* s.messages).filter((message) => message.type === "synthetic")).toHaveLength(3)
|
||||
expect((yield* s.context).at(-1)).toMatchObject(Expected.assistant({}, [Expected.text("Finished")]))
|
||||
})
|
||||
}
|
||||
|
||||
scenario("keeps the empty response bound across an empty output-limit response", function* (s) {
|
||||
yield* s.llm.push(TestLLM.stop(), TestLLM.complete({ reason: { normalized: "length" } }), TestLLM.stop())
|
||||
|
||||
expect(yield* s.runPrompt("Finish the task").pipe(Effect.flip)).toMatchObject({
|
||||
error: { type: "empty-response" },
|
||||
})
|
||||
expect(s.requests).toHaveLength(3)
|
||||
})
|
||||
|
||||
scenario("accepts text supplied only at text end without empty response recovery", function* (s) {
|
||||
yield* s.llm.push(
|
||||
TestLLM.complete(
|
||||
|
||||
Reference in New Issue
Block a user