fix(compaction): guard model update during compaction and validate checkpoint model

This commit is contained in:
YeonGyu-Kim
2026-03-11 21:57:06 +09:00
parent d4232c9eac
commit f7085450f1
7 changed files with 280 additions and 29 deletions
@@ -1,6 +1,7 @@
/// <reference path="../../../bun-test.d.ts" />
import { describe, expect, it } from "bun:test"
import { setCompactionAgentConfigCheckpoint } from "../../shared/compaction-agent-config-checkpoint"
import { createCompactionContextInjector } from "./index"
type SessionMessageResponse = Array<{
@@ -291,4 +292,69 @@ describe("createCompactionContextInjector recovery", () => {
//#then
expect(promptAsyncRecorder.calls.length).toBe(0)
})
it("falls back to the current non-compaction model when a checkpoint model is poisoned", async () => {
//#given
const sessionID = "ses_poisoned_checkpoint_model"
const promptAsyncRecorder = createPromptAsyncRecorder()
setCompactionAgentConfigCheckpoint(sessionID, {
agent: "atlas",
model: { providerID: "anthropic", modelID: "claude-opus-4-1" },
tools: { bash: true },
})
const ctx = createMockContext(
[
[
{
info: {
role: "user",
agent: "atlas",
model: { providerID: "openai", modelID: "gpt-5" },
tools: { bash: true },
},
},
{
info: {
role: "user",
agent: "compaction",
model: { providerID: "anthropic", modelID: "claude-opus-4-1" },
},
},
],
[
{
info: {
role: "user",
agent: "compaction",
model: { providerID: "anthropic", modelID: "claude-opus-4-1" },
},
},
],
[
{
info: {
role: "user",
agent: "atlas",
model: { providerID: "openai", modelID: "gpt-5" },
tools: { bash: true },
},
},
],
],
promptAsyncRecorder.promptAsync,
)
const injector = createCompactionContextInjector({ ctx })
//#when
await injector.event({
event: { type: "session.compacted", properties: { sessionID } },
})
//#then
expect(promptAsyncRecorder.calls.length).toBe(1)
expect(promptAsyncRecorder.calls[0]?.body.model).toEqual({
providerID: "openai",
modelID: "gpt-5",
})
})
})