Skip to content

Commit 139a1c4

Browse files
fix(compaction): respect agent variant config during compaction
The compaction summary message hardcoded its variant to the parent user message's variant, ignoring agent.compaction.variant even though agent.compaction.model is already honored. Resolve the variant from the compaction agent config when it is valid for the model, mirroring the existing resolution in session/prompt.ts, and fall back to the previous behavior otherwise. Closes anomalyco#41578
1 parent fb8344f commit 139a1c4

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

‎packages/opencode/src/session/compaction.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ const layer = Layer.effect(
397397
sessionID: input.sessionID,
398398
mode: "compaction",
399399
agent: "compaction",
400-
variant: userMessage.model.variant,
400+
variant: agent.variant && model.variants?.[agent.variant] ? agent.variant : userMessage.model.variant,
401401
summary: true,
402402
path: {
403403
cwd: ctx.directory,

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,15 @@ function cfg(compaction?: ConfigV1.Info["compaction"]) {
222222
return Layer.succeed(Config.Service, TestConfig.make({ get: () => Effect.succeed({ ...base, compaction }) }))
223223
}
224224

225+
function cfgAgent(agent?: ConfigV1.Info["agent"]) {
226+
const base = Schema.decodeUnknownSync(ConfigV1.Info)({}) as ConfigV1.Info
227+
return Layer.succeed(Config.Service, TestConfig.make({ get: () => Effect.succeed({ ...base, agent }) }))
228+
}
229+
230+
function modelWithVariant(name: string): Provider.Model {
231+
return { ...createModel({ context: 100_000, output: 32_000 }), variants: { [name]: {} } }
232+
}
233+
225234
const defaultProvider = wide()
226235
const compactionTestNode = LayerNode.group([
227236
SessionCompaction.node,
@@ -1660,6 +1669,40 @@ describe("session.compaction.process", () => {
16601669
expect(part?.tail_start_id).toBe(keep.id)
16611670
}).pipe(withCompaction({ config: cfg({ tail_turns: 2, preserve_recent_tokens: 500 }) })),
16621671
)
1672+
1673+
itCompaction.instance(
1674+
"uses the compaction agent's configured variant for the summary message",
1675+
() => {
1676+
const variant = "no-thinking"
1677+
return Effect.gen(function* () {
1678+
const ssn = yield* SessionNs.Service
1679+
const session = yield* ssn.create({})
1680+
const msg = yield* createUserMessage(session.id, "hello")
1681+
const msgs = yield* ssn.messages({ sessionID: session.id })
1682+
1683+
yield* SessionCompaction.use.process({
1684+
parentID: msg.id,
1685+
messages: msgs,
1686+
sessionID: session.id,
1687+
auto: false,
1688+
})
1689+
1690+
const summary = (yield* ssn.messages({ sessionID: session.id })).find(
1691+
(item) => item.info.role === "assistant" && item.info.summary,
1692+
)
1693+
expect(summary?.info.role).toBe("assistant")
1694+
if (summary?.info.role === "assistant") {
1695+
expect(summary.info.variant).toBe(variant)
1696+
}
1697+
}).pipe(
1698+
withCompaction({
1699+
provider: ProviderTest.fake({ model: modelWithVariant(variant) }),
1700+
config: cfgAgent({ compaction: { variant } }),
1701+
}),
1702+
)
1703+
},
1704+
{ git: true },
1705+
)
16631706
})
16641707

16651708
describe("util.token.estimate", () => {

0 commit comments

Comments
 (0)