Skip to content

Commit 83a65e7

Browse files
committed
chore(codex): log handled compaction intercepts
1 parent f202ad6 commit 83a65e7

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

src/agents/pi-hooks/compaction-intercept.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,25 @@ import {
1212
} from "./compaction-intercept-runtime.js";
1313
import compactionInterceptExtension from "./compaction-intercept.js";
1414

15+
const logInfo = vi.hoisted(() => vi.fn());
16+
const logDebug = vi.hoisted(() => vi.fn());
17+
const logWarn = vi.hoisted(() => vi.fn());
18+
19+
vi.mock("../../logging/subsystem.js", () => ({
20+
createSubsystemLogger: () => ({
21+
subsystem: "compaction-intercept",
22+
isEnabled: () => true,
23+
trace: vi.fn(),
24+
debug: logDebug,
25+
info: logInfo,
26+
warn: logWarn,
27+
error: vi.fn(),
28+
fatal: vi.fn(),
29+
raw: vi.fn(),
30+
child: vi.fn(),
31+
}),
32+
}));
33+
1534
type CompactionHandler = (event: unknown, ctx: unknown) => Promise<unknown>;
1635

1736
function stubSessionManager(
@@ -116,6 +135,9 @@ function makeCtx(
116135
}
117136

118137
afterEach(() => {
138+
logInfo.mockClear();
139+
logDebug.mockClear();
140+
logWarn.mockClear();
119141
vi.restoreAllMocks();
120142
});
121143

@@ -181,6 +203,19 @@ describe("compactionInterceptExtension", () => {
181203
details: { engine: "lcm", strategy: "intercept" },
182204
},
183205
});
206+
expect(logInfo).toHaveBeenCalledWith(
207+
"[compaction-intercept] engine handled compaction intercept",
208+
expect.objectContaining({
209+
engineId: "lcm",
210+
sessionId: "abc-123",
211+
tokenBudget: 258_000,
212+
currentTokenCount: 232_000,
213+
tokensBefore: 232_000,
214+
tokensAfter: 80_000,
215+
firstKeptEntryId: "entry-keep-me",
216+
summaryChars: "LCM-produced summary text".length,
217+
}),
218+
);
184219
} finally {
185220
setCompactionInterceptRuntime(sm, null);
186221
}

src/agents/pi-hooks/compaction-intercept.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ export default function compactionInterceptExtension(api: ExtensionAPI): void {
112112
return undefined;
113113
}
114114

115+
log.info("[compaction-intercept] engine handled compaction intercept", {
116+
engineId: engine.info.id,
117+
sessionId,
118+
sessionKey: runtime.sessionKey,
119+
tokenBudget,
120+
currentTokenCount,
121+
tokensBefore: result.tokensBefore,
122+
tokensAfter: result.tokensAfter,
123+
firstKeptEntryId: result.firstKeptEntryId,
124+
summaryChars: result.summary.length,
125+
});
126+
115127
return {
116128
compaction: {
117129
summary: result.summary,

0 commit comments

Comments
 (0)