GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): keep room for the summary's reply when the compaction buffer is small by 2SinceJuly · Pull Request #59226 · anomalyco/opencode

fix(core): keep room for the summary's reply when the compaction buffer is small #59226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2SinceJuly wants to merge 1 commit into anomalyco:dev from 2SinceJuly:fix/compaction-summary-budget

Uh oh!

There was an error while loading. Please reload this page.

Closed

fix(core): keep room for the summary's reply when the compaction buffer is small #59226

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
5a8fd8b
fix(core): keep room for the summary's reply when the buffer is small
2SinceJuly Oct 26, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

18 changes: 14 additions & 4 deletions 18 packages/core/src/session/compaction.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,13 @@ export const layer = Layer.effect(
.resolve({ ...context.session, model: agent.model }, catalog.available)
.pipe(Effect.orElseSucceed(() => undefined)))) ??
context.model
const ceiling = calculateCeiling(model.limit, buffer)
// `buffer` only reserves headroom for the last reply before compaction, so a summary request keeps the
// default reserve as well and its own reply has room to think even when `buffer` is small.
const ceiling = (limit: SessionContext.Loaded["model"]["limit"]) =>
native ? calculateCeiling(limit, buffer) : summaryCeiling(limit, buffer)
const aim = ceiling(model.limit)
// An unknown window never triggers auto compaction, but the compaction request still needs a size to aim for.
const cap = Number.isFinite(ceiling)
? ceiling
: calculateCeiling({ ...model.limit, context: UNKNOWN_WINDOW }, buffer)
const cap = Number.isFinite(aim) ? aim : ceiling({ ...model.limit, context: UNKNOWN_WINDOW })
return { context: model === context.model ? context : { ...context, model }, cap }
})

Expand Down Expand Up @@ -1140,6 +1142,14 @@ const calculateCeiling = (limit: SessionContext.Loaded["model"]["limit"], buffer
return window - Math.max(Math.floor(window * RESERVE_SHARE), window >= 2 * RESERVE_MIN ? RESERVE_MIN : 0)
}

/**
* The largest summary request that still leaves its reply the default reserve. `buffer` is headroom for the last
* reply before compaction, so a small one would cap the summary itself at the buffer size and a reasoning model
* could spend the whole budget thinking; the request therefore keeps at least the default reserve free.
*/
const summaryCeiling = (limit: SessionContext.Loaded["model"]["limit"], buffer: number | undefined) =>
Math.min(calculateCeiling(limit, buffer), calculateCeiling(limit, undefined))

/**
* The largest summary request that leaves `RESERVE_MIN` of the window for the summary, or less when the request
* cannot generate that much. Zero for an unknown window.
Expand Down
31 changes: 29 additions & 2 deletions 31 packages/core/test/session-compaction.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,31 @@ it.effect("compaction keeps the output limit for a request that fits its target"
}),
)

it.effect("a small compaction buffer still leaves the summary the default reserve for its reply", () =>
Effect.scoped(
Effect.gen(function* () {
requests = []
const compaction = yield* SessionCompaction.Service
// This buffer alone would cap the summary at 2k output, which a reasoning model can spend entirely thinking.
yield* compaction.transform((editor) => editor.configure({ buffer: 2_000 }))
const session = yield* insertSession(Session.ID.make("ses_small_buffer"))
const messages = [
SessionMessage.User.make({
id: SessionMessage.ID.create(),
type: "user",
text: "x".repeat(640_000),
time: { created: DateTime.makeUnsafe(0) },
}),
]

expect(yield* compactManually(session, messages)).toEqual({ status: "completed" })
expect(requests).toHaveLength(1)
// 15% of the 200k window is kept free for the reply, rather than the 2k buffer.
expect(requests[0]?.generation).toEqual(GenerationOptions.make({ maxTokens: 30_000 }))
}),
),
)

it.effect("compaction hooks can supply the summary instead of the model", () =>
Effect.gen(function* () {
requests = []
Expand Down Expand Up @@ -1062,7 +1087,8 @@ for (const background of [false, true]) {
system: normal.request.system,
tools: normal.request.tools,
messages: [...normal.request.messages, Message.user(SessionCompaction.buildPrompt(false))],
generation: { maxTokens: summaryBuffer },
// The buffer is below the default reserve, so the summary keeps the reserve for its own reply.
generation: { maxTokens: 30_000 },
})
}),
)
Expand Down Expand Up @@ -1181,7 +1207,8 @@ it.effect("summary measured recovery reuses usage only for the matching agent",
...toLLMMessages(fixture.context.messages, resolved.ref),
Message.user(SessionCompaction.buildPrompt(false)),
],
generation: { maxTokens: summaryBuffer },
// The buffer is below the default reserve, so the summary keeps the reserve for its own reply.
generation: { maxTokens: 30_000 },
})
}),
)
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.