Skip to content

Commit c6c56ac

Browse files
authored
tweak: rename tail_tokens -> preserve_recent_tokens (#23491)
1 parent e539efe commit c6c56ac

File tree

5 files changed

+23
-20
lines changed

5 files changed

+23
-20
lines changed

packages/opencode/src/config/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ const InfoSchema = Schema.Struct({
208208
description:
209209
"Number of recent user turns, including their following assistant/tool responses, to keep verbatim during compaction (default: 2)",
210210
}),
211-
tail_tokens: Schema.optional(NonNegativeInt).annotate({
212-
description: "Token budget for retained recent turn spans during compaction",
211+
preserve_recent_tokens: Schema.optional(NonNegativeInt).annotate({
212+
description: "Maximum number of tokens from recent turns to preserve verbatim after compaction",
213213
}),
214214
reserved: Schema.optional(NonNegativeInt).annotate({
215215
description: "Token buffer for compaction. Leaves enough window to avoid overflow during compaction.",

packages/opencode/src/session/compaction.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,21 @@ export const PRUNE_MINIMUM = 20_000
3434
export const PRUNE_PROTECT = 40_000
3535
const PRUNE_PROTECTED_TOOLS = ["skill"]
3636
const DEFAULT_TAIL_TURNS = 2
37-
const MIN_TAIL_TOKENS = 2_000
38-
const MAX_TAIL_TOKENS = 8_000
37+
const MIN_PRESERVE_RECENT_TOKENS = 2_000
38+
const MAX_PRESERVE_RECENT_TOKENS = 8_000
3939
type Turn = {
4040
start: number
4141
end: number
4242
id: MessageID
4343
}
4444

45-
function tailBudget(input: { cfg: Config.Info; model: Provider.Model }) {
45+
function preserveRecentBudget(input: { cfg: Config.Info; model: Provider.Model }) {
4646
return (
47-
input.cfg.compaction?.tail_tokens ??
48-
Math.min(MAX_TAIL_TOKENS, Math.max(MIN_TAIL_TOKENS, Math.floor(usable(input) * 0.25)))
47+
input.cfg.compaction?.preserve_recent_tokens ??
48+
Math.min(
49+
MAX_PRESERVE_RECENT_TOKENS,
50+
Math.max(MIN_PRESERVE_RECENT_TOKENS, Math.floor(usable(input) * 0.25)),
51+
)
4952
)
5053
}
5154

@@ -134,7 +137,7 @@ export const layer: Layer.Layer<
134137
}) {
135138
const limit = input.cfg.compaction?.tail_turns ?? DEFAULT_TAIL_TURNS
136139
if (limit <= 0) return { head: input.messages, tail_start_id: undefined }
137-
const budget = tailBudget({ cfg: input.cfg, model: input.model })
140+
const budget = preserveRecentBudget({ cfg: input.cfg, model: input.model })
138141
const all = turns(input.messages)
139142
if (!all.length) return { head: input.messages, tail_start_id: undefined }
140143
const recent = all.slice(-limit)

packages/opencode/test/session/compaction.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ describe("session.compaction.process", () => {
925925
auto: false,
926926
})
927927

928-
const rt = runtime("continue", Plugin.defaultLayer, wide(), cfg({ tail_turns: 2, tail_tokens: 10_000 }))
928+
const rt = runtime("continue", Plugin.defaultLayer, wide(), cfg({ tail_turns: 2, preserve_recent_tokens: 10_000 }))
929929
try {
930930
const msgs = await svc.messages({ sessionID: session.id })
931931
const parent = msgs.at(-1)?.info.id
@@ -954,7 +954,7 @@ describe("session.compaction.process", () => {
954954
})
955955
})
956956

957-
test("shrinks retained tail to fit tail token budget", async () => {
957+
test("shrinks retained tail to fit preserve token budget", async () => {
958958
await using tmp = await tmpdir()
959959
await Instance.provide({
960960
directory: tmp.path,
@@ -970,7 +970,7 @@ describe("session.compaction.process", () => {
970970
auto: false,
971971
})
972972

973-
const rt = runtime("continue", Plugin.defaultLayer, wide(), cfg({ tail_turns: 2, tail_tokens: 100 }))
973+
const rt = runtime("continue", Plugin.defaultLayer, wide(), cfg({ tail_turns: 2, preserve_recent_tokens: 100 }))
974974
try {
975975
const msgs = await svc.messages({ sessionID: session.id })
976976
const parent = msgs.at(-1)?.info.id
@@ -999,7 +999,7 @@ describe("session.compaction.process", () => {
999999
})
10001000
})
10011001

1002-
test("falls back to full summary when even one recent turn exceeds tail budget", async () => {
1002+
test("falls back to full summary when even one recent turn exceeds preserve token budget", async () => {
10031003
await using tmp = await tmpdir({ git: true })
10041004
const stub = llm()
10051005
let captured = ""
@@ -1021,7 +1021,7 @@ describe("session.compaction.process", () => {
10211021
auto: false,
10221022
})
10231023

1024-
const rt = liveRuntime(stub.layer, wide(), cfg({ tail_turns: 1, tail_tokens: 20 }))
1024+
const rt = liveRuntime(stub.layer, wide(), cfg({ tail_turns: 1, preserve_recent_tokens: 20 }))
10251025
try {
10261026
const msgs = await svc.messages({ sessionID: session.id })
10271027
const parent = msgs.at(-1)?.info.id
@@ -1051,7 +1051,7 @@ describe("session.compaction.process", () => {
10511051
})
10521052
})
10531053

1054-
test("falls back to full summary when retained tail media exceeds tail budget", async () => {
1054+
test("falls back to full summary when retained tail media exceeds preserve token budget", async () => {
10551055
await using tmp = await tmpdir({ git: true })
10561056
const stub = llm()
10571057
let captured = ""
@@ -1082,7 +1082,7 @@ describe("session.compaction.process", () => {
10821082
auto: false,
10831083
})
10841084

1085-
const rt = liveRuntime(stub.layer, wide(), cfg({ tail_turns: 1, tail_tokens: 100 }))
1085+
const rt = liveRuntime(stub.layer, wide(), cfg({ tail_turns: 1, preserve_recent_tokens: 100 }))
10861086
try {
10871087
const msgs = await svc.messages({ sessionID: session.id })
10881088
const parent = msgs.at(-1)?.info.id
@@ -1544,7 +1544,7 @@ describe("session.compaction.process", () => {
15441544
auto: false,
15451545
})
15461546

1547-
const rt = liveRuntime(stub.layer, wide(), cfg({ tail_turns: 2, tail_tokens: 10_000 }))
1547+
const rt = liveRuntime(stub.layer, wide(), cfg({ tail_turns: 2, preserve_recent_tokens: 10_000 }))
15481548
try {
15491549
let msgs = await svc.messages({ sessionID: session.id })
15501550
let parent = msgs.at(-1)?.info.id

packages/sdk/js/src/v2/gen/types.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,9 +1648,9 @@ export type Config = {
16481648
*/
16491649
tail_turns?: number
16501650
/**
1651-
* Token budget for retained recent turn spans during compaction
1651+
* Maximum number of tokens from recent turns to preserve verbatim after compaction
16521652
*/
1653-
tail_tokens?: number
1653+
preserve_recent_tokens?: number
16541654
/**
16551655
* Token buffer for compaction. Leaves enough window to avoid overflow during compaction.
16561656
*/

packages/sdk/openapi.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11878,8 +11878,8 @@
1187811878
"minimum": 0,
1187911879
"maximum": 9007199254740991
1188011880
},
11881-
"tail_tokens": {
11882-
"description": "Token budget for retained recent turn spans during compaction",
11881+
"preserve_recent_tokens": {
11882+
"description": "Maximum number of tokens from recent turns to preserve verbatim after compaction",
1188311883
"type": "integer",
1188411884
"minimum": 0,
1188511885
"maximum": 9007199254740991

0 commit comments

Comments
 (0)