mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 23:24:00 +03:00
fix(core): don't resend a rejected conversation unchanged when compacting (#61015)
This commit is contained in:
committed by
GitHub
Unverified
parent
01276f9061
commit
6597f6cd6c
@@ -518,7 +518,13 @@ export const layer = Layer.effect(
|
||||
prepared,
|
||||
budget - overhead,
|
||||
send,
|
||||
{ fit: fit - overhead, history: withoutTail(prepared.request, keepID), measured },
|
||||
{
|
||||
fit: fit - overhead,
|
||||
history: withoutTail(prepared.request, keepID),
|
||||
measured,
|
||||
// The provider just rejected this conversation, so sending it unchanged again would be rejected too.
|
||||
text: trigger.reason === "overflow",
|
||||
},
|
||||
background,
|
||||
)
|
||||
if (!keepID) return result
|
||||
@@ -596,7 +602,12 @@ export const layer = Layer.effect(
|
||||
prepared: Prepared,
|
||||
target: number,
|
||||
send: (request: LLMRequest, size?: Estimate) => Effect.Effect<Result, AIError | Failure>,
|
||||
shrink: { readonly fit: number; readonly history: LLMRequest; readonly measured?: Estimate } = {
|
||||
shrink: {
|
||||
readonly fit: number
|
||||
readonly history: LLMRequest
|
||||
readonly measured?: Estimate
|
||||
readonly text?: boolean
|
||||
} = {
|
||||
fit: target,
|
||||
history: prepared.request,
|
||||
},
|
||||
@@ -608,7 +619,7 @@ export const layer = Layer.effect(
|
||||
const policy = yield* SessionRunnerRetry.policy(context.session.id)
|
||||
let rejections = 0
|
||||
let rejected: number | undefined
|
||||
let asText = false
|
||||
let asText = shrink.text ?? false
|
||||
let fit = shrink.fit
|
||||
|
||||
while (true) {
|
||||
|
||||
@@ -3191,6 +3191,38 @@ describe("SessionRunnerLLM", () => {
|
||||
expect((yield* s.messages).find((message) => message.id === compaction.id)).toMatchObject({ status: "completed" })
|
||||
})
|
||||
|
||||
scenario("does not resend a rejected conversation unchanged when compacting", function* (s) {
|
||||
const filler = "context ".repeat(1_000)
|
||||
// The provider counts far more than the characters suggest, so only its rejection shows the conversation is too long.
|
||||
const answer = (index: number) =>
|
||||
TestLLM.complete(
|
||||
{
|
||||
reason: { normalized: "stop" },
|
||||
usage: { inputTokens: 60_000, nonCachedInputTokens: 60_000, outputTokens: 10 },
|
||||
},
|
||||
LLMEvent.textStart({ id: `answer-${index}` }),
|
||||
LLMEvent.textDelta({ id: `answer-${index}`, text: `Answer ${index}` }),
|
||||
LLMEvent.textEnd({ id: `answer-${index}` }),
|
||||
)
|
||||
yield* s.llm.push(...Array.from({ length: 4 }, (_, index) => answer(index)))
|
||||
yield* Effect.forEach(
|
||||
Array.from({ length: 4 }, (_, index) => index),
|
||||
(index) => s.runPrompt(`Request ${index}: ${filler}`),
|
||||
)
|
||||
s.currentModel = recoveryModel
|
||||
s.requests.length = 0
|
||||
yield* s.llm.push(
|
||||
TestLLM.failAfter(providerRejected({ message: "prompt too long", classification: "context-overflow" })),
|
||||
TestLLM.text("## Objective\n- Recovered", "summary"),
|
||||
TestLLM.text("Recovered", "recovered"),
|
||||
)
|
||||
yield* s.runPrompt("Continue")
|
||||
|
||||
expect(s.requests).toHaveLength(3)
|
||||
expect(s.requests[1]?.tools).toEqual([])
|
||||
expect(s.requests[1]?.messages.every((message) => message.role === "user")).toBeTrue()
|
||||
})
|
||||
|
||||
scenario("aims the first overflow compaction below the rejected context", function* (s) {
|
||||
const filler = "context ".repeat(1_000)
|
||||
yield* s.llm.push(...Array.from({ length: 4 }, (_, index) => TestLLM.text(`Answer ${index}`, `answer-${index}`)))
|
||||
|
||||
Reference in New Issue
Block a user